#!/bin/bash
#----------------------------------------------------------------
# Description: Linux Lite Upgrade Script - System
# About: For Linux Lite 3.- Series only
# Licence: GPLv2 Sharing is Caring
# Author: Jerry Bezencon, Ralphy
# Credits: Misko_2083
# Website: https://www.linuxliteos.com
#----------------------------------------------------------------

# Ensure multi-language support
export LANG=C

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

# Keep it clean to reduce errors
apt-get clean all 2>&1 | tee -a $LOGFILE

LL30SYSTEM() {
# Invoke arrays
ARRAYB=()
ARRAYC=()

#Check the arch
arch=$(uname -m)

case "$arch" in
    x86)    arch="x86"  ;;
    i?86)   arch="x86"  ;;
    amd64)  arch="amd64"    ;;
    x86_64) arch="amd64"    ;;
    * ) echo "Your Arch '$arch' -> Its not supported."  ;;
esac

# Populate arrays based on the arch
case "$arch" in
    x86)
    ARRAYB+=('BUPETCSKEL30')
    ARRAYC+=('ADDWALLS')
    ARRAYC+=('ADDLITEWIDGSKEL')
    ARRAYC+=('UPDLITEWIDGSKEL')
    ARRAYC+=('NOTIFYTHMSKEL')
    ARRAYC+=('HTOPSKEL')
    ARRAYC+=('ALLTERTHEME')
    ARRAYC+=('BLURAYVLCSYS')
    ARRAYC+=('ARCTHEMETHUNDERB')
    ARRAYC+=('UPDPKGS')
    ARRAYC+=('ERASEDPKGS')
    ARRAYC+=('INPKCL')
    ARRAYC+=('UPLSBISSUE')
    ARRAYC+=('UPDGRUB')
    ARRAYC+=('UPDPLYM')
    ;;
    amd64)
    ARRAYB+=('BUPETCSKEL3064')
    ARRAYC+=('ADDWALLS')
    ARRAYC+=('ADDLITEWIDGSKEL')
    ARRAYC+=('UPDLITEWIDGSKEL')
    ARRAYC+=('NOTIFYTHMSKEL')
    ARRAYC+=('HTOPSKEL')
    ARRAYC+=('ALLTERTHEME')
    ARRAYC+=('BLURAYVLCSYS')
    ARRAYC+=('ARCTHEMETHUNDERB')
    ARRAYC+=('UPDPKGS')
    ARRAYC+=('ERASEDPKGS')
    ARRAYC+=('INPKCL64')
    ARRAYC+=('UPLSBISSUE')
    ARRAYC+=('UPDGRUB')
    ARRAYC+=('UPDPLYM')
    ;;
esac
}

LL32SYSTEM() {
# Invoke arrays
ARRAYB=()
ARRAYC=()

#Check the arch
arch=$(uname -m)

case "$arch" in
    x86)    arch="x86"  ;;
    i?86)   arch="x86"  ;;
    amd64)  arch="amd64"    ;;
    x86_64) arch="amd64"    ;;
    * ) echo "Your Arch '$arch' -> Its not supported."  ;;
esac

# Populate arrays based on the arch
case "$arch" in
    x86)
    ARRAYB+=('BUPETCSKEL32')
    ARRAYC+=('ADDWALLS')
    ARRAYC+=('UPDLITEWIDGSKEL')
    ARRAYC+=('NOTIFYTHMSKEL')
    ARRAYC+=('ALLTERTHEME')
    ARRAYC+=('BLURAYVLCSYS')
    ARRAYC+=('ARCTHEMETHUNDERB')
    ARRAYC+=('UPDPKGS')
    ARRAYC+=('ERASEDPKGS')
    ARRAYC+=('INPKCL')
    ARRAYC+=('UPLSBISSUE')
    ARRAYC+=('UPDGRUB')
    ARRAYC+=('UPDPLYM')
    ;;
    amd64)
    ARRAYB+=('BUPETCSKEL3264')
    ARRAYC+=('ADDWALLS')
    ARRAYC+=('UPDLITEWIDGSKEL')
    ARRAYC+=('NOTIFYTHMSKEL')
    ARRAYC+=('ALLTERTHEME')
    ARRAYC+=('BLURAYVLCSYS')
    ARRAYC+=('ARCTHEMETHUNDERB')
    ARRAYC+=('UPDPKGS')
    ARRAYC+=('ERASEDPKGS')
    ARRAYC+=('INPKCL64')
    ARRAYC+=('UPLSBISSUE')
    ARRAYC+=('UPDGRUB')
    ARRAYC+=('UPDPLYM')
    ;;
