Various tweaks

This commit is contained in:
zawz 2020-07-03 14:05:03 +02:00
parent 6f32cfe7e4
commit 355fb99dc1
3 changed files with 38 additions and 29 deletions

View file

@ -11,7 +11,8 @@ Sends notification when the given command finished executing
-t <sec> Time the notification stays. By default 2
-T <title> Notification title
-m <string> Displays this message when finished. Variable resolution on
> Default message is '<command> finished'"
> Default message is '<command> finished'
-y Display a yes/no prompt instead. Time doesn't apply"
}
warning () {
@ -25,42 +26,46 @@ error () {
_args=""
# $1 = message , $2 = time , $3 = title
# $1 = message , $2 = title , $3 = time
notify () {
if which kdialog >/dev/null
then
kdialog --passivepopup "$1" $2 --title "$3"
kdialog --passivepopup "$1" "$3" --title "$2"
elif which notify-send >/dev/null
then
notify-send -t $2 "$3" "$1"
notify-send -t "$3" "$2" "$1"
else echo "No supported notification" >&2 && return 1
fi
}
yesno () {
if which kdialog >/dev/null
then
kdialog --yesno "$1" --title "$2"
elif which zenity
then
zenity --question --text="$1" --title="$2"
else "No supported prompt"
fi
}
# read options
while getopts ":hm:T:t:" opt;
while getopts ":hym:T:t:" opt;
do
case $opt in
h)
usage
exit 0
exit 1
;;
y) _opt_y=y ;;
m)
if [ ! -n "$OPTARG" ]
then
error "m needs an argument"
exit
fi
[ ! -n "$OPTARG" ] && { error "m needs an argument" ; exit 2; }
message=$OPTARG
_opt_m=y
;;
T) title="$OPTARG" ;;
t) _arg_t="$OPTARG" ;;
\?)
echo "Uknown option: $OPTARG"
usage
exit 1
;;
T) title=$OPTARG ;;
t) _arg_t=$OPTARG ;;
\?) echo "Uknown option: $OPTARG" && usage && exit 2 ;;
esac
done
@ -76,4 +81,9 @@ else
[ -z "$title" ] && title="Ping"
fi
notify "$message" $_arg_t "$title"
if [ -n "$_opt_y" ]
then
yesno "$message" "$title"
else
notify "$message" "$title" "$_arg_t"
fi

View file

@ -31,9 +31,9 @@ abort()
exit "$1"
}
APT_PACKAGES="gcc g++ git make cmake libsdl2-dev libicu-dev pkg-config libjansson-dev libspeex-dev libspeexdsp-dev libcurl4-openssl-dev libcrypto++-dev libfontconfig1-dev libfreetype6-dev libpng-dev libssl-dev libzip-dev duktape-dev"
APT_PACKAGES="gcc g++ git make cmake libsdl2-dev libicu-dev pkg-config libjansson-dev libspeex-dev libspeexdsp-dev libcurl4-openssl-dev libcrypto++-dev libfontconfig1-dev libfreetype6-dev libpng-dev libssl-dev libzip-dev"
DNF_PACKAGES="gcc gcc-c++ jansson-devel openssl-devel SDL2-devel libicu-devel speexdsp-devel libcurl-devel cmake fontconfig-devel freetype-devel libpng-devel libzip-devel mesa-libGL-devel"
PACMAN_PACKAGES="gcc gcc-libs git cmake sdl2 fontconfig libzip libpng curl jansson speexdsp openssl icu duktape"
PACMAN_PACKAGES="gcc gcc-libs git cmake sdl2 fontconfig libzip libpng curl jansson speexdsp openssl icu"
echo_white "Installing packages"
if which apt >/dev/null 2>&1

View file

@ -2,7 +2,7 @@
linuxpkgnames=""
lock_file=/tmp/update.lock
lock_file=/tmp/sysupdate.lock
get_running_programs()
{
@ -22,17 +22,18 @@ stop()
fetch_error()
{
echo "Error: Could not fetch packages" > /dev/stderr
kdialog --passivepopup "Error during system updates: could not fetch packages" 60 --title "System Updates"
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" > /dev/stderr
kdialog --passivepopup "Error during system updates: could not upgrade" 60 --title "System Updates"
znotif -T "System updates" -t 120 -m "Error during system updates: could not upgrade"
stop 3
}
which zupdate >/dev/null || { echo "zupdate not installed" >&2; exit 4; }
# Check if another process is running
if [ -n "$(pgrep zupdate)" ] || [ -f "$lock_file" ]
@ -42,8 +43,6 @@ then
fi
touch "$lock_file"
which zupdate >/dev/null || { echo "zupdate not installed" >&2; stop 4; }
# package manager specific variables
if which apt >/dev/null 2>&1
then
@ -72,17 +71,17 @@ fi
running_programs=$(get_running_programs "$packages")
if [ -n "$running_programs" ]
then
if ! kdialog --yesno "The following running programs have recieved updates: \n$(echo "$running_programs" | sed 's|^| - |g')" --yes-label "Continue" --no-label "Cancel" --title "Updates"
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" > /dev/stderr
stop 3
fi
fi
kdialog --passivepopup "Installing updates for $size download" 10 --title "System Updates"
znotif -T "System Updates" -t 10 -m "Installing updates for $size download"
#update
zupdate -yu || update_error
#end update
kdialog --passivepopup "Updates finished" 5 --title "System Updates"
znotif -T "System Updates" -t 5 -m "Updates finished"
stop 0