I have a bash script which makes some system changes involving a list of URL addresses beginning with "http", and I'm trying to write a GUI for it.
I'm stuck with the following last part:
changes="$(cat /home/$USER/.updates.log | grep http)"
if [ "$changes" != 0 ]; then
zenity --question --text "Changes found in:\n$changes\n\nWould you like to update now?"
if [ $? = 0 ]
then
# password
sudo_password="$(gksudo --print-pass --description 'MyScript' -- : 2>/dev/null)"
# check for null entry or cancellation
if [[ ${?} != 0 || -z ${sudo_password} ]]
then
exit 4
fi
if ! sudo -kSp '' [ 1 ] <<<"${sudo_password}" 2>/dev/null
then
exit 4
fi
# notify
notify-send "Applying updates..." -i gtk-dialog-info -t 1000 -u normal &
# proceed to update
cuser="${SUDO_USER:-$USER}"
sudo -Sp '' sudo /usr/local/bin/MyScript <<<"${sudo_password}"
# option to view log
new_update="$(cat /home/$USER/.updates.log | grep 'MyScript completed at ' | awk -F ' at ' '{print $2}')"
zenity --question --text "MyScript updated at $new_update\n\nWould you like to view the log file now?"
if [ $? = 0 ]
then
# display log
zenity --text-info --filename=/home/$USER/.updates.log --width 680 --height 680
fi
fi
fi
Actually, it seems the tricky part for me is here:
if [ "$changes" != 0 ]; then
I want to simply display a message like "No updates found; exiting..." if that file contains no lines beginning with "http" but this simply creates a blank line in the zenity question dialog box. It seems I need to modify this line, and also add another command under "else" but I just don't know how and where...
;
after yourif
statement? you only need it if thethen
part follows in the same line, in different lines you don't need that.