New setup ; updater ; more options
This commit is contained in:
parent
b62a523289
commit
de3ed9a061
|
@ -13,7 +13,9 @@ version for debian and archlinux (separrating AUR and System available
|
||||||
updates). More functions will be added soon...
|
updates). More functions will be added soon...
|
||||||
|
|
||||||
# Dependancies
|
# 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
|
# How to install
|
||||||
```
|
```
|
||||||
|
@ -22,3 +24,8 @@ cd upd
|
||||||
chmod +x setup.sh
|
chmod +x setup.sh
|
||||||
./setup.sh
|
./setup.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
|
# How to upgrade
|
||||||
|
```
|
||||||
|
upd -U
|
||||||
|
```
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# version: 0.0.1
|
|
||||||
# file: upd.conf
|
# file: upd.conf
|
||||||
# Folder: /etc/upd
|
# Folder: /etc/upd
|
||||||
# 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
|
||||||
|
|
||||||
|
app_name="upd"
|
||||||
|
|
||||||
# local home
|
# local home
|
||||||
upd_dir_home="$HOME/.config/upd"
|
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"
|
upd_script_updater="/var/lib/upd/scripts/updater"
|
||||||
|
|
||||||
# Onlinde Repo
|
# Onlinde Repo
|
||||||
upd_repo_upd="https://git.a-lec.org/echolib/upd/-/raw/main/usr/local/bin/upd"
|
repo="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_tar="https://git.a-lec.org/echolib/upd/-/archive/main/upd-main.tar.gz"
|
||||||
|
|
129
setup.sh
129
setup.sh
|
@ -1,8 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# version: 0.1
|
|
||||||
# file: setup.sh
|
# file: setup.sh
|
||||||
# Folder: filebox (from git clone)
|
# Folder: upd (from git clone)
|
||||||
# git clone https://git.a-lec.org/echolib/filebox.git
|
# git clone https://git.a-lec.org/echolib/upd.git
|
||||||
# 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
|
||||||
unset ${!setup_@}
|
unset ${!setup_@}
|
||||||
|
@ -12,19 +11,37 @@ unset ${!setup_@}
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
# Directories to CHOWN -R
|
# Directories to CHOWN -R
|
||||||
set_dir_R_CHO=(
|
set_dir_R_CHO=(
|
||||||
/var/lib/upd
|
var/lib/upd
|
||||||
/etc/upd
|
etc/upd
|
||||||
)
|
)
|
||||||
|
|
||||||
# bin Directories: Check ONLY with mkdir -p
|
# Directories to check ONLY with mkdir -p
|
||||||
setup_dir_bin="/usr/local/bin"
|
setup_dir_bin="usr/local/bin"
|
||||||
|
|
||||||
# filename application to CHOWN
|
# main app name
|
||||||
setup_file_bin="upd"
|
setup_app_name="upd"
|
||||||
|
# filename application to CHOWN + CHMOD 755
|
||||||
|
set_files_R_CHO=(
|
||||||
|
upd
|
||||||
|
)
|
||||||
|
|
||||||
# bin uri
|
# bin uri
|
||||||
set_bin_uri="$setup_dir_bin/$setup_file_bin"
|
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
|
# Check commands function
|
||||||
#------------------------
|
#------------------------
|
||||||
|
@ -42,15 +59,15 @@ fi
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
case "$1" in
|
case "$1" in
|
||||||
remove|-R)
|
remove|-R)
|
||||||
[[ -f "$set_bin_uri" ]] \
|
[[ -f "/$set_bin_uri" ]] \
|
||||||
&& echo "- Removing $set_bin_uri" \
|
&& echo "- Removing /$set_bin_uri" \
|
||||||
&& sudo rm -f "$set_bin_uri"
|
&& sudo rm -f "/$set_bin_uri"
|
||||||
|
|
||||||
for setup_folder in ${set_dir_R_CHO[@]}
|
for setup_folder in ${set_dir_R_CHO[@]}
|
||||||
do
|
do
|
||||||
[[ -d "$setup_folder" ]] \
|
[[ -d "/$setup_folder" ]] \
|
||||||
&& echo "- Removing $setup_folder" \
|
&& echo "- Removing /$setup_folder" \
|
||||||
&& sudo rm -rf "$setup_folder"
|
&& sudo rm -rf "/$setup_folder"
|
||||||
done
|
done
|
||||||
echo "# upd is uninstalled. Thank you for testing."
|
echo "# upd is uninstalled. Thank you for testing."
|
||||||
;;
|
;;
|
||||||
|
@ -60,51 +77,54 @@ esac
|
||||||
# Installation Process
|
# Installation Process
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
setup__install() {
|
setup__install() {
|
||||||
for setup_folder in ${set_dir_R_CHO[@]}
|
|
||||||
do
|
setup__gen_process() {
|
||||||
echo "- Folder: $setup_folder"
|
echo "- Folder: /$1"
|
||||||
|
|
||||||
echo -ne " Created:"
|
echo -ne " Created:"
|
||||||
sudo mkdir -p "$setup_folder" \
|
sudo mkdir -p "/$1" \
|
||||||
&& cmd_res="$?" \
|
&& cmd_res="$?" \
|
||||||
&& setup__check_err
|
&& setup__check_err
|
||||||
|
|
||||||
echo -ne " Owner $setup_user:"
|
case "$2" in
|
||||||
sudo chown -R "$setup_user":"$setup_user" "$setup_folder" \
|
chdir)
|
||||||
&& cmd_res="$?" \
|
echo -ne " Owner $setup_user:"
|
||||||
&& setup__check_err
|
sudo chown -R "$setup_user":"$setup_user" "/$1" \
|
||||||
|
&& cmd_res="$?" \
|
||||||
|
&& setup__check_err
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
echo -ne " Copy files:"
|
echo -ne " Copy files:"
|
||||||
sudo rsync -a "${PWD}$setup_folder/" "$setup_folder/" \
|
sudo rsync -a "$1/" "/$1/" \
|
||||||
&& cmd_res="$?" \
|
&& cmd_res="$?" \
|
||||||
&& setup__check_err
|
&& setup__check_err
|
||||||
|
}
|
||||||
|
|
||||||
|
for setup_folder in ${set_dir_R_CHO[@]}
|
||||||
|
do
|
||||||
|
setup__gen_process "$setup_folder" chdir
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "- Folder: $setup_dir_bin"
|
setup__gen_process "$setup_dir_bin"
|
||||||
echo -ne " Created:"
|
for setup_file in ${set_files_R_CHO[@]}
|
||||||
sudo mkdir -p "$setup_dir_bin" \
|
do
|
||||||
&& cmd_res="$?" \
|
echo -ne " Owner $setup_user for $setup_file:"
|
||||||
&& setup__check_err
|
sudo chown "$setup_user":"$setup_user" "/$setup_dir_bin/$setup_file" \
|
||||||
|
&& cmd_res="$?" \
|
||||||
|
&& setup__check_err
|
||||||
|
sudo chmod 755 "/$setup_dir_bin/$setup_file"
|
||||||
|
done
|
||||||
|
|
||||||
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"
|
|
||||||
|
|
||||||
printf '\n%b\n%b\n%b\n' \
|
printf '\n%b\n%b\n%b\n' \
|
||||||
"# Thank you for installing upd." \
|
"# Thank you for installing upd." \
|
||||||
" (You can remove the repo and use upd -U to update)" \
|
" (You can remove the repo and use upd -U to update)" \
|
||||||
" Have fun !"
|
" Have fun !"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------
|
||||||
|
# MAIN PROCESS
|
||||||
|
#----------------------------------------------------------------------
|
||||||
# PWD is Not a repo
|
# PWD is Not a repo
|
||||||
! [[ -d ".git" ]] \
|
! [[ -d ".git" ]] \
|
||||||
&& echo "! No repository here" \
|
&& echo "! No repository here" \
|
||||||
|
@ -113,9 +133,9 @@ printf '\n%b\n%b\n%b\n' \
|
||||||
|
|
||||||
# Updaate && Check Version
|
# Updaate && Check Version
|
||||||
setup_ins_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=`
|
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" ]] \
|
[[ "$setup_ins_version" == "$setup_new_version" ]] \
|
||||||
&& echo "$setup_file_bin is already up to date" \
|
&& 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
|
&& exit 0
|
||||||
|
|
||||||
# Directory project name (First folder from git clone)
|
# Directory project name (First folder from git clone)
|
||||||
setup_folder_git_name=`basename ${PWD}`
|
read -rp ": Set $setup_app_name for user $USER (Y|n|[set])? " setup_user
|
||||||
read -rp ": Set $setup_folder_git_name for user ($USER)? " setup_user
|
|
||||||
case "$setup_user" in
|
case "$setup_user" in
|
||||||
""|Y|y|O|o)
|
""|Y|y|O|o)
|
||||||
setup_user="$USER"
|
setup_user="$USER"
|
||||||
;;
|
;;
|
||||||
|
N|n)
|
||||||
|
unset ${!setup_@}
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
! [[ `awk -F: '{print $1}' /etc/passwd | grep "$setup_user"` ]] \
|
! [[ `awk -F: '{print $1}' /etc/passwd | grep "$setup_user"` ]] \
|
||||||
&& echo "! No registred user: $setup_user" \
|
&& echo "! No registred user: $setup_user" \
|
||||||
|
@ -137,18 +160,8 @@ case "$setup_user" in
|
||||||
;;
|
;;
|
||||||
esac
|
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
|
||||||
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
|
read -rp "# Ready to install (y|N)? " setup_confirm
|
||||||
case "$setup_confirm" in
|
case "$setup_confirm" in
|
||||||
Y|y|O|o) setup__install ;;
|
Y|y|O|o) setup__install ;;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# version: 0.0.9
|
# version: 0.0.10
|
||||||
# file: upd
|
# file: upd
|
||||||
# Folder: /usr/local/bin
|
# Folder: /usr/local/bin
|
||||||
# By echolib
|
# By echolib
|
||||||
|
@ -27,6 +27,10 @@ case "$2" in
|
||||||
! [[ -f "$1" ]] \
|
! [[ -f "$1" ]] \
|
||||||
&& touch "$1"
|
&& touch "$1"
|
||||||
;;
|
;;
|
||||||
|
read)
|
||||||
|
clear
|
||||||
|
cat "$1"
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,14 +109,20 @@ case "$1" in
|
||||||
;;
|
;;
|
||||||
|
|
||||||
-vv)
|
-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
|
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)
|
-U)
|
||||||
if__file "$upd_script_updater" source
|
if__file "$upd_script_updater" source
|
||||||
upd__Updater
|
Updater
|
||||||
|
;;
|
||||||
|
|
||||||
|
--readme)
|
||||||
|
if__file "/var/lib/upd/README.md" read
|
||||||
;;
|
;;
|
||||||
|
|
||||||
help|--help|-h|*)
|
help|--help|-h|*)
|
||||||
|
|
|
@ -13,7 +13,9 @@ version for debian and archlinux (separrating AUR and System available
|
||||||
updates). More functions will be added soon...
|
updates). More functions will be added soon...
|
||||||
|
|
||||||
# Dependancies
|
# 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
|
# How to install
|
||||||
```
|
```
|
||||||
|
@ -22,3 +24,8 @@ cd upd
|
||||||
chmod +x setup.sh
|
chmod +x setup.sh
|
||||||
./setup.sh
|
./setup.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
|
# How to upgrade
|
||||||
|
```
|
||||||
|
upd -U
|
||||||
|
```
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# version: 0.0.1
|
|
||||||
# file: check
|
# file: check
|
||||||
# Folder: /var/lib/upd/scripts
|
# Folder: /var/lib/upd/scripts
|
||||||
# By echolib
|
# By echolib
|
||||||
|
|
|
@ -6,11 +6,12 @@
|
||||||
|
|
||||||
upd__help() {
|
upd__help() {
|
||||||
cat << EOHELP
|
cat << EOHELP
|
||||||
# upd : System Updater
|
# upd : System Updater
|
||||||
check | -c : Check for updates (or just type upd)
|
--readme : Show readme
|
||||||
list | -l : List updates (Check if none)
|
check | -c : Check for updates (or just type upd)
|
||||||
-v : Show Installed version
|
list | -l : List updates (Check if none)
|
||||||
-vv : Show Installed and Available versions
|
-v : Show Installed version
|
||||||
-U : Check and Update upd
|
-vv : Show Installed and Available versions
|
||||||
|
-U : Check and Update upd
|
||||||
EOHELP
|
EOHELP
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# file: tools
|
# file: tools
|
||||||
# Folder: /var/lib/filebox/scripts/
|
# Folder: /var/lib/filebox/scripts
|
||||||
# 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
|
||||||
|
|
||||||
|
|
|
@ -7,33 +7,42 @@
|
||||||
#======================================================================
|
#======================================================================
|
||||||
# Automatic Updater
|
# Automatic Updater
|
||||||
#======================================================================
|
#======================================================================
|
||||||
upd__Updater() {
|
Updater() {
|
||||||
if__command curl
|
if__command curl
|
||||||
upd_cur=`awk 'NR==2 {print $3}' "/usr/local/bin/upd"`
|
if__command rsync
|
||||||
upd_onl=`curl -s "$upd_repo_upd" | awk 'NR==2 {print $3}'`
|
|
||||||
|
|
||||||
printf -v versions '%s\n%s' "$upd_cur" "$upd_onl"
|
v_cur=`awk 'NR==2 {print $3}' "/usr/local/bin/$app_name"`
|
||||||
[[ `sort -V <<< "$versions" | tail -1` == $upd_cur ]] \
|
echo -n "# $app_name Current: $v_cur | "
|
||||||
&& echo "# upd is up to date. Current: $upd_cur | Online: $upd_onl" \
|
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
|
&& return
|
||||||
|
|
||||||
# Get archive
|
# Get archive
|
||||||
cd /tmp
|
cd /tmp
|
||||||
curl -L -o upd-main.tar.gz "$upd_repo_tar" 2>/dev/null
|
curl -L -o ${app_name}-main.tar.gz "$repo_tar" 2>/dev/null
|
||||||
! [[ -f "upd-main.tar.gz" ]] \
|
! [[ -f "${app_name}-main.tar.gz" ]] \
|
||||||
&& echo "! Download error" \
|
&& echo "! Download error" \
|
||||||
&& return
|
&& return
|
||||||
|
|
||||||
tar -xzf upd-main.tar.gz
|
tar -xzf ${app_name}-main.tar.gz
|
||||||
cd upd-main
|
cd ${app_name}-main
|
||||||
rsync -a --delete "usr/local/bin/" "/usr/local/bin"
|
rsync -a --delete "usr/local/bin/" "/usr/local/bin"
|
||||||
rsync -a --delete "var/lib/upd/" "/var/lib/upd/"
|
rsync -a --delete "var/lib/${app_name}/" "/var/lib/${app_name}/"
|
||||||
rsync -a --delete "etc/upd/" "/etc/upd/"
|
rsync -a --delete "etc/${app_name}/" "/etc/${app_name}/"
|
||||||
|
|
||||||
# Check
|
# Check
|
||||||
upd_cur=`awk 'NR==2 {print $3}' "/usr/local/bin/upd"`
|
v_cur=`awk 'NR==2 {print $3}' "/usr/local/bin/$app_name"`
|
||||||
echo "# upd updated to: $upd_cur"
|
echo "# $app_name updated to: $v_cur"
|
||||||
|
|
||||||
rm -rf /tmp/upd-main
|
rm -rf /tmp/${app_name}-main
|
||||||
rm -f upd-main.tar.gz
|
rm -f ${app_name}-main.tar.gz
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# version: 0.1
|
|
||||||
# file: setup.sh
|
# file: setup.sh
|
||||||
# Folder: filebox (from git clone)
|
# Folder: upd (from git clone)
|
||||||
# git clone https://git.a-lec.org/echolib/filebox.git
|
# git clone https://git.a-lec.org/echolib/upd.git
|
||||||
# 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
|
||||||
unset ${!setup_@}
|
unset ${!setup_@}
|
||||||
|
@ -12,19 +11,37 @@ unset ${!setup_@}
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
# Directories to CHOWN -R
|
# Directories to CHOWN -R
|
||||||
set_dir_R_CHO=(
|
set_dir_R_CHO=(
|
||||||
/var/lib/upd
|
var/lib/upd
|
||||||
/etc/upd
|
etc/upd
|
||||||
)
|
)
|
||||||
|
|
||||||
# bin Directories: Check ONLY with mkdir -p
|
# Directories to check ONLY with mkdir -p
|
||||||
setup_dir_bin="/usr/local/bin"
|
setup_dir_bin="usr/local/bin"
|
||||||
|
|
||||||
# filename application to CHOWN
|
# main app name
|
||||||
setup_file_bin="upd"
|
setup_app_name="upd"
|
||||||
|
# filename application to CHOWN + CHMOD 755
|
||||||
|
set_files_R_CHO=(
|
||||||
|
upd
|
||||||
|
)
|
||||||
|
|
||||||
# bin uri
|
# bin uri
|
||||||
set_bin_uri="$setup_dir_bin/$setup_file_bin"
|
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
|
# Check commands function
|
||||||
#------------------------
|
#------------------------
|
||||||
|
@ -42,15 +59,15 @@ fi
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
case "$1" in
|
case "$1" in
|
||||||
remove|-R)
|
remove|-R)
|
||||||
[[ -f "$set_bin_uri" ]] \
|
[[ -f "/$set_bin_uri" ]] \
|
||||||
&& echo "- Removing $set_bin_uri" \
|
&& echo "- Removing /$set_bin_uri" \
|
||||||
&& sudo rm -f "$set_bin_uri"
|
&& sudo rm -f "/$set_bin_uri"
|
||||||
|
|
||||||
for setup_folder in ${set_dir_R_CHO[@]}
|
for setup_folder in ${set_dir_R_CHO[@]}
|
||||||
do
|
do
|
||||||
[[ -d "$setup_folder" ]] \
|
[[ -d "/$setup_folder" ]] \
|
||||||
&& echo "- Removing $setup_folder" \
|
&& echo "- Removing /$setup_folder" \
|
||||||
&& sudo rm -rf "$setup_folder"
|
&& sudo rm -rf "/$setup_folder"
|
||||||
done
|
done
|
||||||
echo "# upd is uninstalled. Thank you for testing."
|
echo "# upd is uninstalled. Thank you for testing."
|
||||||
;;
|
;;
|
||||||
|
@ -60,51 +77,54 @@ esac
|
||||||
# Installation Process
|
# Installation Process
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
setup__install() {
|
setup__install() {
|
||||||
for setup_folder in ${set_dir_R_CHO[@]}
|
|
||||||
do
|
setup__gen_process() {
|
||||||
echo "- Folder: $setup_folder"
|
echo "- Folder: /$1"
|
||||||
|
|
||||||
echo -ne " Created:"
|
echo -ne " Created:"
|
||||||
sudo mkdir -p "$setup_folder" \
|
sudo mkdir -p "/$1" \
|
||||||
&& cmd_res="$?" \
|
&& cmd_res="$?" \
|
||||||
&& setup__check_err
|
&& setup__check_err
|
||||||
|
|
||||||
echo -ne " Owner $setup_user:"
|
case "$2" in
|
||||||
sudo chown -R "$setup_user":"$setup_user" "$setup_folder" \
|
chdir)
|
||||||
&& cmd_res="$?" \
|
echo -ne " Owner $setup_user:"
|
||||||
&& setup__check_err
|
sudo chown -R "$setup_user":"$setup_user" "/$1" \
|
||||||
|
&& cmd_res="$?" \
|
||||||
|
&& setup__check_err
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
echo -ne " Copy files:"
|
echo -ne " Copy files:"
|
||||||
sudo rsync -a "${PWD}$setup_folder/" "$setup_folder/" \
|
sudo rsync -a "$1/" "/$1/" \
|
||||||
&& cmd_res="$?" \
|
&& cmd_res="$?" \
|
||||||
&& setup__check_err
|
&& setup__check_err
|
||||||
|
}
|
||||||
|
|
||||||
|
for setup_folder in ${set_dir_R_CHO[@]}
|
||||||
|
do
|
||||||
|
setup__gen_process "$setup_folder" chdir
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "- Folder: $setup_dir_bin"
|
setup__gen_process "$setup_dir_bin"
|
||||||
echo -ne " Created:"
|
for setup_file in ${set_files_R_CHO[@]}
|
||||||
sudo mkdir -p "$setup_dir_bin" \
|
do
|
||||||
&& cmd_res="$?" \
|
echo -ne " Owner $setup_user for $setup_file:"
|
||||||
&& setup__check_err
|
sudo chown "$setup_user":"$setup_user" "/$setup_dir_bin/$setup_file" \
|
||||||
|
&& cmd_res="$?" \
|
||||||
|
&& setup__check_err
|
||||||
|
sudo chmod 755 "/$setup_dir_bin/$setup_file"
|
||||||
|
done
|
||||||
|
|
||||||
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"
|
|
||||||
|
|
||||||
printf '\n%b\n%b\n%b\n' \
|
printf '\n%b\n%b\n%b\n' \
|
||||||
"# Thank you for installing upd." \
|
"# Thank you for installing upd." \
|
||||||
" (You can remove the repo and use upd -U to update)" \
|
" (You can remove the repo and use upd -U to update)" \
|
||||||
" Have fun !"
|
" Have fun !"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------
|
||||||
|
# MAIN PROCESS
|
||||||
|
#----------------------------------------------------------------------
|
||||||
# PWD is Not a repo
|
# PWD is Not a repo
|
||||||
! [[ -d ".git" ]] \
|
! [[ -d ".git" ]] \
|
||||||
&& echo "! No repository here" \
|
&& echo "! No repository here" \
|
||||||
|
@ -113,9 +133,9 @@ printf '\n%b\n%b\n%b\n' \
|
||||||
|
|
||||||
# Updaate && Check Version
|
# Updaate && Check Version
|
||||||
setup_ins_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=`
|
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" ]] \
|
[[ "$setup_ins_version" == "$setup_new_version" ]] \
|
||||||
&& echo "$setup_file_bin is already up to date" \
|
&& 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
|
&& exit 0
|
||||||
|
|
||||||
# Directory project name (First folder from git clone)
|
# Directory project name (First folder from git clone)
|
||||||
setup_folder_git_name=`basename ${PWD}`
|
read -rp ": Set $setup_app_name for user $USER (Y|n|[set])? " setup_user
|
||||||
read -rp ": Set $setup_folder_git_name for user ($USER)? " setup_user
|
|
||||||
case "$setup_user" in
|
case "$setup_user" in
|
||||||
""|Y|y|O|o)
|
""|Y|y|O|o)
|
||||||
setup_user="$USER"
|
setup_user="$USER"
|
||||||
;;
|
;;
|
||||||
|
N|n)
|
||||||
|
unset ${!setup_@}
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
! [[ `awk -F: '{print $1}' /etc/passwd | grep "$setup_user"` ]] \
|
! [[ `awk -F: '{print $1}' /etc/passwd | grep "$setup_user"` ]] \
|
||||||
&& echo "! No registred user: $setup_user" \
|
&& echo "! No registred user: $setup_user" \
|
||||||
|
@ -137,18 +160,8 @@ case "$setup_user" in
|
||||||
;;
|
;;
|
||||||
esac
|
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
|
||||||
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
|
read -rp "# Ready to install (y|N)? " setup_confirm
|
||||||
case "$setup_confirm" in
|
case "$setup_confirm" in
|
||||||
Y|y|O|o) setup__install ;;
|
Y|y|O|o) setup__install ;;
|
||||||
|
|
Loading…
Reference in New Issue