Fix: filename leading space - more stats - better display

This commit is contained in:
Cyrille L 2022-03-31 15:54:47 +02:00
parent 8542fa5fa1
commit 6eddf80ddc
3 changed files with 86 additions and 72 deletions

View File

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
# version: 0.1.5 # version: 0.1.7
# file: filebox # file: filebox
# Folder: /usr/local/bin # Folder: /usr/local/bin
# By echolib # By echolib
@ -69,6 +69,10 @@ if__command() {
# Main for script: Check/Source files & Create folders # Main for script: Check/Source files & Create folders
if__file "/etc/filebox/filebox.conf" source if__file "/etc/filebox/filebox.conf" source
if__file "$fb_dir_scripts/tools" source if__file "$fb_dir_scripts/tools" source
if__file "$fb_dir_scripts/updater" source
if__file "$fb_dir_scripts/mount__srv" source
if__file "$fb_dir_scripts/send__files" source
if__folder "$fb_dir_conf_user" if__folder "$fb_dir_conf_user"
# Check local folders # Check local folders
@ -103,30 +107,22 @@ case "$1" in
shift shift
done done
if__file "$fb_file_conf_srv$fb_name_srv.conf" source if__file "$fb_file_conf_srv$fb_name_srv.conf" source
if__file "$fb_dir_scripts/mount__srv" source
if__file "$fb_dir_scripts/send__files" source
send__files send__files
;; ;;
unmount|-u) unmount|-u)
if__file "$fb_dir_scripts/mount__srv" source
case "$2" in
ul)
case "$3" in case "$3" in
"") true ;; "") true ;;
*) fb_name_srv="$3" ;; *) fb_name_srv="$3" ;;
esac esac
if__folder "$fb_dir_mnt_ul/$fb_name_srv" config if__folder "$fb_dir_mnt_ul/$fb_name_srv" config
if__file "$fb_file_conf_srv$fb_name_srv.conf" source if__file "$fb_file_conf_srv$fb_name_srv.conf" source
case "$2" in
ul)
mount__srv ul -U mount__srv ul -U
;; ;;
dl) dl)
case "$3" in
"") true ;;
*) fb_name_srv="$3" ;;
esac
if__folder "$fb_dir_mnt_dl/$fb_name_srv" config
if__file "$fb_file_conf_srv$fb_name_srv.conf" source
mount__srv dl -U mount__srv dl -U
;; ;;
*) *)
@ -147,21 +143,16 @@ case "$1" in
get__files get__files
;; ;;
-U)
if__file "$fb_dir_scripts/updater" source
Updater
;;
version|-v) version|-v)
awk 'NR==2 {print "# Installed:",$3}' "/usr/local/bin/filebox" awk 'NR==2 {print "# Installed:",$3}' "/usr/local/bin/upd"
;; ;;
-vv) -vv)
v_cur=`awk 'NR==2 {print $3}' "/usr/local/bin/$app_name"` script__versions
echo -n "# $app_name Current: $v_cur | " ;;
if__command curl
v_onl=`curl -s "$repo" | awk 'NR==2 {print $3}'` -U)
echo -ne "Online: $v_onl\n" Updater
;; ;;
--readme) --readme)

View File

