#!/bin/bash
#-----------------------------------------------------------------------------------------
# Name: Linux Lite Updates
# Description: A GUI tool to easily install Updates in Linux Lite.
# Authors: Misko_2083, Jerry Bezencon, gerito1, Ralphy
# Website: https://www.linuxliteos.com
#-----------------------------------------------------------------------------------------

_APPNAME="Linux Lite Updates"                # Application name variable
_MYUPDUSER=$(whoami)
_ICON="/usr/share/icons/Faenza/apps/scalable/synaptic.svg"     # Linux Lite icon variable
_UPDATES=$(mktemp /tmp/updateslist.XXXXXX)   # Updates log variable
_DATE=$(date +"%A-%d-%B-%Y-%T")              # Date variable
_TMPU="/tmp/_updusr"
_PLAIN="/tmp/updateslist.txt"
_LLUPDATES="/var/log/llupdates.log"
if [ ! -f "$_TMPU" ]; then echo "$_MYUPDUSER" > "$_TMPU"; chmod 600 "$_TMPU"; fi
_SVUSER=$(cat "$_TMPU")

# function remove temp files
rm_temp_files() {
rm -f $_SVUSER
rm -f $_TMPU
rm -f $_UPDATES
rm -f $_PLAIN
rm -f /tmp/updateslist.*
}

# function view, save update log
view_save_log() {
  _ANS=$(zenity --text-info --width="780" --height="400" --title=" $_APPNAME - Error log" \
                --extra-button="Copy to clipboard" --ok-label="Save..." --cancel-label="Quit" --filename="$_LLUPDATES" 2>/dev/null); _OPT=$(echo $?)
    if [[ "$_ANS" =~ "Copy to clipboard" ]]; then
      sudo -u ${SUDO_USER:-$_SVUSER} xclip -selection c "$_LLUPDATES"
      xhost local:$_SVUSER > /dev/null 2>&1
      export DISPLAY=:0
      _NTFYICON="/usr/share/icons/Faenza/places/48/distributor-logo-ubuntu.png"
      notify-send -i "$_NTFYICON" 'Updates Log copied to clipboard' "Go to www.linuxliteos.com/forums and paste the log into a new or existing thread." -t 10000
      xhost - >/dev/null 2>&1; rm_temp_files; exit 0
    fi
    case $_OPT in
       0) szSavePath=$(zenity --title="    Save Updates Log" --width="550" --height="380" --file-selection --filename="/home/$_SVUSER/llupdates.log" \
                              --window-icon="$_ICON" --file-filter='*.log' --file-filter='All files | *' --save --confirm-overwrite 2>/dev/null)
           if [ "$?" -eq "0" ]; then sudo -u ${SUDO_USER:-$_SVUSER} cp "$_LLUPDATES" "$szSavePath"; rm_temp_files; else rm_temp_files; exit 0 ; fi ;;
       1) rm_temp_files; exit 0 ;;
    esac
}

# Check Internet access
if eval "curl -sk google.com" >> /dev/null 2>&1; then :; else # Prompt ERROR internet connection check failed and exit
  zenity --info --width="320" --height="120" --ok-label="Close" --title="  $_APPNAME" \
         --text="\n<b>Your computer is not connected to the internet</b> \n \nLinux Lite cannot check for updates. Please check your internet connection and try again." 2>/dev/null
  rm_temp_files; exit 0
fi

# Kill off any package managers that may be running
if [ "$(pidof synaptic)" ]; then killall -9 synaptic; fi
if [ ! -z "$(pgrep gdebi-gtk)" ]; then killall -9 gdebi-gtk; fi

# start dialog - Ask for elevation, else exit
if [ $EUID -ne 0 ]; then
   zenity --question --width="320" --height="100" --window-icon="$_ICON" --ok-label="Continue" --cancel-label="Cancel" --title="  $_APPNAME" \
       --text="\nLinux Lite will now fetch the Updates list\n\nClick <b>Cancel</b> to exit now or <b>Continue</b> to proceed." 2>/dev/null
   case $? in
      0) pkexec "$0"; if [ "${PIPESTATUS[@]}" -eq "126" ]; then rm_temp_files; fi; exit 0 ;;
      1) rm_temp_files; exit 0 ;;
   esac
