Author Topic: apt-get upgrade and yad  (Read 2115 times)

misko_2083

  • Posts: 70
    • View Profile
apt-get upgrade and yad
« on: January 12, 2016, 07:54:41 PM »
I've been playing with a little script to update packages.
So here is the thing. When a package manager has an exclusive lock and this script tries to start the update, it calls a function to check wheather there is a lock or not.
If there is a lock it opens a Yad progress dialog which waits until the package manager (synaptic, gdebi-gtk, aptitude, apt...) releases the lock.
Now, when I click on Cancel on that same dialog Yad kills the parent process but there is still a child process that is checking the lock.
It eventualy closes when the package manager is closed, but I wonder if there is a way to kill it along with the parent.

The problem is in function checklock. When the synaptic is running and you select the 'Update Packages' from the main dialog, click the Cancel and look for the process with htop.
Any suggestions are welcome.  :)
Code: [Select]
#!/bin/bash
# Licensed under the GNU GPLv3.
#.%%...%%..%%%%%%...%%%%...%%..%%...%%%%.._.
#.%%%.%%%....%%....%%......%%.%%...%%..%%.2.
#.%%.%.%%....%%.....%%%%...%%%%....%%..%%.0.
#.%%...%%....%%........%%..%%.%%...%%..%%.8.
#.%%...%%..%%%%%%...%%%%...%%..%%...%%%%..3.
# Bash/YAD Debian Package Updater based on Linux Lite update tool
# ------- Change log ------
# Switched to YAD and adapted to Debian
# Added: a main dialog loop, log, option to purge the lists, about dialog
# Added: a check for exclusive lock
# -----------------------------------
# Note:  function checklock -> if Cancel is selected while the package manager (synaptic) is open
#        Yad progress kills the parent but will not kill the child process running the exclusive lock check
#        Subshell will be running until the package manager releases the lock
# -----------------------------------
# Milos Pavlovic
#

APPNAME="Update Tool"
LOGFILE=/var/log/misko-update.log
UPDATELOG=/var/log/last-update-log.log
# dist-upgrade or upgrade, change next line
COMMAND=dist-upgrade
# Yad window icon
ic=/usr/local/bin/images/vsidoorb_80.png

# Make sure only root can run our script
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root!" 1>&2
echo "TIP: Use gksudo or a similar tool." 1>&2
exit 1
fi

function log(){
message="$@"
echo '['$(date +%D\ %H:%M:%S)'] '$message | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})*)?m//g" | fold -sw 76 >>$LOGFILE
}

function checklock () {
# Checks for exclusive lock and wait until package managers are closed
while  fuser /var/lib/dpkg/lock 2>&1 >/dev/null  ; do
echo "# Waiting for other software managers to finish..." $"\n"
if [ "$(pidof synaptic)" ]; then
echo "# Waiting for other software managers to finish..." $"\nsynaptic"
fi
echo 1
sleep 1
echo 30
sleep 1
echo 60
sleep 1
if [ ! -z "$(pgrep gdebi-gtk)" ]; then
echo "# Waiting for other software managers to finish..." $"\ngdebi-gtk"
fi
echo 95
sleep 1
done | yad --progress --title="$APPNAME - close any open package managers" --percentage=20 --auto-close --auto-kill --button="Cancel:1"
if [[ $? -eq 1 ]];then
sleep 1
exit
fi
}


function showlog () {
if [[ ! -f $LOGFILE ]]; then
yad --info --title="$APPNAME Info" --text="No log file."
elif  [[  -z "$(cat $LOGFILE)"  ]]; then
yad --info --title="$APPNAME Info" --text="Log is empty."
else
yad --text-info  --button="Open log in Medit:0" --button="Close:1" --title="$APPNAME log file -> $log" --height=600 --width=800 --filename="$LOGFILE"
if [ "${PIPESTATUS[0]}" -eq "0" ]; then
medit "$LOGFILE" &
fi
fi
return
}

function about () {
yad --info --title="About $APPNAME " --height=20 --width=300 --text="$APPNAME is a small update GUI, fork of Linux Lite Upgrade tool and very easy to use.\n\nLicence GPL v3.\n\n Milos Pavlovic 2016"
return
}

