#!/bin/bash
#----------------------------------------------------------------
# Description: Linux Lite Upgrade Script - System
# About: For Linux Lite 2.- Series only
# Authors: Misko_2083, Jerry Bezencon
# 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
   sudo killall -9 synaptic 
else
   echo""
fi

if [ -z "$(pgrep gdebi-gtk)" ]
then
   echo ""
else
   killall -9 gdebi-gtk
fi

# Linux Lite default dialog icon
ic="/usr/share/icons/zenity-llcc.png"

# Get username
_USER="$@"

LL20SYSTEM() {
# Invoke arrays
ARRAYB=()
ARAYC=()

#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+=('BUPETCSKEL')
    ARRAYC+=('UPD1')
    ARRAYC+=('ERASEDPKG')
    ARRAYC+=('CRLCL')
    ARRAYC+=('INPKCL')
    ARRAYC+=('ADDWALL1')
    ARRAYC+=('UPLSBISSUE')
    ARRAYC+=('UPGRUB')
    ARRAYC+=('LBPLYUB')
    ARRAYC+=('SYSAUTH')
    ARRAYC+=('ROOTTERTHEM')
    ARRAYC+=('NWLOG')
    ;;
    amd64)
    ARRAYB+=('BUPETCSKEL64')
    ARRAYC+=('UPD1')
    ARRAYC+=('ERASEDPKG')
    ARRAYC+=('CRLCL')
    ARRAYC+=('INPKCL64')
    ARRAYC+=('ADDWALL1')
    ARRAYC+=('UPLSBISSUE')
    ARRAYC+=('UPGRUB')
    ARRAYC+=('LBPLYUB')
    ARRAYC+=('SYSAUTH')
    ARRAYC+=('ROOTTERTHEM')
    ARRAYC+=('NWLOG')
    ;;
esac
}

LL22SYSTEM() {
# 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+=('BUPETCSKEL')
    ARRAYC+=('UPD1')
    ARRAYC+=('ERASEDPKG')
    ARRAYC+=('CRLCL')
    ARRAYC+=('ADDPPAS')
    ARRAYC+=('INPKCL')
    ARRAYC+=('ADDWALL1')
    ARRAYC+=('ADDTHEME1')
    ARRAYC+=('UPLSBISSUE')
    ARRAYC+=('UPGRUB')
    ARRAYC+=('LBPLYUB')
    ARRAYC+=('SYSAUTH')
    ARRAYC+=('ROOTTERTHEM')
    ARRAYC+=('ADDROOTBASHRC1')
    ARRAYC+=('NWLOG')
    ;;
    amd64)
    ARRAYB+=('BUPETCSKEL64')
    ARRAYC+=('UPD1')
    ARRAYC+=('ERASEDPKG')
    ARRAYC+=('CRLCL')
    ARRAYC+=('ADDPPAS')
    ARRAYC+=('INPKCL64')
    ARRAYC+=('ADDWALL1')
    ARRAYC+=('ADDTHEME1')
    ARRAYC+=('UPLSBISSUE')
    ARRAYC+=('UPGRUB')
    ARRAYC+=('LBPLYUB')
    ARRAYC+=('SYSAUTH')
    ARRAYC+=('ROOTTERTHEM')
    ARRAYC+=('ADDROOTBASHRC1')
    ARRAYC+=('NWLOG')
    ;;
esac
}

LL24SYSTEM() {
# 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+=('BUPETCSKEL')
    ARRAYC+=('UPD1')
    ARRAYC+=('ERASEDPKG')
    ARRAYC+=('ADDPPAS')
    ARRAYC+=('INPKCL')
    ARRAYC+=('ADDWALL1')
    ARRAYC+=('ADDTHEME1')
    ARRAYC+=('UPLSBISSUE')
    ARRAYC+=('UPGRUB')
    ARRAYC+=('LBPLYUB')
    ARRAYC+=('SYSAUTH')
    ARRAYC+=('ADDROOTBASHRC1')
    ;;
    amd64)
    ARRAYB+=('BUPETCSKEL64')
    ARRAYC+=('UPD1')
    ARRAYC+=('ERASEDPKG')
    ARRAYC+=('ADDPPAS')
    ARRAYC+=('INPKCL64')
    ARRAYC+=('ADDWALL1')
    ARRAYC+=('ADDTHEME1')
    ARRAYC+=('UPLSBISSUE')
    ARRAYC+=('UPGRUB')
    ARRAYC+=('LBPLYUB')
    ARRAYC+=('SYSAUTH')
    ARRAYC+=('ADDROOTBASHRC1')
    ;;