@ -15,17 +15,20 @@ if__folder "$fb_dir_mnt" cd
# Server Stats # Server Stats
df -h \ df -h \
| grep "$fb_srv_mnt_dl" \ | grep "$fb_srv_mnt_dl" \
| awk '{print \ | awk \
"# Space Total: "$2 \ '{print \
" | Used: "$3" ("$5")" \ ": Space Total: "$2, \
"| Used: "$3" ("$5")," \
"| Free: "$4}' "| Free: "$4}'
fb_dirs_nbr=`find . -maxdepth 1 -type d | wc -l` fb_dirs_nbr=`find . -maxdepth 1 -type d | wc -l`
fb_dirs_nbr_t=`find . -type d | wc -l`
fb_files_nbr=`find . -maxdepth 1 -type f | wc -l` fb_files_nbr=`find . -maxdepth 1 -type f | wc -l`
printf '%b%b%b\n' \ fb_files_nbr_t=`find . -type f | wc -l`
"# $C_Yellow$fb_dirs_nbr folders$NC $Pp_Grey " \ printf '%b%b\n%b\n' \
"$C_Cyan$fb_files_nbr files$NC " \ ": Folders: $C_Yellow$fb_dirs_nbr$NC/$fb_dirs_nbr_t $Pp_Grey " \
"in '$fb_srv_mnt_dl'" "Files: $C_Cyan$fb_files_nbr$NC/$fb_files_nbr_t" \
": Mounted: ${C_Yellow}$fb_srv_mnt_dl$NC > $PWD"
# Create profile # Create profile
touch "$fb_file_profile_list" touch "$fb_file_profile_list"
@ -43,8 +46,8 @@ fi
# Show items list and ask # Show items list and ask
#====================================================================== #======================================================================
user__select() { user__select() {
echo -e "$C_Grey# Profile List:$NC $fb_profile_list\n" #echo -e "$C_Grey# Profile List:$NC $fb_profile_list\n"
echo
cat -n "$fb_file_list" | column -t -s'|' cat -n "$fb_file_list" | column -t -s'|'
fb_max_items=`cat "$fb_file_list" | wc -l` fb_max_items=`cat "$fb_file_list" | wc -l`
@ -52,7 +55,8 @@ echo
read -rp "- Select files to download: " user_selections read -rp "- Select files to download: " user_selections
case "$user_selections" in case "$user_selections" in
"") return ;; "") return ;;
l|L) get__files ;; l) get__files ;;
L) rm -f "$fb_file_list";rm -f "$fb_file_profile_list";get__files ;;
*) get__selections ;; *) get__selections ;;
esac esac
} }
@ -73,6 +77,7 @@ do
(( $fb_line <= 0 )) || \ (( $fb_line <= 0 )) || \
(( $fb_line > $fb_max_items )) \ (( $fb_line > $fb_max_items )) \
&& continue && continue
fb_filename=` fb_filename=`
cat -n "$fb_file_list" \ cat -n "$fb_file_list" \
| awk -F"|" -v l="$fb_line" 'NR==l {print $4}'` | awk -F"|" -v l="$fb_line" 'NR==l {print $4}'`
@ -100,7 +105,10 @@ if__command rsync
if__command numfmt if__command numfmt
# Check free space # Check free space
fb_file_bsize=`du -s -B1 "$fb_filename" | awk '{print $1}'` fb_file_bsize=`du -s -B1 "$fb_filename" 2>/dev/null | awk '{print $1}'`
! [[ $fb_file_bsize ]] \
&& echo -e "! ${C_Red}Error$NC on $fb_filename" \
&& return
fb_free_bsize=`df -B1 "$fb_local_dir" | awk 'NR==2 {print $4}'` fb_free_bsize=`df -B1 "$fb_local_dir" | awk 'NR==2 {print $4}'`
fb_file_keep_bsize=$(( fb_keep_bsize + fb_file_bsize )) fb_file_keep_bsize=$(( fb_keep_bsize + fb_file_bsize ))
@ -119,7 +127,7 @@ printf '%b%b\n' \
"- $fb_file_hsize < ($fb_free_hdisk - $fb_keep_hsize): " \ "- $fb_file_hsize < ($fb_free_hdisk - $fb_keep_hsize): " \
"$fb_local_dir > $fb_filename" "$fb_local_dir > $fb_filename"
rsync -a --update --info=progress2 \ rsync -a --update --info=progress2 2>/dev/null \
"$fb_filename" "$fb_local_dir" "$fb_filename" "$fb_local_dir"
chmod -R go+rx "$fb_local_dir" chmod -R go+rx "$fb_local_dir"
} }
@ -133,21 +141,24 @@ create__list() {
touch "$fb_file_list" touch "$fb_file_list"
echo -ne ": Checking files..." echo -ne ": Checking files..."
while read -r "fb_rights" "b" "c" "d" "d" \ while read -r "fb_rights" "b" "c" "d" "e" \
"fb_date" \ "fb_date" \
"fb_time" \ "fb_time_file"
"fb_file"
do do
fb_time=`echo $fb_time_file | cut -d' ' -f1`
fb_file=${fb_time_file/$fb_time /}
[[ "$fb_rights" =~ "d" ]] \ [[ "$fb_rights" =~ "d" ]] \
&& fb_color="$C_Yellow" \ && fb_color="$C_Yellow" \
|| fb_color="$C_Cyan" || fb_color="$C_Cyan"
echo -ne "\r\033[2K: Checking files... $fb_file" echo -ne "\r\033[2K: Checking files... $fb_file"
fb_file_hsize=`du -sh "$fb_file" | awk '{print $1}'` fb_file_hsize=`du -sh "$fb_file" 2>/dev/null | awk '{print $1}'`
! [[ "$fb_file_hsize" ]] \
&& fb_file_hsize="0"
echo -e "$C_Grey$fb_date|$fb_time$NC|$fb_color$fb_file_hsize$NC|$fb_file" \ echo -e "$C_Grey$fb_date|$fb_time$NC|$fb_color$fb_file_hsize$NC|$fb_file" \
>> "$fb_file_list" >> "$fb_file_list"
done < <(command ls -lt --time-style=long-iso | awk 'NR > 1') done < <(command ls -lt --time-style=long-iso | awk -F' ' 'NR > 1')
echo -ne "\r\033[2K" echo -ne "\r\033[2K"
} }