function update() {

# Temporary file for error tracking
TMPLIST=$(mktemp /tmp/repos.XXXXXX)

APTUPDATE=$(grep '^deb' -c /etc/apt/sources.list) # Total number of repositories registered, this is approximated

apt-get update 2>&1 | tee $TMPLIST | awk -v total=$APTUPDATE '/^Ign|^Get/{count++;$1=""} FNR { if (total != 0){percentage=int (100*count/total);print (percentage < 90?percentage:90),"\n#",substr($0, 0, 128) }; fflush(stdout)}' \
| yad --progress --text="Updating package lists..." --window-icon="$ic" --title="Updating Software Sources - please wait..." --percentage=0 --auto-close --width=600

if [ "${PIPESTATUS[0]}" -ne "0" ]; then
err_msg=$(awk '/^(W:|E:)/{$1=""; print $0}' $TMPLIST | tail -n 1 ) #Get errors/warnings
log "ERROR: $err_msg"
unset APTUPDATE
rm -f $TMPLIST
unset TMPLIST
yad --error \
--title="Error" --text="$APPNAME couldn't fetch the package cache information lists.\nCheck the log for details"

return
fi

log "INFO: Software sources were updated."

unset APTUPDATE
rm -f $TMPLIST
unset TMPLIST

#  Temporary list of available updates
UPDATES=$(mktemp /tmp/updateslist.XXXXXX)

# Creates a list in /tmp/updateslist
apt-get --just-print $COMMAND 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  | yad --progress --window-icon="$ic" --pulsate --title="Calculating Updates" --text="Please wait..." --auto-close

# 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
log "INFO: No updates are available."
rm -f $UPDATES
unset UPDATES
yad --info --window-icon=$ic --title="$APPNAME" \
--text="No Updates Available"

return
fi
# Log available updates
    lst_upgrades=$(awk 'BEGIN { FS = "[ ]" } { print $3 }' $UPDATES)
    log "INFO: Updates available: $lst_upgrades"
    unset lst_upgrades

# 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 yad dialog to show update list
yad --text-info --window-icon="$ic" --ok-label="Update" --cancel-label="Cancel" --title="Available Updates" --width=780 --height=300 --filename="$UPDATES"

# Continue script if no halt
if [ "$?" -eq "0" ];then


# Write log
log "INFO: Update started."

# Remove tmp file and unset variable
rm -f $UPDATES
unset UPDATES

# Begin upgrade
DEBIAN_FRONTEND=noninteractive apt-get  -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" $COMMAND --show-progress -y  2>&1 | tee $UPDATELOG | awk ' BEGIN { FS=" "; total=1;end_download=0} /upgraded/ {total= $1 + $3;FS="[ :]" } /^Get:[[:digit:]]+/ {printf "#Downloading %s %s %s\n",$5,$(NF-1),$NF;print int(($2 - 1) * 100 / total); fflush(stdout)} /^\(Reading / {if (end_download==0){print 100;fflush(stdout);end_download=1}} /^(Preparing|Unpacking|Selecting|Processing|Setting|Download)/ {print "#", $0; fflush(stdout)}  /^Progress/ {print  match($0, /([0-9]+)/, arr); if(arr[1] != "") print arr[1] ; fflush(stdout)}' \
| ( yad --window-icon=$ic --progress --width=600 --text="Downloading package(s)...\nThis may take a while." --title="Downloading - please wait..." --percentage=0 --auto-close ; yad --progress --window-icon=$ic --width=600 --text="Installing and configuring packages...\nThis may take a while." --title="Installing - please wait..." --auto-close )

if [ "${PIPESTATUS[0]}" -ne "0" ]; then
err_msg=$(awk '/^(W:|E:)/{$1=""; print $0}' $UPDATELOG | tail -n 1)
log "ERROR:$err_msg"
yad --error \
--title="Error" --window-icon="$ic" --text="Updates have failed.\nCheck the log for details."
return
fi

# Halt updates script if user selects Cancel
else
log "INFO: User has canceled software upgrades."
rm -f $UPDATES
unset UPDATES
return
fi

log "INFO: Updates successfully installed."

PROCEED=$(yad --question --title="$APPNAME" --text="Updates have finished installing.\n\nWould you like to view the $APPNAME log?"; echo $?)

if [ ${PROCEED} -eq 1 ]; then
yad --info --title="$APPNAME" --text="Updates Complete."
return;
else
yad --text-info --ok-label="Quit" --cancel-label="Cancel" --title="Updates Log" --width=700 --height=300 --filename="$UPDATELOG"
fi

return
}


# Start the main loop
while (true); do
selection=$(yad --list --radiolist --title="$APPNAME" --window-icon="$ic" --text="Pick a task" --height=310 --width=350 --hide-column=2 --button="Exit:1" --button="Select:0" --column="Pick" --column="Function" --column="Task" \
"TRUE" "update" "Update Packages" "FALSE" "showlog" "Show log" "FALSE" "purgecache" "Purge the old cache" "FALSE" "about" "About this application" "FALSE" "exit" "Exit" --print-column=2) || exit
selection=$(echo $selection | cut -d '|' -f 1)

