From 909bfe6de697556f0b667b1e403202d0e790e9cc Mon Sep 17 00:00:00 2001 From: Cyrille L Date: Thu, 24 Mar 2022 11:40:21 +0100 Subject: [PATCH] New: updater ; fix setup --- README.md | 3 +++ etc/upd/upd.conf | 9 ++++++++- setup.sh | 18 ++++++++++------- usr/local/bin/upd | 17 ++++++++++++++-- var/lib/upd/README.md | 3 +++ var/lib/upd/scripts/help | 6 ++++-- var/lib/upd/scripts/tools | 2 +- var/lib/upd/scripts/updater | 39 +++++++++++++++++++++++++++++++++++++ var/lib/upd/setup.sh | 18 ++++++++++------- 9 files changed, 95 insertions(+), 20 deletions(-) create mode 100644 var/lib/upd/scripts/updater diff --git a/README.md b/README.md index 74a1c5e..37f4130 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,9 @@ doing for now, is checking for updates and showing packages old and new version for debian and archlinux (separrating AUR and System available updates). More functions will be added soon... +# Dependancies +- curl (to check available version and let upd -U update himself) + # How to install ``` git clone https://git.a-lec.org/echolib/upd diff --git a/etc/upd/upd.conf b/etc/upd/upd.conf index 88b6e8e..d3212ed 100644 --- a/etc/upd/upd.conf +++ b/etc/upd/upd.conf @@ -8,8 +8,15 @@ # local home upd_dir_home="$HOME/.config/upd" -# Script +# Files upd_file_check="$upd_dir_home/check" upd_file_check_aur="$upd_dir_home/check_aur" + +# Script upd_script_check="/var/lib/upd/scripts/check" upd_script_help="/var/lib/upd/scripts/help" +upd_script_updater="/var/lib/upd/scripts/updater" + +# Onlinde Repo +upd_repo_upd="https://git.a-lec.org/echolib/upd/-/raw/main/usr/local/bin/upd" +upd_repo_tar="https://git.a-lec.org/echolib/upd/-/archive/main/upd-main.tar.gz" diff --git a/setup.sh b/setup.sh index 3300f9a..baa47aa 100644 --- a/setup.sh +++ b/setup.sh @@ -84,21 +84,25 @@ echo -ne " Created:" sudo mkdir -p "$setup_dir_bin" \ && cmd_res="$?" \ && setup__check_err - + echo "- File: $setup_file_bin" +echo -ne " Copy $PWD$set_bin_uri + chmod 755:" +sudo cp -f "$PWD$set_bin_uri" \ + "$set_bin_uri" \ + && cmd_res="$?" \ + && setup__check_err + echo -ne " Owner $setup_user:" sudo chown "$setup_user":"$setup_user" "$set_bin_uri" \ && cmd_res="$?" \ && setup__check_err -echo -ne " Copy $PWD$set_bin_uri:" -sudo cp -f "$PWD$set_bin_uri" \ - "$set_bin_uri" \ - && cmd_res="$?" \ - && setup__check_err sudo chmod 755 "$set_bin_uri" -echo -e "\n# Thank you for installing upd. Have fun !" +printf '\n%b\n%b\n%b\n' \ + "# Thank you for installing upd." \ + " (You can remove the repo and use upd -U to update)" \ + " Have fun !" } # PWD is Not a repo diff --git a/usr/local/bin/upd b/usr/local/bin/upd index d6dcad9..055d9c1 100755 --- a/usr/local/bin/upd +++ b/usr/local/bin/upd @@ -1,5 +1,5 @@ #!/bin/bash -# version: 0.0.6 +# version: 0.0.7 # file: upd # Folder: /usr/local/bin # By echolib @@ -95,10 +95,23 @@ case "$1" in && upd__prepare_show \ || upd -c ;; + + version|-v) + awk 'NR==2 {print "# Installed:",$3}' "/usr/local/bin/upd" + ;; + + -vv) + awk 'NR==2 {print "# Installed:",$3}' "/usr/local/bin/upd" + curl -s "$upd_repo_upd" | awk 'NR==2 {print "# Available:",$3}' + ;; + + -U) + if__file "$upd_script_updater" source + upd__Updater + ;; help|--help|-h|*) if__file "$upd_script_help" source upd__help ;; esac - diff --git a/var/lib/upd/README.md b/var/lib/upd/README.md index 74a1c5e..37f4130 100644 --- a/var/lib/upd/README.md +++ b/var/lib/upd/README.md @@ -12,6 +12,9 @@ doing for now, is checking for updates and showing packages old and new version for debian and archlinux (separrating AUR and System available updates). More functions will be added soon... +# Dependancies +- curl (to check available version and let upd -U update himself) + # How to install ``` git clone https://git.a-lec.org/echolib/upd diff --git a/var/lib/upd/scripts/help b/var/lib/upd/scripts/help index b297e8d..a306370 100644 --- a/var/lib/upd/scripts/help +++ b/var/lib/upd/scripts/help @@ -1,7 +1,6 @@ #!/bin/bash -# version: 0.0.1 # file: help -# Folder: /var/lib/upd/scripts +# Folder: /var/lib/upd/scripts/ # By echolib # License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 @@ -10,5 +9,8 @@ cat << EOHELP # upd : System Updater check | -c : Check for updates list | -l : List updates (Check if none) + -v : Show Installeed version + -vv : Show Installed and Available versions + -U : Check and Update upd EOHELP } diff --git a/var/lib/upd/scripts/tools b/var/lib/upd/scripts/tools index 0ea0ddd..e22bcc2 100644 --- a/var/lib/upd/scripts/tools +++ b/var/lib/upd/scripts/tools @@ -1,6 +1,6 @@ #!/bin/bash # file: tools -# Folder: /var/lib/filebox/scripts +# Folder: /var/lib/filebox/scripts/ # By echolib # License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 diff --git a/var/lib/upd/scripts/updater b/var/lib/upd/scripts/updater new file mode 100644 index 0000000..d16e0a8 --- /dev/null +++ b/var/lib/upd/scripts/updater @@ -0,0 +1,39 @@ +#!/bin/bash +# file: updater +# Folder: /var/lib/upd/scripts/ +# By echolib +# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 + +#====================================================================== +# Automatic Updater +#====================================================================== +upd__Updater() { +upd_cur=`awk 'NR==2 {print $3}' "/usr/local/bin/upd"` +upd_onl=`curl -s "$upd_repo_upd" | awk 'NR==2 {print $3}'` + +printf -v versions '%s\n%s' "$upd_cur" "$upd_onl" +[[ `sort -V <<< "$versions" | tail -1` == $upd_cur ]] \ + && echo "# upd is up to date. Current: $upd_cur | Online: $upd_onl" \ + && return + +# Get archive +cd /tmp +curl -L -o upd-main.tar.gz "$upd_repo_tar" 2>/dev/null +if [[ -f "upd-main.tar.gz" ]];then + tar -xzf upd-main.tar.gz + cd upd-main + rsync -a --delete "usr/local/bin/" "/usr/local/bin" + rsync -a --delete "var/lib/upd/" "/var/lib/upd/" + rsync -a --delete "etc/upd/" "/etc/upd/" + + # Check + upd_cur=`awk 'NR==2 {print $3}' "/usr/local/bin/upd"` + echo "# upd updated to: $upd_cur" + + rm -rf /tmp/upd-main + rm -f upd-main.tar.gz +else + echo "! Download error" +fi + +} diff --git a/var/lib/upd/setup.sh b/var/lib/upd/setup.sh index 3300f9a..baa47aa 100644 --- a/var/lib/upd/setup.sh +++ b/var/lib/upd/setup.sh @@ -84,21 +84,25 @@ echo -ne " Created:" sudo mkdir -p "$setup_dir_bin" \ && cmd_res="$?" \ && setup__check_err - + echo "- File: $setup_file_bin" +echo -ne " Copy $PWD$set_bin_uri + chmod 755:" +sudo cp -f "$PWD$set_bin_uri" \ + "$set_bin_uri" \ + && cmd_res="$?" \ + && setup__check_err + echo -ne " Owner $setup_user:" sudo chown "$setup_user":"$setup_user" "$set_bin_uri" \ && cmd_res="$?" \ && setup__check_err -echo -ne " Copy $PWD$set_bin_uri:" -sudo cp -f "$PWD$set_bin_uri" \ - "$set_bin_uri" \ - && cmd_res="$?" \ - && setup__check_err sudo chmod 755 "$set_bin_uri" -echo -e "\n# Thank you for installing upd. Have fun !" +printf '\n%b\n%b\n%b\n' \ + "# Thank you for installing upd." \ + " (You can remove the repo and use upd -U to update)" \ + " Have fun !" } # PWD is Not a repo