esac
}

LL34SYSTEM() {
# Invoke arrays
ARRAYB=()
ARRAYC=()

#Check the arch
arch=$(uname -m)

case "$arch" in
    x86)    arch="x86"  ;;
    i?86)   arch="x86"  ;;
    amd64)  arch="amd64"    ;;
    x86_64) arch="amd64"    ;;
    * ) echo "Your Arch '$arch' -> Its not supported."  ;;
esac

# Populate arrays based on the arch
case "$arch" in
    x86)
    ARRAYB+=('BUPETCSKEL34')
    ARRAYC+=('ADDWALLS')
    ARRAYC+=('BLURAYVLCSYS')
    ARRAYC+=('ARCTHEMETHUNDERB')
    ARRAYC+=('UPDPKGS')
    ARRAYC+=('ERASEDPKGS')
    ARRAYC+=('INPKCL')
    ARRAYC+=('UPLSBISSUE')
    ARRAYC+=('UPDGRUB')
    ARRAYC+=('UPDPLYM')
    ;;
    amd64)
    ARRAYB+=('BUPETCSKEL3464')
    ARRAYC+=('ADDWALLS')
    ARRAYC+=('BLURAYVLCSYS')
    ARRAYC+=('ARCTHEMETHUNDERB')
    ARRAYC+=('UPDPKGS')
    ARRAYC+=('ERASEDPKGS')
    ARRAYC+=('INPKCL64')
    ARRAYC+=('UPLSBISSUE')
    ARRAYC+=('UPDGRUB')
    ARRAYC+=('UPDPLYM')
    ;;
esac
}

LL36SYSTEM() {
# Invoke arrays
ARRAYB=()
ARRAYC=()

#Check the arch
arch=$(uname -m)

case "$arch" in
    x86)    arch="x86"  ;;
    i?86)   arch="x86"  ;;
    amd64)  arch="amd64"    ;;
    x86_64) arch="amd64"    ;;
    * ) echo "Your Arch '$arch' -> Its not supported."  ;;
esac

# Populate arrays based on the arch
case "$arch" in
    x86)
    ARRAYB+=('BUPETCSKEL36')
    ARRAYC+=('ADDWALLS')
    ARRAYC+=('UPDPKGS')
    ARRAYC+=('ERASEDPKGS')
    ARRAYC+=('INPKCL')
    ARRAYC+=('UPLSBISSUE')
    ARRAYC+=('UPDGRUB')
    ARRAYC+=('UPDPLYM')
    ;;
    amd64)
    ARRAYB+=('BUPETCSKEL3664')
    ARRAYC+=('ADDWALLS')
    ARRAYC+=('UPDPKGS')
    ARRAYC+=('ERASEDPKGS')
    ARRAYC+=('INPKCL64')
    ARRAYC+=('UPLSBISSUE')
    ARRAYC+=('UPDGRUB')
    ARRAYC+=('UPDPLYM')
    ;;
esac
}

# Backup /etc/skel/ Linux Lite 3.0
BUPETCSKEL30() {
  log_upgrade "BUPETCSKEL30"
  echo "#⚫ Backing up /etc/skel files..." && sleep 2
  mkdir -p /etc/skel/.llupgradebackup/3.0 2>&1 | tee -a $LOGFILE
  cp /etc/skel/.config/htop/htoprc /etc/skel/.llupgradebackup/3.0 2>&1 | tee -a $LOGFILE
  cp /etc/skel/.config/lxterminal/lxterminal.conf /etc/skel/.llupgradebackup/3.0 2>&1 | tee -a $LOGFILE
}

BUPETCSKEL3064() {
  log_upgrade "BUPETCSKEL3064"
  echo "#⚫ Backing up /etc/skel files..." && sleep 2
  mkdir -p /etc/skel/.llupgradebackup/3.0 2>&1 | tee -a $LOGFILE
  cp /etc/skel/.config/lxterminal/lxterminal.conf /etc/skel/.llupgradebackup/3.0 2>&1 | tee -a $LOGFILE
}

