[eos-bash-shared] many small apps: notify if yad is not installed; also small fixes

This commit is contained in:
manuel
2024-08-01 19:03:50 +03:00
parent 15d7f9e7ce
commit 39f2f1228a
10 changed files with 180 additions and 53 deletions
+2 -4
View File
@@ -29,10 +29,8 @@ export -f Restart_me
yad_ChangeDisplayResolution() {
local reso="$1"
local progname="${BASH_SOURCE[1]}" # "$(basename $0)"
if ! type xrandr >& /dev/null ; then
DIE "this implementation needs package 'xorg-xrandr'."
fi
local progname=${0##*/}
eos-assert-deps $progname xorg-xrandr yad || return 1
local query="$(xrandr --query)"
local output="$(echo "$query" | grep -m1 " connected " | awk '{print $1}')"
local xrandr="xrandr --output $output --mode"
+2
View File
@@ -187,6 +187,8 @@ Main()
local retval=0
local oldies
eos-assert-deps $progname yad || return 1
[ -n "$implementation_default" ] || implementation_default=git
# options will override the default values
+1
View File
@@ -6,6 +6,7 @@ UserWants() {
case "$user_wants" in
cli | both) [ "$1" = "cli" ] && return 0 ;;
esac
which yad &>/dev/null || return 1
case "$user_wants" in
gui | both) [ "$1" = "gui" ] && return 0 ;;
esac
+50 -2
View File
@@ -31,16 +31,64 @@ source /etc/eos-script-lib-yad.conf # for EOS_ROOTER and other configs
export EOS_WICON=/usr/share/endeavouros/EndeavourOS-icon.png
export EOS_YAD_STARTER_CMD="/usr/bin/yad --window-icon=$EOS_WICON"
eos_yad() {
GDK_BACKEND=x11 $EOS_YAD_STARTER_CMD "$@"
eos_yad_orig() { GDK_BACKEND=x11 $EOS_YAD_STARTER_CMD "$@"; }
eos_yad_chk() { # eos_yad() with a check that the required 'yad' package is installed
if [ -x /usr/bin/yad ] ; then
eos_yad_orig "$@"
else
echo "${BASH_SOURCE[1]##*/}: error: this app requires package 'yad'" >&2
exit 1
fi
}
case "$EOS_USE_TEST_FOR_YAD" in
yes) eos_yad() { eos_yad_chk "$@" ; } ;;
*) eos_yad() { eos_yad_orig "$@" ; } ;;
esac
translations_dir=/usr/share/endeavouros/scripts # needed in translations.bash
source $translations_dir/translations.bash || {
echo "$translations_dir/translations.bash not found!" >&2
exit 1
}
yad_missing_check() {
if [ "${EOS_YAD_MISSING_NOTIFICATION^^}" = "YES" ] ; then
if ! which yad &>/dev/null ; then
local app="$1"
local timeout="$2"
[ "$timeout" ] || timeout=10000
local msg="Some operations require yad installed."
eos_notification "$ICO_INFO" normal $timeout "$app" "Notification from $app" "$msg"
fi
fi
}
eos-assert-deps() { # params: prog deps
local -r prog="$1"
shift
local failcount=0
local dep
for dep in "$@" ; do
which "$dep" &>/dev/null || {
echo "==> $prog requires package '$dep'" >&2
((failcount++))
}
done
return $failcount
}
eos-assert-deps-fast() { # params: prog deps
local -r prog="$1"
shift
local failcount=0
which "$@" &>/dev/null || {
failcount=$?
echo "==> $prog: missing $failcount of packages: $*"
}
return $failcount
}
eos_icon_path() {
# on success, echo full icon path and return 0
# on failure, return 1
+4
View File
@@ -216,3 +216,7 @@ EOS_LOCATION_PROVIDER_URL="https://ipinfo.io"
## will be shown after updating certain system packages.
## Supported values: "yes" (=default) or "no".
EOS_REBOOT_RECOMMENDING=yes
## EOS_YAD_MISSING_NOTIFICATION specifies whether some EndeavourOS apps show a notification
## when 'yad' might be needed but is not installed.
EOS_YAD_MISSING_NOTIFICATION=yes
+23 -9
View File
@@ -94,6 +94,27 @@ ReopenStdin() {
fi
}
CanUseYad() {
# check if yad exists, and if so, can we use it
local -n _use_yad="$1"
if expac -Q %n yad >/dev/null ; then
_use_yad=yes # yad is installed
if [ "$EUID" = "0" ] && eos_is_in_chroot ; then
_use_yad=no # don't use yad in chroot
else
case "$XDG_SESSION_TYPE" in
tty) _use_yad=no ;; # tty does not support yad
x11) [ "$DISPLAY" ] || _use_yad=no ;; # no DISPLAY, no yad
wayland-*) [ "$WAYLAND_DISPLAY" ] || _use_yad=no ;; # same with wayland
esac
fi
else
_use_yad=no # yad is not installed
fi
}
Main() {
local -r progname="${0##*/}"
local -r log=/tmp/tmp.$progname.log
@@ -106,21 +127,14 @@ Main() {
termbin
)
local expire=7 # this initial value here will always be overwritten by eos-sendlog
local yad=yes
local yad=""
local infile=""
local commands=""
local stdin_needs_opening=no
source /usr/share/endeavouros/scripts/eos-script-lib-yad || exit 1
if [ "$EUID" = "0" ] && eos_is_in_chroot ; then
yad=no
else
case "$XDG_SESSION_TYPE" in
x11) [ "$DISPLAY" ] || yad=no ;;
wayland-*) [ "$WAYLAND_DISPLAY" ] || yad=no ;;
esac
fi
CanUseYad yad
while [ "$1" ] ; do
case "$1" in
+1
View File
@@ -39,6 +39,7 @@ Main()
x86_64) ;;
*) DIE "This program is supported only on x86_64 machines." ;; # because of mirrors...
esac
eos-assert-deps $progname yad || return 1
local date=$(/usr/bin/date +%Y%m%d-%H%M) # for temporary backup file
local stopdate="$(/usr/bin/date +%Y/%m/%d)" # for checking if user selected this date
local mlist=/etc/pacman.d/mirrorlist
+90 -36
View File
@@ -21,7 +21,52 @@ Cmd() { # Show a command, run it, and exit on issues.
"$@" || DIE "'$*' failed."
}
MirrorCheckResult() {
local ml="$1"
local ret=0
echo2 "==> $ml contains:"
echo2 " known mirrors: ${#supported[@]}"
if [ ${#unsupported[@]} -eq 0 ] ; then
echo2 " unknown mirrors: 0"
else
echo2 " unknown or offline mirrors: ${#unsupported[@]}"
printf "%s\n" "${unsupported[@]}" | sed 's|^| Server = |'
fi
[ ${#unsupported[@]} -eq 0 ] && [ ${#supported[@]} -gt 0 ] # create the return code, 0=success, 1=fail
}
Hardware-x86_64() { [ $(eos_GetArch) = x86_64 ] || DIE "sorry, this implementation supports only x86_64 environment"; }
CheckYourArchMirrorlist() {
Hardware-x86_64
local url="https://archlinux.org/mirrorlist/?use_mirror_status=on"
local lm
local all_working_mirrors
local local_mirrors
local supported=()
local unsupported=()
# get working mirrors from the Arch mirrorlist page
all_working_mirrors=$(curl --fail -Lsm 30 "$url") || DIE "failed to fetch available mirrors (curl code $?)"
[ "$all_working_mirrors" ] || DIE "-> archlinux.org/mirrorlist failed"
readarray -t all_working_mirrors <<< $(echo "$all_working_mirrors" | tail -n +7 | grep "^#Server = " | awk '{print $NF}')
# get mirrors from local mirrorlist
readarray -t local_mirrors <<< $(grep "^[ \t]*Server[ \t]*=[ \t]*" $aml | awk '{print $NF}')
for lm in "${local_mirrors[@]}" ; do
if printf "%s\n" "${all_working_mirrors[@]}" | grep "$lm" >/dev/null ; then
supported+=("$lm")
else
unsupported+=("$lm")
fi
done
MirrorCheckResult $aml
}
CheckYourEndeavourosMirrorlist() {
Hardware-x86_64
local -r mirrors=( # for downloading the latest endeavouros-mirrorlist package
https://mirror.alpix.eu/endeavouros/repo/endeavouros/x86_64 # Germany
https://mirror.moson.org/endeavouros/repo/endeavouros/x86_64 # Germany
@@ -29,7 +74,6 @@ CheckYourEndeavourosMirrorlist() {
)
local url data
local -r tmpfile=/tmp/eos-ml.p
local -r eml=/etc/pacman.d/endeavouros-mirrorlist
local good_mirrors local_mirrors
local lm
local unsupported=() supported=()
@@ -54,7 +98,8 @@ CheckYourEndeavourosMirrorlist() {
url+="/$data"
curl -Lsm 30 -o$tmpfile $url
good_mirrors=$(tar xvf $tmpfile etc/pacman.d/endeavouros-mirrorlist -O 2>/dev/null | grep "^Server = " | sed 's|^Server = ||')
good_mirrors=$(tar xvf $tmpfile ${eml:1} -O 2>/dev/null | grep "^Server = " | sed 's|^Server = ||')
rm -f $tmpfile
local_mirrors=$(grep "^[ \t]*Server[ \t]*=[ \t]*" $eml | sed 's|^Server = ||')
for lm in $local_mirrors ; do
@@ -64,16 +109,7 @@ CheckYourEndeavourosMirrorlist() {
unsupported+=($lm)
fi
done
echo2 "Statistics from file $eml:"
echo2 "* contains ${#supported[@]} known mirror definitions."
printf2 "* contains ${#unsupported[@]} unknown mirror definitions"
if [ ${#unsupported[@]} -eq 0 ] ; then
echo2 "."
else
echo2 ":"
printf "%s\n" "${unsupported[@]}" | sed 's|^| Server = |'
fi
rm -f $tmpfile
MirrorCheckResult $eml
return
fi
@@ -108,7 +144,7 @@ OptionCheck() {
Options() {
local opts
local lopts="aur,clear-databases,dump-options,keyrings-reset,nvidia,nvidia-auto,no-keyring,no-sync,helper:,min-free-bytes:,paru,yay,pacman,help"
lopts+=",show-only-fixed,show-upstream-news,check-mirrors-eos"
lopts+=",show-only-fixed,show-upstream-news,check-mirrors-arch,check-mirrors-eos,check-mirrors"
local sopts="h"
opts="$(/usr/bin/getopt -o=$sopts --longoptions $lopts --name "$progname" -- "$@")" || {
@@ -117,9 +153,19 @@ Options() {
}
eval set -- "$opts"
local ret=0
while true ; do
case "$1" in
--check-mirrors-eos) CheckYourEndeavourosMirrorlist; exit ;;
--check-mirrors) CheckYourEndeavourosMirrorlist || ((ret++))
CheckYourArchMirrorlist || ((ret++))
exit $ret
;;
--check-mirrors-arch) CheckYourArchMirrorlist || ((ret++))
exit $ret
;;
--check-mirrors-eos) CheckYourEndeavourosMirrorlist || ((ret++))
exit $ret
;;
--nvidia) OptionCheck "$1" && nvidia=yes ;;
--no-keyring) keyring=no ;;
--no-sync) sync=":" ;;
@@ -157,38 +203,44 @@ Essentially runs commands 'pacman -Syu' and optionally 'yay -Sua' or 'paru -Sua'
$progname includes (by default) special help in the following situations:
- A dangling pacman db lock file (/var/lib/pacman/db.lck).
- Disk space availability for updates (with a configurable minimum space).
- Keyring package updating before others.
- Keyring package updating before updating other packages.
- Running the 'sync' command after update.
Optional help:
- Can clear package databases in case of contant problems with them.
- Can reset keyrings in case of constant problems with them.
- Can check the validity of the locally configured lists of mirrors.
- Updates AUR packages (with option --helper, see Usage below).
- Ad hoc check for Nvidia GPU driver vs. kernel updates (non-dkms only).
Usage: $progname [options]
Options:
--help, -h This help.
--check-mirrors-eos Check file /etc/pacman.d/endeavouros-mirrorlist for unsupported mirrors.
--nvidia Check also nvidia driver vs. kernel updates. Useful only with the Nvidia GPU.
--clear-databases Clears package database files.
Use this only if package database issues constantly make system update fail.
--keyrings-reset Resets Arch and EndeavourOS keyrings.
Use this only if keyring issues constantly make system update fail.
--no-keyring Do not try to update keyrings first.
--no-sync Do not run 'sync' after update.
--show-only-fixed Show only packages that have already been fixed (runs: arch-audit -u) and exit.
--show-upstream-news Show the news page of the upstream site and exit.
--helper AUR helper name. Supported: yay, paru, pacman.
Default: pacman
Other AUR helpers supporting option -Sua like yay should work as well.
--paru Same as --helper=paru.
--yay Same as --helper=yay.
--aur Uses the AUR helper configured in /etc/eos-script-lib-yad.conf.
--pacman Same as --helper=pacman. Default. (Note: pacman does not support AUR directly).
--min-free-bytes Minimum amount of free space (in bytes) that the root partition should have
before updating. Otherwise a warning message will be displayed.
Default: $min_free_bytes
--help, -h This help.
--check-mirrors Check files $eml and $aml
for unsupported mirrors.
This may be useful when one or more mirrors start failing unexpectedly.
Note: only x86_64 hardware is supported.
--check-mirrors-eos Check files $eml for unsupported mirrors.
--check-mirrors-arch Check files $aml for unsupported mirrors.
--nvidia Check also nvidia driver vs. kernel updates. Useful only with the Nvidia GPU.
--clear-databases Clears package database files.
Use this only if package database issues constantly make system update fail.
--keyrings-reset Resets Arch and EndeavourOS keyrings.
Use this only if keyring issues constantly make system update fail.
--no-keyring Do not try to update keyrings first.
--no-sync Do not run 'sync' after update.
--show-only-fixed Show only packages that have already been fixed (runs: arch-audit -u) and exit.
--show-upstream-news Show the news page of the upstream site and exit.
--helper AUR helper name. Supported: yay, paru, pacman.
Default: pacman
Other AUR helpers supporting option -Sua like yay should work as well.
--paru Same as --helper=paru.
--yay Same as --helper=yay.
--aur Uses the AUR helper configured in /etc/eos-script-lib-yad.conf.
--pacman Same as --helper=pacman. Default. (Note: pacman does not support AUR directly).
--min-free-bytes Minimum amount of free space (in bytes) that the root partition should have
before updating. Otherwise a warning message will be displayed.
Default: $min_free_bytes
Tip: create an alias in file ~/.bashrc for eos-update to have the options you need, for example:
@@ -252,6 +304,8 @@ Main() {
local nvidia=no # user may enable Nvidia check with --nvidia
local nvidia_opt=""
local sync="sync"
local -r eml=/etc/pacman.d/endeavouros-mirrorlist
local -r aml=/etc/pacman.d/mirrorlist
local -r RED=$'\e[0;91m'
local -r GREEN=$'\e[0;92m'
+6 -2
View File
@@ -33,12 +33,14 @@ Untagged() { echo "$1" | sed -e 's|<[/]*[ib]>||g' ; }
eos_yad_infomsg() {
local msg="$1"
Untagged "$msg" >&2
which yad &>/dev/null && \
eos_yad --form --text="$(Monospaced "$msg")" --title="Message" --tail --wrap --image=info \
--button=yad-quit:0 "$@"
}
DIE() {
Untagged "$1" >&2
which yad &>/dev/null && \
eos_yad --form --text="$(Monospaced "$1")\n" --title="$progname: error" \
--width=400 \
--image=error --button=yad-ok:0
@@ -56,8 +58,8 @@ WallpaperSelect() {
height=$hmin
fi
eos-assert-deps $progname yad || exit 1
pic="$(eos_yad --file --filename="$picfolder" --width=700 --height=$height --title="Choose wallpaper file")"
test $? -eq 0 || exit 1
}
XfceSetWallpaper() {
@@ -323,12 +325,14 @@ EOF
Main()
{
local progname="$(basename "$0")"
local progname=${0##*/}
local DE="$(eos_GetDeOrWm)"
local picfolder=/usr/share/endeavouros/backgrounds
local pic=""
local history_of_backgrounds="$HOME/.$progname.history-of-wallpapers" # saves history of wallpaper file names
yad_missing_check $progname
case "$DE" in
XFCE) type xrandr >& /dev/null || DIE "Sorry, this implementation needs package 'xorg-xrandr' on Xfce." ;;
esac
+1
View File
@@ -88,6 +88,7 @@ AddCommand() {
_paccache_cleaner_manager()
{
local progname=paccache-service-manager
eos-assert-deps $progname yad || return 1
local dir=/etc/systemd/system
local dir2=/usr/lib/systemd/system # current values may be only here...
local service=$dir/paccache.service