readme and license
[whiptailexamples/.git] / demo.sh
1 #!/bin/bash
2 # Whiptail is the interactive shell Scrpting
3 OPTION=$(whiptail --title "Whiptail Shell Script Menu" --menu "Choose your option" 15 60 4 \
4 "1" "Change Password" \
5 "2" "Change UserName" \
6 "3" "Change Email" \
7 "4" "exit"  3>&1 1>&2 2>&3)
8
9 exitstatus=$?
10 if [ $exitstatus = 0 ]; then
11     echo "Your chosen option:" $OPTION
12
13 case $OPTION in
14   1) echo "Option1 Selected"
15      if (whiptail --title "Change Password" --yes-button "Yes" --no-button "No"  --yesno "Do you need to changed Password ?" 10 60) then
16     echo "password Selection Yes$?."
17      
18     # Start Password Box
19     PASSWORD=$(whiptail --passwordbox "please enter your secret password" 8 78 --title "Change Password" 3>&1 1>&2 2>&3)
20                                                                         # A trick to swap stdout and stderr.
21     # Again, you can pack this inside if, but it seems really long for some 80-col terminal users.
22      exitstatus=$?
23  if [ $exitstatus = 0 ]; then
24      echo "User selected Ok and entered " $PASSWORD
25      touch sample_out_put.txt
26      echo $PASSWORD > sample_out_put.txt
27             
28             # Start Progress Bar
29       {
30        for ((i = 0 ; i <= 100 ; i+=5)); do
31   sleep 0.3
32   echo $i
33      done
34       } | whiptail --gauge "Password Updating.." 6 50 0
35             # End Progress Bar    
36
37  else
38      echo "User selected Cancel."
39  fi
40
41     # End Password Box 
42      else
43     echo "Password Selection No$?."
44      fi
45      ;;
46   2) echo "option2 Selected"
47  # Change User Name Box
48  NAME=$(whiptail --inputbox "Change Username " 8 78  --title "Changed UserName" 3>&1 1>&2 2>&3) 
49  exitstatus=$?
50  if [ $exitstatus = 0 ]; then
51      echo "UserName Changed " $NAME
52  if (whiptail --title "Confirm Change UserName" --yes-button "Yes" --no-button "No"  --yesno "Do you need to changed UserName ?" 10 60)  then
53      echo "Username Confirm Yes$?."
54      # Start Progress Bar
55       {
56        for ((i = 0 ; i <= 100 ; i+=5)); do
57   sleep 0.3
58   echo $i
59        done
60       } | whiptail --gauge "UserName Updating.." 6 50 0
61             # End Progress Bar 
62  else
63   echo"Confirm Failed"
64  fi
65
66  else 
67     echo "UserName Not Changed"
68  fi
69
70      ;;
71   3) echo "Option3 Selected"
72      
73      ;;
74   4) echo "exit"
75      {
76     for ((i = 0 ; i <= 100 ; i+=5)); do
77         sleep 0.1
78         echo $i
79     done
80      } | whiptail --gauge "exit..." 6 50 0
81 esac
82
83 else
84     echo "You chose Cancel."
85 fi