On 31/08/2019 08:11, Paul Sutton wrote:
>
> On 30/08/2019 18:11, Greg Wooledge wrote:
>> On Fri, Aug 30, 2019 at 05:31:50PM +0100, Paul Sutton wrote:
>>> What tool is used to produce the graphical interface for programs such
>>> as tasksel
>> A program named dialog, or whiptail which is basically "dialog lite".
>> Both of these are in packages with the same name as the program.
>>
>> ii  dialog         1.3-20190211-1 amd64        Displays user-friendly dialog 
>> box
>> ii  whiptail       0.52.20-8      amd64        Displays user-friendly dialog 
>> box
> Cool thanks for this,  I will have a look.
>
> Regards
>
> Paul


Another question

Using whiptail and trying to add a gui wrapper around a shell script I
wrote to add a menu to the update process.

#!/bin/bash
echo "This script MUST be run with root priviledges"
echo
echo "Enter number of the option you would like"
echo
OPTIONS="Update List Upgrade Autoremove Clean Quit"
echo
select opt in $OPTIONS; do
        if [ "$opt" = "Update" ] ; then
            echo Update
            apt update
        elif [ "$opt" = "List" ] ; then
            echo "List Upgradable package"
            apt upgrade
        elif [ "$opt" = "Upgrade" ] ; then
            echo "Upgrade packages"
            apt upgrade -y
        elif [ "$opt" = "Autoremove" ] ; then
            echo "Autoremove packages"
            apt autoremove
        elif [ "$opt" = "Clean" ] ; then
            echo "Clean Up"
            apt clean
        elif [ "$opt" = "Quit" ] ; then
            echo "Thank you and goodbye"
            exit
        else
            echo "bad option"
        fi
    done


The above works fine


I am now trying to create a checkbox option menu so that the user can
choose which options are needed then when pressing ok these are executed
in order.


whiptail --title "Check list example" --checklist \
"Choose user's permissions" 20 78 4 \
"NET_OUTBOUND" "Allow connections to other hosts" ON \
"NET_INBOUND" "Allow connections from other hosts" OFF \
"LOCAL_MOUNT" "Allow mounting of local devices" OFF \
"REMOTE_MOUNT" "Allow mounting of remote devices" OFF

I am just struggling to figure out how to :

take the above, if the user chooses say 1,2 and 4 then the commands associated 
with those options are executed.

so I could edit the above to say for the first option

"UPDATE" "RUN apt update" OFF \

Then if that option is selected it runs 
apt update

So another example I found to try and help me was

#!/bin/bash
DISTROS=$(whiptail --title "Test Checklist Dialog" --checklist \
"Choose preferred Linux distros" 15 40 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

But I am still confused as to how to actually take each selected option and use 
if / else statements to do something with this.  I think the issue is I don't 
really understand stderr properly or how to capture more than one option.

Been trying different things for about an hour, so can keep trying just not 
getting very far. 

So far I have come up with the following for what I trying to do.  So can add / 
remove options to the checklist menu ok. 

whiptail --title "Check list example" --checklist \
"Choose user's permissions" 20 40 4 \
"Hello" "Print Hello" OFF \
"Goodbye" "Print Goodbye" OFF \
"CYA" "Print cya" OFF \

CHOICEs=$?

echo $CHOICEs
echo $?

which just outputs for example 

"Hello" "Goodbye"0
0


https://en.wikibooks.org/wiki/Bash_Shell_Scripting/Whiptail is sort of useful 
for getting menus up but not doing anything with the output, it seems to assume 
people know how to do that confidently.

Thanks

Paul 

-- 
Paul Sutton
http://www.zleap.net
gnupg : 7D6D B682 F351 8D08 1893  1E16 F086 5537 D066 302D

https://fediverse.party/ - zl...@social.isurf.ca

Reply via email to