case "$selection" in
update) checklock; update
;;
showlog) showlog
;;
purgecache) checklock; sudo rm -vfd /var/lib/apt/lists/*  || yad --error --text="Error while purging the cache\nTry doing it manualy\nsudo rm -vfd /var/lib/apt/lists/* "
;;
about) about
;;
exit) exit 0
;;
esac
done

VastOne

  •      v-ger
  • Posts: 3964
    • View Profile
    • VSIDO Community
Re: apt-get upgrade and yad
« Reply #1 on: January 13, 2016, 12:58:40 AM »
Have you seen this discussion?

Will take a look at the script and try to debug as well

What do you name it?  I know I can use any, just wanting to know your naming convention

Thanks
VSIDO      VSIDO Twitter     VSIDO FB     VSIDO Google+   

I dev VSIDO

misko_2083

  • Posts: 70
    • View Profile
Re: apt-get upgrade and yad
« Reply #2 on: January 13, 2016, 06:39:10 AM »
Have you seen this discussion?

Will take a look at the script and try to debug as well

What do you name it?  I know I can use any, just wanting to know your naming convention

Thanks
Thank you.
I haven't came up with a name. Might as well be updater.sh as I named it here.  :D

I've come up with a solution. Killing all the processes with the name from basename.
Using the basename means the script name can be anything.
Code: [Select]
function checklock () {
# Checks for exclusive lock and wait until package managers are closed
while  fuser /var/lib/dpkg/lock 2>&1 >/dev/null  ; do
echo "# Waiting for other software managers to finish..." $"\n"
if [ "$(pidof synaptic)" ]; then
echo "# Waiting for other software managers to finish..." $"\nsynaptic"
fi
echo 1
sleep 1
echo 30
sleep 1
echo 60
sleep 1
if [ ! -z "$(pgrep gdebi-gtk)" ]; then
echo "# Waiting for other software managers to finish..." $"\ngdebi-gtk"
fi
echo 95
sleep 1
done | (if ! yad --progress --title="$APPNAME - close any open package managers" --percentage=20 --auto-close --button="Cancel:1";then killall $(basename $0); exit; fi)

}

misko_2083

  • Posts: 70
    • View Profile
Re: apt-get upgrade and yad
« Reply #3 on: January 13, 2016, 07:08:43 AM »
Hmm, yad-updater.sh would be a good name.  ;D
Fixed the text in the progress when downloading packages. It should display the package name when downloading, but not tested yet.
So here is the whole thing
Code: [Select]
#!/bin/bash
# Licensed under the GNU GPLv3.
#.%%...%%..%%%%%%...%%%%...%%..%%...%%%%.._.
#.%%%.%%%....%%....%%......%%.%%...%%..%%.2.
#.%%.%.%%....%%.....%%%%...%%%%....%%..%%.0.
#.%%...%%....%%........%%..%%.%%...%%..%%.8.
#.%%...%%..%%%%%%...%%%%...%%..%%...%%%%..3.
# Bash/YAD Debian Package Updater based on Linux Lite update tool
# ------- Change log ------
# Switched to YAD and adapted to Debian
# Added: a main dialog loop, log, option to purge the lists, about dialog
# Added: a check for exclusive lock
# -----------------------------------
# Note:
# -----------------------------------
# Milos Pavlovic
#

APPNAME="Update Tool"
LOGFILE=/var/log/misko-update.log
UPDATELOG=/var/log/last-update-log.log
# dist-upgrade or upgrade, change next line
COMMAND=dist-upgrade
# Yad window icon
ic=/usr/local/bin/images/vsidoorb_80.png

# Make sure only root can run our script
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root!" 1>&2
echo "TIP: Use gksudo or a similar tool." 1>&2
exit 1
fi

function log(){
message="$@"
echo '['$(date +%D\ %H:%M:%S)'] '$message | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})*)?m//g" | fold -sw 76 >>$LOGFILE
}

function checklock () {
# Checks for exclusive lock and wait until package managers are closed
while  fuser /var/lib/dpkg/lock 2>&1 >/dev/null  ; do
echo "# Waiting for other software managers to finish..." $"\n"
if [ "$(pidof synaptic)" ]; then
echo "# Waiting for other software managers to finish..." $"\nsynaptic"
fi
echo 1
sleep 1
echo 30
sleep 1
echo 60
sleep 1
if [ ! -z "$(pgrep gdebi-gtk)" ]; then
echo "# Waiting for other software managers to finish..." $"\ngdebi-gtk"
fi
echo 95
sleep 1
done | (if ! yad --progress --title="$APPNAME - close any open package managers" --percentage=20 --auto-close --button="Cancel:1";then killall $(basename $0); exit; fi)

}


function showlog () {
if [[ ! -f $LOGFILE ]]; then
yad --info --title="$APPNAME Info" --text="No log file."
elif  [[  -z "$(cat $LOGFILE)"  ]]; then
yad --info --title="$APPNAME Info" --text="Log is empty."
else
yad --text-info  --button="Open log in Medit:0" --button="Close:1" --title="$APPNAME log file -> $log" --height=600 --width=800 --filename="$LOGFILE"
if [ "${PIPESTATUS[0]}" -eq "0" ]; then
medit "$LOGFILE" &
fi
fi
return
}

function about () {
yad --info --title="About $APPNAME " --height=20 --width=300 --text="$APPNAME is a small update GUI, fork of Linux Lite Upgrade tool and very easy to use.\n\nLicence GPL v3.\n\n Milos Pavlovic 2016"
return
}

function update() {

# Temporary file for error tracking
TMPLIST=$(mktemp /tmp/repos.XXXXXX)

APTUPDATE=$(grep '^deb' -c /etc/apt/sources.list) # Total number of repositories registered, this is approximated

apt-get update 2>&1 | tee $TMPLIST | awk -v total=$APTUPDATE '/^Ign|^Get/{count++;$1=""} FNR { if (total != 0){percentage=int (100*count/total);print (percentage < 90?percentage:90),"\n#",substr($0, 0, 128) }; fflush(stdout)}' \
| yad --progress --text="Updating package lists..." --window-icon="$ic" --title="Updating Software Sources - please wait..." --percentage=0 --auto-close --width=600

if [ "${PIPESTATUS[0]}" -ne "0" ]; then
err_msg=$(awk '/^(W:|E:)/{$1=""; print $0}' $TMPLIST | tail -n 1 ) #Get errors/warnings
log "ERROR: $err_msg"
unset APTUPDATE
rm -f $TMPLIST
unset TMPLIST
yad --error \
--title="Error" --text="$APPNAME couldn't fetch the package cache information lists.\nCheck the log for details"

return
fi

log "INFO: Software sources were updated."

unset APTUPDATE
rm -f $TMPLIST
unset TMPLIST

#  Temporary list of available updates
UPDATES=$(mktemp /tmp/updateslist.XXXXXX)

# Creates a list in /tmp/updateslist
apt-get --just-print $COMMAND 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  | yad --progress --window-icon="$ic" --pulsate --title="Calculating Updates" --text="Please wait..." --auto-close

# 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
log "INFO: No updates are available."
rm -f $UPDATES
unset UPDATES
yad --info --window-icon=$ic --title="$APPNAME" \
--text="No Updates Available"

return
fi
# Log available updates
    lst_upgrades=$(awk 'BEGIN { FS = "[ ]" } { print $3 }' $UPDATES)
    log "INFO: Updates available: $lst_upgrades"
    unset lst_upgrades

# 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 yad dialog to show update list
yad --text-info --window-icon="$ic" --button="Update:0" --button="Cancel:1" --title="Available Updates" --width=780 --height=300 --filename="$UPDATES"

# Continue script if no halt
if [ "$?" -eq "0" ];then


# Write log
log "INFO: Update started."

# Remove tmp file and unset variable
rm -f $UPDATES
unset UPDATES

# Begin upgrade
DEBIAN_FRONTEND=noninteractive apt-get  -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" $COMMAND --show-progress -y  2>&1 | tee $UPDATELOG | awk ' BEGIN { FS=" "; total=1;end_download=0} /upgraded/ {total= $1 + $3;FS="[ :]" } /^Get:[[:digit:]]+/ {printf "#Downloading %s %s %s\n",$7,$(NF-1),$NF;print int(($2 - 1) * 100 / total); fflush(stdout)} /^\(Reading / {if (end_download==0){print 100;fflush(stdout);end_download=1}} /^(Preparing|Unpacking|Selecting|Processing|Setting|Download)/ {print "#", $0; fflush(stdout)}  /^Progress/ {print  match($0, /([0-9]+)/, arr); if(arr[1] != "") print arr[1] ; fflush(stdout)}' \
| ( yad --window-icon=$ic --progress --width=600 --text="Downloading package(s)...\nThis may take a while." --title="Downloading - please wait..." --percentage=0 --auto-close ; yad --progress --window-icon=$ic --width=600 --text="Installing and configuring packages...\nThis may take a while." --title="Installing - please wait..." --auto-close )

if [ "${PIPESTATUS[0]}" -ne "0" ]; then
err_msg=$(awk '/^(W:|E:)/{$1=""; print $0}' $UPDATELOG | tail -n 1)
log "ERROR:$err_msg"
yad --error \
--title="Error" --window-icon="$ic" --text="Updates have failed.\nCheck the log for details."
return
fi

# Halt updates script if user selects Cancel
else
log "INFO: User has canceled software upgrades."
rm -f $UPDATES
unset UPDATES
return
fi

log "INFO: Updates successfully installed."

PROCEED=$(yad --question --title="$APPNAME" --text="Updates have finished installing.\n\nWould you like to view the $APPNAME log?"; echo $?)

if [ ${PROCEED} -eq 1 ]; then
yad --info --title="$APPNAME" --text="Updates Complete."
return;
else
yad --text-info --ok-label="Quit" --cancel-label="Cancel" --title="Updates Log" --width=700 --height=300 --filename="$UPDATELOG"
fi

return
}


# Start the main loop
while (true); do
selection=$(yad --list --radiolist --title="$APPNAME" --window-icon="$ic" --text="Pick a task" --height=310 --width=350 --hide-column=2 --button="Exit:1" --button="Select:0" --column="Pick" --column="Function" --column="Task" \
"TRUE" "update" "Update Packages" "FALSE" "showlog" "Show log" "FALSE" "purgecache" "Purge the old cache" "FALSE" "about" "About this application" "FALSE" "exit" "Exit" --print-column=2) || exit
selection=$(echo $selection | cut -d '|' -f 1)

case "$selection" in
update) checklock; update
;;
showlog) showlog
;;
purgecache) checklock; sudo rm -vfd /var/lib/apt/lists/*  || yad --error --text="Error while purging the cache\nTry doing it manualy sudo rm /var/lib/apt/lists/* -vf"
;;
about) about
;;
exit) exit 0
;;
esac
done
Also fixed the button name here.

Could be an issue here and there but it's updating packages.
Having an option to select which package to update appears too complicated right now. I'll skip that one because it look's like a dependancy hell to me. :D

~RaMich~

  • Posts: 2
    • View Profile
Re: apt-get upgrade and yad
« Reply #4 on: August 27, 2017, 06:59:04 PM »
.. ich hab` mir den code geschnappt und `was rumgespielt
Code: [Select]
#!/bin/bash
#
APPNAME="Update Tool"
SCRIPTPFAD=$(dirname $(readlink -f $0))
LOGFILE=/var/log/misko-update.log
UPDATELOG=/var/log/last-update-log.log
#log einrückung und format
indent_weite="sed 's/^/                     |/'"
maximal_weite="70"
# dist-upgrade or upgrade, change next line
COMMAND=dist-upgrade
# Yad window icon
#ic=/usr/share/icons/oxygen/22x22/apps/system-software-update.png
#ic=/usr/share/icons/oxygen/22x22/apps/system-software-update-alpha.png
ic=/usr/local/bin/images/vsidoorb_80.png

function log_date(){
    message="$@"
    echo '['$(date +%d.%m.%Y\ %H:%M:%S)'] '$message | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})*)?m//g" | fold -sw 76 >> $LOGFILE
}

function log_indent(){
    message="$@"
    string=$($message | sed -n -e '1h;2,$H;${x;s/\n/ /g;p}')
    echo '                     |'$message | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})*)?[m|K]//g" | fold -sw 76 >> $LOGFILE
}

function indent() {
string=$(echo $@ | fmt --width=$maximal_weite  | eval "$indent_weite")
echo "$string" >> $LOGFILE
}

function checklock () {
  # Checks for exclusive lock and wait until package managers are closed
  while  fuser /var/lib/dpkg/lock 2>&1 >/dev/null  ; do
      echo "# !     . . .       . . .   warte auf Beendung andere Software-Manager   . . .     . . .      !" $"\n"
      if [ "$(pidof synaptic)" ]; then
          echo "# !     . . .       . . .   warte auf Beendung andere Software-Manager   . . .     . . .      !" $"\nsynaptic"
      fi
      echo 1
      sleep 1
      echo 30
      sleep 1
      echo 60
      sleep 1
      if [ ! -z "$(pgrep gdebi-gtk)" ]; then
          echo "# !     . . .       . . .   warte auf Beendung andere Software-Manager   . . .     . . .      !" $"\ngdebi-gtk"
      fi
      echo 95
      sleep 1
  done | (if ! yad  --progress \
                    --posx=50 \
                    --posy=50 \
                    --window-icon="$ic" \
                    --title="$APPNAME - schließen Sie alle geöffneten Paket-Manager !" \
                    --percentage=20 \
                    --auto-close \
                    --button="abbrechen:1";then killall $(basename $0); exit 0; fi)
}

function showlog () {
      if [[ ! -f $LOGFILE ]]; then
          yad --posx=50 \
              --posy=50 \
              --info \
              --window-icon="$ic" \
              --title="$APPNAME Info" \
              --text="kein log vorhanden."
      elif  [[  -z "$(cat $LOGFILE)"  ]]; then
          yad --posx=50 \
              --posy=50 \
              --info \
              --window-icon="$ic" \
              --title="$APPNAME Info" \
              --text="kein eintrag im log."
      else
          yad --posx=50 \
              --posy=50 \
              --text-info \
              --wrap \
              --window-icon="$ic" \
              --title="$APPNAME log file -> $LOGFILE" \
              --on-top \
              --button="update:0" \
              --button="update-log:1" \
              --button="log mit Kate öffnen:2" \
              --button="reverse:3" \
              --button="schließen:4" \
              --button="beenden:5" \
              --height=600 \
              --width=800 \
              --filename="$LOGFILE"
              BUTTON_SEL_RET=$?
  echo function showlog BUTTON_SEL_RET = $BUTTON_SEL_RET
          if [ "$BUTTON_SEL_RET" = "0" ]; then
              checklock; update
          elif [ "$BUTTON_SEL_RET" = "1" ]; then
              last-update-log
          elif [ "$BUTTON_SEL_RET" = "2" ]; then
              kate "$LOGFILE" &
          elif [ "$BUTTON_SEL_RET" = "3" ]; then
              showreverslog
          elif [ "$BUTTON_SEL_RET" = "4" ]; then
              main
          elif [ "$BUTTON_SEL_RET" = "5" ]; then
              exit 0
          fi
      fi
      main
}

function showreverslog () {
    if [[ ! -f $LOGFILE ]]; then
        yad --posx=50 --posy=50 --info --window-icon="$ic" --title="$APPNAME Info" --text="kein log vorhanden."
    elif  [[  -z "$(cat $LOGFILE)"  ]]; then
        yad --posx=50 --posy=50 --info --window-icon="$ic" --title="$APPNAME Info" --text="kein eintrag im log."
    else
        text=$(cat -n $LOGFILE | sort -nr | cut -b 8- )
        echo "$text" | \
        yad --posx=50 \
            --posy=50 \
            --text-info \
            --wrap \
            --window-icon="$ic" \
            --title="$APPNAME log file -> $LOGFILE" \
            --on-top \
            --height=600 \
            --width=800 \
            --button="update:0" \
            --button="update-log:1" \
            --button="log mit Kate öffnen:2" \
            --button="chronologisch:3" \
            --button="schließen:4" \
            --button="beenden:5"
            BUTTON_SEL_RET=$?
echo function showreverslog BUTTON_SEL_RET = $BUTTON_SEL_RET
        if [ "$BUTTON_SEL_RET" = "0" ]; then
            checklock; update
        elif [ "$BUTTON_SEL_RET" = "1" ]; then
            last-update-log
        elif [ "$BUTTON_SEL_RET" = "2" ]; then
            kate "$LOGFILE" &
        elif [ "$BUTTON_SEL_RET" = "3" ]; then
            showlog
        elif [ "$BUTTON_SEL_RET" = "4" ]; then
            main
        elif [ "$BUTTON_SEL_RET" = "5" ]; then
            exit
        fi
    fi
    main
}

function last-update-log () {
    if [[ ! -f $UPDATELOG ]]; then
        yad --posx=50 \
            --posy=50 \
            --info \
            --window-icon="$ic" \
            --title="$APPNAME Info" \
            --text="kein log vorhanden."
    elif  [[  -z "$(cat $UPDATELOG)"  ]]; then
        yad --posx=50 \
            --posy=50 \
            --info \
            --window-icon="$ic" \
            --title="$APPNAME Info" \
            --text="kein eintrag im log."
    else
        yad --posx=50 \
            --posy=50 \
            --text-info \
            --wrap \
            --window-icon="$ic" \
            --title="$APPNAME log file -> $UPDATELOG" \
            --button="update:0" \
            --button="Protokoll anzeigen:1" \
            --button="log mit Kate öffnen:2" \
            --button="schließen:3" \
            --button="beenden:4" \
            --height=600 \
            --width=800 \
            --filename="$UPDATELOG"
            BUTTON_SEL_RET=$?
echo function last-update-log BUTTON_SEL_RET = $BUTTON_SEL_RET
        if [ "$BUTTON_SEL_RET" = "0" ]; then
            checklock; update
echo function last-update-log im  0-teil nach funktionsaufruf
        elif [ "$BUTTON_SEL_RET" = "1" ]; then
            showreverslog
        elif [ "$BUTTON_SEL_RET" = "2" ]; then
            kate "$UPDATELOG" &
        elif [ "$BUTTON_SEL_RET" = "3" ]; then
            main
        elif [ "$BUTTON_SEL_RET" = "4" ]; then
            exit 0
        fi
    fi
    main
}

function about () {
    yad --posx=50 \
        --posy=50 \
        --info\
        --window-icon="$ic"\
        --title="über $APPNAME "\
        --on-top \
        --height=20\
        --width=300\
        --button="Update starten:0" \
        --button="schließen:1" \
        --button="beenden:2" \
        --text="$APPNAME ist ein kleines Update GUI, abgeleitet vom Linux Lite Upgrade-Tool und sehr einfach zu bedienen.\n\nÜbersetzt vom <a href='http://vsido.org/index.php?topic=1118.msg12502#msg12502'>http://vsido.org</a> Thread \n\nLicence GPL v3.\n\n Milos Pavlovic 2016"
         BUTTON_SEL_RET=$?
echo function about BUTTON_SEL_RET = $BUTTON_SEL_RET
        if [ "$BUTTON_SEL_RET" -eq "0" ]; then
            checklock; update
        elif [ "$BUTTON_SEL_RET" -eq "1" ]; then
            main
        elif [ "$BUTTON_SEL_RET" -eq "2" ]; then
            exit
        fi
}

function update() {
  # Temporary file for error tracking
  TMPLIST=$(mktemp /tmp/repos.XXXXXX)

  APTUPDATE=$(grep '^deb' -c /etc/apt/sources.list) # Total number of repositories registered, this is approximated

  apt-get update 2>&1 | tee $TMPLIST \
                      | awk -v total=$APTUPDATE '/^Ign|^Get/{count++;$1=""} FNR { if (total != 0){percentage=int (100*count/total);print (percentage < 90?percentage:90),"\n#",substr($0, 0, 128) }; fflush(stdout)}' \
                      | yad --progress \
                            --posx=50 \
                            --posy=50 \
                            --window-icon="$ic" \
                            --title="aktualisiere Softwarequellen - bitte warten..." \
                            --text="Paketlisten aktualisieren..." \
                            --percentage=0 \
                            --width=650 \
                            --button="schließen:0" \
                            --auto-close
                            BUTTON_SEL_RET=$?
  echo function update Paketlisten aktualisieren BUTTON_SEL_RET = $BUTTON_SEL_RET
      if [ "$BUTTON_SEL_RET" -ne "0" ]; then
          err_msg=$(awk '/^(W:|E:)/{$1=""; print $0}' $TMPLIST | tail -n 1 )    #Get errors/warnings
          log_date "ERROR: $err_msg"
          unset APTUPDATE
          rm -f $TMPLIST
          unset TMPLIST
          yad --posx=50 \
              --posy=50 \
              --error \
              --title="Error" \
              --text="$APPNAME konnte Paket-Cache Informationslisten nicht holen.\nÜberprüfen Sie das Protokoll für Details"
          main
      fi

  log_date "INFO: Software-Quellen wurden aktualisiert."

  unset APTUPDATE
  rm -f $TMPLIST
  unset TMPLIST

  #  Temporary list of available updates
  UPDATES=$(mktemp /tmp/updateslist.XXXXXX)

  apt-get --just-print $COMMAND 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  \
      | yad --progress \
            --posx=50 \
            --posy=50 \
            --window-icon="$ic" \
            --title="berechne Updates" \
            --text="bitte warten..." \
            --width=300 \
            --pulsate \
            --button="schließen:0" \
            --auto-close
            BUTTON_SEL_RET=$?
  echo function update berechne Updates BUTTON_SEL_RET = $BUTTON_SEL_RET
  # 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
      log_date "INFO: keine Updates verfügbar."
      rm -f $UPDATES
      unset UPDATES
      yad --posx=50 \
          --posy=50 \
          --info \
          --window-icon=$ic \
          --title="$APPNAME" \
          --on-top \
          --button="Protokoll anzeigen:0" \
          --button="schließen:1" \
          --button="beenden:2" \
          --text="keine Updates verfügbar"
          BUTTON_SEL_RET=$?
  echo function update keine Updates BUTTON_SEL_RET = $BUTTON_SEL_RET
          if [ "$BUTTON_SEL_RET" -eq "0" ]; then
              showreverslog
          elif [ "$BUTTON_SEL_RET" -eq "1" ]; then
  echo function update keine Updates  \>\> im 1-zweig schließen
              main
          elif [ "$BUTTON_SEL_RET" -eq "2" ]; then
              exit 0
          fi
  fi
      # Log available updates
      lst_upgrades=$(awk 'BEGIN { FS = "[ ]" } { print $3 }' $UPDATES  | sed ':a;N;$!ba;s/\n/ /g')
      log_date "INFO: Updates verfügbar:"
      indent $lst_upgrades
      unset lst_upgrades

  # Insert text into  /tmp/updateslist.XXXXXX
  sed -i -e '1 i\Liste der verfügbaren Updates' -e '1 i\Klicken Sie auf Update um fortzufahren oder Abbrechen um den Update-Vorgang zu stoppen\n'  $UPDATES

  # Erase existing available info
  sudo dpkg --clear-avail

  # Call the yad dialog to show update list
  yad --posx=50 \
      --posy=50 \
      --text-info \
      --window-icon="$ic" \
      --title="Verfügbare Updates" \
      --button="Update:0" \
      --button="abbrechen:1" \
      --width=800 \
      --height=300 \
      --filename="$UPDATES"
      BUTTON_SEL_RET=$?
  echo function update Verfügbare Updates BUTTON_SEL_RET = $BUTTON_SEL_RET
      # Continue script if no halt
      if [ "$BUTTON_SEL_RET" -eq "0" ];then

          # Write log
          log_date "INFO: Update started."

          # Remove tmp file and unset variable
          rm -f $UPDATES
          unset UPDATES

          # Begin upgrade
                   
          DEBIAN_FRONTEND=noninteractive apt-get  -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" $COMMAND --show-progress -y  2>&1 \
          | tee $UPDATELOG \
          | awk ' BEGIN { FS=" "; total=1;end_download=0} /upgraded/ {total= $1 + $3;FS="[ :]" } /^Get:[[:digit:]]+/ {printf "#Downloading %s %s %s\n",$7,$(NF-1),$NF;print int(($2 - 1) * 100 / total); fflush(stdout)} /^\(Reading / {if (end_download==0){print 100;fflush(stdout);end_download=1}} /^(Preparing|Unpacking|Selecting|Processing|Setting|Download)/ {print "#", $0; fflush(stdout)}  /^Progress/ {print  match($0, /([0-9]+)/, arr); if(arr[1] != "") print arr[1] ; fflush(stdout)}' \
          | ( yad --progress \
                  --posx=50 \
                  --posy=50 \
                  --window-icon=$ic \
                  --title="herunterladen - bitte warten..." \
                  --text="Pakete werden runtergeladen ... \nDies kann eine Weile dauern." \
                  --width=600 \
                  --percentage=0 \
                  --button="schließen:0" \
                  --auto-close ;\
              yad --progress \
                  --posx=50 \
                  --posy=50 \
                  --window-icon=$ic \
                  --title="Installation - bitte warten ..." \
                  --text="Konfigurieren und Installieren von Paketen ... \n Dies kann eine Weile dauern." \
                  --width=600 \
                  --percentage=0 \
                  --button="schließen:0" \
                  --auto-close )
                  BUTTON_SEL_RET=$?
  echo function update BUTTON_SEL_RET = $BUTTON_SEL_RET
          if [ "$BUTTON_SEL_RET" -ne "0" ]; then
              err_msg=$(awk '/^(W:|E:)/{$1=""; print $0}' $UPDATELOG | tail -n 1)
              log_date "ERROR:$err_msg"
              yad --posx=50 --posy=50 --error --title="Error" --window-icon="$ic" --text="Updates sind gescheitert.\nÜberprüfen Sie das Protokoll für Details."
              main
          fi

      # Halt updates script if user selects Cancel
      else
          log_date "INFO: Software-Upgrades vom Benutzer abgebrochen."
          rm -f $UPDATES
          unset UPDATES
          main
      fi

  log_date "INFO: Updates erfolgreich installiert."

  yad --posx=50 \
      --posy=50 \
      --question \
      --window-icon="$ic" \
      --title="$APPNAME" \
      --text="Updates wurden vollständig installiert.\n\nMöchten Sie das $APPNAME Protokoll anzuzeigen?" \
      --button="ja:0" \
      --button="nein:1"
      BUTTON_SEL_RET=$?
  echo function update Updates wurden vollständig installiert BUTTON_SEL_RET = $BUTTON_SEL_RET
  if [ $BUTTON_SEL_RET -eq 1 ]; then
      yad --posx=50 \
          --posy=50 \
          --info \
          --window-icon="$ic" \
          --title="$APPNAME" \
          --width=250 \
          --text="Aktualisierungen abgeschlossen." \
          --button="schließen:0" \
          --button="beenden:1"
          BUTTON_SEL_RET=$?
      echo function update Aktualisierungen abgeschlossen BUTTON_SEL_RET = $BUTTON_SEL_RET
      if [ "$BUTTON_SEL_RET" -eq "0" ]; then
          main;
      elif [ "$BUTTON_SEL_RET" -eq "1" ]; then
          exit
      fi
  else
      yad --posx=50 \
          --posy=50 \
          --text-info \
          --wrap \
          --window-icon="$ic" \
          --title="$APPNAME log file -> $UPDATELOG" \
          --height=600 \
          --width=800 \
          --on-top \
          --button="autoremove:0" \
          --button="Protokoll:1" \
          --button="schließen:2" \
          --button="beenden:3" \
          --filename="$UPDATELOG"
          BUTTON_SEL_RET=$?
      echo function update Updates Log BUTTON_SEL_RET = $BUTTON_SEL_RET
  fi
      if [ "$BUTTON_SEL_RET" -eq "0" ]; then
          autoremove
          main
      elif [ "$BUTTON_SEL_RET" -eq "1" ]; then
          showreverslog
      elif [ "$BUTTON_SEL_RET" -eq "2" ]; then
          main
      elif [ "$BUTTON_SEL_RET" -eq "3" ]; then
          exit
      fi
}

function autoremove() {
xterm -e 'read line <<TEXT_MARKE
apt-get autoremove
TEXT_MARKE
eval $line; bash'
        main
}

function main() {
selection=$(yad --posx=50 \
                --posy=50 \
                --list \
                --title="$APPNAME" \
                --window-icon="$ic" \
                --text="Option wählen --> Doppelklick" \
                --height=175 \
                --width=225 \
                --hide-column=1 \
                --no-buttons \
                --no-headers \
                --column="Function" \
                --column="option" \
                   "update" "➊ Update Packages" \
                   "showlog" "➋ Protokoll anzeigen" \
                   "showreverslog" "➌ Protokoll reverse anzeigen" \
                   "purgecache" "➍ apt info-cach löschen" \
                   "autoremove" "➎ apt autoremove" \
                   "about" "➏ über diese Anwendung" \
                   "exit" "➐ beenden" \
                --print-column=1) || exit
                selection=$(echo $selection | cut -d '|' -f 1)
echo function main selection = $selection
    case "$selection" in
        update) checklock; update
        ;;
        showlog) showlog
        ;;
        showreverslog) showreverslog
        ;;
        purgecache) checklock; sudo rm -vfd /var/lib/apt/lists/*  || yad --posx=50 --posy=50 --error --text="! Fehler, kann cache nicht löschen.\nVersuchen Sie es manuell mittels:\nsudo rm /var/lib/apt/lists/* -vf"
        ;;
        autoremove) autoremove
        ;;
        about) about
        ;;
        exit) exit 0
        ;;
    esac
}

# Make sure only root can run our script
if [[ $EUID -ne 0 ]]; then
    echo
    echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    echo "x   Dieses Skript muss als root ausgeführt werden!         x" 1>&2
    echo "x   Tipp: Verwenden Sie gksu oder ein ähnliches Werkzeug.  x" 1>&2
    echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    echo
    SCRIPT=$( readlink -m $( type -p $0 ))
    EXPECTPFAD=$(mktemp /tmp/expectScriptStart.XXXXXX.exp)

    echo "schreibe hilfs-script"
    echo
    echo expect temp datei: \"$EXPECTPFAD\"
    #--expect script anlegen uns schreiben--------------------------------
    echo "#!/usr/bin/expect" >> $EXPECTPFAD 2>&1
    echo "spawn gksu $SCRIPT" >> $EXPECTPFAD 2>&1
    echo "spawn shred -u $EXPECTPFAD" >> $EXPECTPFAD 2>&1
    echo "expect eof" >> $EXPECTPFAD 2>&1
    #--------------------------------------------------------------------------
    chmod +x $EXPECTPFAD
    #--------------------------------------------------------------------------
    expectScriptStart="$(cat $EXPECTPFAD)"
    echo dateiinhalt:
    echo .....................................................
    echo "$expectScriptStart"
    echo .....................................................
    echo starte hilfs-script
    echo
    exec $EXPECTPFAD
    exit 0
fi
#----------------das script an sich-----------------------------------------------------------------
SCRIPT=$( readlink -m $( type -p $0 ))
#echo \$SCRIPT: $SCRIPT
main


VastOne

  •      v-ger
  • Posts: 3964
    • View Profile
    • VSIDO Community
Re: apt-get upgrade and yad
« Reply #5 on: August 27, 2017, 07:10:55 PM »
Hi ~RaMich~ and welcome to VSIDO    Hi ~ RaMich ~ und willkommen bei VSIDO

I think the translation is something like:

I played with the code and broke it... :D 

VSIDO      VSIDO Twitter     VSIDO FB     VSIDO Google+   

I dev VSIDO

~RaMich~

  • Posts: 2
    • View Profile
Re: apt-get upgrade and yad
« Reply #6 on: August 27, 2017, 07:25:30 PM »
wenn du meinst?
teste es. irgendwo speichern, ausführbar machen und los gehts. .. sofern auch alle neuen Abhängigkeiten installiert sind.

VastOne

  •      v-ger
  • Posts: 3964
    • View Profile
    • VSIDO Community
Re: apt-get upgrade and yad
« Reply #7 on: August 27, 2017, 07:28:19 PM »
wenn du meinst?
teste es. irgendwo speichern, ausführbar machen und los gehts. .. sofern auch alle neuen Abhängigkeiten installiert sind.

Quote
if you think?
try it. somewhere save, execute and go. .. as long as all new dependencies are installed.

OK I will test it 
VSIDO      VSIDO Twitter     VSIDO FB     VSIDO Google+   

I dev VSIDO

VastOne

  •      v-ger
  • Posts: 3964
    • View Profile
    • VSIDO Community
Re: apt-get upgrade and yad
« Reply #8 on: August 27, 2017, 07:30:40 PM »
Tested and the conversion to German works perfectly...

Good work!
VSIDO      VSIDO Twitter     VSIDO FB     VSIDO Google+   

I dev VSIDO