fi

if [ "$?" -eq "0" ];then
  # xclip check/ install
  if [ -z  "$(dpkg -l | grep -E '^ii' | grep xclip)" ]; then
    apt-get install xclip -y | zenity  --progress --pulsate --window-icon="$_ICON" --auto-close --no-cancel --width="320" --height="80" --title="$_APPNAME" \
                                       --text="Preparing... please wait..." 2>/dev/null
  fi

# Repositories registered
_SLIST=$(grep '^deb ' -c /etc/apt/sources.list)
_SLISTD=$(grep -R --exclude="*.save" '^deb ' -c /etc/apt/sources.list.d/ | grep -c /)
APTUPDATE=$(($_SLIST + $_SLISTD)) # Total of repositories registered, this is approximated
apt-get update 2>&1 | tee "$_LLUPDATES" |
awk -v total=$APTUPDATE '/^Ign|^ Get/{count++;$1=""} FNR { if (total != 0){percentage=int (1000*count/total);print (percentage < 90?percentage:99),"\n#",substr($0, 0, 128) }; fflush(stdout)}' \
| zenity --progress --width="600" --text="Updating package lists..." --window-icon="$_ICON" --title="Updating Software Sources - please wait..." --percentage="0" --no-cancel --pulsate --auto-close 2>/dev/null
    if [ "${PIPESTATUS[0]}" -ne "0" ]; then
        unset APTUPDATE; rm_temp_files; unset _UPDATES
        sed -i '1 i\===========================\
Install Updates Error log\
===========================\
Install Updates could not fetch the package cache information lists.\
Go to https://www.linuxliteos.com/forums/ and paste the log below into a new or existing thread for assistance.\n\
============ Log ===========\n' "$_LLUPDATES"
        sleep 4 | zenity --progress --pulsate --window-icon="error" --auto-close --no-cancel --width="380" --height="80" --title="$_APPNAME - Error" \
                         --text="Errors occurred while fetching packages cache information lists.\n✔ Retrieving error log, please wait..." 2>/dev/null
        view_save_log; exit 1
    fi
  unset APTUPDATE

  # Creates a list in /tmp/updateslist
  # initialize html page
  ( echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Final//EN">'
  echo '<html style="width: 98%;"><head>'
  echo "<title>List of available Updates</title>"
  echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">'
  echo '</head><body style="width: 100%;">') >> $_UPDATES
  echo '<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAG7AAABuwBHnU4NQAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAxCSURBVGiB1ZpdjCTXVcd/59ZXz/R0z8y
  Ovev1x+7aGIKDHdlBVkBYiEhEigIoQkLiBYgt3lGCkBDIT0G8IYR4QLwEJB6SByMhFBRFygvCYSFxsBIgXn/E69j7NTvrnd2Znv6quvccHm5VdfdMz669ih+40t1bc+tW9fmf//m6t1bMjP/PzX3E75e6f2QtXfg1kQToAPlnfumZlU//8tMbZ07f319b666vFiv9LGc9S1zP4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6XRK0PgNIM8Sgvf44OMzviL4ilAtdrGA23Z4T9vzfsJXXn6RC5e+d0T4C5e+x1defpG8nyw8k2w7pK6S59W0eLir1jJgqngfCKVnWpaMp56q9KCBEJTJeBILP+9j+VF3O9RF
  lQemXdxbGcEbwRsajM6W8eWvvsDuwfVWgN2D63z5qy/Q2YprmvXurYxTZRcsxPOkYwDotd3hXvBVy0CRJfS6Bb2VgrVORn+tQ1FkrHYyOkVGCDHxheCP7aqe9dWE+9/oYQeC94b38Vua39zlxb9/Hh8qfKji9eZuvFevswPhvjd6bHQzNHi2b432iduIaKL1OAX2zr+2/fpvPvf4p6yufe7WGmtc
  ZvvzzSXw0HqX98+POPjUBO3U73bCZfsBf/nSHwNw2X5A7hy+zndu7Fj9boeH+13SxGEI/3Fh+wKwV8uMmBki0gOeylP3G5/55Nlff+7JB8+e3lrrxUMmaWN+G/udOzInzaGULK6HOjiocmsw4q1rO1x6+Brjh2anC5PbUeLOxmwTVLxXcPqdTR7d2mB9JWV7dzj49v9effdbr777L6XXrwP/Y2aD
  BoAAp4CfA54GzgHrd6Xg3loK9O//2eLM1sfyExtnstXeg1kXYHC1Gt5+rxrdfKPcvfH69D1gH2i+mOwBPwa+D/wQuG5mJs1pr0R1bQIP1MIvzzI/mZYAa8SP1etAv57frwUdAwfA/Dfbsr63Ddyy2sZbAE0TkZSopY/6f7I0zVF/8yUKfJzzKeDNbOEb1v8BmSBqeHp22RIAAAAASUVORK5CYII="
  alt="" width="32" height="32" style="float:left; margin:0 5px 5px 0;" /></p>' >> $_UPDATES
  echo '<h1 class="title">Updates Available for your System</h1><table style="width: 100%;">' >> $_UPDATES
  echo "<tr><td class="value"><i>Click <b>Update Now</b> to install the updates listed below or <b>Cancel</b> to exit.</i></td></tr>" >> $_UPDATES
  echo '<tr><td><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAtgAAAALCAYAAABF5vqtAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpw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nXU/Ww3OkXTNE7bhAT9GYR7GPhGoRtCG0T3eFujx+oDgmHsBDA5bvfvWETge9c0D95k6tGQgmqhF1g4m3Vceue+tcuPnBW33PDh5gtxIwpL5RmJ0qwAn2hj9Z8ZIch
  EFVE4Ym8j4jK6FaLKSnWTzA+t0lXvXDg0flItEmU/uyUZSDEcr1LNs9oJ1BMZGoXg0gcmWF01yRu3Imtv40H0iew1tA7a7NN48Phlg+4Te7F+NyAamyJaMrJhl7D2eAZi8yFp68g0aL7yG3wTQo3pnV6zwgdhFgRgPxHdWnJCsAxPimwGYM+I1OzFc6R6yBAgXYH9fHPkL/N7hZ9lW2I4wO04rVH
  j55Wul2vyH7gpQssNPE84C5lXi80Si9vZk+dXgW4BdbZcx5Yrt9oBdc2WOP7tXsN/2kMVLbEbF73X+FtAWMFSr9vXzstZMtTfPiXrQV9tpbtR8rVYPhmrVqtWarXEpgKpWY1Ot2je0P0+oRCvglsYEAAAAAElFTkSuQmCC"
  alt="" width="700" height="11" style="float:center; margin:0 1px 1px 0;" /></td></tr>' >> $_UPDATES
  ( echo "<tr><td colspan="2" class="sstitle">&nbsp;&nbsp;&nbsp;&nbsp;List of available Updates</td></tr>" && echo "<tr><td><p></p></td></tr>") >> $_UPDATES

  apt-get --just-print dist-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}' > $_PLAIN
  sed '
  s:^:<tr><td class="field">:;
  s:$:</td></tr>:
  ' $_PLAIN >> $_UPDATES
  # updates footer
  ( echo "<tr><td><p></p></td></tr>" && echo "</html>" ) >> $_UPDATES

  # Check for available updates; if none then remove /tmp/updateslist.XXXXXX and display up-to-date dialog
      if [  -z "$(cat $_PLAIN)"  ]; then
        rm_temp_files; unset _UPDATES
        zenity --info --window-icon="$_ICON"  --width="180" --height="60" --title="  $_APPNAME" \
               --text="\nYour system is up to date." 2>/dev/null
        exit 0
      fi