# Backup /etc/skel/ Linux Lite 3.2
BUPETCSKEL32() {
  log_upgrade "BUPETCSKEL32"
  echo "#⚫ Backing up /etc/skel files..." && sleep 2
  mkdir -p /etc/skel/.llupgradebackup/3.2 2>&1 | tee -a $LOGFILE
  cp /etc/skel/.config/htop/htoprc /etc/skel/.llupgradebackup/3.2 2>&1 | tee -a $LOGFILE
  cp /etc/skel/.config/lxterminal/lxterminal.conf /etc/skel/.llupgradebackup/3.2 2>&1 | tee -a $LOGFILE
}

BUPETCSKEL3264() {
  log_upgrade "BUPETCSKEL3264"
  echo "#⚫ Backing up /etc/skel files..." && sleep 2
  mkdir -p /etc/skel/.llupgradebackup/3.2 2>&1 | tee -a $LOGFILE
  cp /etc/skel/.config/htop/htoprc /etc/skel/.llupgradebackup/3.2 2>&1 | tee -a $LOGFILE
  cp /etc/skel/.config/lxterminal/lxterminal.conf /etc/skel/.llupgradebackup/3.2 2>&1 | tee -a $LOGFILE
}

# Backup /etc/skel/ Linux Lite 3.4
BUPETCSKEL34() {
  log_upgrade "BUPETCSKEL34"
  echo "#⚫ Backing up /etc/skel files..." && sleep 2
  mkdir -p /etc/skel/.llupgradebackup/3.4 2>&1 | tee -a $LOGFILE
  cp /etc/skel/.config/htop/htoprc /etc/skel/.llupgradebackup/3.4 2>&1 | tee -a $LOGFILE
  cp /etc/skel/.config/lxterminal/lxterminal.conf /etc/skel/.llupgradebackup/3.4 2>&1 | tee -a $LOGFILE
}

BUPETCSKEL3464() {
  log_upgrade "BUPETCSKEL3464"
  echo "#⚫ Backing up /etc/skel files..." && sleep 2
  mkdir -p /etc/skel/.llupgradebackup/3.4 2>&1 | tee -a $LOGFILE
  cp /etc/skel/.config/htop/htoprc /etc/skel/.llupgradebackup/3.4 2>&1 | tee -a $LOGFILE
  cp /etc/skel/.config/lxterminal/lxterminal.conf /etc/skel/.llupgradebackup/3.4 2>&1 | tee -a $LOGFILE
}

# Backup /etc/skel/ Linux Lite 3.6
BUPETCSKEL36() {
  log_upgrade "BUPETCSKEL36"
  echo "#⚫ Backing up /etc/skel files..." && sleep 2
  mkdir -p /etc/skel/.llupgradebackup/3.6 2>&1 | tee -a $LOGFILE
  cp /etc/skel/.config/htop/htoprc /etc/skel/.llupgradebackup/3.6 2>&1 | tee -a $LOGFILE
  cp /etc/skel/.config/lxterminal/lxterminal.conf /etc/skel/.llupgradebackup/3.6 2>&1 | tee -a $LOGFILE
}

BUPETCSKEL3664() {
  log_upgrade "BUPETCSKEL3464"
  echo "#⚫ Backing up /etc/skel files..." && sleep 2
  mkdir -p /etc/skel/.llupgradebackup/3.6 2>&1 | tee -a $LOGFILE
  cp /etc/skel/.config/htop/htoprc /etc/skel/.llupgradebackup/3.6 2>&1 | tee -a $LOGFILE
  cp /etc/skel/.config/lxterminal/lxterminal.conf /etc/skel/.llupgradebackup/3.6 2>&1 | tee -a $LOGFILE
}

# Add new wallpapers
ADDWALLS() {
  log_upgrade "ADDWALLS"
  UPDATER=$( stdbuf -oL /bin/bash \-c '(cd /tmp && wget http://repo.linuxliteos.com/upgrade/3.0-3.8/walls38.tar.gz &&  tar -xvf walls38.tar.gz -C /usr/share/backgrounds/xfce/ && cd /usr/share/backgrounds/xfce/ && chown root:root * && chmod 644 * && sleep 2 )' 2>&1 | tee -a $LOGFILE |
  stdbuf -oL sed -n -e 's/^\(.\{128\}\).*/\1/' -e '/\[*$/ s/^/# /p' -e '/\*$/ s/^/# /p' |zenity --progress --width=600 --auto-close --no-cancel --percentage="$PERCENTAGE"  --title="Adding new wallpapers...")
unset UPDATER
}

