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 <sec> Time the notification stays. By default 2
-T <title> Notification title -T <title> Notification title
-m <string> Displays this message when finished. Variable resolution on -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 () { warning () {
@ -25,42 +26,46 @@ error () {
_args="" _args=""
# $1 = message , $2 = time , $3 = title # $1 = message , $2 = title , $3 = time
notify () { notify () {
if which kdialog >/dev/null if which kdialog >/dev/null
then then
kdialog --passivepopup "$1" $2 --title "$3" kdialog --passivepopup "$1" "$3" --title "$2"
elif which notify-send >/dev/null elif which notify-send >/dev/null
then then
notify-send -t $2 "$3" "$1" notify-send -t "$3" "$2" "$1"
else echo "No supported notification" >&2 && return 1 else echo "No supported notification" >&2 && return 1
fi 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 # read options
while getopts ":hm:T:t:" opt; while getopts ":hym:T:t:" opt;
do do
case $opt in case $opt in
h) h)
usage usage
exit 0 exit 1
;; ;;
y) _opt_y=y ;;
m) m)
if [ ! -n "$OPTARG" ] [ ! -n "$OPTARG" ] && { error "m needs an argument" ; exit 2; }
then
error "m needs an argument"
exit
fi
message=$OPTARG message=$OPTARG
_opt_m=y _opt_m=y
;; ;;
T) title="$OPTARG" ;; T) title=$OPTARG ;;
t) _arg_t="$OPTARG" ;; t) _arg_t=$OPTARG ;;
\?) \?) echo "Uknown option: $OPTARG" && usage && exit 2 ;;
echo "Uknown option: $OPTARG"
usage
exit 1
;;
esac esac
done done
@ -76,4 +81,9 @@ else
[ -z "$title" ] && title="Ping" [ -z "$title" ] && title="Ping"
fi 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" 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" 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" echo_white "Installing packages"
if which apt >/dev/null 2>&1 if which apt >/dev/null 2>&1

View file

@ -2,7 +2,7 @@
linuxpkgnames="" linuxpkgnames=""
lock_file=/tmp/update.lock lock_file=/tmp/sysupdate.lock
get_running_programs() get_running_programs()
{ {
@ -22,17 +22,18 @@ stop()
fetch_error() fetch_error()
{ {
echo "Error: Could not fetch packages" > /dev/stderr 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 stop 3
} }
update_error() update_error()
{ {
echo "Error: Could not upgrade system" > /dev/stderr 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 stop 3
} }
which zupdate >/dev/null || { echo "zupdate not installed" >&2; exit 4; }
# Check if another process is running # Check if another process is running
if [ -n "$(pgrep zupdate)" ] || [ -f "$lock_file" ] if [ -n "$(pgrep zupdate)" ] || [ -f "$lock_file" ]
@ -42,8 +43,6 @@ then
fi fi
touch "$lock_file" touch "$lock_file"
which zupdate >/dev/null || { echo "zupdate not installed" >&2; stop 4; }
# package manager specific variables # package manager specific variables
if which apt >/dev/null 2>&1 if which apt >/dev/null 2>&1
then then
@ -72,17 +71,17 @@ fi
running_programs=$(get_running_programs "$packages") running_programs=$(get_running_programs "$packages")
if [ -n "$running_programs" ] if [ -n "$running_programs" ]
then 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 then
echo "Update cancelled" > /dev/stderr echo "Update cancelled" > /dev/stderr
stop 3 stop 3
fi fi
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 #update
zupdate -yu || update_error zupdate -yu || update_error
#end update #end update
kdialog --passivepopup "Updates finished" 5 --title "System Updates" znotif -T "System Updates" -t 5 -m "Updates finished"
stop 0 stop 0