Initial
authorJoonas Viskari <joonas.viskari@gmail.com>
Thu, 14 Jun 2018 10:25:29 +0000 (13:25 +0300)
committerJoonas Viskari <joonas.viskari@gmail.com>
Thu, 14 Jun 2018 10:25:29 +0000 (13:25 +0300)
12 files changed:
checklist.sh [new file with mode: 0755]
demo.sh [new file with mode: 0755]
inputbox.sh [new file with mode: 0755]
menubox.sh [new file with mode: 0755]
msgbox.sh [new file with mode: 0755]
passwd.sh [new file with mode: 0755]
progress.sh [new file with mode: 0755]
radiolist.sh [new file with mode: 0755]
text.txt [new file with mode: 0644]
textbox.sh [new file with mode: 0755]
yesno.sh [new file with mode: 0755]
yesno2.sh [new file with mode: 0755]

diff --git a/checklist.sh b/checklist.sh
new file mode 100755 (executable)
index 0000000..0acc110
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/bash
+DISTROS=$(whiptail --title "Test Checklist Dialog" --checklist \
+"Choose preferred Linux distros" 15 60 4 \
+"debian" "Venerable Debian" ON \
+"ubuntu" "Popular Ubuntu" OFF \
+"centos" "Stable CentOS" ON \
+"mint" "Rising Star Mint" OFF 3>&1 1>&2 2>&3)
+exitstatus=$?
+if [ $exitstatus = 0 ]; then
+    echo "Your favorite distros are:" $DISTROS
+else
+    echo "You chose Cancel."
+fi
diff --git a/demo.sh b/demo.sh
new file mode 100755 (executable)
index 0000000..16fca9c
--- /dev/null
+++ b/demo.sh
@@ -0,0 +1,85 @@
+#!/bin/bash
+# Whiptail is the interactive shell Scrpting
+OPTION=$(whiptail --title "Whiptail Shell Script Menu" --menu "Choose your option" 15 60 4 \
+"1" "Change Password" \
+"2" "Change UserName" \
+"3" "Change Email" \
+"4" "exit"  3>&1 1>&2 2>&3)
+
+exitstatus=$?
+if [ $exitstatus = 0 ]; then
+    echo "Your chosen option:" $OPTION
+
+case $OPTION in
+  1) echo "Option1 Selected"
+     if (whiptail --title "Change Password" --yes-button "Yes" --no-button "No"  --yesno "Do you need to changed Password ?" 10 60) then
+    echo "password Selection Yes$?."
+     
+    # Start Password Box
+    PASSWORD=$(whiptail --passwordbox "please enter your secret password" 8 78 --title "Change Password" 3>&1 1>&2 2>&3)
+                                                                        # A trick to swap stdout and stderr.
+    # Again, you can pack this inside if, but it seems really long for some 80-col terminal users.
+     exitstatus=$?
+ if [ $exitstatus = 0 ]; then
+     echo "User selected Ok and entered " $PASSWORD
+     touch sample_out_put.txt
+     echo $PASSWORD > sample_out_put.txt
+            
+            # Start Progress Bar
+      {
+       for ((i = 0 ; i <= 100 ; i+=5)); do
+  sleep 0.3
+  echo $i
+     done
+      } | whiptail --gauge "Password Updating.." 6 50 0
+            # End Progress Bar    
+
+ else
+     echo "User selected Cancel."
+ fi
+
+    # End Password Box 
+     else
+    echo "Password Selection No$?."
+     fi
+     ;;
+  2) echo "option2 Selected"
+ # Change User Name Box
+ NAME=$(whiptail --inputbox "Change Username " 8 78  --title "Changed UserName" 3>&1 1>&2 2>&3) 
+ exitstatus=$?
+ if [ $exitstatus = 0 ]; then
+     echo "UserName Changed " $NAME
+ if (whiptail --title "Confirm Change UserName" --yes-button "Yes" --no-button "No"  --yesno "Do you need to changed UserName ?" 10 60)  then
+     echo "Username Confirm Yes$?."
+     # Start Progress Bar
+      {
+       for ((i = 0 ; i <= 100 ; i+=5)); do
+  sleep 0.3
+  echo $i
+       done
+      } | whiptail --gauge "UserName Updating.." 6 50 0
+            # End Progress Bar 
+ else
+  echo"Confirm Failed"
+ fi
+
+ else 
+    echo "UserName Not Changed"
+ fi
+
+     ;;
+  3) echo "Option3 Selected"
+     
+     ;;
+  4) echo "exit"
+     {
+    for ((i = 0 ; i <= 100 ; i+=5)); do
+        sleep 0.1
+        echo $i
+    done
+     } | whiptail --gauge "exit..." 6 50 0
+esac
+
+else
+    echo "You chose Cancel."
+fi
diff --git a/inputbox.sh b/inputbox.sh
new file mode 100755 (executable)
index 0000000..db0d1d5
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/bash
+PET=$(whiptail --title "Test Free-form Input Box" --inputbox "What is your pet's name?" 10 60 Wigglebutt 3>&1 1>&2 2>&3)
+exitstatus=$?
+if [ $exitstatus = 0 ]; then
+    echo "Your pet name is:" $PET
+else
+    echo "You chose Cancel."
+fi
diff --git a/menubox.sh b/menubox.sh
new file mode 100755 (executable)
index 0000000..44473d1
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/bash
+OPTION=$(whiptail --title "Test Menu Dialog" --menu "Choose your option" 15 60 4 \
+"1" "Grilled Spicy Sausage" \
+"2" "Grilled Halloumi Cheese" \
+"3" "Charcoaled Chicken Wings" \
+"4" "Fried Aubergine"  3>&1 1>&2 2>&3)
+exitstatus=$?
+if [ $exitstatus = 0 ]; then
+    echo "Your chosen option:" $OPTION
+else
+    echo "You chose Cancel."
+fi
diff --git a/msgbox.sh b/msgbox.sh
new file mode 100755 (executable)
index 0000000..7795c0c
--- /dev/null
+++ b/msgbox.sh
@@ -0,0 +1,2 @@
+#!/bin/bash
+whiptail --title "Test Message Box" --msgbox "Create a message box with whiptail. Choose Ok to continue." 10 60
diff --git a/passwd.sh b/passwd.sh
new file mode 100755 (executable)
index 0000000..ec00ab7
--- /dev/null
+++ b/passwd.sh
@@ -0,0 +1,9 @@
+#!/bin/bash
+PASSWORD=$(whiptail --title "Test Password Box" --passwordbox "Enter your password and choose Ok to continue." 10 60 3>&1 1>&2 2>&3)
+exitstatus=$?
+if [ $exitstatus = 0 ]; then
+    echo "Your password is:" $PASSWORD
+else
+    echo "You chose Cancel."
+fi
diff --git a/progress.sh b/progress.sh
new file mode 100755 (executable)
index 0000000..f9c46a8
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/bash
+{
+    for ((i = 0 ; i <= 100 ; i+=20)); do
+        sleep 1
+        echo $i
+    done
+} | whiptail --gauge "Please wait while installing" 6 60 0
diff --git a/radiolist.sh b/radiolist.sh
new file mode 100755 (executable)
index 0000000..9f0b3c6
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/bash
+DISTROS=$(whiptail --title "Test Checklist Dialog" --radiolist \
+"What is the Linux distro of your choice?" 15 60 4 \
+"debian" "Venerable Debian" ON \
+"ubuntu" "Popular Ubuntu" OFF \
+"centos" "Stable CentOS" OFF \
+"mint" "Rising Star Mint" OFF 3>&1 1>&2 2>&3)
+exitstatus=$?
+if [ $exitstatus = 0 ]; then
+    echo "The chosen distro is:" $DISTROS
+else
+    echo "You chose Cancel."
+fi
diff --git a/text.txt b/text.txt
new file mode 100644 (file)
index 0000000..c3646bd
--- /dev/null
+++ b/text.txt
@@ -0,0 +1,32 @@
+Box options: 
+       --msgbox <text> <height> <width>
+       --yesno  <text> <height> <width>
+       --infobox <text> <height> <width>
+       --inputbox <text> <height> <width> [init] 
+       --passwordbox <text> <height> <width> [init] 
+       --textbox <file> <height> <width>
+       --menu <text> <height> <width> <listheight> [tag item] ...
+       --checklist <text> <height> <width> <listheight> [tag item status]...
+       --radiolist <text> <height> <width> <listheight> [tag item status]...
+       --gauge <text> <height> <width> <percent>
+Options: (depend on box-option)
+       --clear                         clear screen on exit
+       --defaultno                     default no button
+       --default-item <string>         set default string
+       --fb, --fullbuttons             use full buttons
+       --nocancel                      no cancel button
+       --yes-button <text>             set text of yes button
+       --no-button <text>              set text of no button
+       --ok-button <text>              set text of ok button
+       --cancel-button <text>          set text of cancel button
+       --noitem                        don't display items
+       --notags                        don't display tags
+       --separate-output               output one line at a time
+       --output-fd <fd>                output to fd, not stdout
+       --title <title>                 display title
+       --backtitle <backtitle>         display backtitle
+       --scrolltext                    force vertical scrollbars
+       --topleft                       put window in top-left corner
+       -h, --help                      print this message
+       -v, --version                   print version information
+
diff --git a/textbox.sh b/textbox.sh
new file mode 100755 (executable)
index 0000000..1110941
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/bash
+whiptail --backtitle "backtitle" --title "Test Message Box" --textbox --scrolltext text.txt 20 80
diff --git a/yesno.sh b/yesno.sh
new file mode 100755 (executable)
index 0000000..db8b277
--- /dev/null
+++ b/yesno.sh
@@ -0,0 +1,6 @@
+#!/bin/bash
+if (whiptail --title "Test Yes/No Box" --yesno "Choose between Yes and No." 10 60) then
+    echo "You chose Yes. Exit status was $?."
+else
+    echo "You chose No. Exit status was $?."
+fi
diff --git a/yesno2.sh b/yesno2.sh
new file mode 100755 (executable)
index 0000000..90fbfff
--- /dev/null
+++ b/yesno2.sh
@@ -0,0 +1,6 @@
+#!/bin/bash
+if (whiptail --title "Test Yes/No Box" --yes-button "Skittles" --no-button "M&M's"  --yesno "Which do you like better?" 10 60) then
+    echo "You chose Skittles Exit status was $?."
+else
+    echo "You chose M&M's. Exit status was $?."
+fi