esac
}

LL26SYSTEM() {
# 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+=('BUPETCSKEL')
    ARRAYC+=('UPD1')
    ARRAYC+=('ERASEDPKG')
    ARRAYC+=('ADDPPAS')
    ARRAYC+=('INPKCL')
    ARRAYC+=('ADDWALL1')
    ARRAYC+=('UPLSBISSUE')
    ARRAYC+=('UPGRUB')
    ARRAYC+=('LBPLYUB')
    ARRAYC+=('SYSAUTH')
    ;;
    amd64)
    ARRAYB+=('BUPETCSKEL64')
    ARRAYC+=('UPD1')
    ARRAYC+=('ERASEDPKG')
    ARRAYC+=('ADDPPAS')
    ARRAYC+=('INPKCL64')
    ARRAYC+=('ADDWALL1')
    ARRAYC+=('UPLSBISSUE')
    ARRAYC+=('UPGRUB')
    ARRAYC+=('LBPLYUB')
    ARRAYC+=('SYSAUTH')
    ;;
esac
}

# Backup /etc/skel/
BUPETCSKEL() {
       echo "#Backing up /etc/skel files..." 
        sleep 2
        cp /etc/skel/.config/lxterminal/lxterminal.conf /etc/skel/.llupgradebackup/2.8
        cp /etc/skel/.config/xfce4/panel/whiskermenu-1.rc /etc/skel/.llupgradebackup/2.8
        cp /etc/skel/.local/share/applications/exo-terminal-emulator.desktop /etc/skel/.llupgradebackup/2.8
        cp /etc/skel/.local/share/applications/exo-file-manager.desktop /etc/skel/.llupgradebackup/2.8
        cp /etc/skel/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-keyboard-shortcuts.xml /etc/skel/.llupgradebackup/2.8
        cp /etc/skel/.local/share/applications/exo-file-manager.desktop /etc/skel/.llupgradebackup/2.8
        cp /etc/skel/.local/share/applications/alacarte-made-2.desktop /etc/skel/.llupgradebackup/2.8
        cp /etc/skel/.local/share/applications/alacarte-made-4.desktop /etc/skel/.llupgradebackup/2.8
        cp /etc/skel/.local/share/applications/alacarte-made-5.desktop /etc/skel/.llupgradebackup/2.8
        cp /etc/skel/.local/share/applications/alacarte-made-6.desktop /etc/skel/.llupgradebackup/2.8
        cp /etc/skel/.local/share/applications/alacarte-made-7.desktop /etc/skel/.llupgradebackup/2.8
        cp /etc/skel/.local/share/applications/alacarte-made-10.desktop.backup /etc/skel/.llupgradebackup/2.8
        cp /etc/skel/.local/share/applications/alacarte-made-11.desktop.backup /etc/skel/.llupgradebackup/2.8
        cp /etc/skel/.config/Thunar/uca.xml /etc/skel/.llupgradebackup/2.8

}

BUPETCSKEL64() {
	echo "#Backing up /etc/skel files..."
        sleep 2
        cp /etc/skel/.config/lxterminal/lxterminal.conf /etc/skel/.llupgradebackup/2.8
        cp /etc/skel/.config/xfce4/panel/whiskermenu-1.rc /etc/skel/.llupgradebackup/2.8
        cp /etc/skel/.local/share/applications/exo-terminal-emulator.desktop /etc/skel/.llupgradebackup/2.8
        cp /etc/skel/.local/share/applications/exo-file-manager.desktop /etc/skel/.llupgradebackup/2.8
        cp /etc/skel/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-keyboard-shortcuts.xml /etc/skel/.llupgradebackup/2.8
        cp /etc/skel/.local/share/applications/exo-file-manager.desktop /etc/skel/.llupgradebackup/2.8
        cp /etc/skel/.local/share/applications/alacarte-made-2.desktop /etc/skel/.llupgradebackup/2.8
        cp /etc/skel/.config/Thunar/uca.xml /etc/skel/.llupgradebackup/2.8
}