# Get Conky for Linux Lite 3.0 add it to /etc/skel
ADDLITEWIDGSKEL() {
  log_upgrade "ADDLITEWIDGSKEL"
  UPDATER=$( stdbuf -oL /bin/bash \-c '(cd /etc/skel && wget http://repo.linuxliteos.com/upgrade/3.0-3.2/liteconkywidget.tar.gz && tar xvzf liteconkywidget.tar.gz && rm liteconkywidget.tar.gz &&  chown root:root .conky && sleep 2 )' 2>&1 | tee -a $LOGFILE |
  stdbuf -oL sed -n -e 's/^\(.\{128\}\).*/\1/' -e '/\[*$/ s/^/# /p' -e '/\*$/ s/^/# /p' |
  zenity --progress --width=600 --auto-close --no-cancel --percentage="$PERCENTAGE" --title="Adding Lite Widget into skel...")
  if [ $? = 1 ]; then zenity --info --title="$APPNAME" --text="\nError:\n${line}"; fi
unset UPDATER
}

# Improvements to the Lite Desktop Widget
UPDLITEWIDGSKEL() {
  log_upgrade "UPDLITEWIDGSKEL"
  UPDATER=$( stdbuf -oL /bin/bash \-c '( sed -i "s/Logged in as.*/${color}Logged in as:   \${alignr}\${color}\$USER"/g /etc/skel/.conky/widget && sleep 2 )' 2>&1 | tee -a $LOGFILE |
  stdbuf -oL sed -n -e 's/^\(.\{128\}\).*/\1/' -e '/\[*$/ s/^/# /p' -e '/\*$/ s/^/# /p' |
  zenity --progress --width=600 --auto-close --no-cancel --percentage="$PERCENTAGE" --title="Updating the Lite Desktop Widget in skel...")
  if [ $? = 1 ]; then zenity --info --title="$APPNAME" --text="\nError:\n${line}"; fi
unset UPDATER
}

# Change Notification theme
NOTIFYTHMSKEL() {
  log_upgrade "NOTIFYTHMSKEL"
  UPDATER=$( stdbuf -oL /bin/bash \-c '(mv /etc/skel/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-notifyd.xml /etc/skel/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-notifyd.xml.backup ;
  touch /etc/skel/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-notifyd.xml ;
  echo "<?xml version="1.0" encoding="UTF-8"?>" >> /etc/skel/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-notifyd.xml ;
  echo " " >> /etc/skel/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-notifyd.xml ;
  echo "<channel name="xfce4-notifyd" version="1.0">" >> /etc/skel/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-notifyd.xml ;
  echo "  <property name="notify-location" type="uint" value="2"/>" >> /etc/skel/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-notifyd.xml ;
  echo "  <property name="theme" type="string" value="Default"/>" >> /etc/skel/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-notifyd.xml ;
  echo "  <property name="expire-timeout" type="int" value="5"/>" >> /etc/skel/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-notifyd.xml ;
  echo "</channel>" >> /etc/skel/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-notifyd.xml && sleep 2 )' 2>&1 | tee -a $LOGFILE |
  stdbuf -oL sed -n -e 's/^\(.\{128\}\).*/\1/' -e '/\[*$/ s/^/# /p' -e '/\*$/ s/^/# /p' |
  zenity --progress --width=600 --auto-close --no-cancel --percentage="$PERCENTAGE" --title="Changing Notification theme in skel...")
  if [ $? = 1 ]; then zenity --info --title="$APPNAME" --text="\nError:\n${line}"; fi
unset UPDATER
}

