Added setup.sh, fix readme, and code

This commit is contained in:
Cyrille L 2022-03-21 17:33:58 +01:00
parent e48bd0b131
commit 3206b724b8
6 changed files with 314 additions and 23 deletions

View File

@ -14,18 +14,19 @@ server "upload" folder with your friends.
- sshfs - sshfs
# How to install ? # How to install ?
Create folders from list below and to avoid sudo for non root user, You can manually copy, folders and files from this repo, or use setup.sh
use chown. Then, chmod 755 filebox so that it can be started
``` ```
# Create and own folders git clone https://git.a-lec.org/echolib/filebox
sudo mkdir -p /etc/filebox && sudo chown -R $USER:$USER /etc/filebox cd filebox
sudo mkdir -p /var/lib/filebox && sudo chown -R $USER:$USER /var/lib/filebox chmod +x setup.sh
# Copy executable filebox file: # Install and/or Update repo and filebox
sudp cp filebox /usr/local/bin/filebox ./setup.sh
sudo chown $USER:$USER /usr/local/bin/filebox
sudo chmod 755 /usr/local/bin/filebox # Removing filebox
./setup.sh -R
``` ```
# Files and Folders configuration # Files and Folders configuration
@ -100,8 +101,8 @@ In that (Upload LOCAL Folder)/(server name) you could put all your
torrent files, but whatever you want, so they can be uploaded to your torrent files, but whatever you want, so they can be uploaded to your
server. server.
filebox will check for free space on server before uploading. A reserved filebox will check for free space on server before uploading a file. A
5Go free space on your server (configurable in /etc/filebox/filebox.conf) reserved 5Go free space on your server (configurable in /etc/filebox/filebox.conf)
is set. is set.
Do not forget to unmount your mounted points using: Do not forget to unmount your mounted points using:

143
setup.sh Normal file
View File

@ -0,0 +1,143 @@
#!/bin/bash
# version: 0.1
# file: setup.sh
# Folder: filebox (from git clone)
# git clone https://git.a-lec.org/echolib/filebox.git
# By echolib
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
unset ${!setup_@}
#----------------------------------------------------------------------
# Configuration ; folders and files to create/chown/copy...
#----------------------------------------------------------------------
# Directories to CHOWN -R
set_dir_R_CHO=(
/var/lib/filebox
/etc/filebox
)
# bin Directories: Check ONLY with mkdir -p
setup_dir_bin="/usr/local/bin"
# filename application to CHOWN
setup_file_bin="filebox"
# bin uri
set_bin_uri="$setup_dir_bin/$setup_file_bin"
#------------------------
# Check commands function
#------------------------
filebox__check_err() {
if (( cmd_res == 0 ));then
echo -ne " OK\n"
else
echo -ne " Error $cmd_res\n"
exit 1
fi
}
#----------------------------------------------------------------------
# Remove Process
#----------------------------------------------------------------------
case "$1" in
remove|-R)
[[ -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"
done
echo "# filebox is uninstalled. Thank you for testing."
;;
esac
#----------------------------------------------------------------------
# Installation Process
#----------------------------------------------------------------------
setup__install() {
for setup_folder in ${set_dir_R_CHO[@]}
do
echo "- Folder: $setup_folder"
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
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
echo -e "\n# Thank you for installing filebox. Have fun"
}
# PWD is Not a repo
! [[ -d ".git" ]] \
&& echo "! No repository here" \
&& unset ${!setup_@} \
&& exit 0
# Updaate && Check Version
git pull
setup_ins_version=`
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"`
[[ "$setup_ins_version" == "$setup_ins_version" ]] \
&& echo "$setup_file_bin is already up to date" \
&& unset ${!setup_@} \
&& 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
case "$setup_user" in
""|Y|y|O|o)
setup_user="$USER"
;;
*)
! [[ `awk -F: '{print $1}' /etc/passwd | grep "$setup_user"` ]] \
&& echo "! No registred user: $setup_user" \
&& unset ${!setup_@} \
&& exit 1
;;
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"
read -rp "# Ready to install (y|N)? " setup_confirm
case "$setup_confirm" in
Y|y|O|o) setup__install ;;
*) unset ${!setup_@};exit 0 ;;
esac

View File

@ -74,6 +74,7 @@ if__folder "$fb_dir_conf_user"
# Check local folders # Check local folders
if__file "$fb_file_conf_loc" conf if__file "$fb_file_conf_loc" conf
if__file "$fb_file_conf_loc" source if__file "$fb_file_conf_loc" source
# Save current folder # Save current folder
pwd_folder=${PWD} pwd_folder=${PWD}

View File

