HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials

HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials (http://www.howtoforge.com/forums/index.php)
-   Programming/Scripts (http://www.howtoforge.com/forums/forumdisplay.php?f=7)
-   -   Help With GUI Menu (http://www.howtoforge.com/forums/showthread.php?t=24633)

nightfire 30th June 2008 19:07

Help With GUI Menu
 
OK, I very, very, very new at this and don't know what I doing. I'm really trying so try to be kind . Here is what I'm trying to do. I have this script that I'm working on.


Code:

#!/bin/sh

# this is my first menu script.
# I'm tring to get Zenity to work with it So I can have a full GUI Menu
if [ $(whoami) != "root" ] ; then
      zenity --error \
          --text="Please Run This as Root"
exit 1
fi



clear;
        echo "Hello, What would you like me to install for you? "
       
        sleep 1
       
# GUI Menu I am Tring to get to work
#zenity --height=600 --width=800 \
#        --title="Install Menu" \
#        --text="Pick your Poison" \
#        --list \
#        --checklist \
#        --column="Pick This" \
#    --column="#" \
#    --column="Program" \
#        --column="Action" \
#          "False" "1" "Backgrounds" "(These are a colection from the all over the internet)" \
#          "False" "2" "Backgrounds" "(These are a colection from http://wallpapers-n-etc.com)" \
#          "False" "3" "icons" "(This will install some extra icon sets from gnome-look)" \
#          "False" "4" "Video setup" "(This will install DVD Playback Codecs and Players)" \
#          "False" "5" "themes" "(This will add some Extra Themes for gnome)" \
#          "False" "6" "compiz fusion" "(This will install Compiz Fusion from Fedora Repo)" \
#          "False" "7" "awn" "(This will install the AWN Dock)" \
         







#The Menu
        echo "..........................."
        echo "...........MENU............"
        echo
        echo "1 Backgrounds 1" "(These are a colection from the all over the internet)"
  echo "2 Backgrounds 2" "(These are a colection from http://wallpapers-n-etc.com)"
        echo "3 icons"  "(This will install some extra icon sets from gnome-look)"
#        echo "4 Video setup"  "(This will install DVD Playback Codecs and Players)"
#Still working on this
        echo "5 themes"  "(This will add some Extra Themes for gnome)"
        echo "6 compiz fusion"  "(This will install Compiz Fusion from Fedora Repo)"
        echo "7 awn"  "(This will install the AWN Dock)"

#Execute Menu Choice       
        read choice
     
        while [[ $choice != 0 ]]
        do
          case $choice in
            1)  clear;
      rpm -Uvh 'http://192.168.2.4/downloads/nfbackgrounds-1-1.fc9.noarch.rpm'
      P=nfbackgrounds
      rpm -qa "$P" > tl
      my_size=$( wc -l < t1 )
      echo "Checking install status"
      if [[ $( rpm -qa $P ) =~ ${P} ]]
      then
        zenity --info \
                --text="Backgrounds were installed.  Right click on desktop to change Background"
      else
        zenity --error \
            --text="Backgrounds Were not installed"
      fi
      rm t1               
                ;;
        2)  clear;
      rpm -Uvh 'http://192.168.2.3/downloads/nfbackground2-1-1.fc9.noarch.rpm'
      P=nfbackgrounds2
      rpm -qa "$P" > t1
      my_size=$( wc -l < t1 )
      echo "Checking install status"
      if [[ $( rpm -qa $P ) =~ ${P} ]]
      then
        zenity --info \
                --text="Backgrounds were installed.  Right click on desktop to change Background"
      else
        zenity --error \
            --text="Backgrounds Were not installed"
      fi
      rm t1               
      ;;
            3)  clear;
      yum -y install wget
      wget 192.168.2.4/downloads/nficons.tar.gz
      tar zxvf nficons.tar.gz -C /usr/share/icons
      rm nficons.tar.gz
                ;;
            4)  clear;
                su -c 'rpm -i http://rpm.livna.org/livna-release-8.rpm'
      wget 192.168.2.4/downloads/dvdplayback.sh
      sh dvdplayback.sh
      rm dvdplayback.sh
                ;;
            5)  clear;
      yum -y install wget
                wget 192.168.2.4/downloads/nfthemesf8.tar.gz
                tar zxvf nfthemesf8.tar.gz -C /usr/share/themes
      rm nfthemesf8.tar.gz
      ;;
            6)  clear;
                yum -y install ccsm emerald-themes compizconfig-backend-kconfig compizconfig-backend-gconf fusion-icon* emerald compiz-fusion compiz-fusion-gnome libcompizconfig compiz-gnome compiz-bcop compiz compizconfig-python compiz-fusion-extras compiz-fusion-extras-gnome compiz-kde
      P=compiz-fusion-gnome
      rpm -qa "$P" > t1
      my_size=$( wc -l < t1 )
      echo "Checking install status"
      if [[ $( rpm -qa $P ) =~ ${P} ]]
      then
        zenity --info \
                --text="compiz fusion was installed."
      else
        zenity --error \
            --text="compiz fusion was not installed"
      fi
      rm t1
                ;;
            7)  clear;
                yum -y install avant-window-navigator awn-extras
                P=avant-window-navigator
      rpm -qa "$P" > t1
      my_size=$( wc -l < t1 )
      echo "Checking install status"
      if [[ $( rpm -qa $P ) =~ ${P} ]]
      then
        zenity --info \
                --text="avant-window-navigator was installed."
      else
        zenity --error \
            --text="avant-window-navigator was not installed"
      rm tl
      fi
      ;;
            *)  clear;
                echo "You have entered an invalid option!"
                ;;
          esac