# Change to new HTOP theme, file is: /etc/skel/.config/htop/htoprc
HTOPSKEL() {
  log_upgrade "HTOPSKEL"
  UPDATER=$( stdbuf -oL /bin/bash \-c '(touch /etc/skel/.config/htop/htoprc ;
  echo "fields=0 48 17 18 38 39 40 2 46 47 49 1" >> /etc/skel/.config/htop/htoprc ;
  echo "sort_key=46" >> /etc/skel/.config/htop/htoprc ;
  echo "sort_direction=1" >> /etc/skel/.config/htop/htoprc ;
  echo "hide_threads=0" >> /etc/skel/.config/htop/htoprc ;
  echo "hide_kernel_threads=1" >> /etc/skel/.config/htop/htoprc ;
  echo "hide_userland_threads=0" >> /etc/skel/.config/htop/htoprc ;
  echo "shadow_other_users=0" >> /etc/skel/.config/htop/htoprc ;
  echo "show_thread_names=0" >> /etc/skel/.config/htop/htoprc ;
  echo "show_program_path=1" >> /etc/skel/.config/htop/htoprc ;
  echo "highlight_base_name=0" >> /etc/skel/.config/htop/htoprc ;
  echo "highlight_megabytes=1" >> /etc/skel/.config/htop/htoprc ;
  echo "highlight_threads=1" >> /etc/skel/.config/htop/htoprc ;
  echo "tree_view=0" >> /etc/skel/.config/htop/htoprc ;
  echo "header_margin=1" >> /etc/skel/.config/htop/htoprc ;
  echo "detailed_cpu_time=0" >> /etc/skel/.config/htop/htoprc ;
  echo "cpu_count_from_zero=0" >> /etc/skel/.config/htop/htoprc ;
  echo "update_process_names=0" >> /etc/skel/.config/htop/htoprc ;
  echo "account_guest_in_cpu_meter=0" >> /etc/skel/.config/htop/htoprc ;
  echo "color_scheme=5" >> /etc/skel/.config/htop/htoprc ;
  echo "delay=15" >> /etc/skel/.config/htop/htoprc ;
  echo "left_meters=LeftCPUs2 Memory Swap" >> /etc/skel/.config/htop/htoprc ;
  echo "left_meter_modes=1 1 1" >> /etc/skel/.config/htop/htoprc ;
  echo "right_meters=RightCPUs2 Tasks LoadAverage Uptime" >> /etc/skel/.config/htop/htoprc ;
  echo "right_meter_modes=1 2 2 2" >> /etc/skel/.config/htop/htoprc && sleep 2 )' 2>&1 | tee -a $LOGFILE |
  stdbuf -oL sed -n -e 's/^\(.\{128\}\).*/\1/' -e '/\[*$/ s/^/# /p' -e '/\*$/ s/^/# /p' |
  zenity --progress --width=600 --auto-close --no-cancel --percentage="$PERCENTAGE" --title="Updating to new Resource Usage theme in skel...")
  if [ $? = 1 ]; then zenity --info --title="$APPNAME" --text="\nError:\n${line}"; fi
unset UPDATER
}

# Modify Terminal theme in /etc/skel
ALLTERTHEME() {
  log_upgrade "ALLTERTHEME"
  UPDATER=$( stdbuf -oL /bin/bash \-c '(mv /etc/skel/.config/lxterminal/lxterminal.conf /etc/skel/.config/lxterminal/lxterminal.conf.backup ;
  touch /etc/skel/.config/lxterminal/lxterminal.conf ;
  echo "[general]" >> /etc/skel/.config/lxterminal/lxterminal.conf ;
  echo "fontname=Monospace 10" >> /etc/skel/.config/lxterminal/lxterminal.conf ;
  echo "selchars=-A-Za-z0-9,./?%&#:_" >> /etc/skel/.config/lxterminal/lxterminal.conf ;
  echo "scrollback=100000" >> /etc/skel/.config/lxterminal/lxterminal.conf ;
  echo "bgcolor=#1A1E1F" >> /etc/skel/.config/lxterminal/lxterminal.conf ;
  echo "bgalpha=65535" >> /etc/skel/.config/lxterminal/lxterminal.conf ;
  echo "fgcolor=#f0f0f0" >> /etc/skel/.config/lxterminal/lxterminal.conf ;
  echo "disallowbold=false" >> /etc/skel/.config/lxterminal/lxterminal.conf ;
  echo "cursorblinks=true" >> /etc/skel/.config/lxterminal/lxterminal.conf ;
  echo "cursorunderline=false" >> /etc/skel/.config/lxterminal/lxterminal.conf ;
  echo "audiblebell=false" >> /etc/skel/.config/lxterminal/lxterminal.conf ;
  echo "tabpos=top" >> /etc/skel/.config/lxterminal/lxterminal.conf ;
  echo "hidescrollbar=false" >> /etc/skel/.config/lxterminal/lxterminal.conf ;
  echo "hidemenubar=false" >> /etc/skel/.config/lxterminal/lxterminal.conf ;
  echo "hideclosebutton=false" >> /etc/skel/.config/lxterminal/lxterminal.conf ;
  echo "disablef10=true" >> /etc/skel/.config/lxterminal/lxterminal.conf ;
  echo "disablealt=false" >> /etc/skel/.config/lxterminal/lxterminal.conf ;
  mv /root/.config/lxterminal/lxterminal.conf /root/.config/lxterminal/lxterminal.conf.backup ;
  cp /etc/skel/.config/lxterminal/lxterminal.conf /root/.config/lxterminal/ ;
  chown root:root /root/.config/lxterminal/lxterminal.conf && sleep 2 )' 2>&1 | tee -a $LOGFILE |
  stdbuf -oL sed -n -e 's/^\(.\{128\}\).*/\1/' -e '/\[*$/ s/^/# /p' -e '/\*$/ s/^/# /p' |
  zenity --progress --width=600 --auto-close --no-cancel --percentage="$PERCENTAGE" --title="Updating system Terminal theme in skel...")
  if [ $? = 1 ]; then zenity --info --title="$APPNAME" --text="\nError:\n${line}"; fi