View File

@ -1,29 +1,42 @@
#!/bin/bash #!/bin/bash
# file: updater # file: updater
# Folder: /var/lib/upd/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
#======================================================================
# script version checker
#======================================================================
script__versions() {
if__command curl
v_cur=`awk 'NR==2 {print $3}' "/usr/local/bin/$app_name"`
v_onl=`curl -s "$repo" | awk 'NR==2 {print $3}'`
if ! [[ $v_onl ]];then
echo "! Unknown available version"
upd_err=true
return 1
fi
printf -v versions '%s\n%s' "$v_cur" "$v_onl"
if [[ `sort -V <<< "$versions" | tail -1` == $v_cur ]];then
echo "# $app_name is up to date (version: $v_cur)"
upd_err=true
return 0
else
echo -e "- $app_name $C_Yellow$v_cur$NC -> $C_Green$v_onl$NC"
fi
}
#====================================================================== #======================================================================
# Automatic Updater # Automatic Updater
#====================================================================== #======================================================================
Updater() { Updater() {
if__command curl
if__command rsync if__command rsync
script__versions
v_cur=`awk 'NR==2 {print $3}' "/usr/local/bin/$app_name"` [[ $upd_err ]] \
echo -n "# $app_name Current: $v_cur | " && return 1
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 # Get archive
cd /tmp cd /tmp
@ -32,16 +45,15 @@ curl -L -o ${app_name}-main.tar.gz "$repo_tar" 2>/dev/null
&& echo "! Download error" \ && echo "! Download error" \
&& return && return
tar -xzf ${app_name}-main.tar.gz 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 cd "${app_name}-main"
v_cur=`awk 'NR==2 {print $3}' "/usr/local/bin/$app_name"` cp -f "usr/local/bin/$app_name" "/usr/local/bin/$app_name"
echo "# $app_name updated to: $v_cur" rsync -a --delete "var/lib/$app_name/" "/var/lib/$app_name/"
rsync -a --delete "etc/$app_name/" "/etc/$app_name/"
rm -rf /tmp/${app_name}-main upd -v
rm -f ${app_name}-main.tar.gz
rm -rf "/tmp/${app_name}-main"
rm -f "/tmp/${app_name}-main.tar.gz"
} }