02-20-2015, 10:33 AM
OK how about now? First dialog is removed.
Code:
#!/bin/bash
#-----------------------------------------------------------------------------------------
# Name: Linux Lite Updates
# Description: A GUI tool to easily install Updates in Linux Lite.
# Authors: Misko_2083, Jerry Bezencon
# Date: 2015
# Website: https://www.freecinema2022.gq
#-----------------------------------------------------------------------------------------
# Kill off any package managers that may be running
if [ "$(pidof synaptic)" ]
then
sudo killall -9 synaptic
else
echo""
fi
if [ -z "$(pgrep gdebi-gtk)" ]
then
echo ""
else
killall -9 gdebi-gtk
fi
UPDATES=$(mktemp /tmp/updateslist.XXXXXX)
# Linux Lite default dialog icon
ic="/usr/share/icons/zenity-llcc.png"
APTUPDATE=$( stdbuf -oL /bin/bash \-c '(sudo apt-get update \-y )' 2>&1 |
stdbuf -oL sed -n -e 's/^\(.\{64\}\).*/\1/' -e '/\[*$/ s/^/# /p' -e '/\*$/ s/^/# /p' | #sed 's/^\(.\{64\}\).*/\1/' Display only the first 64 characters
zenity --progress --title="Updating package information..." --pulsate \
--width=600 --auto-close )
unset APTUPDATE
# Creates a list in /tmp/updateslist
LISTNAMES=$(apt-get --just-print upgrade 2>&1 | perl -ne 'if (/Inst\s([\w,\-,\d,\.,~,:,\+]+)\s\[([\w,\-,\d,\.,~,:,\+]+)\]\s\(([\w,\-,\d,\.,~,:,\+]+)\)? /i) {print "Name: $1 INSTALLED: $2 AVAILABLE: $3\n"}' | awk '{print NR,":\t"$0}' | tee $UPDATES)
# Check if any updates are available, if there are none, script pops up dialog box saying 'No Updates Available', removes /tmp/updateslist.XXXXXX
if [ -z "$(cat $UPDATES)" ]; then
zenity --info --window-icon="/usr/share/icons/zenity-llcc.png" --title="Linux Lite Updates" \
--text="No Updates Available"
rm $UPDATES
exit 0
fi
# Insert text into /tmp/updateslist.XXXXXX
sed -i -e '1 i\List of available Updates' -e '1 i\Click Update to continue or Cancel to stop the update process\n' $UPDATES
# Erase existing available info
sudo dpkg --clear-avail
# Call the zenity dialog to show update list
zenity --text-info --ok-label="Update" --cancel-label="Cancel" --title="Linux Lite Updates" --width=780 --height=300 --filename="$UPDATES"
if [ "$?" -eq "0" ];then
# Continue script if no halt
INSTALL_ICON="/usr/share/icons/zenity-llcc.png"
APPNAME="Linux Lite Updates"
#remove tmp file
rm $UPDATES
RUNUPDATES=$( stdbuf -oL /bin/bash \-c '(sudo DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade \-y )' 2>&1 | tee /var/log/llupdates.log |
stdbuf -oL sed -n -e 's/^\(.\{64\}\).*/\1/' -e '/\[*$/ s/^/# /p' -e '/\*$/ s/^/# /p' |
zenity --progress --title="Updating..." --pulsate \
--width=600 --auto-close )
if [ "${PIPESTATUS[0]}" -ne "0" ]; then
zenity --error \
--title="Error" --text="$APPNAME Updates have failed."
exit 0
fi
# Halt updates script if user selects Cancel
else
rm $UPDATES
unset UPDATES
unset RUNUPDATES
exit 0
fi
unset UPDATES
unset RUNUPDATES
PROCEED=$(zenity --question --title="$APPNAME Updates" --window-icon=/usr/share/icons/zenity-llcc.png --text="Updates have finished installing.\n\nWould you like to view the $APPNAME Updates log?"; echo $?)
if [ ${PROCEED} -eq 1 ]; then
zenity --info --title="$APPNAME Updates" --window-icon="${INSTALL_ICON}" --text="$APPNAME Updates Complete."
exit;
else
zenity --text-info --ok-label="Save Updates Log" --cancel-label="Close" --title="Updates Log" --width=700 --height=300 --filename="/var/log/llupdates.log"
if [ $? -ne 0 ]; then
exit;
else
#Generate the save list and on the first occurance of "FALSE" change it to "TRUE"
LL_LIST_D=(`awk -F':' '$3>=1000 && $3<=60000 {print "FALSE","/home/"$1}' /etc/passwd |sed '0,/FALSE/s/FALSE/TRUE/'`)
#Add optional save location
LL_LIST_H=(`awk -F':' '$3>=1000 && $3<=60000 {print "FALSE","/home/"$1"/Desktop"}' /etc/passwd`)
save_location=$(zenity --title="System Report Save Location" --list --radiolist --text="Select save location:" --column="Select" --column="Save file location:" --width=325 --height=300 "${LL_LIST_D[@]}" "${LL_LIST_H[@]}")
if [ $? -ne 0 ]; then
unset LL_LIST_D
unset LL_LIST_H
unset save_location
exit 0
else
#Extract username
LL_USER=$(echo "$save_location" | cut -d'/' -f3)
# Add filename to the save path
SAVE_PATH=$(echo $save_location| sed 's,.*,&\/var/log/llupdates.log,g')
#Checks if the file exists. If it does asks for confirmation.
if [ ! -z "$(echo $SAVE_PATH)" ]; then
if zenity --question --title="$APPNAME Updates" --window-icon=/usr/share/icons/zenity-llcc.png --text="file ${SAVE_PATH} allready exists.\nWould you like to overwite the file?"; then
cp /var/log/llupdates.log $save_location
chown $LL_USER $SAVE_PATH # Change the ownership to LL_USER
else
unset save_location
unset LL_LIST_D
unset LL_LIST_H
unset SAVE_PATH
unset LL_USER
exit 1
fi
else
cp /var/log/llupdates.log $save_location
chown $LL_USER $SAVE_PATH # Change the ownership to LL_USER
fi
fi
fi
fi
unset LL_LIST_D
unset LL_LIST_H
unset SAVE_PATH
unset LL_USER
unset save_location
exit 0