unset UPDATER
}

# Bluray additional support in VLC - SYSTEM
BLURAYVLCSYS() {
  log_upgrade "BLURAYVLCSYS"
  UPDATER=$( stdbuf -oL /bin/bash \-c '(mkdir -p /etc/skel/.config/aacs && cd /etc/skel/.config/aacs/ && wget http://repo.linuxliteos.com/upgrade/3.0-3.6/KEYDB.cfg && sleep 2 )' 2>&1 | tee -a $LOGFILE |
  stdbuf -oL sed -n -e 's/^\(.\{128\}\).*/\1/' -e '/\[*$/ s/^/# /p' -e '/\*$/ s/^/# /p' |
  zenity --progress --width=600 --auto-close --no-cancel --percentage="$PERCENTAGE" --title="Adding additional Bluray support for VLC in skel...")
  if [ $? = 1 ]; then zenity --info --title="$APPNAME" --text="\nError:\n${line}"; fi
unset UPDATER
}

# Add Arc theme to Thunderbird
# Credit - Nicolas Bernaerts, https://github.com/NicolasBernaerts/ubuntu-scripts/tree/master/mozilla
ARCTHEMETHUNDERB() {
  log_upgrade "ARCTHEMETHUNDERB"
  UPDATER=$( stdbuf -oL /bin/bash \-c '(wget -O /usr/local/sbin/mozilla-extension-manager http://repo.linuxliteos.com/upgrade/3.0-3.6/mozilla-extension-manager && chmod +x /usr/local/sbin/mozilla-extension-manager && mozilla-extension-manager --system --thunderbird --install http://repo.linuxliteos.com/upgrade/3.0-3.6/arcthunderbird.xpi && sleep 2 )' 2>&1 | tee -a $LOGFILE |
  stdbuf -oL sed -n -e 's/^\(.\{128\}\).*/\1/' -e '/\[*$/ s/^/# /p' -e '/\*$/ s/^/# /p' |
  zenity --progress --width=600 --auto-close --no-cancel --percentage="$PERCENTAGE" --title="Adding Arc theme to Thunderbird globally...")
  if [ $? = 1 ]; then zenity --info --title="$APPNAME" --text="\nError:\n${line}"; fi
unset UPDATER
}

# Get list of available updated packages
UPDPKGS() {
  log_upgrade "UPDPKGS"
  UPDATER=$( stdbuf -oL /bin/bash \-c '( apt-get update \-y )' 2>&1 | tee -a $LOGFILE | stdbuf -oL sed -n -e 's/^\(.\{128\}\).*/\1/' -e '/\[*$/ s/^/# /p' -e '/\*$/ s/^/# /p' |
  zenity --progress --width=600 --auto-close --no-cancel --percentage="$PERCENTAGE" --title="Updating repositories..." --text="Updating repositories...")
  if [ $? = 1 ]; then zenity --info --title="$APPNAME" --text="\nError:\n${line}"; fi
unset UPDATER
}

