Added setup.sh, fix readme, and code
This commit is contained in:
parent
e48bd0b131
commit
3206b724b8
23
README.md
23
README.md
|
@ -14,18 +14,19 @@ server "upload" folder with your friends.
|
|||
- sshfs
|
||||
|
||||
# How to install ?
|
||||
Create folders from list below and to avoid sudo for non root user,
|
||||
use chown. Then, chmod 755 filebox so that it can be started
|
||||
You can manually copy, folders and files from this repo, or use setup.sh
|
||||
|
||||
|
||||
```
|
||||
# Create and own folders
|
||||
sudo mkdir -p /etc/filebox && sudo chown -R $USER:$USER /etc/filebox
|
||||
sudo mkdir -p /var/lib/filebox && sudo chown -R $USER:$USER /var/lib/filebox
|
||||
git clone https://git.a-lec.org/echolib/filebox
|
||||
cd filebox
|
||||
chmod +x setup.sh
|
||||
|
||||
# Copy executable filebox file:
|
||||
sudp cp filebox /usr/local/bin/filebox
|
||||
sudo chown $USER:$USER /usr/local/bin/filebox
|
||||
sudo chmod 755 /usr/local/bin/filebox
|
||||
# Install and/or Update repo and filebox
|
||||
./setup.sh
|
||||
|
||||
# Removing filebox
|
||||
./setup.sh -R
|
||||
```
|
||||
|
||||
# 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
|
||||
server.
|
||||
|
||||
filebox will check for free space on server before uploading. A reserved
|
||||
5Go free space on your server (configurable in /etc/filebox/filebox.conf)
|
||||
filebox will check for free space on server before uploading a file. A
|
||||
reserved 5Go free space on your server (configurable in /etc/filebox/filebox.conf)
|
||||
is set.
|
||||
|
||||
Do not forget to unmount your mounted points using:
|
||||
|
|
|
@ -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
|
|
@ -74,6 +74,7 @@ if__folder "$fb_dir_conf_user"
|
|||
# Check local folders
|
||||
if__file "$fb_file_conf_loc" conf
|
||||
if__file "$fb_file_conf_loc" source
|
||||
|
||||
# Save current folder
|
||||
pwd_folder=${PWD}
|
||||
|
||||
|
|
|
@ -14,18 +14,19 @@ server "upload" folder with your friends.
|
|||
- sshfs
|
||||
|
||||
# How to install ?
|
||||
Create folders from list below and to avoid sudo for non root user,
|
||||
use chown. Then, chmod 755 filebox so that it can be started
|
||||
You can manually copy, folders and files from this repo, or use setup.sh
|
||||
|
||||
|
||||
```
|
||||
# Create and own folders
|
||||
sudo mkdir -p /etc/filebox && sudo chown -R $USER:$USER /etc/filebox
|
||||
sudo mkdir -p /var/lib/filebox && sudo chown -R $USER:$USER /var/lib/filebox
|
||||
git clone https://git.a-lec.org/echolib/filebox
|
||||
cd filebox
|
||||
chmod +x setup.sh
|
||||
|
||||
# Copy executable filebox file:
|
||||
sudp cp filebox /usr/local/bin/filebox
|
||||
sudo chown $USER:$USER /usr/local/bin/filebox
|
||||
sudo chmod 755 /usr/local/bin/filebox
|
||||
# Install and/or Update repo and filebox
|
||||
./setup.sh
|
||||
|
||||
# Removing filebox
|
||||
./setup.sh -R
|
||||
```
|
||||
|
||||
# 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
|
||||
server.
|
||||
|
||||
filebox will check for free space on server before uploading. A reserved
|
||||
5Go free space on your server (configurable in /etc/filebox/filebox.conf)
|
||||
filebox will check for free space on server before uploading a file. A
|
||||
reserved 5Go free space on your server (configurable in /etc/filebox/filebox.conf)
|
||||
is set.
|
||||
|
||||
Do not forget to unmount your mounted points using:
|
||||
|
|
|
@ -13,9 +13,11 @@ if__command rsync
|
|||
|
||||
if [[ `command ls -A "$fb_dir_files"` ]];then
|
||||
mount__srv ul
|
||||
|
||||
fb_server_bsize=`
|
||||
df -B1 | grep "$fb_srv_mnt_ul" | awk 'NR==2 {print $4}'`
|
||||
fb_server_rbsize=$(( fb_server_bsize + fb_keep_sbsize ))
|
||||
|
||||
clear
|
||||
while read -r "item"
|
||||
do
|
||||
|
@ -34,6 +36,6 @@ if [[ `command ls -A "$fb_dir_files"` ]];then
|
|||
fi
|
||||
done < <(ls -1)
|
||||
else
|
||||
echo -e "$I_YELLOW Nothing to upload in $fb_dir_files..."
|
||||
echo -e "$I_Yellow Nothing to upload in $fb_dir_files..."
|
||||
fi
|
||||
}
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue