New setup ; updater ; more options

This commit is contained in:
Cyrille L 2022-03-24 17:29:18 +01:00
parent b62a523289
commit de3ed9a061
10 changed files with 209 additions and 149 deletions

View File

@ -13,7 +13,9 @@ 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)
- bash
- curl (to check available version)
- rsync (to update files with upd -U)
# How to install
```
@ -22,3 +24,8 @@ cd upd
chmod +x setup.sh
./setup.sh
```
# How to upgrade
```
upd -U
```

View File

@ -1,10 +1,11 @@
#!/bin/bash
# version: 0.0.1
# file: upd.conf
# Folder: /etc/upd
# By echolib
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
app_name="upd"
# local home
upd_dir_home="$HOME/.config/upd"
@ -18,5 +19,5 @@ 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"
repo="https://git.a-lec.org/echolib/upd/-/raw/main/usr/local/bin/upd"
repo_tar="https://git.a-lec.org/echolib/upd/-/archive/main/upd-main.tar.gz"

119
setup.sh
View File

@ -1,8 +1,7 @@
#!/bin/bash
# version: 0.1
# file: setup.sh
# Folder: filebox (from git clone)
# git clone https://git.a-lec.org/echolib/filebox.git
# Folder: upd (from git clone)
# git clone https://git.a-lec.org/echolib/upd.git
# By echolib
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
unset ${!setup_@}
@ -12,19 +11,37 @@ unset ${!setup_@}
#----------------------------------------------------------------------
# Directories to CHOWN -R
set_dir_R_CHO=(
/var/lib/upd
/etc/upd
var/lib/upd
etc/upd
)
# bin Directories: Check ONLY with mkdir -p
setup_dir_bin="/usr/local/bin"
# Directories to check ONLY with mkdir -p
setup_dir_bin="usr/local/bin"
# filename application to CHOWN
setup_file_bin="upd"
# main app name
setup_app_name="upd"
# filename application to CHOWN + CHMOD 755
set_files_R_CHO=(
upd
)
# bin uri
set_bin_uri="$setup_dir_bin/$setup_file_bin"
#======================================================================
#----------------------
# Check commands exists
#----------------------
if__command() {
! [[ `command -v $1` ]] \
&& echo -e "! Missing $1 command" \
&& exit 1
}
if__command sudo
if__command rsync
#------------------------
# Check commands function
#------------------------
@ -42,15 +59,15 @@ fi
#----------------------------------------------------------------------
case "$1" in
remove|-R)
[[ -f "$set_bin_uri" ]] \
&& echo "- Removing $set_bin_uri" \
&& sudo rm -f "$set_bin_uri"
[[ -f "/$set_bin_uri" ]] \
&& echo "- Removing /$set_bin_uri" \
&& sudo rm -f "/$set_bin_uri"
for setup_folder in ${set_dir_R_CHO[@]}
do
[[ -d "$setup_folder" ]] \
&& echo "- Removing $setup_folder" \
&& sudo rm -rf "$setup_folder"
[[ -d "/$setup_folder" ]] \
&& echo "- Removing /$setup_folder" \
&& sudo rm -rf "/$setup_folder"
done
echo "# upd is uninstalled. Thank you for testing."
;;
@ -60,44 +77,44 @@ esac
# Installation Process
#----------------------------------------------------------------------
setup__install() {
for setup_folder in ${set_dir_R_CHO[@]}
do
echo "- Folder: $setup_folder"
setup__gen_process() {
echo "- Folder: /$1"
echo -ne " Created:"
sudo mkdir -p "$setup_folder" \
sudo mkdir -p "/$1" \
&& cmd_res="$?" \
&& setup__check_err
case "$2" in
chdir)
echo -ne " Owner $setup_user:"
sudo chown -R "$setup_user":"$setup_user" "$setup_folder" \
sudo chown -R "$setup_user":"$setup_user" "/$1" \
&& cmd_res="$?" \
&& setup__check_err
;;
esac
echo -ne " Copy files:"
sudo rsync -a "${PWD}$setup_folder/" "$setup_folder/" \
sudo rsync -a "$1/" "/$1/" \
&& cmd_res="$?" \
&& setup__check_err
}
for setup_folder in ${set_dir_R_CHO[@]}
do
setup__gen_process "$setup_folder" chdir
done
echo "- Folder: $setup_dir_bin"
echo -ne " Created:"
sudo mkdir -p "$setup_dir_bin" \
setup__gen_process "$setup_dir_bin"
for setup_file in ${set_files_R_CHO[@]}
do
echo -ne " Owner $setup_user for $setup_file:"
sudo chown "$setup_user":"$setup_user" "/$setup_dir_bin/$setup_file" \
&& 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
sudo chmod 755 "$set_bin_uri"
sudo chmod 755 "/$setup_dir_bin/$setup_file"
done
printf '\n%b\n%b\n%b\n' \
"# Thank you for installing upd." \
@ -105,6 +122,9 @@ printf '\n%b\n%b\n%b\n' \
" Have fun !"
}
#----------------------------------------------------------------------
# MAIN PROCESS
#----------------------------------------------------------------------
# PWD is Not a repo
! [[ -d ".git" ]] \
&& echo "! No repository here" \
@ -113,9 +133,9 @@ printf '\n%b\n%b\n%b\n' \
# Updaate && Check Version
setup_ins_version=`
awk 'NR==2 {print $3}' "$setup_dir_bin/$setup_file_bin" 2>/dev/null`
awk 'NR==2 {print $3}' "/$setup_dir_bin/$setup_file_bin" 2>/dev/null`
setup_new_version=`
awk 'NR==2 {print $3}' "$PWD$setup_dir_bin/$setup_file_bin"`
awk 'NR==2 {print $3}' "$setup_dir_bin/$setup_file_bin" 2>/dev/null`
[[ "$setup_ins_version" == "$setup_new_version" ]] \
&& echo "$setup_file_bin is already up to date" \
@ -123,12 +143,15 @@ awk 'NR==2 {print $3}' "$PWD$setup_dir_bin/$setup_file_bin"`
&& exit 0
# Directory project name (First folder from git clone)
setup_folder_git_name=`basename ${PWD}`
read -rp ": Set $setup_folder_git_name for user ($USER)? " setup_user
read -rp ": Set $setup_app_name for user $USER (Y|n|[set])? " setup_user
case "$setup_user" in
""|Y|y|O|o)
setup_user="$USER"
;;
N|n)
unset ${!setup_@}
exit 1
;;
*)
! [[ `awk -F: '{print $1}' /etc/passwd | grep "$setup_user"` ]] \
&& echo "! No registred user: $setup_user" \
@ -137,18 +160,8 @@ case "$setup_user" in
;;
esac
echo -e "\n# Installation Schema:"
for setup_folder in ${set_dir_R_CHO[@]}
do
printf '%s%s\n' \
"- Folder: $setup_folder " \
"; sudo mkdir -p + sudo chown -R $setup_user:$setup_user"
done
echo "- Folder: $setup_dir_bin ; sudo mkdir -p"
echo "- File: $set_bin_uri ; sudo cp + sudo chown $setup_user:$setup_user"
echo
echo "# Version: $setup_ins_version > $setup_new_version"
echo "# $setup_app_name Version: $setup_ins_version > $setup_new_version"
read -rp "# Ready to install (y|N)? " setup_confirm
case "$setup_confirm" in
Y|y|O|o) setup__install ;;

View File

@ -1,5 +1,5 @@
#!/bin/bash
# version: 0.0.9
# version: 0.0.10
# file: upd
# Folder: /usr/local/bin
# By echolib
@ -27,6 +27,10 @@ case "$2" in
! [[ -f "$1" ]] \
&& touch "$1"
;;
read)
clear
cat "$1"
;;
esac
}
@ -105,14 +109,20 @@ case "$1" in
;;
-vv)
awk 'NR==2 {print "# Installed:",$3}' "/usr/local/bin/upd"
v_cur=`awk 'NR==2 {print $3}' "/usr/local/bin/$app_name"`
echo -n "# $app_name Current: $v_cur | "
if__command curl
curl -s "$upd_repo_upd" | awk 'NR==2 {print "# Available:",$3}'
v_onl=`curl -s "$repo" | awk 'NR==2 {print $3}'`
echo -ne "Online: $v_onl\n"
;;
-U)
if__file "$upd_script_updater" source
upd__Updater
Updater
;;
--readme)
if__file "/var/lib/upd/README.md" read
;;
help|--help|-h|*)

View File

@ -13,7 +13,9 @@ 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)
- bash
- curl (to check available version)
- rsync (to update files with upd -U)
# How to install
```
@ -22,3 +24,8 @@ cd upd
chmod +x setup.sh
./setup.sh
```
# How to upgrade
```
upd -U
```

View File

@ -1,5 +1,4 @@
#!/bin/bash
# version: 0.0.1
# file: check
# Folder: /var/lib/upd/scripts
# By echolib

View File

@ -7,6 +7,7 @@
upd__help() {
cat << EOHELP
# upd : System Updater
--readme : Show readme
check | -c : Check for updates (or just type upd)
list | -l : List updates (Check if none)
-v : Show Installed version

View File

@ -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

View File

@ -7,33 +7,42 @@
#======================================================================
# Automatic Updater
#======================================================================
upd__Updater() {
Updater() {
if__command curl
upd_cur=`awk 'NR==2 {print $3}' "/usr/local/bin/upd"`
upd_onl=`curl -s "$upd_repo_upd" | awk 'NR==2 {print $3}'`
if__command rsync
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" \
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
cd /tmp
curl -L -o upd-main.tar.gz "$upd_repo_tar" 2>/dev/null
! [[ -f "upd-main.tar.gz" ]] \
curl -L -o ${app_name}-main.tar.gz "$repo_tar" 2>/dev/null
! [[ -f "${app_name}-main.tar.gz" ]] \
&& echo "! Download error" \
&& return
tar -xzf upd-main.tar.gz
cd upd-main
tar -xzf ${app_name}-main.tar.gz
cd ${app_name}-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/"
rsync -a --delete "var/lib/${app_name}/" "/var/lib/${app_name}/"
rsync -a --delete "etc/${app_name}/" "/etc/${app_name}/"
# Check
upd_cur=`awk 'NR==2 {print $3}' "/usr/local/bin/upd"`
echo "# upd updated to: $upd_cur"
v_cur=`awk 'NR==2 {print $3}' "/usr/local/bin/$app_name"`
echo "# $app_name updated to: $v_cur"
rm -rf /tmp/upd-main
rm -f upd-main.tar.gz
rm -rf /tmp/${app_name}-main
rm -f ${app_name}-main.tar.gz
}

View File

@ -1,8 +1,7 @@
#!/bin/bash
# version: 0.1
# file: setup.sh
# Folder: filebox (from git clone)
# git clone https://git.a-lec.org/echolib/filebox.git
# Folder: upd (from git clone)
# git clone https://git.a-lec.org/echolib/upd.git
# By echolib
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
unset ${!setup_@}
@ -12,19 +11,37 @@ unset ${!setup_@}
#----------------------------------------------------------------------
# Directories to CHOWN -R
set_dir_R_CHO=(
/var/lib/upd
/etc/upd
var/lib/upd
etc/upd
)
# bin Directories: Check ONLY with mkdir -p
setup_dir_bin="/usr/local/bin"
# Directories to check ONLY with mkdir -p
setup_dir_bin="usr/local/bin"
# filename application to CHOWN
setup_file_bin="upd"
# main app name
setup_app_name="upd"
# filename application to CHOWN + CHMOD 755
set_files_R_CHO=(
upd
)
# bin uri
set_bin_uri="$setup_dir_bin/$setup_file_bin"
#======================================================================
#----------------------
# Check commands exists
#----------------------
if__command() {
! [[ `command -v $1` ]] \
&& echo -e "! Missing $1 command" \
&& exit 1
}
if__command sudo
if__command rsync
#------------------------
# Check commands function
#------------------------
@ -42,15 +59,15 @@ fi
#----------------------------------------------------------------------
case "$1" in
remove|-R)
[[ -f "$set_bin_uri" ]] \
&& echo "- Removing $set_bin_uri" \
&& sudo rm -f "$set_bin_uri"
[[ -f "/$set_bin_uri" ]] \
&& echo "- Removing /$set_bin_uri" \
&& sudo rm -f "/$set_bin_uri"
for setup_folder in ${set_dir_R_CHO[@]}
do
[[ -d "$setup_folder" ]] \
&& echo "- Removing $setup_folder" \
&& sudo rm -rf "$setup_folder"
[[ -d "/$setup_folder" ]] \
&& echo "- Removing /$setup_folder" \
&& sudo rm -rf "/$setup_folder"
done
echo "# upd is uninstalled. Thank you for testing."
;;
@ -60,44 +77,44 @@ esac
# Installation Process
#----------------------------------------------------------------------
setup__install() {
for setup_folder in ${set_dir_R_CHO[@]}
do
echo "- Folder: $setup_folder"
setup__gen_process() {
echo "- Folder: /$1"
echo -ne " Created:"
sudo mkdir -p "$setup_folder" \
sudo mkdir -p "/$1" \
&& cmd_res="$?" \
&& setup__check_err
case "$2" in
chdir)
echo -ne " Owner $setup_user:"
sudo chown -R "$setup_user":"$setup_user" "$setup_folder" \
sudo chown -R "$setup_user":"$setup_user" "/$1" \
&& cmd_res="$?" \
&& setup__check_err
;;
esac
echo -ne " Copy files:"
sudo rsync -a "${PWD}$setup_folder/" "$setup_folder/" \
sudo rsync -a "$1/" "/$1/" \
&& cmd_res="$?" \
&& setup__check_err
}
for setup_folder in ${set_dir_R_CHO[@]}
do
setup__gen_process "$setup_folder" chdir
done
echo "- Folder: $setup_dir_bin"
echo -ne " Created:"
sudo mkdir -p "$setup_dir_bin" \
setup__gen_process "$setup_dir_bin"
for setup_file in ${set_files_R_CHO[@]}
do
echo -ne " Owner $setup_user for $setup_file:"
sudo chown "$setup_user":"$setup_user" "/$setup_dir_bin/$setup_file" \
&& 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
sudo chmod 755 "$set_bin_uri"
sudo chmod 755 "/$setup_dir_bin/$setup_file"
done
printf '\n%b\n%b\n%b\n' \
"# Thank you for installing upd." \
@ -105,6 +122,9 @@ printf '\n%b\n%b\n%b\n' \
" Have fun !"
}
#----------------------------------------------------------------------
# MAIN PROCESS
#----------------------------------------------------------------------
# PWD is Not a repo
! [[ -d ".git" ]] \
&& echo "! No repository here" \
@ -113,9 +133,9 @@ printf '\n%b\n%b\n%b\n' \
# Updaate && Check Version
setup_ins_version=`
awk 'NR==2 {print $3}' "$setup_dir_bin/$setup_file_bin" 2>/dev/null`
awk 'NR==2 {print $3}' "/$setup_dir_bin/$setup_file_bin" 2>/dev/null`
setup_new_version=`
awk 'NR==2 {print $3}' "$PWD$setup_dir_bin/$setup_file_bin"`
awk 'NR==2 {print $3}' "$setup_dir_bin/$setup_file_bin" 2>/dev/null`
[[ "$setup_ins_version" == "$setup_new_version" ]] \
&& echo "$setup_file_bin is already up to date" \
@ -123,12 +143,15 @@ awk 'NR==2 {print $3}' "$PWD$setup_dir_bin/$setup_file_bin"`
&& exit 0
# Directory project name (First folder from git clone)
setup_folder_git_name=`basename ${PWD}`
read -rp ": Set $setup_folder_git_name for user ($USER)? " setup_user
read -rp ": Set $setup_app_name for user $USER (Y|n|[set])? " setup_user
case "$setup_user" in
""|Y|y|O|o)
setup_user="$USER"
;;
N|n)
unset ${!setup_@}
exit 1
;;
*)
! [[ `awk -F: '{print $1}' /etc/passwd | grep "$setup_user"` ]] \
&& echo "! No registred user: $setup_user" \
@ -137,18 +160,8 @@ case "$setup_user" in
;;
esac
echo -e "\n# Installation Schema:"
for setup_folder in ${set_dir_R_CHO[@]}
do
printf '%s%s\n' \
"- Folder: $setup_folder " \
"; sudo mkdir -p + sudo chown -R $setup_user:$setup_user"
done
echo "- Folder: $setup_dir_bin ; sudo mkdir -p"
echo "- File: $set_bin_uri ; sudo cp + sudo chown $setup_user:$setup_user"
echo
echo "# Version: $setup_ins_version > $setup_new_version"
echo "# $setup_app_name Version: $setup_ins_version > $setup_new_version"
read -rp "# Ready to install (y|N)? " setup_confirm
case "$setup_confirm" in
Y|y|O|o) setup__install ;;