# Get list of available updated packages
UPD1() {
#sed 's/^\(.\{128\}\).*/\1/' Display only the first 128 characters
UPDATER=$( stdbuf -oL /bin/bash \-c '(sudo apt-get update \-y )' 2>&1 |
stdbuf -oL sed -n -e 's/^\(.\{128\}\).*/\1/' -e '/\[*$/ s/^/# /p' -e '/\*$/ s/^/# /p' |
zenity --progress --percentage="$PERCENTAGE"  --title="Updating package information..." \
--width=600 --auto-close )
            if [ $? = 1 ]; then
                zenity --info --title="Lite Upgrade" --text="Error:\n${line}"
            fi    
unset UPDATER
}

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

# Create /etc/apt/apt.conf.d/local to leave /etc/issue and /etc/lsb-release defaults (only needed in LL 2.2)
CRLCL() {
UPDATER=$( stdbuf -oL /bin/bash \-c '(cd /tmp && wget http://repo.linuxliteos.com/upgrade/local && sudo mv local /etc/apt/apt.conf.d/ && sudo chown root:root /etc/apt/apt.conf.d/local && sleep 2 )' 2>&1 |
stdbuf -oL sed -n -e 's/^\(.\{128\}\).*/\1/' -e '/\[*$/ s/^/# /p' -e '/\*$/ s/^/# /p' |
zenity --progress --percentage="$PERCENTAGE"  --title="Automating packaging defaults..." \
--width=600 --auto-close )
            if [ $? = 1 ]; then
                zenity --info --title="Lite Upgrade" --text="Error:\n${line}"
            fi    
unset UPDATER
}

# Add any new PPA's
ADDPPAS() {
UPDATER=$( stdbuf -oL /bin/bash \-c '(sudo DEBIAN_FRONTEND=noninteractive apt-get upgrade -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" \-y && sudo add-apt-repository ppa:nemh/systemback \-y && sudo apt-get update )' 2>&1 |
stdbuf -oL sed -n -e 's/^\(.\{128\}\).*/\1/' -e '/\[*$/ s/^/# /p' -e '/\*$/ s/^/# /p' |
zenity --progress --percentage="$PERCENTAGE"  --title="Adding new PPA's, Downloading and Installing new packages..." \
--width=600 --auto-close )
unset UPDATER
}

# Install new packages, remove obsolete packages, clean up
INPKCL() {
UPDATER=$( stdbuf -oL /bin/bash \-c '(sudo DEBIAN_FRONTEND=noninteractive apt-get upgrade -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" \-y && sudo apt-get install locate vpnc openconnect network-manager-openconnect-gnome network-manager-vpnc-gnome gvfs-fuse network-manager-openvpn mugshot ntp ntpdate tumbler-plugins-extra mtpfs libmtp9 libmtp-runtime libmtp-common mtp-tools libnet-smtp-ssl-perl exfat-fuse exfat-utils inxi libreoffice-gnome dmz-cursor-theme file-roller lite-welcome lite-cleaner lite-manual catfish deja-dup system-config-date light-locker thunar-archive-plugin whiskermenu cups-pdf gnome-disk-utility browser-plugin-vlc lupin-casper systemback lite-controlcenter ttf-ubuntu-font-family gufw thunar-media-tags-plugin btrfs-tools libhal1-flash libde265 vlc-plugin-libde265 xbacklight xdg-user-dirs-gtk gtk2-engines \-y && sudo apt-get update \-y && sudo apt-get remove xarchiver \-y && sudo apt-get autoremove \-y && sudo apt-get clean )' 2>&1 |
stdbuf -oL sed -n -e 's/^\(.\{128\}\).*/\1/' -e '/\[*$/ s/^/# /p' -e '/\*$/ s/^/# /p' |
zenity --progress --percentage="$PERCENTAGE"  --title="Downloading and Installing new packages..." \
--width=600 --auto-close )
unset UPDATER
}

