90 lines
1.9 KiB
Bash
Executable file
90 lines
1.9 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
linuxpkgnames=""
|
|
|
|
[ -z "$TMPDIR" ] && TMPDIR=/tmp
|
|
|
|
lock_file="$TMPDIR/sysupdate.lock"
|
|
|
|
get_running_programs()
|
|
{
|
|
echo "$*" | tr '-' '_' | grep -qwE "$(echo "$linuxpkgnames" | tr '-' '_')" && echo linux
|
|
for I in $*
|
|
do
|
|
pgrep -xi "$I" >/dev/null && echo $I
|
|
done
|
|
}
|
|
|
|
stop()
|
|
{
|
|
rm "$lock_file"
|
|
exit $1
|
|
}
|
|
|
|
fetch_error()
|
|
{
|
|
echo "Error: Could not fetch packages" >&2
|
|
znotif -T "System updates" -t 120 -m "Error during system updates: could not fetch packages"
|
|
stop 3
|
|
}
|
|
|
|
update_error()
|
|
{
|
|
echo "Error: Could not upgrade system" >&2
|
|
znotif -T "System updates" -t 120 -m "Error during system updates: could not upgrade"
|
|
stop 3
|
|
}
|
|
|
|
which zupdate >/dev/null 2>&1 || { echo "zupdate not installed" >&2; exit 4; }
|
|
which znotif >/dev/null 2>&1 || { echo "znotif not installed" >&2; exit 4; }
|
|
|
|
# Check if another process is running
|
|
if [ -n "$(pgrep zupdate)" ] || [ -f "$lock_file" ]
|
|
then
|
|
echo "Updates are already running" >&2
|
|
exit 1
|
|
fi
|
|
touch "$lock_file"
|
|
|
|
# package manager specific variables
|
|
if which apt >/dev/null 2>&1
|
|
then
|
|
linuxpkgnames="linux-image-.*"
|
|
elif which pacman > /dev/null 2>&1
|
|
then
|
|
linuxpkgnames="linux|linux-hardened|linux-lts|linux-zen|linux-mainline|linux-rt|linux-git|linux-next"
|
|
else
|
|
echo "Unsupported package manager" >&2
|
|
stop 2
|
|
fi
|
|
|
|
#fetch updates
|
|
|
|
size=$(zupdate -Mkd) || fetch_error
|
|
|
|
packages=$(zupdate -L | cut -d' ' -f1) || fetch_error
|
|
|
|
if [ -z "$packages" ]
|
|
then
|
|
echo "No updates"
|
|
stop 0
|
|
fi
|
|
|
|
# find running updates
|
|
running_programs=$(get_running_programs "$packages")
|
|
if [ -n "$running_programs" ]
|
|
then
|
|
if ! znotif -T "System Updates" -y -m "The following running programs have recieved updates: \n$(echo "$running_programs" | sed 's|^| - |g')\nProceed?"
|
|
then
|
|
echo "Update cancelled" >&2
|
|
stop 5
|
|
fi
|
|
fi
|
|
|
|
znotif -T "System Updates" -t 10 -m "Installing updates for $size download"
|
|
#update
|
|
zupdate -yu || update_error
|
|
#end update
|
|
znotif -T "System Updates" -t 5 -m "Updates finished"
|
|
|
|
stop 0
|