# Erase existing available info
ERASEDPKGS() {
  log_upgrade "ERASEDPKGS"
  UPDATER=$( stdbuf -oL /bin/bash \-c '( dpkg --clear-avail )' 2>&1 | tee -a $LOGFILE | stdbuf -oL sed -n -e 's/^\(.\{128\}\).*/\1/' -e '/\[*$/ s/^/# /p' -e '/\*$/ s/^/# /p' |
  zenity --progress --width=600 --auto-close --no-cancel --percentage="$PERCENTAGE"  --title="Clearing dpkg..." --text="Clearing dpkg...")
  if [ $? = 1 ]; then zenity --info --title="$APPNAME" --text="\nError:\n${line}"; fi
unset UPDATER
}

# Install new packages, remove obsolete packages, clean up - 32BIT
INPKCL() {
  log_upgrade "INPKCL"
  UPDATER=$( stdbuf -oL /bin/bash \-c '(DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" \-y && apt-get install libreoffice-gnome linux-generic conky-all xserver-xorg-input-joystick joystick yad lite-updatesnotify xclip libaacs0 libbluray-bdj libbluray1 lite-sources regionset mythes-en-us gnome-font-viewer \-y && echo flashplugin-installer flashplugin-installer/local string | debconf-set-selections && apt-get install flashplugin-installer \-y && apt-get update \-y && apt-get remove adobe-flashplugin \-y && apt-get remove --purge unattended-upgrades \-y && rm -rf /var/log/unattended-upgrades && systemctl disable apt-daily.service && systemctl disable apt-daily.timer && systemctl disable apt-daily-upgrade.timer && apt-get autoremove \-y && apt-get clean )' 2>&1 | tee -a $LOGFILE |
  stdbuf -oL sed -n -e 's/^\(.\{128\}\).*/\1/' -e '/\[*$/ s/^/# /p' -e '/\*$/ s/^/# /p' |
  zenity --progress --width=600 --auto-close --no-cancel --percentage="$PERCENTAGE"  --title="Downloading and Installing new packages..." --text="Downloading and Installing new packages...")
unset UPDATER
}

# Install new packages, remove obsolete packages, clean up - 64BIT
INPKCL64() {
  log_upgrade "INPKCL64"
  UPDATER=$( stdbuf -oL /bin/bash \-c '(DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" \-y && apt-get install libreoffice-gnome linux-generic conky-all xserver-xorg-input-joystick joystick yad lite-updatesnotify xclip libaacs0 libbluray-bdj libbluray1 lite-sources regionset mythes-en-us gnome-font-viewer \-y && echo flashplugin-installer flashplugin-installer/local string | debconf-set-selections && apt-get install flashplugin-installer \-y && apt-get update \-y && apt-get remove adobe-flashplugin \-y && apt-get remove --purge unattended-upgrades \-y && rm -rf /var/log/unattended-upgrades && systemctl disable apt-daily.service && systemctl disable apt-daily.timer && systemctl disable apt-daily-upgrade.timer && apt-get autoremove \-y && apt-get clean )' 2>&1 | tee -a $LOGFILE |
  stdbuf -oL sed -n -e 's/^\(.\{128\}\).*/\1/' -e '/\[*$/ s/^/# /p' -e '/\*$/ s/^/# /p' |
  zenity --progress --width=600 --auto-close --no-cancel --percentage="$PERCENTAGE"  --title="Downloading and Installing new packages..." --text="Downloading and Installing new packages...")
unset UPDATER
}

# Update lsb_release and issue files /etc changes, update /etc/llver
UPLSBISSUE() {
  log_upgrade "UPLSBISSUE"
  UPDATER=$( stdbuf -oL /bin/bash \-c '( sed -i "s/DISTRIB_DESCRIPTION=.*/DISTRIB_DESCRIPTION=\"Linux Lite "'$UPGR'"\"/g" /etc/lsb-release && echo "Linux Lite $UPGR LTS \n \l" | tee /etc/issue && echo "Linux Lite $UPGR" | tee /etc/llver && sleep 2 )' 2>&1 | tee -a $LOGFILE | stdbuf -oL sed -n -e '/\[*$/ s/^/# /p' -e '/\*$/ s/^/# /p' |
  zenity --progress --width=600 --auto-close --no-cancel --percentage="$PERCENTAGE"  --title="Updating version information...")
  if [ $? = 1 ]; then zenity --info --title="$APPNAME" --text="\nError:\n${line}"; fi
unset UPDATER
}