INPKCL64() {
UPDATER=$( stdbuf -oL /bin/bash \-c '(sudo DEBIAN_FRONTEND=noninteractive apt-get upgrade \-y && sudo apt-get install locate vpnc openconnect network-manager-openconnect-gnome network-manager-vpnc-gnome gvfs-fuse network-manager-openvpn mugshot ntp ntpdate tumbler-plugins-extra mtpfs libmtp9:amd64 libmtp-runtime libmtp-common mtp-tools libnet-smtp-ssl-perl exfat-fuse exfat-utils inxi libreoffice-gnome dmz-cursor-theme file-roller lite-welcome lite-cleaner lite-manual catfish deja-dup system-config-date light-locker thunar-archive-plugin whiskermenu cups-pdf gnome-disk-utility browser-plugin-vlc lupin-casper systemback lite-controlcenter ttf-ubuntu-font-family gufw thunar-media-tags-plugin btrfs-tools libhal1-flash libde265 vlc-plugin-libde265 xbacklight xdg-user-dirs-gtk gtk2-engines \-y && sudo apt-get update \-y && sudo apt-get remove xarchiver \-y && sudo apt-get autoremove \-y && sudo apt-get clean )' 2>&1 |
stdbuf -oL sed -n -e 's/^\(.\{128\}\).*/\1/' -e '/\[*$/ s/^/# /p' -e '/\*$/ s/^/# /p' |
zenity --progress --percentage="$PERCENTAGE"  --title="Downloading and Installing new packages..." \
--width=600 --auto-close )
            if [ $? = 1 ]; then
                zenity --info --title="Lite Upgrade" --text="Error:\n${line}"
            fi    
unset UPDATER
}

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

# Add new Theme/s
ADDTHEME1() {
UPDATER=$( stdbuf -oL /bin/bash \-c '(cd /tmp && wget http://repo.linuxliteos.com/upgrade/themes/themes.tar.gz && sudo tar -xvf themes.tar.gz -C /usr/share/themes/ && cd /usr/share/backgrounds/xfce/ && sleep 2 )' 2>&1 |
stdbuf -oL sed -n -e 's/^\(.\{128\}\).*/\1/' -e '/\[*$/ s/^/# /p' -e '/\*$/ s/^/# /p' |
zenity --progress --percentage="$PERCENTAGE"  --title="Adding new Theme..." \
--width=600 --auto-close )
unset UPDATER
}

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

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

# /lib/plymouth/themes/ubuntu-text/ changes
LBPLYUB() {
UPDATER=$( stdbuf -oL /bin/bash \-c '(sudo sed -i "s/^title=Linux Lite.*$/title=Linux Lite 2.8/g" /lib/plymouth/themes/ubuntu-text/ubuntu-text.plymouth && sudo sed -i "s/^title=Ubuntu.*$/title=Linux Lite 2.8/g" /lib/plymouth/themes/ubuntu-text/ubuntu-text.plymouth && sudo sed -i "s/black=0x2c001e/black=0x000000/g" /lib/plymouth/themes/ubuntu-text/ubuntu-text.plymouth && sudo sed -i "s/white=0xffffff/white=0xffffff/g" /lib/plymouth/themes/ubuntu-text/ubuntu-text.plymouth && sudo sed -i "s/brown=0xff4012/brown=0xffff00/g" /lib/plymouth/themes/ubuntu-text/ubuntu-text.plymouth && sudo sed -i "s/blue=0x988592/blue=0x000000/g" /lib/plymouth/themes/ubuntu-text/ubuntu-text.plymouth && sudo update-initramfs -u )' 2>&1 |
stdbuf -oL sed -n -e 's/^\(.\{128\}\).*/\1/' -e '/\[*$/ s/^/# /p' -e '/\*$/ s/^/# /p' |
zenity --progress --percentage="$PERCENTAGE"  --title="Updating boot configuration please wait..." \
--width=600 --auto-close )
            if [ $? = 1 ]; then
                zenity --info --title="Lite Upgrade" --text="Error:\n${line}"
            fi    
unset UPDATER
}

# Fix syslog, auth.log not logging
SYSAUTH() {
UPDATER=$( stdbuf -oL /bin/bash \-c '(sudo chown syslog:adm /var/log/syslog && sudo chmod 640 /var/log/syslog && sudo chown syslog:adm /var/log/auth.log && sudo chmod 640 /var/log/auth.log && sudo service rsyslog restart )' 2>&1 |
stdbuf -oL sed -n -e 's/^\(.\{128\}\).*/\1/' -e '/\[*$/ s/^/# /p' -e '/\*$/ s/^/# /p' |
zenity --progress --percentage="$PERCENTAGE"  --title="Fixing syslog and auth.log..." \
--width=600 --auto-close )
            if [ $? = 1 ]; then
                zenity --info --title="Lite Upgrade" --text="Error:\n${line}"
            fi    
}

