New version : fixes

This commit is contained in:
Cyrille L 2022-03-28 15:19:19 +02:00
parent df9a099520
commit 1b69849f85
6 changed files with 114 additions and 42 deletions

View File

@ -16,6 +16,7 @@ upd_file_check_aur="$upd_dir_home/check_aur"
# Script # Script
upd_script_check="/var/lib/upd/scripts/check" upd_script_check="/var/lib/upd/scripts/check"
upd_script_help="/var/lib/upd/scripts/help" 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_updater="/var/lib/upd/scripts/updater"
# Onlinde Repo # Onlinde Repo

View File

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
# version: 0.0.11 # version: 0.0.12
# file: upd # file: upd
# Folder: /usr/local/bin # Folder: /usr/local/bin
# By echolib # By echolib
@ -70,17 +70,20 @@ fi
#====================================================================== #======================================================================
# Main # Main
#====================================================================== #======================================================================
if__file "/etc/upd/upd.conf" source
if__file "/var/lib/upd/scripts/tools" source
if__arch if__arch
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__folder "$upd_dir_home" make if__folder "$upd_dir_home" make
if__file "$upd_file_check" create if__file "$upd_file_check" create
# create specific db file for aur packages
[[ "$aur" == "yay" ]] \ [[ "$aur" == "yay" ]] \
&& if__file "$upd_file_check_aur" create && if__file "$upd_file_check_aur" create
if__file "$upd_script_check" source
case "$1" in case "$1" in
"") "")
upd check upd check
@ -109,19 +112,14 @@ case "$1" in
;; ;;
-vv) -vv)
v_cur=`awk 'NR==2 {print $3}' "/usr/local/bin/$app_name"` script__versions
echo -n "# $app_name Current: $v_cur | "
if__command curl
v_onl=`curl -s "$repo" | awk 'NR==2 {print $3}'`
echo -ne "Online: $v_onl\n"
;; ;;
-U) -U)
if__file "$upd_script_updater" source
Updater Updater
;; ;;
--readme) readme)
if__file "/var/lib/upd/README.md" read if__file "/var/lib/upd/README.md" read
;; ;;

View File

@ -21,6 +21,8 @@ upd__prepare_show
# Check for updates if debian (apt based) # Check for updates if debian (apt based)
#====================================================================== #======================================================================
upd__check_deb() { upd__check_deb() {
upd__sudoroot # Tools: Check if user is admin
sudo apt-get update -qq sudo apt-get update -qq
upd_file_tmp_apt=`mktemp` upd_file_tmp_apt=`mktemp`
@ -46,6 +48,13 @@ upd__prepare_show
#====================================================================== #======================================================================
upd__prepare_show() { upd__prepare_show() {
echo -ne "\r\033[2K" echo -ne "\r\033[2K"
upd -vv
echo
upd__reboot_set() {
upd_reboot="$Pp_Grey ${C_Red}Reboot$NC required"
upd_inf="$I_Red"
}
# if erboot # if erboot
case "$arch" in case "$arch" in
@ -53,12 +62,11 @@ case "$arch" in
[[ `uname -r | sed 's/-/./'` \ [[ `uname -r | sed 's/-/./'` \
!= `pacman -Q linux | sed 's/linux //'` \ != `pacman -Q linux | sed 's/linux //'` \
]] \ ]] \
&& upd_reboot="$Pp_Grey ${C_Red}Reboot$NC needed" \ && upd__reboot_set
&& upd_inf="$I_Red"
;; ;;
apt) apt)
[[ -f /var/run/reboot-required ]] \ [[ -f /var/run/reboot-required ]] \
&& upd_reboot="$Pp_Grey ${C_Red}Reboot$NC needed" && upd__reboot_set
;; ;;
esac esac
@ -100,11 +108,11 @@ upd__show() {
upd__filters() { upd__filters() {
printf '%b%b%b%b%b\n' \ printf '%b%b%b%b%b\n' \
"${C_Color}$list${NC} " \ "$C_Color$list$NC " \
"${C_Color}$pkg${NC}|" \ "$C_Color$pkg$NC|" \
"${C_Yellow}$old${NC}|" \ "$C_Yellow$old$NC|" \
"${C_Grey}$sep${NC}|" \ "$C_Grey$sep$NC|" \
"${C_Green}$new${NC}" \ "$C_Green$new$NC" \
>> "$upd_file_tmp" >> "$upd_file_tmp"
} }
@ -114,7 +122,7 @@ do
case "$pkg" in case "$pkg" in
linux*) linux*)
list="!" list="!"
C_Color="${C_Yellow}" C_Color="$C_Yellow"
upd__filters upd__filters
;; ;;
*) *)
@ -126,7 +134,7 @@ do
list="+" list="+"
;; ;;
esac esac
C_Color="${NC}" C_Color="$NC"
upd__filters upd__filters
;; ;;
esac esac

