You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
158 lines
4.9 KiB
158 lines
4.9 KiB
#!/bin/bash
|
|
# Description: This script ask user for update system
|
|
ENABLED=no
|
|
[[ ${ENABLED} == "yes" ]] || exit 0
|
|
|
|
DEBUGMODE=no
|
|
. /usr/lib/ublinux/functions
|
|
. /usr/lib/ublinux/default
|
|
debug_mode "$0" "$@"
|
|
|
|
SOURCE=${SYSCONF}/config; [ -f ${SOURCE} ] && . ${SOURCE} 2>/dev/null
|
|
SOURCE=${SYSCONF}/update; [ -f ${SOURCE} ] && . ${SOURCE} 2>/dev/null
|
|
|
|
|
|
function stopstatus()
|
|
{
|
|
[ "$VERBOSE" = "1" -a "$STATUSPID" != "" ] && kill $STATUSPID 2>/dev/null && STATUSPID=
|
|
}
|
|
|
|
function dialogreboot()
|
|
{
|
|
MSG01=$(gettext -s "System update is over")
|
|
MSG02=$(gettext -s "System updated. Please reboot computer.")
|
|
MSG03=$(gettext -s "Reboot now")
|
|
MSG04=$(gettext -s "No, i will reboot later")
|
|
CHOISE=$(Xdialog --title "$MSG01" --radiolist "$MSG02" 0 0 3 "1" "$MSG03" on "2" "$MSG04" off 2>&1 | tail -1)
|
|
[ "$CHOISE" = "1" ] || exit 0
|
|
systemctl reboot
|
|
reboot
|
|
}
|
|
|
|
function dialogrevert()
|
|
{
|
|
stopstatus
|
|
MSG01=$(gettext -s "It's possible to revert update.")
|
|
MSG02=$(gettext -s "System started from backup version currently.")"\n"$(gettext -s "If you have a problems with new version, you can revert update.")"\n"$(gettext -s "Do you want to remove new version and switch to old one?")
|
|
MSG03=$(gettext -s "Yes, downgrade back to old version now")
|
|
MSG04=$(gettext -s "No, do nothing right now")
|
|
CHOISE=$(Xdialog --title "$MSG01" --radiolist "$MSG02" 0 0 3 "1" "$MSG03" off "2" "$MSG04" on 2>&1 | tail -1)
|
|
[ "$CHOISE" = "1" ] && return 0
|
|
return 1
|
|
}
|
|
|
|
function dialogerrorlog()
|
|
{
|
|
stopstatus
|
|
MSG01=$(gettext -s "Update was unsuccessful.")
|
|
cat $LOGFILE-$(id -u).log $LOGFILE-0.log > $LOGFILE.log 2>/dev/null
|
|
Xdialog --title "$MSG01" --no-cancel --textbox $LOGFILE.log 0 0
|
|
exit 1
|
|
}
|
|
|
|
function dialognoupdates()
|
|
{
|
|
stopstatus
|
|
MSG01=$(gettext -s "System update")
|
|
MSG02=$(gettext -s "Updates were not found at server.")
|
|
Xdialog --title "$MSG01" --msgbox "$MSG02" 0 0
|
|
}
|
|
|
|
function errorexit()
|
|
{
|
|
stopstatus
|
|
if [ "$VERBOSE" = "1" ] ;then
|
|
MSG01=$(gettext -s "Error")
|
|
MSG02=$(gettext -s "$1")
|
|
Xdialog --title "$MSG01" --msgbox "$MSG02" 0 0
|
|
else
|
|
echo $1
|
|
fi
|
|
exit 1
|
|
}
|
|
|
|
# $1 text string
|
|
function dialogupdate()
|
|
{
|
|
stopstatus
|
|
MSG01=$(gettext -s "Please select")
|
|
MSG02=$(gettext -s "$1")
|
|
MSG03=$(gettext -s "Do you want to update it now?")
|
|
MSG04=$(gettext -s "Yes, right now")
|
|
MSG05=$(gettext -s "No, later")
|
|
MSG06=$(gettext -s "Never, don't ask me again")
|
|
CHOISE=$(Xdialog --title "$MSG01" --radiolist "$MSG02\n$MSG03" 0 0 4 "1" "$MSG04" on "2" "$MSG05" off "3" "$MSG06" off 2>&1 | tail -1)
|
|
if [ "$CHOISE" = "3" ] ;then
|
|
touch $UBLINUXPATH/.dontupdateublinux 2>/dev/null || touch $HOME/.config/.dontupdateublinux
|
|
fi
|
|
[ "$CHOISE" = "1" ] && return 0
|
|
return 1
|
|
}
|
|
|
|
export TEXTDOMAINDIR=/usr/share/locale
|
|
export TEXTDOMAIN=ublinux_functions
|
|
echo $PATH | grep -q /usr/lib/ublinux/scripts || PATH=/usr/lib/ublinux/scripts:$PATH
|
|
. /usr/lib/os-release
|
|
. /usr/lib/ublinux/functions
|
|
. /usr/lib/ublinux/default
|
|
SOURCE=${SYSCONF}/config; [ -f ${SOURCE} ] && . ${SOURCE} 2>/dev/null
|
|
DEBUGMODE=no
|
|
debug_mode "$0" "$@"
|
|
LOGFILE=/tmp/ublinuxupdate
|
|
|
|
UBLINUXPATH=/mnt/livemedia/ublinux
|
|
[ -f /mnt/live/etc/modules ] && . /mnt/live/etc/modules
|
|
[ ! -z "$UBLINUXMODS" -a -d "$UBLINUXMODS/base" ] && UBLINUXPATH="$UBLINUXMODS"
|
|
[ -f "$UBLINUXPATH/vmlinuz" -a -d "$UBLINUXPATH/base" ] || errorexit "Can't find system folder"
|
|
|
|
NEEDREBOOT=0
|
|
[ "$1" = "--verbose" ] && VERBOSE=1
|
|
grep -q "ub.from=ublinux.bak" /proc/cmdline && RUNFROMBACKUP=1
|
|
|
|
if [ "$VERBOSE" = "1" ] ;then
|
|
MSG01=$(gettext -s "System update")
|
|
MSG02=$(gettext -s "Please wait. Connecting to server...")
|
|
Xdialog --title "$MSG01" --no-close --no-buttons --infobox "\n$MSG02\n" 0 0 990000 2>/dev/null &
|
|
STATUSPID=$!
|
|
fi
|
|
|
|
#check for readonly filesystem
|
|
ublinuxupdate --checkdir || errorexit "Can't find system folder"
|
|
|
|
if [ "$RUNFROMBACKUP" != "1" ] ;then
|
|
#check for internet connection
|
|
if [ "$VERBOSE" = "1" ] ;then
|
|
ping -c 1 -W 1 77.88.8.8 >/dev/null 2>&1 || errorexit "Not connected to internet"
|
|
else
|
|
#check if update is disabled or auto
|
|
echo $UBLINUXUPDATE | grep -qi ^ask$ || exit 0
|
|
[ -f $UBLINUXPATH/.dontupdateublinux -o -f $HOME/.config/.dontupdateublinux ] && exit 0
|
|
fi
|
|
ublinuxupdate --checkserver || errorexit "Can't connect with server"
|
|
fi
|
|
|
|
#check for updates
|
|
MSG01=$(gettext -s "New version of")" $PRETTY_NAME "$(gettext -s "is detected on server.")
|
|
MSG02=$(gettext -s "New updates for")" $PRETTY_NAME "$(gettext -s "are detected on server.")
|
|
if ublinuxupdate --checknewversion ;then
|
|
if dialogupdate "$MSG01" ;then
|
|
ublinuxupdate --updateversion || dialogerrorlog
|
|
grep -qi "please reboot" ${LOGFILE}-*.log && NEEDREBOOT=1
|
|
fi
|
|
elif ublinuxupdate --checkupdates ;then
|
|
if dialogupdate "$MSG02" ;then
|
|
ublinuxupdate --updatebase || dialogerrorlog
|
|
grep -qi "please reboot" ${LOGFILE}-*.log && NEEDREBOOT=1
|
|
fi
|
|
elif [ "$RUNFROMBACKUP" = "1" ] ;then
|
|
dialognoupdates
|
|
if dialogrevert ;then
|
|
ublinuxupdate --revertversion || dialogerrorlog
|
|
NEEDREBOOT=1
|
|
fi
|
|
elif [ "$VERBOSE" = "1" ] ;then
|
|
dialognoupdates
|
|
fi
|
|
|
|
[ "$NEEDREBOOT" = "1" ] && dialogreboot
|