From 47f8ac76298a9df697a7239a1b9c6d3503e26866 Mon Sep 17 00:00:00 2001 From: Cyrille L Date: Wed, 30 Mar 2022 11:01:08 +0200 Subject: [PATCH] New: archlinux user can upgrade system --- etc/upd/upd.conf | 1 + usr/local/bin/upd | 12 ++++++++++- var/lib/upd/scripts/check | 2 +- var/lib/upd/scripts/tools | 3 +++ var/lib/upd/scripts/upgrader | 42 ++++++++++++++++++++++++++++++++++++ 5 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 var/lib/upd/scripts/upgrader diff --git a/etc/upd/upd.conf b/etc/upd/upd.conf index 185c567..e46feab 100644 --- a/etc/upd/upd.conf +++ b/etc/upd/upd.conf @@ -18,6 +18,7 @@ upd_script_check="/var/lib/upd/scripts/check" upd_script_help="/var/lib/upd/scripts/help" upd_script_tools="/var/lib/upd/scripts/tools" upd_script_updater="/var/lib/upd/scripts/updater" +upd_script_upgrader="/var/lib/upd/scripts/upgrader" # Onlinde Repo repo="https://git.a-lec.org/echolib/upd/-/raw/main/usr/local/bin/upd" diff --git a/usr/local/bin/upd b/usr/local/bin/upd index f56e44c..3ad0928 100755 --- a/usr/local/bin/upd +++ b/usr/local/bin/upd @@ -1,5 +1,5 @@ #!/bin/bash -# version: 0.0.14 +# version: 0.0.15 # file: upd # Folder: /usr/local/bin # By echolib @@ -119,6 +119,16 @@ case "$1" in Updater ;; + -u) + if__file "$upd_script_upgrader" source + case "$arch" in + pacman) + upd__check_arch + upg__arch + ;; + esac + ;; + readme) if__file "/var/lib/upd/README.md" read ;; diff --git a/var/lib/upd/scripts/check b/var/lib/upd/scripts/check index 42f18f9..2daab46 100644 --- a/var/lib/upd/scripts/check +++ b/var/lib/upd/scripts/check @@ -12,7 +12,7 @@ checkupdates > "$upd_file_check" # if arch AUR with yay [[ "$aur" == "yay" ]] \ - && yay -Qu > "$upd_file_check_aur" + && yay -Qu --aur > "$upd_file_check_aur" upd__prepare_show } diff --git a/var/lib/upd/scripts/tools b/var/lib/upd/scripts/tools index e46f393..bccff25 100644 --- a/var/lib/upd/scripts/tools +++ b/var/lib/upd/scripts/tools @@ -94,5 +94,8 @@ case "$is_admin" in echo "! No admin rights" exit 1 ;; + sudo-1) + sudo -v + ;; esac } diff --git a/var/lib/upd/scripts/upgrader b/var/lib/upd/scripts/upgrader new file mode 100644 index 0000000..bddbfe6 --- /dev/null +++ b/var/lib/upd/scripts/upgrader @@ -0,0 +1,42 @@ +#!/bin/bash +# file: upgrader +# Folder: /var/lib/upd/scripts/ +# By echolib +# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 + +#====================================================================== +# script version checker +#====================================================================== +upg__arch() { + +(( $upd_nbr == 0 )) && (( $upd_nbr_aur == 0 )) \ + && echo "# No updates available" \ + && exit 0 + +[[ -f /var/lib/pacman/db.lck ]] \ + && printf '%b%b\n' \ + "$I_Red System is upgrading... " \ + "or pacman is locked (/var/lib/pacman/db.lck)" \ + && return + +upd__sudoroot # Tools: Check if user is admin +echo "# Syncing..." +sudo pacman -Sy &>/dev/null +echo -ne "\r\033[2K" + +upd_pkg_upg="--ignore=linux --ignore=linux-headers" +if [[ `grep "^linux-" "$upd_file_check"` ]];then + read -rp "! Upgrade Kernel (y|N)? " upd_arch_ask + case "$upd_arch_ask" in + Y|y) unset upd_pkg_upg ;; + *) true ;; + esac +fi + +echo -e "${I_Yellow} Upgrading System...\n" +sudo pacman -Su --needed $upd_pkg_upg + +if [[ "$aur" == "yay" ]] && (( $upd_nbr_aur > 0 ));then + yay -Syu --save --sudoloop --nocleanmenu --nodiffmenu +fi +}