View File

@ -7,11 +7,11 @@
upd__help() { upd__help() {
cat << EOHELP cat << EOHELP
# upd : System Updater # upd : System Updater
--readme : Show readme readme : Show readme
check | -c : Check for updates (or just type upd) check | -c : Check for updates (or just type upd)
list | -l : List updates (Check if none) list | -l : List updates (Check if none)
-v : Show Installed version -v : Show Installed version
-vv : Show Installed and Available versions -vv : Show if new version available
-U : Check and Update upd -U : Check and Update upd
EOHELP EOHELP
} }

View File

@ -39,3 +39,60 @@ Bo_Grey="\e[2m(\e[0m"
Bc_Grey="\e[2m)\e[0m" Bc_Grey="\e[2m)\e[0m"
Pp_Grey="\e[2m|\e[0m" Pp_Grey="\e[2m|\e[0m"
Dp_Grey="\e[2m:\e[0m" Dp_Grey="\e[2m:\e[0m"
#======================================================================
# Set $is_admin : Is user Root or Sudo ?
#======================================================================
isadmin() {
is__admin_show() {
echo -e "$isa_c $USER ${C_Grey}has$NC $user_admin"
}
if_admin=`id -u`
if (( $if_admin )) && (( $if_admin == 0 ));then
is_admin="${C_Red}root$NC"
user_admin=$is_admin
isa_c="$I_Red"
is__admin_show
return
fi
if ! [[ `command -v sudo` ]];then
is_admin="user"
user_admin="${C_Cyan}NO rights$NC"
isa_c="$I_Cyan"
is__admin_show
return
fi
user_prompt=`sudo -nv 2>&1`
code_return="$?"
if (( $code_return == 1 ));then
is_admin="sudo-1"
user_admin="${C_Green}no rights yet$NC"
isa_c="$I_Green"
else
is_admin="sudo-0"
user_admin="${C_Yellow}rights$NC"
isa_c="$I_Yellow"
fi
is__admin_show
}
#======================================================================
# Continue if root / sudo
#======================================================================
upd__sudoroot() {
if__command sudo
# Check if sudo rights
isadmin
case "$is_admin" in
user)
echo "! No admin rights"
exit 1
;;
esac
}

View File

@ -4,26 +4,34 @@
# By echolib # By echolib
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 # License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
#======================================================================
# script version checker
#======================================================================
script__versions() {
if__command curl
v_cur=`awk 'NR==2 {print $3}' "/usr/local/bin/$app_name"`
v_onl=`curl -s "$repo" | awk 'NR==2 {print $3}'`
! [[ $v_onl ]] \
&& echo "! Unknown available version" \
&& exit 1
printf -v versions '%s\n%s' "$v_cur" "$v_onl"
if [[ `sort -V <<< "$versions" | tail -1` == $v_cur ]];then
echo "# $app_name is up to date (version: $v_cur)"
exit 0
else
echo -e "- $app_name $C_Yellow$v_cur$NC -> $C_Green$v_onl$NC"
fi
}
#====================================================================== #======================================================================
# Automatic Updater # Automatic Updater
#====================================================================== #======================================================================
Updater() { Updater() {
if__command curl
if__command rsync if__command rsync
script__versions
v_cur=`awk 'NR==2 {print $3}' "/usr/local/bin/$app_name"`
echo -n "# $app_name Current: $v_cur | "
v_onl=`curl -s "$repo" | awk 'NR==2 {print $3}'`
if ! [[ $v_onl ]];then
echo -ne "Online: Unknown\n"
exit 1
else
echo -ne "Online: $v_onl\n"
fi
printf -v versions '%s\n%s' "$v_cur" "$v_onl"
[[ `sort -V <<< "$versions" | tail -1` == $v_cur ]] \
&& return
# Get archive # Get archive
cd /tmp cd /tmp
@ -34,9 +42,9 @@ curl -L -o ${app_name}-main.tar.gz "$repo_tar" 2>/dev/null
tar -xzf ${app_name}-main.tar.gz tar -xzf ${app_name}-main.tar.gz
cd ${app_name}-main cd ${app_name}-main
rsync -a --delete "usr/local/bin/" "/usr/local/bin" rsync -a "usr/local/bin/" "/usr/local/bin"
rsync -a --delete "var/lib/${app_name}/" "/var/lib/${app_name}/" rsync -a --delete "var/lib/$app_name/" "/var/lib/$app_name/"
rsync -a --delete "etc/${app_name}/" "/etc/${app_name}/" rsync -a --delete "etc/$app_name/" "/etc/$app_name/"
# Check # Check
v_cur=`awk 'NR==2 {print $3}' "/usr/local/bin/$app_name"` v_cur=`awk 'NR==2 {print $3}' "/usr/local/bin/$app_name"`