#Menu Loop
        echo "..........................."
        echo "...........MENU............"
        echo
        echo "1 Backgrounds 1" "(These are a colection from the all over the internet)"
  echo "2 Backgrounds 2" "(These are a colection from http://wallpapers-n-etc.com)"
        echo "3 icons"  "(This will install some extra icon sets from gnome-look)"
#        echo "4 Video setup"  "(This will install DVD Playback Codecs and Players)"
        echo "5 themes"  "(This will add some Extra Themes for gnome)"
        echo "6 compiz fusion"  "(This will install Compiz Fusion from Fedora Repo)"
        echo "7 awn"  "(This will install the AWN Dock)"

        read choice
      done

Now what I'm trying to get working is the Zenity Menu. If I take the away the #'s the menu comes up the way I want it to. But my problem is how do I get it to run the commands that I have listed here 1-7? This is where I'm stuck. Hope I'm making sense and someone can help. If i run the script as is It work fine but it has to loop back after one command. I want it to have a GUI and be able to select more then one item to install at a time.
Thanks in advance for the help.

burschik 1st July 2008 14:57

Apparently, you are not using the return value(s) of zenity. Try this:

HTML Code:

read -a choice  <<EOF
$(zenity --height=600 --width=800 \
        --title="Install Menu" \
        --list \
        --checklist \
        --column="Pick This" \
    --column="#" \
    --column="Program" \
        --column="Action" \
          "False" "1" "Backgrounds" "(These are a colection from the all over the internet)" \
          "False" "2" "Backgrounds" "(These are a colection from http://wallpapers-n-etc.com)" \
          "False" "3" "icons" "(This will install some extra icon sets from gnome-look)" \
          "False" "4" "Video setup" "(This will install DVD Playback Codecs and Players)" \
          "False" "5" "themes" "(This will add some Extra Themes for gnome)" \
          "False" "6" "compiz fusion" "(This will install Compiz Fusion from Fedora Repo)" \
          "False" "7" "awn" "(This will install the AWN Dock)" | tr '|' ' ')
EOF

echo "${choice[@]}"


nightfire 1st July 2008 15:42

getting there :)
 
Burschik, Thank you for the help. If you can suggest some good books out there so I can learn this better that would be great. I'm finding info here and there around the net but don't under stand what allot of the variables are yet. So with this project here is where I stand. The Zenity menu now will run the command but it stays in a loop. It just keeps running the same one. So if I pick 3 programs to install it just loops the 1st one. I know this more advance and probably shouldn't be attempting to do this but I'm more of hands on then reader to understand things.

Code:

#!/bin/sh

# this is my first menu script.
# I'm tring to get Zenity to work with it So I can have a full GUI Menu
#if [ $(whoami) != "root" ] ; then
#      zenity --error \
#        --text="Please Run This as Root"
#exit 1
#fi



clear;
        echo "Hello, What would you like me to install for you? "
       
        sleep 1
       