# Erase existing available info
dpkg --clear-avail
else
  rm_temp_files; unset _UPDATES; exit 0
fi

# Call the zenity dialog to show update list
zenity --text-info --window-icon="$_ICON" --ok-label="Update Now" --cancel-label="Cancel" --title="  $_APPNAME" --width="760" --height="400" --html --no-interaction --filename="$_UPDATES" 2>/dev/null
      if [ "$?" -eq "0" ];then
        # Continue script if no halt, remove tmp file and unset variables
        rm $_UPDATES; unset _UPDATES

#Begin upgrade
DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" dist-upgrade -y  2>&1 | tee "$_LLUPDATES" |
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 "#", substr($0, 0, 128); fflush(stdout)}' \
  | ( zenity --progress --width="600" --window-icon="$_ICON" --percentage="0" --no-cancel --auto-close --title="Downloading - please wait..." --text="Downloading package(s)...\nThis may take a while."  2>/dev/null;
      zenity --progress --window-icon="$_ICON" --width="600" --text="Installing and configuring packages...\nThis may take a while." --title="Installing - please wait..." --no-cancel --pulsate --auto-close 2>/dev/null)

    if [ "${PIPESTATUS[0]}" -ne "0" ]; then
      sed -i '1 i\===========================\
Install Updates Error log\
===========================\
Install Updates could not successfully download and install available updates.\
Go to https://www.linuxliteos.com/forums/ and paste the log below into a new or existing thread for assistance.\n\
============ Log ===========\n' "$_LLUPDATES"
      sleep 4 | zenity --progress --pulsate --window-icon="error" --auto-close --no-cancel --width="320" --height="80" --title="$_APPNAME - Error" \
                       --text="Errors occurred while updating. \n✔ Retrieving errors log. Please wait..." 2>/dev/null
      view_save_log; exit 0
    fi

    # Halt updates script if user selects Cancel
    else
       rm_temp_files; unset _UPDATES
       zenity --info --width="200" --timeout="3" --window-icon="$_ICON" --title="  $_APPNAME" --text="\nUpdates have been canceled." 2>/dev/null
       exit 0
    fi

