New setup ; updater ; more options
This commit is contained in:
parent
8c65014654
commit
82f1b3a5b5
10
README.md
10
README.md
|
@ -10,13 +10,13 @@ server "upload" folder with your friends.
|
||||||
|
|
||||||
# dependencies
|
# dependencies
|
||||||
- bash
|
- bash
|
||||||
|
- curl (to check available version)
|
||||||
- rsync
|
- rsync
|
||||||
- sshfs
|
- sshfs
|
||||||
|
|
||||||
# How to install ?
|
# How to install ?
|
||||||
You can manually copy, folders and files from this repo, or use setup.sh
|
You can manually copy, folders and files from this repo, or use setup.sh
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
git clone https://git.a-lec.org/echolib/filebox
|
git clone https://git.a-lec.org/echolib/filebox
|
||||||
cd filebox
|
cd filebox
|
||||||
|
@ -108,7 +108,7 @@ is set.
|
||||||
Do not forget to unmount your mounted points using:
|
Do not forget to unmount your mounted points using:
|
||||||
|
|
||||||
```
|
```
|
||||||
filebox -U [OPT] (server name)
|
filebox -u [OPT] (server name)
|
||||||
```
|
```
|
||||||
|
|
||||||
# Help
|
# Help
|
||||||
|
@ -136,7 +136,7 @@ $ filebox [ARGS]
|
||||||
[OPT]
|
[OPT]
|
||||||
-k : Copy, not move
|
-k : Copy, not move
|
||||||
|
|
||||||
unmount | -U [OPT] [NAME]
|
unmount | -u [OPT] [NAME]
|
||||||
: Unmount directories
|
: Unmount directories
|
||||||
[OPT]
|
[OPT]
|
||||||
dl : Download directory only
|
dl : Download directory only
|
||||||
|
@ -145,6 +145,10 @@ $ filebox [ARGS]
|
||||||
get | -g [NAME]
|
get | -g [NAME]
|
||||||
: List and choose files to download from server
|
: List and choose files to download from server
|
||||||
|
|
||||||
|
-v : Show Installed version
|
||||||
|
-vv : Show Installed and Available versions
|
||||||
|
-U : Check and Update filebox
|
||||||
|
|
||||||
# Items Selector
|
# Items Selector
|
||||||
: L > Load again the list
|
: L > Load again the list
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,8 @@ fb_keep_bsize=10737418240
|
||||||
# Reserved free space: 5Go (server)
|
# Reserved free space: 5Go (server)
|
||||||
fb_keep_sbsize=5368709120
|
fb_keep_sbsize=5368709120
|
||||||
|
|
||||||
|
|
||||||
|
app_name="filebox"
|
||||||
# -------
|
# -------
|
||||||
# Folders
|
# Folders
|
||||||
# -------
|
# -------
|
||||||
|
@ -34,3 +36,7 @@ fb_file_conf_loc="$fb_dir_conf_user/filebox_loc.conf"
|
||||||
fb_file_list="$fb_dir_conf_user/filelist"
|
fb_file_list="$fb_dir_conf_user/filelist"
|
||||||
# Profile file
|
# Profile file
|
||||||
fb_file_profile_list="$fb_dir_conf_user/profile"
|
fb_file_profile_list="$fb_dir_conf_user/profile"
|
||||||
|
|
||||||
|
# repo
|
||||||
|
repo="https://git.a-lec.org/echolib/filebox/-/raw/main/usr/local/bin/filebox"
|
||||||
|
repo_tar="https://git.a-lec.org/echolib/filebox/-/archive/main/filebox-main.tar.gz"
|
||||||
|
|
141
setup.sh
141
setup.sh
|
@ -1,5 +1,4 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# version: 0.1
|
|
||||||
# file: setup.sh
|
# file: setup.sh
|
||||||
# Folder: filebox (from git clone)
|
# Folder: filebox (from git clone)
|
||||||
# git clone https://git.a-lec.org/echolib/filebox.git
|
# git clone https://git.a-lec.org/echolib/filebox.git
|
||||||
|
@ -12,23 +11,41 @@ unset ${!setup_@}
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
# Directories to CHOWN -R
|
# Directories to CHOWN -R
|
||||||
set_dir_R_CHO=(
|
set_dir_R_CHO=(
|
||||||
/var/lib/filebox
|
var/lib/filebox
|
||||||
/etc/filebox
|
etc/filbox
|
||||||
)
|
)
|
||||||
|
|
||||||
# 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="filebox"
|
setup_app_name="filebox"
|
||||||
|
# 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
|
||||||
#------------------------
|
#------------------------
|
||||||
filebox__check_err() {
|
setup__check_err() {
|
||||||
if (( cmd_res == 0 ));then
|
if (( cmd_res == 0 ));then
|
||||||
echo -ne " OK\n"
|
echo -ne " OK\n"
|
||||||
else
|
else
|
||||||
|
@ -42,17 +59,17 @@ 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 "# filebox is uninstalled. Thank you for testing."
|
echo "# upd is uninstalled. Thank you for testing."
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
@ -60,38 +77,54 @@ esac
|
||||||
# Installation Process
|
# Installation Process
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
setup__install() {
|
setup__install() {
|
||||||
|
|
||||||
|
setup__gen_process() {
|
||||||
|
echo "- Folder: /$1"
|
||||||
|
|
||||||
|
echo -ne " Created:"
|
||||||
|
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" "/$1" \
|
||||||
|
&& cmd_res="$?" \
|
||||||
|
&& setup__check_err
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
echo -ne " Copy files:"
|
||||||
|
sudo rsync -a "$1/" "/$1/" \
|
||||||
|
&& cmd_res="$?" \
|
||||||
|
&& setup__check_err
|
||||||
|
}
|
||||||
|
|
||||||
for setup_folder in ${set_dir_R_CHO[@]}
|
for setup_folder in ${set_dir_R_CHO[@]}
|
||||||
do
|
do
|
||||||
echo "- Folder: $setup_folder"
|
setup__gen_process "$setup_folder" chdir
|
||||||
echo -ne " Created:"
|
|
||||||
sudo mkdir -p "$setup_folder" \
|
|
||||||
&& cmd_res="$?" \
|
|
||||||
&& filebox__check_err
|
|
||||||
echo -ne " Owner $setup_user:"
|
|
||||||
sudo chown -R "$setup_user":"$setup_user" "$setup_folder" \
|
|
||||||
&& cmd_res="$?" \
|
|
||||||
&& filebox__check_err
|
|
||||||
done
|
done
|
||||||
echo "- Folder: $setup_dir_bin"
|
|
||||||
echo -ne " Created:"
|
|
||||||
sudo mkdir -p "$setup_dir_bin" \
|
|
||||||
&& cmd_res="$?" \
|
|
||||||
&& filebox__check_err
|
|
||||||
echo "- File: $setup_file_bin"
|
|
||||||
echo -ne " Copy:"
|
|
||||||
sudo cp "$PWD$set_bin_uri" \
|
|
||||||
"$set_bin_uri" \
|
|
||||||
&& cmd_res="$?" \
|
|
||||||
&& filebox__check_err
|
|
||||||
echo -ne " Owner $setup_user:"
|
|
||||||
sudo chown "$setup_user":"$setup_user" "$set_bin_uri" \
|
|
||||||
&& cmd_res="$?" \
|
|
||||||
&& filebox__check_err
|
|
||||||
sudo chmod 755 "$set_bin_uri"
|
|
||||||
|
|
||||||
echo -e "\n# Thank you for installing filebox. Have fun !"
|
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
|
||||||
|
sudo chmod 755 "/$setup_dir_bin/$setup_file"
|
||||||
|
done
|
||||||
|
|
||||||
|
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 !"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------
|
||||||
|
# MAIN PROCESS
|
||||||
|
#----------------------------------------------------------------------
|
||||||
# PWD is Not a repo
|
# PWD is Not a repo
|
||||||
! [[ -d ".git" ]] \
|
! [[ -d ".git" ]] \
|
||||||
&& echo "! No repository here" \
|
&& echo "! No repository here" \
|
||||||
|
@ -99,24 +132,26 @@ echo -e "\n# Thank you for installing filebox. Have fun !"
|
||||||
&& exit 0
|
&& exit 0
|
||||||
|
|
||||||
# Updaate && Check Version
|
# Updaate && Check Version
|
||||||
git pull
|
|
||||||
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_ins_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" \
|
||||||
&& unset ${!setup_@} \
|
&& unset ${!setup_@} \
|
||||||
&& 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" \
|
||||||
|
@ -125,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.1.3
|
# version: 0.1.4
|
||||||
# file: filebox
|
# file: filebox
|
||||||
# Folder: /usr/local/bin
|
# Folder: /usr/local/bin
|
||||||
# By echolib
|
# By echolib
|
||||||
|
@ -108,7 +108,7 @@ case "$1" in
|
||||||
send__files
|
send__files
|
||||||
;;
|
;;
|
||||||
|
|
||||||
unmount|-U)
|
unmount|-u)
|
||||||
if__file "$fb_dir_scripts/mount__srv" source
|
if__file "$fb_dir_scripts/mount__srv" source
|
||||||
case "$2" in
|
case "$2" in
|
||||||
ul)
|
ul)
|
||||||
|
@ -147,6 +147,27 @@ case "$1" in
|
||||||
get__files
|
get__files
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
-U)
|
||||||
|
if__file "$fb_dir_scripts/updater" source
|
||||||
|
Updater
|
||||||
|
;;
|
||||||
|
|
||||||
|
version|-v)
|
||||||
|
awk 'NR==2 {print "# Installed:",$3}' "/usr/local/bin/filebox"
|
||||||
|
;;
|
||||||
|
|
||||||
|
-vv)
|
||||||
|
v_cur=`awk 'NR==2 {print $3}' "/usr/local/bin/$app_name"`
|
||||||
|
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"
|
||||||
|
;;
|
||||||
|
|
||||||
|
--readme)
|
||||||
|
if__file "/var/lib/filebox/README.md" read
|
||||||
|
;;
|
||||||
|
|
||||||
--help|-h|help|*)
|
--help|-h|help|*)
|
||||||
if__file "$fb_dir_scripts/help" read
|
if__file "$fb_dir_scripts/help" read
|
||||||
;;
|
;;
|
||||||
|
|
|
@ -10,13 +10,13 @@ server "upload" folder with your friends.
|
||||||
|
|
||||||
# dependencies
|
# dependencies
|
||||||
- bash
|
- bash
|
||||||
|
- curl (to check available version)
|
||||||
- rsync
|
- rsync
|
||||||
- sshfs
|
- sshfs
|
||||||
|
|
||||||
# How to install ?
|
# How to install ?
|
||||||
You can manually copy, folders and files from this repo, or use setup.sh
|
You can manually copy, folders and files from this repo, or use setup.sh
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
git clone https://git.a-lec.org/echolib/filebox
|
git clone https://git.a-lec.org/echolib/filebox
|
||||||
cd filebox
|
cd filebox
|
||||||
|
@ -108,7 +108,7 @@ is set.
|
||||||
Do not forget to unmount your mounted points using:
|
Do not forget to unmount your mounted points using:
|
||||||
|
|
||||||
```
|
```
|
||||||
filebox -U [OPT] (server name)
|
filebox -u [OPT] (server name)
|
||||||
```
|
```
|
||||||
|
|
||||||
# Help
|
# Help
|
||||||
|
@ -136,7 +136,7 @@ $ filebox [ARGS]
|
||||||
[OPT]
|
[OPT]
|
||||||
-k : Copy, not move
|
-k : Copy, not move
|
||||||
|
|
||||||
unmount | -U [OPT] [NAME]
|
unmount | -u [OPT] [NAME]
|
||||||
: Unmount directories
|
: Unmount directories
|
||||||
[OPT]
|
[OPT]
|
||||||
dl : Download directory only
|
dl : Download directory only
|
||||||
|
@ -145,6 +145,10 @@ $ filebox [ARGS]
|
||||||
get | -g [NAME]
|
get | -g [NAME]
|
||||||
: List and choose files to download from server
|
: List and choose files to download from server
|
||||||
|
|
||||||
|
-v : Show Installed version
|
||||||
|
-vv : Show Installed and Available versions
|
||||||
|
-U : Check and Update filebox
|
||||||
|
|
||||||
# Items Selector
|
# Items Selector
|
||||||
: L > Load again the list
|
: L > Load again the list
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,8 @@ $ filebox [ARGS]
|
||||||
: No [NAME], use (default)
|
: No [NAME], use (default)
|
||||||
|
|
||||||
[ARGS]:
|
[ARGS]:
|
||||||
help
|
help : This Help
|
||||||
: This Help
|
--readme : Show readme
|
||||||
|
|
||||||
config | -C [OPT] [NAME]
|
config | -C [OPT] [NAME]
|
||||||
: Configure access to a server [NAME]
|
: Configure access to a server [NAME]
|
||||||
|
@ -20,7 +20,7 @@ $ filebox [ARGS]
|
||||||
[OPT]
|
[OPT]
|
||||||
-k : Copy, not move
|
-k : Copy, not move
|
||||||
|
|
||||||
unmount | -U [OPT] [NAME]
|
unmount | -u [OPT] [NAME]
|
||||||
: Unmount directories
|
: Unmount directories
|
||||||
[OPT]
|
[OPT]
|
||||||
dl : Download directory only
|
dl : Download directory only
|
||||||
|
@ -29,6 +29,10 @@ $ filebox [ARGS]
|
||||||
get | -g [NAME]
|
get | -g [NAME]
|
||||||
: List and choose files to download from server
|
: List and choose files to download from server
|
||||||
|
|
||||||
|
-v : Show Installed version
|
||||||
|
-vv : Show Installed and Available versions
|
||||||
|
-U : Check and Update filebox
|
||||||
|
|
||||||
# Items Selector
|
# Items Selector
|
||||||
: L > Load again the list
|
: L > Load again the list
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# file: updater
|
||||||
|
# Folder: /var/lib/upd/scripts/
|
||||||
|
# By echolib
|
||||||
|
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
|
||||||
|
|
||||||
|
#======================================================================
|
||||||
|
# Automatic Updater
|
||||||
|
#======================================================================
|
||||||
|
Updater() {
|
||||||
|
if__command curl
|
||||||
|
if__command rsync
|
||||||
|
|
||||||
|
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 ${app_name}-main.tar.gz "$repo_tar" 2>/dev/null
|
||||||
|
! [[ -f "${app_name}-main.tar.gz" ]] \
|
||||||
|
&& echo "! Download error" \
|
||||||
|
&& return
|
||||||
|
|
||||||
|
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/${app_name}/" "/var/lib/${app_name}/"
|
||||||
|
rsync -a --delete "etc/${app_name}/" "/etc/${app_name}/"
|
||||||
|
|
||||||
|
# Check
|
||||||
|
v_cur=`awk 'NR==2 {print $3}' "/usr/local/bin/$app_name"`
|
||||||
|
echo "# $app_name updated to: $v_cur"
|
||||||
|
|
||||||
|
rm -rf /tmp/${app_name}-main
|
||||||
|
rm -f ${app_name}-main.tar.gz
|
||||||
|
}
|
|
@ -1,5 +1,4 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# version: 0.1
|
|
||||||
# file: setup.sh
|
# file: setup.sh
|
||||||
# Folder: filebox (from git clone)
|
# Folder: filebox (from git clone)
|
||||||
# git clone https://git.a-lec.org/echolib/filebox.git
|
# git clone https://git.a-lec.org/echolib/filebox.git
|
||||||
|
@ -12,23 +11,41 @@ unset ${!setup_@}
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
# Directories to CHOWN -R
|
# Directories to CHOWN -R
|
||||||
set_dir_R_CHO=(
|
set_dir_R_CHO=(
|
||||||
/var/lib/filebox
|
var/lib/filebox
|
||||||
/etc/filebox
|
etc/filbox
|
||||||
)
|
)
|
||||||
|
|
||||||
# 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="filebox"
|
setup_app_name="filebox"
|
||||||
|
# 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
|
||||||
#------------------------
|
#------------------------
|
||||||
filebox__check_err() {
|
setup__check_err() {
|
||||||
if (( cmd_res == 0 ));then
|
if (( cmd_res == 0 ));then
|
||||||
echo -ne " OK\n"
|
echo -ne " OK\n"
|
||||||
else
|
else
|
||||||
|
@ -42,17 +59,17 @@ 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 "# filebox is uninstalled. Thank you for testing."
|
echo "# upd is uninstalled. Thank you for testing."
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
@ -60,38 +77,54 @@ esac
|
||||||
# Installation Process
|
# Installation Process
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
setup__install() {
|
setup__install() {
|
||||||
|
|
||||||
|
setup__gen_process() {
|
||||||
|
echo "- Folder: /$1"
|
||||||
|
|
||||||
|
echo -ne " Created:"
|
||||||
|
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" "/$1" \
|
||||||
|
&& cmd_res="$?" \
|
||||||
|
&& setup__check_err
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
echo -ne " Copy files:"
|
||||||
|
sudo rsync -a "$1/" "/$1/" \
|
||||||
|
&& cmd_res="$?" \
|
||||||
|
&& setup__check_err
|
||||||
|
}
|
||||||
|
|
||||||
for setup_folder in ${set_dir_R_CHO[@]}
|
for setup_folder in ${set_dir_R_CHO[@]}
|
||||||
do
|
do
|
||||||
echo "- Folder: $setup_folder"
|
setup__gen_process "$setup_folder" chdir
|
||||||
echo -ne " Created:"
|
|
||||||
sudo mkdir -p "$setup_folder" \
|
|
||||||
&& cmd_res="$?" \
|
|
||||||
&& filebox__check_err
|
|
||||||
echo -ne " Owner $setup_user:"
|
|
||||||
sudo chown -R "$setup_user":"$setup_user" "$setup_folder" \
|
|
||||||
&& cmd_res="$?" \
|
|
||||||
&& filebox__check_err
|
|
||||||
done
|
done
|
||||||
echo "- Folder: $setup_dir_bin"
|
|
||||||
echo -ne " Created:"
|
|
||||||
sudo mkdir -p "$setup_dir_bin" \
|
|
||||||
&& cmd_res="$?" \
|
|
||||||
&& filebox__check_err
|
|
||||||
echo "- File: $setup_file_bin"
|
|
||||||
echo -ne " Copy:"
|
|
||||||
sudo cp "$PWD$set_bin_uri" \
|
|
||||||
"$set_bin_uri" \
|
|
||||||
&& cmd_res="$?" \
|
|
||||||
&& filebox__check_err
|
|
||||||
echo -ne " Owner $setup_user:"
|
|
||||||
sudo chown "$setup_user":"$setup_user" "$set_bin_uri" \
|
|
||||||
&& cmd_res="$?" \
|
|
||||||
&& filebox__check_err
|
|
||||||
sudo chmod 755 "$set_bin_uri"
|
|
||||||
|
|
||||||
echo -e "\n# Thank you for installing filebox. Have fun !"
|
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
|
||||||
|
sudo chmod 755 "/$setup_dir_bin/$setup_file"
|
||||||
|
done
|
||||||
|
|
||||||
|
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 !"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------
|
||||||
|
# MAIN PROCESS
|
||||||
|
#----------------------------------------------------------------------
|
||||||
# PWD is Not a repo
|
# PWD is Not a repo
|
||||||
! [[ -d ".git" ]] \
|
! [[ -d ".git" ]] \
|
||||||
&& echo "! No repository here" \
|
&& echo "! No repository here" \
|
||||||
|
@ -99,24 +132,26 @@ echo -e "\n# Thank you for installing filebox. Have fun !"
|
||||||
&& exit 0
|
&& exit 0
|
||||||
|
|
||||||
# Updaate && Check Version
|
# Updaate && Check Version
|
||||||
git pull
|
|
||||||
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_ins_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" \
|
||||||
&& unset ${!setup_@} \
|
&& unset ${!setup_@} \
|
||||||
&& 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" \
|
||||||
|
@ -125,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