@ -14,18 +14,19 @@ server "upload" folder with your friends.
- sshfs - sshfs
# How to install ? # How to install ?
Create folders from list below and to avoid sudo for non root user, You can manually copy, folders and files from this repo, or use setup.sh
use chown. Then, chmod 755 filebox so that it can be started
``` ```
# Create and own folders git clone https://git.a-lec.org/echolib/filebox
sudo mkdir -p /etc/filebox && sudo chown -R $USER:$USER /etc/filebox cd filebox
sudo mkdir -p /var/lib/filebox && sudo chown -R $USER:$USER /var/lib/filebox chmod +x setup.sh
# Copy executable filebox file: # Install and/or Update repo and filebox
sudp cp filebox /usr/local/bin/filebox ./setup.sh
sudo chown $USER:$USER /usr/local/bin/filebox
sudo chmod 755 /usr/local/bin/filebox # Removing filebox
./setup.sh -R
``` ```
# Files and Folders configuration # Files and Folders configuration
@ -100,8 +101,8 @@ In that (Upload LOCAL Folder)/(server name) you could put all your
torrent files, but whatever you want, so they can be uploaded to your torrent files, but whatever you want, so they can be uploaded to your
server. server.
filebox will check for free space on server before uploading. A reserved filebox will check for free space on server before uploading a file. A
5Go free space on your server (configurable in /etc/filebox/filebox.conf) reserved 5Go free space on your server (configurable in /etc/filebox/filebox.conf)
is set. is set.
Do not forget to unmount your mounted points using: Do not forget to unmount your mounted points using:

View File

@ -13,9 +13,11 @@ if__command rsync
if [[ `command ls -A "$fb_dir_files"` ]];then if [[ `command ls -A "$fb_dir_files"` ]];then
mount__srv ul mount__srv ul
fb_server_bsize=` fb_server_bsize=`
df -B1 | grep "$fb_srv_mnt_ul" | awk 'NR==2 {print $4}'` df -B1 | grep "$fb_srv_mnt_ul" | awk 'NR==2 {print $4}'`
fb_server_rbsize=$(( fb_server_bsize + fb_keep_sbsize )) fb_server_rbsize=$(( fb_server_bsize + fb_keep_sbsize ))
clear clear
while read -r "item" while read -r "item"
do do
@ -34,6 +36,6 @@ if [[ `command ls -A "$fb_dir_files"` ]];then
fi fi
done < <(ls -1) done < <(ls -1)
else else
echo -e "$I_YELLOW Nothing to upload in $fb_dir_files..." echo -e "$I_Yellow Nothing to upload in $fb_dir_files..."
fi fi
} }

143
var/lib/filebox/setup.sh Normal file
View File

@ -0,0 +1,143 @@
#!/bin/bash
# version: 0.1
# file: setup.sh
# Folder: filebox (from git clone)
# git clone https://git.a-lec.org/echolib/filebox.git
# By echolib
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
unset ${!setup_@}
#----------------------------------------------------------------------
# Configuration ; folders and files to create/chown/copy...
#----------------------------------------------------------------------
# Directories to CHOWN -R
set_dir_R_CHO=(
/var/lib/filebox
/etc/filebox
)
# bin Directories: Check ONLY with mkdir -p
setup_dir_bin="/usr/local/bin"
# filename application to CHOWN
setup_file_bin="filebox"
# bin uri
set_bin_uri="$setup_dir_bin/$setup_file_bin"
#------------------------
# Check commands function
#------------------------
filebox__check_err() {
if (( cmd_res == 0 ));then
echo -ne " OK\n"
else
echo -ne " Error $cmd_res\n"
exit 1
fi
}
#----------------------------------------------------------------------
# Remove Process
#----------------------------------------------------------------------
case "$1" in
remove|-R)
[[ -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"
done
echo "# filebox is uninstalled. Thank you for testing."
;;
esac
#----------------------------------------------------------------------
# Installation Process
#----------------------------------------------------------------------
setup__install() {
for setup_folder in ${set_dir_R_CHO[@]}
do
echo "- Folder: $setup_folder"
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
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
echo -e "\n# Thank you for installing filebox. Have fun"
}
# PWD is Not a repo
! [[ -d ".git" ]] \
&& echo "! No repository here" \
&& unset ${!setup_@} \
&& exit 0
# Updaate && Check Version
git pull
setup_ins_version=`
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"`
[[ "$setup_ins_version" == "$setup_ins_version" ]] \
&& echo "$setup_file_bin is already up to date" \
&& unset ${!setup_@} \
&& 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
case "$setup_user" in
""|Y|y|O|o)
setup_user="$USER"
;;
*)
! [[ `awk -F: '{print $1}' /etc/passwd | grep "$setup_user"` ]] \
&& echo "! No registred user: $setup_user" \
&& unset ${!setup_@} \
&& exit 1
;;
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"
read -rp "# Ready to install (y|N)? " setup_confirm
case "$setup_confirm" in
Y|y|O|o) setup__install ;;
*) unset ${!setup_@};exit 0 ;;
esac