# If Ubuntu base package has been upgraded during Install Updates, /usr/share/plymouth/themes/ubuntu-text/ubuntu-text.plymouth
llverprnt=$(awk '{print}' /etc/llver)
checkdefplym="/usr/share/plymouth/themes/ubuntu-text/ubuntu-text.plymouth"

if grep -q 0x988592 "$checkdefplym"; then
  sed -i "s/^title=Ubuntu.*$/title=$llverprnt/g" /usr/share/plymouth/themes/ubuntu-text/ubuntu-text.plymouth ;
  sed -i "s/black=0x2c001e/black=0x000000/g" /usr/share/plymouth/themes/ubuntu-text/ubuntu-text.plymouth ;
  sed -i "s/white=0xffffff/white=0xffffff/g" /usr/share/plymouth/themes/ubuntu-text/ubuntu-text.plymouth ;
  sed -i "s/brown=0xff4012/brown=0xffff00/g" /usr/share/plymouth/themes/ubuntu-text/ubuntu-text.plymouth ;
  sed -i "s/blue=0x988592/blue=0x000000/g" /usr/share/plymouth/themes/ubuntu-text/ubuntu-text.plymouth && update-initramfs -u |
  zenity --progress --width=600 --auto-close --no-cancel --pulsate --title="Updating boot configuration please wait..."
else
	echo " "
fi

    PROCEED=$(zenity --question --width="300" --height="80" --title="  $_APPNAME" --window-icon="$_ICON" --text="\n$_APPNAME completed successfully.\n\nWould you like to view the $_APPNAME log?" 2>/dev/null ; echo $?)
    if [ ${PROCEED} -eq 1 ]; then rm_temp_files; :; else
      zenity --text-info --width="750" --height="400" --cancel-label="Quit" --ok-label="Save..." --title="  $_APPNAME - Log" --filename="$_LLUPDATES" 2>/dev/null
        if [ $? -eq 0 ]; then
          # Save report
          szSavePath=$(zenity --width="550" --height="380" --title=" Save Updates log" --file-selection --filename=/home/$_SVUSER/llupdates-"${_DATE}".txt --file-filter='*.txt' \
                              --file-filter='All files | *' --save --confirm-overwrite 2>/dev/null)
          sudo -u ${SUDO_USER:-$_SVUSER} cp "$_LLUPDATES" "$szSavePath"; rm_temp_files; else rm_temp_files; :
        fi
    fi
    if [ -s /var/run/reboot-required ]; then
        zenity --question --width="300" --height="100" --ok-label="Reboot now" --cancel-label="Continue using my system" --title=" $_APPNAME - Reboot required" \
               --text="\nPrevious updates require rebooting the system for changes to take effect.\n\n          Would you like to reboot now?" 2>/dev/null
        if [ "$?" -eq "0" ]; then reboot; else exit 0 ; fi
    fi

exit 0