# Set root's Terminal theme - TO BE CHANGED FOR 2.6
ROOTTERTHEM() {
UPDATER=$( stdbuf -oL /bin/bash \-c '(sudo mv /root/.config/lxterminal/lxterminal.conf /root/.config/lxterminal/lxterminal.conf.backup && sudo cp /etc/skel/.config/lxterminal/lxterminal.conf /root/.config/lxterminal/ && sudo chown root:root /root/.config/lxterminal/lxterminal.conf && sleep 2 )' 2>&1 |
stdbuf -oL sed -n -e 's/^\(.\{128\}\).*/\1/' -e '/\[*$/ s/^/# /p' -e '/\*$/ s/^/# /p' |
zenity --progress --percentage="$PERCENTAGE"  --title="Setting Terminal theme..." \
--width=600 --auto-close )
            if [ $? = 1 ]; then
                zenity --info --title="Lite Upgrade" --text="Error:\n${line}"
            fi    
unset UPDATER
}

# Add new Root .bashrc
ADDROOTBASHRC1() {
UPDATER=$( stdbuf -oL /bin/bash \-c '(cd /tmp && wget http://repo.linuxliteos.com/upgrade/bashrc-root-2.6 && sudo mv bashrc-root-2.6 .bashrc && sudo mv /tmp/.bashrc /root && sleep 2 )' 2>&1 |
stdbuf -oL sed -n -e 's/^\(.\{128\}\).*/\1/' -e '/\[*$/ s/^/# /p' -e '/\*$/ s/^/# /p' |
zenity --progress --percentage="$PERCENTAGE"  --title="Adding new Root Terminal theme..." \
--width=600 --auto-close )
unset UPDATER
}

# Update to new login screen
NWLOG() {
UPDATER=$( stdbuf -oL /bin/bash \-c '(cd /tmp && wget https://github.com/linuxlite/litelogin/archive/master.zip && unzip master.zip && sudo cp /tmp/litelogin-master/usr/share/lightdm-webkit/themes/linuxlite/index.theme /usr/share/lightdm-webkit/themes/linuxlite && sudo cp /tmp/litelogin-master/usr/share/lightdm-webkit/themes/linuxlite/index.html /usr/share/lightdm-webkit/themes/linuxlite && sudo cp /tmp/litelogin-master/usr/share/lightdm-webkit/themes/linuxlite/low_contrast_linen.png /usr/share/lightdm-webkit/themes/linuxlite && sudo cp /tmp/litelogin-master/usr/share/lightdm-webkit/themes/linuxlite/style.css /usr/share/lightdm-webkit/themes/linuxlite && sudo rm -rf master.zip && sudo rm -rf litelogin-master/ && sleep 2 )' 2>&1 |
stdbuf -oL sed -n -e 's/^\(.\{128\}\).*/\1/' -e '/\[*$/ s/^/# /p' -e '/\*$/ s/^/# /p' |
zenity --progress --percentage="$PERCENTAGE"  --title="Updating to new login theme..." \
--width=600 --auto-close )
            if [ $? = 1 ]; then
                zenity --info --title="Lite Upgrade" --text="Error:\n${line}"
            fi    
unset UPDATER
return
}

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

if [ "$LLVER" == "2.0" ]; then
    LL20SYSTEM
elif [ "$LLVER" == "2.2" ]; then
    LL22SYSTEM
elif [ "$LLVER" == "2.4" ]; then
    LL24SYSTEM
elif [ "$LLVER" == "2.6" ]; then
    LL26SYSTEM
elif [ "$LLVER" == "2.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
                zenity --error --title="Lite Upgrade" --text="There was an error while performing upgrades:\n ${line}"
                exit 1
            fi    
        let i++
         (( PERCENTAGE = 100 \* ${i} / ${TOTAL_LINES} ))
         echo "$PERCENTAGE"

        if [ "$PERCENTAGE" == "100" ]; then
            echo "#Done"
            sleep 2
        fi
    
    done| zenity --progress  --title="Lite Upgrade" --auto-kill --auto-close --width=300
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
                zenity --info --title="Lite Upgrade" --text="Error:\n${line}"
            fi    
        let i++

        if [ "$PERCENTAGE" == "100" ]; then
            echo "#Done"
            sleep 2
        fi
    
    done
fi

unset ARAYB
unset ARAYC
unset _USER
