From 07b69b20a7aefd3b10d58000bd56923149ce5c79 Mon Sep 17 00:00:00 2001 From: Cyrille L Date: Wed, 29 Jun 2022 15:27:20 +0200 Subject: [PATCH] Version 0.1.2 (news for arch users) --- README.md | 2 +- usr/local/bin/upd | 97 +++++++++---------------------- var/lib/upd/README.md | 2 +- var/lib/upd/scripts/check | 65 +++++++++++++++------ var/lib/upd/scripts/help | 38 ++++++------ var/lib/upd/scripts/upgrader | 108 ++++++++++++++++++++++++++++++++--- 6 files changed, 195 insertions(+), 117 deletions(-) diff --git a/README.md b/README.md index df3a933..79a873e 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ updates). More functions will be added soon... # Dependancies - bash - curl (to check available version) -- rsync (to update files with upd -U) +- rsync (to update upd files with upd -U) # How to install ``` diff --git a/usr/local/bin/upd b/usr/local/bin/upd index b706083..6fe6e8a 100755 --- a/usr/local/bin/upd +++ b/usr/local/bin/upd @@ -1,5 +1,5 @@ #!/bin/bash -# version: 0.1.1 +# version: 0.1.2 # file: upd # Folder: /usr/local/bin # By echolib @@ -21,12 +21,15 @@ case "$2" in ! [[ -f "$1" ]] \ && echo "# Missing file: $1" \ && exit + source "$1" ;; + create) ! [[ -f "$1" ]] \ && touch "$1" ;; + read) clear cat "$1" @@ -41,10 +44,12 @@ if ! [[ -d "$1" ]];then mkdir -p "$1" if__folder "$1" check ;; + check) echo "! Missing folder: $1" exit ;; + *) echo "! Missing folder: $1" exit @@ -56,11 +61,13 @@ fi if__arch() { if [[ `command -v apt` ]];then arch="apt" + elif [[ `command -v pacman` ]];then arch="pacman" if__command "checkupdates" [[ `command -v yay` ]] \ && aur=yay + else echo "! upd is not yet ready for this System" exit @@ -76,6 +83,8 @@ if__file "/etc/upd/upd.conf" source if__file "$upd_script_tools" source if__file "$upd_script_updater" source if__file "$upd_script_check" source +if__file "$upd_script_upgrader" source +if__file "$upd_script_help" source if__folder "$upd_dir_home" make if__file "$upd_file_check" create @@ -85,74 +94,20 @@ if__file "$upd_file_check" create && if__file "$upd_file_check_aur" create case "$1" in - "") - upd check - ;; - - check|-c) - echo -ne "# Checking for updates..." - case "$arch" in - pacman) - upd__check arch - ;; - apt) - upd__check deb - ;; - esac - ;; - - -cr) - upd_cr=true - upd__check_reboot - ;; - - list|-l) - (( `cat "$upd_file_check" | wc -l` > 0 )) \ - && upd__prepare_show \ - || upd -c - ;; - - version|-v) - awk 'NR==2 {print "# Installed:",$3}' "/usr/local/bin/upd" - ;; - - -vv) - script__versions - ;; - - -vvv) - verbose=true - script__versions - ;; - - -U) - Updater - ;; - - -u) - if__file "$upd_script_upgrader" source - sysup="system" - upg__main - ;; - - -f) - if__file "$upd_script_upgrader" source - sysup="full" - upg__main - ;; - - -a) - if__file "$upd_script_upgrader" source - sysup="aur" - upg__main - ;; - - readme) - if__file "/var/lib/upd/README.md" read - ;; - - help|--help|-h|*) - if__file "$upd_script_help" source - upd__help - ;; + readme) if__file "/var/lib/upd/README.md" read ;; + help|--help|-h) upd__help ;; + ""|check|-c) check__OPTIONS ;; + clean|-C) clean__OPTIONS ;; + -cr) upd_cr=true;upd__check_reboot ;; + list|-l) upd__list ;; + version|-v) awk 'NR==2 {print "# Installed:",$3}' "/usr/local/bin/upd" ;; + -vv) script__versions ;; + -vvv) verbose=true;script__versions ;; + -U) Updater ;; + -u) sysup="system";upg__main ;; + -f) sysup="full";upg__main ;; + --arch_mirror|-am) arch__mirror ;; + --arch-repair|-ar) arch__mirror;arch__repair ;; + -A) sysup="aur";upg__main ;; + *) echo "! Bad argument '$1' : see upd --help" ;; esac diff --git a/var/lib/upd/README.md b/var/lib/upd/README.md index df3a933..79a873e 100644 --- a/var/lib/upd/README.md +++ b/var/lib/upd/README.md @@ -15,7 +15,7 @@ updates). More functions will be added soon... # Dependancies - bash - curl (to check available version) -- rsync (to update files with upd -U) +- rsync (to update upd files with upd -U) # How to install ``` diff --git a/var/lib/upd/scripts/check b/var/lib/upd/scripts/check index dfa6e78..cc28777 100644 --- a/var/lib/upd/scripts/check +++ b/var/lib/upd/scripts/check @@ -4,16 +4,36 @@ # By echolib # License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 + #====================================================================== -# Check for updates if archlinux +# Check for updates #====================================================================== -upd__check() { -case "$1" in - arch) upd__check_arch ;; - deb) upd__check_deb +check__OPTIONS() { +echo -ne "# Checking for updates..." +case "$arch" in + pacman) upd__check_arch ;; + apt) upd__sudoroot;upd__check_deb ;; esac } + +#====================================================================== +# Cleaning System +#====================================================================== +clean__OPTIONS() { +upd__sudoroot +clear +echo "# Cleaning System..." +case "$arch" in + pacman) upd__clean_arch ;; + apt) upd__clean_deb ;; +esac +} + + +#====================================================================== +# Check for updates from ArchLinux +#====================================================================== upd__check_arch() { checkupdates > "$upd_file_check" @@ -24,13 +44,12 @@ checkupdates > "$upd_file_check" upd__prepare_show } + #====================================================================== -# Check for updates if debian (apt based) +# Check for updates from {deb]ian #====================================================================== upd__check_deb() { echo -upd__sudoroot # Tools: Check if user is admin - sudo apt-get update -qq upd_file_tmp_apt=`mktemp` @@ -38,10 +57,10 @@ sudo apt list --upgradable -a 2>/dev/null \ | grep "now" \ > "$upd_file_tmp_apt" - # Converting datas [[ -f "$upd_file_check" ]] \ && rm -f "$upd_file_check" + touch "$upd_file_check" while read -r "pkg" "old" "new" do @@ -55,6 +74,7 @@ rm -f "$upd_file_tmp_apt" upd__prepare_show } + #====================================================================== # Check and show if reboot is required #====================================================================== @@ -68,11 +88,10 @@ upd__check_reboot() { # if erboot case "$arch" in pacman) - [[ `uname -r | sed 's/-/./'` \ - != `pacman -Q linux | sed 's/linux //'` \ - ]] \ - && upd__reboot_set + [[ `uname -r` == `file /boot/vmlinuz-linux | awk '{print $9}'` ]] \ + || upd__reboot_set ;; + apt) [[ -f /var/run/reboot-required ]] \ && upd__reboot_set @@ -80,16 +99,13 @@ case "$arch" in esac # Reboot message only: if called from option -cr -if [[ $upd_cr ]];then - if [[ $upd_reboot ]];then +if [[ $upd_cr ]] && [[ $upd_reboot ]];then echo -e "$upd_reboot" exit 137 - else - exit 0 - fi fi } + #====================================================================== # Prepare datas to show & show resume #====================================================================== @@ -131,6 +147,7 @@ printf '%b%b%b\n' \ "$upd_reboot" } + #====================================================================== # Show updates & resume #====================================================================== @@ -155,11 +172,13 @@ do C_Color="$C_Yellow" upd__filters ;; + *) case "$1" in "$upd_file_check") list="-" ;; + "$upd_file_check_aur") list="+" ;; @@ -174,3 +193,13 @@ cat "$upd_file_tmp" | column -t -s'|' echo rm -f "$upd_file_tmp" } + + +#====================================================================== +# Show updates & resume +#====================================================================== +upd__list() { +(( `cat "$upd_file_check" | wc -l` > 0 )) \ + && upd__prepare_show \ + || echo "! No packages found. Try upd check" +} diff --git a/var/lib/upd/scripts/help b/var/lib/upd/scripts/help index b9da4a4..04981ca 100644 --- a/var/lib/upd/scripts/help +++ b/var/lib/upd/scripts/help @@ -6,25 +6,29 @@ upd__help() { cat << EOHELP -# upd : System Updater (check for updates and show them) - readme : Show readme - check | -c : Check for updates (or just type upd) - -cr : Put upd -cr in bashrc profile to check if reboot needed - (useless if you put upd) - list | -l : List updates (Check if none) - -v : Show Installed version - -vv : Show if new version available - -vvv : + online version - -U : Check and Update upd +# upd : System Updater (check and show updates) + readme : Show readme + check | -c : Check for updates (or just type upd) + -cr : Check if reboot is required + (also done with command upd) + list | -l : List updates + -v : Show Installed version + -vv : Show if new version available + -vvv : + online version + -U : Check and Update upd + clean | -C : Clean logs, old unnsed dependancies, some cache - [arch] - -u : update system only - -f : update system + AUR - -a : update AUR packages only + [archlinux] + -u : update system only + -f : update system + AUR + -A : update AUR packages only + --arch_mirror | -am : update mirrorlist only + --arch-repair | -ar : update mirrors, archlinux-keyrings, clean + and update system (not AUR) - [deb] - -u : upgrade - -f : full-upgrade + [debian] + -u : upgrade + -f : full-upgrade EOHELP } diff --git a/var/lib/upd/scripts/upgrader b/var/lib/upd/scripts/upgrader index e2765ec..6d6b137 100644 --- a/var/lib/upd/scripts/upgrader +++ b/var/lib/upd/scripts/upgrader @@ -4,8 +4,9 @@ # By echolib # License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 + #====================================================================== -# Upgrade system +# Upgrade system manager from command #====================================================================== upg__main() { case "$sysup" in @@ -19,6 +20,7 @@ case "$sysup" in upg__arch_system ;; + apt) clear upd__check_deb @@ -74,13 +76,16 @@ rm -f "$upd_file_check" rm -f "$upd_file_check_aur" } + +#====================================================================== +# ArchLinux: upgrade packages fom Legacy only +#====================================================================== upg__arch_system() { [[ -f /var/lib/pacman/db.lck ]] \ && echo -e "$I_Red System is locked: /var/lib/pacman/db.lck" \ && return upd__sudoroot # Tools: Check if user is admin - echo "# Syncing..." sudo pacman -Sy &>/dev/null @@ -96,17 +101,25 @@ echo -e "$I_Yellow Upgrading System...\n" sudo pacman -Su --noconfirm --needed $upd_pkg_upg } + +#====================================================================== +# ArchLinux: upgrade packages fom AUR only +#====================================================================== upg__arch_aur() { upd__sudoroot # Tools: Check if user is admin -if [[ "$aur" == "yay" ]];then - echo -e "$I_Yellow Upgrading AUR packages...\n" - yay -Syu --aur --save --sudoloop \ - --nocleanmenu --nodiffmenu --noeditmenu --noupgrademenu -else - echo "$I_Red Not using yay ; abandon" -fi +! [[ "$aur" == "yay" ]] \ + && echo "$I_Red Not using yay ; abandon" \ + && exit + +echo -e "$I_Yellow Upgrading AUR packages...\n" +yay -Syu --aur --save --sudoloop \ + --nocleanmenu --nodiffmenu --noeditmenu --noupgrademenu } + +#====================================================================== +# [deb]ian : aliases +#====================================================================== upg__deb_upgrade() { sudo apt upgrade -y } @@ -114,3 +127,80 @@ sudo apt upgrade -y upg__deb_full_upgrade() { sudo apt full-upgrade -y } + + +#====================================================================== +# ArchLinux: update mirrorlist, doing backup +#====================================================================== +arch__mirror() { +! [[ "$arch" == "pacman" ]] \ + && echo "! System is not archlinux" \ + && exit + +upd__sudoroot +! [[ `command -v reflector` ]] \ + && echo "! Missing: reflector ; Try: pacman -S reflector rsync curl" \ + && exit + +if [[ -f "/etc/pacman.d/mirrorlist.bak" ]];then + echo "! A backup already exists: /etc/pacman.d/mirrorlist.bak" + echo "> Backing up mirrorlist: /etc/pacman.d/mirrorlist.upd" + sudo cp -f /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.upd +else + echo "> Backing up mirrorlist: /etc/pacman.d/mirrorlist.bak" + sudo cp -f /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.bak +fi + +echo "! Getting new mirrors..." +sudo reflector --latest 10 \ + --protocol https \ + --sort rate \ + --download-timeout 4 \ + --save /etc/pacman.d/mirrorlist +} + + +#====================================================================== +# ArchLinux: Ty to Repair +#====================================================================== +arch__repair() { +echo "! Repairing archlinux keys..." +sudo pacman -Sy archlinux-keyring +echo "! Cleaning cache..." +sudo pacman -Scc + +sysup="system" +upg__main +} + + +#====================================================================== +# Cleaing commons +#====================================================================== +upd__clean_commons() { +sudo journalctl --vacuum-time=3d +echo +[[ -d "~/.cache/" ]] \ + && sudo du -sh ~/.cache/ \ + && rm -rf ~/.cache/* \ + && echo +} + + +#====================================================================== +# Cleaing arch +#====================================================================== +upd__clean_arch() { +upd__clean_commons +sudo pacman -Sc +sudo pacman -Rns $(pacman -Qtdq) +} + + +#====================================================================== +# Cleaing deb +#====================================================================== +upd__clean_deb() { +upd__clean_commons +sudo apt autoremovee +}