# Update grub
UPDGRUB() {
  log_upgrade "UPDGRUB"
  UPDATER=$( stdbuf -oL /bin/bash \-c '( update-grub && sleep 2 )' 2>&1 | tee -a $LOGFILE | stdbuf -oL sed -n -e '/\[*$/ s/^/# /p' -e '/\*$/ s/^/# /p' |
  zenity --progress --width=600 --auto-close --no-cancel --percentage="$PERCENTAGE" --title="Updating Grub..." --text="Updating Grub...")
  if [ $? = 1 ]; then zenity --info --title="$APPNAME" --text="\nError:\n${line}"; fi
unset UPDATER
}

# Update /usr/share/plymouth/themes/ubuntu-text/ubuntu-text.plymouth
UPDPLYM() {
  log_upgrade "UPDPLYM"
  UPDATER=$( stdbuf -oL /bin/bash \-c '( sed -i "s/^title=Linux Lite.*$/title=Linux Lite "'$UPGR'"/g" /usr/share/plymouth/themes/ubuntu-text/ubuntu-text.plymouth ;
  sed -i "s/^title=Ubuntu.*$/title=Linux Lite "'$UPGR'"/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 && sleep 2 )' 2>&1 | tee -a $LOGFILE |
  stdbuf -oL sed -n -e 's/^\(.\{128\}\).*/\1/' -e '/\[*$/ s/^/# /p' -e '/\*$/ s/^/# /p' |
  zenity --progress --width=600 --auto-close --no-cancel --percentage="$PERCENTAGE" --title="Updating boot configuration please wait...")
  if [ $? = 1 ]; then zenity --info --title="$APPNAME" --text="\nError:\n${line}"; fi
unset UPDATER
return
}

#Check the version and start  the appropriate function
LLVER=$(awk '{print $3}' /etc/llver)

  if [ "$LLVER" == "3.0" ]; then LL30SYSTEM
elif [ "$LLVER" == "3.2" ]; then LL32SYSTEM
elif [ "$LLVER" == "3.4" ]; then LL34SYSTEM
elif [ "$LLVER" == "3.6" ]; then LL36SYSTEM
elif [ "$LLVER" == "3.8" ]; then zenity --info --text="You are already running the latest release."; exit 0
  fi
# Check if ARRAYB is empty
# If it is skip the execution
if [ ${#ARRAYB[@]} -ne 0 ]; then
    x=0
    for k in "${!ARRAYB[@]}"; do  x=$(( $x + 1 )); done  # Get the total number of selected items in array B
    TOTAL_LINES=$x
    i=0
    printf '%s \n' "${ARRAYB[@]}"|
    while read  line; do
      $line     # Execute functions one by one
        if [ $? = 1 ]; then log_upgrade "Error - $line"; zenity --error --title="$APPNAME" --text="An error occurred while performing upgrades:\n ${line}"; exit 1 ; fi
        let i++
          (( PERCENTAGE = 100 \* ${i} / ${TOTAL_LINES} ))
        echo "$PERCENTAGE"
        if [ "$PERCENTAGE" == "100" ]; then echo "#⚫ Completed." && sleep 2; fi
    done| zenity --progress  --title="$APPNAME" --auto-kill --auto-close --no-cancel --width=400
fi
# Check if ARRAYC is empty
# If it is skip the execution
if [ ${#ARRAYC[@]} -ne 0 ]; then
    x=0
    for k in "${!ARRAYC[@]}"; do  x=$(( $x + 1 )); done  # Get the total number of selected items in the array
    i=0
    TOTAL_LINES=$x
    PERCENTAGE=0
    printf '%s \n' "${ARRAYC[@]}"|
    while read  line; do
        (( PERCENTAGE = 100 \* ${i} / ${TOTAL_LINES} ))
        $line     # Execute functions one by one
        if [ $? = 1 ]; then log_upgrade "Error - $line"; zenity --error --title="$APPNAME" --text="An error occurred while performing upgrades:\n ${line}"; fi
        let i++
    if [ "$PERCENTAGE" == "100" ]; then echo "#⚫ Completed." && sleep 2 ; fi
    done
fi

unset ARRAYB
unset ARRAYC
unset MYUSER