read -a choice  <<EOF
$(zenity --height=400 --width=800 \
        --title="Install Menu" \
        --list \
        --checklist \
        --column="Pick This" \
    --column="#" \
    --column="Program" \
        --column="Action" \
          "False" "1" "Backgrounds" "(These are a colection from the all over the internet)" \
          "False" "2" "Backgrounds" "(These are a colection from http://wallpapers-n-etc.com)" \
          "False" "3" "icons" "(This will install some extra icon sets from gnome-look)" \
          "False" "4" "Video setup" "(This will install DVD Playback Codecs and Players)" \
          "False" "5" "themes" "(This will add some Extra Themes for gnome)" \
          "False" "6" "compiz fusion" "(This will install Compiz Fusion from Fedora Repo)" \
          "False" "7" "awn" "(This will install the AWN Dock)" | tr '|' ' ')
EOF

echo "${choice[@]}"


     
        while [[ $choice != 0 ]]
        do
          case $choice in
            1)  clear;
      rpm -Uvh 'http://192.168.2.4/downloads/nfbackgrounds-1-1.fc9.noarch.rpm'
      P=nfbackgrounds
      rpm -qa "$P" > tl
      my_size=$( wc -l < t1 )
      echo "Checking install status"
      if [[ $( rpm -qa $P ) =~ ${P} ]]
      then
        zenity --info \
                --text="Backgrounds were installed.  Right click on desktop to change Background"
      else
        zenity --error \
            --text="Backgrounds Were not installed"
      fi
      rm t1               
                ;;
        2)  clear;
      rpm -Uvh 'http://192.168.2.3/downloads/nfbackground2-1-1.fc9.noarch.rpm'
      P=nfbackgrounds2
      rpm -qa "$P" > t1
      my_size=$( wc -l < t1 )
      echo "Checking install status"
      if [[ $( rpm -qa $P ) =~ ${P} ]]
      then
        zenity --info \
                --text="Backgrounds were installed.  Right click on desktop to change Background"
      else
        zenity --error \
            --text="Backgrounds Were not installed"
      fi
      rm t1               
      ;;
            3)  clear;
      yum -y install wget
      wget 192.168.2.4/downloads/nficons.tar.gz
      tar zxvf nficons.tar.gz -C /usr/share/icons
      rm nficons.tar.gz
                ;;
            4)  clear;
                su -c 'rpm -i http://rpm.livna.org/livna-release-8.rpm'
      wget 192.168.2.4/downloads/dvdplayback.sh
      sh dvdplayback.sh
      rm dvdplayback.sh
                ;;
            5)  clear;
      yum -y install wget
                wget 192.168.2.4/downloads/nfthemesf8.tar.gz
                tar zxvf nfthemesf8.tar.gz -C /usr/share/themes
      rm nfthemesf8.tar.gz
      ;;
            6)  clear;
                yum -y install ccsm emerald-themes compizconfig-backend-kconfig compizconfig-backend-gconf fusion-icon* emerald compiz-fusion compiz-fusion-gnome libcompizconfig compiz-gnome compiz-bcop compiz compizconfig-python compiz-fusion-extras compiz-fusion-extras-gnome compiz-kde
      P=compiz-fusion-gnome
      rpm -qa "$P" > t1
      my_size=$( wc -l < t1 )
      echo "Checking install status"
      if [[ $( rpm -qa $P ) =~ ${P} ]]
      then
        zenity --info \
                --text="compiz fusion was installed."
      else
        zenity --error \
            --text="compiz fusion was not installed"
      rm t1
      fi
      ;;
            7)  clear;
                yum -y install avant-window-navigator awn-extras
                P=avant-window-navigator
      rpm -qa "$P" > t1
      my_size=$( wc -l < t1 )
      echo "Checking install status"
      if [[ $( rpm -qa $P ) =~ ${P} ]]
      then
        zenity --info \
                --text="avant-window-navigator was installed."
      else
        zenity --error \
            --text="avant-window-navigator was not installed"
      rm tl
      fi
      ;;
            *)  clear;
                echo "You have entered an invalid option!"
                ;;
          esac

      done

Thanks again in advance

burschik 1st July 2008 16:27

Try the Advanced Bash Scripting Guide at http://tldp.org/LDP/abs/html/

You need to understand that "choice" is an array variable. For this reason, "$choice" only returns the first element of the array. You need to iterate over all array elements.


All times are GMT +2. The time now is 13:13.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.