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
# version: 0.1.5
# version: 0.1.7
# file: filebox
# Folder: /usr/local/bin
# By echolib
@ -69,6 +69,10 @@ if__command() {
# Main for script: Check/Source files & Create folders
if__file "/etc/filebox/filebox.conf" 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"
# Check local folders
@ -103,30 +107,22 @@ case "$1" in
shift
done
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
;;
unmount|-u)
if__file "$fb_dir_scripts/mount__srv" source
case "$3" in
"") true ;;
*) fb_name_srv="$3" ;;
esac
if__folder "$fb_dir_mnt_ul/$fb_name_srv" config
if__file "$fb_file_conf_srv$fb_name_srv.conf" source
case "$2" in
ul)
case "$3" in
"") true ;;
*) fb_name_srv="$3" ;;
esac
if__folder "$fb_dir_mnt_ul/$fb_name_srv" config
if__file "$fb_file_conf_srv$fb_name_srv.conf" source
mount__srv ul -U
;;
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
;;
*)
@ -147,21 +143,16 @@ case "$1" in
get__files
;;
-U)
if__file "$fb_dir_scripts/updater" source
Updater
;;
version|-v)
awk 'NR==2 {print "# Installed:",$3}' "/usr/local/bin/filebox"
awk 'NR==2 {print "# Installed:",$3}' "/usr/local/bin/upd"
;;
-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"
script__versions
;;
-U)
Updater
;;
--readme)

View File

@ -15,17 +15,20 @@ if__folder "$fb_dir_mnt" cd
# Server Stats
df -h \
| grep "$fb_srv_mnt_dl" \
| awk '{print \
"# Space Total: "$2 \
" | Used: "$3" ("$5")" \
" | Free: "$4}'
| awk \
'{print \
": Space Total: "$2, \
"| Used: "$3" ("$5")," \
"| Free: "$4}'
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`
printf '%b%b%b\n' \
"# $C_Yellow$fb_dirs_nbr folders$NC $Pp_Grey " \
"$C_Cyan$fb_files_nbr files$NC " \
"in '$fb_srv_mnt_dl'"
fb_files_nbr_t=`find . -type f | wc -l`
printf '%b%b\n%b\n' \
": Folders: $C_Yellow$fb_dirs_nbr$NC/$fb_dirs_nbr_t $Pp_Grey " \
"Files: $C_Cyan$fb_files_nbr$NC/$fb_files_nbr_t" \
": Mounted: ${C_Yellow}$fb_srv_mnt_dl$NC > $PWD"
# Create profile
touch "$fb_file_profile_list"
@ -43,8 +46,8 @@ fi
# Show items list and ask
#======================================================================
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'|'
fb_max_items=`cat "$fb_file_list" | wc -l`
@ -52,8 +55,9 @@ echo
read -rp "- Select files to download: " user_selections
case "$user_selections" in
"") return ;;
l|L) get__files ;;
*) get__selections ;;
l) get__files ;;
L) rm -f "$fb_file_list";rm -f "$fb_file_profile_list";get__files ;;
*) get__selections ;;
esac
}
@ -73,6 +77,7 @@ do
(( $fb_line <= 0 )) || \
(( $fb_line > $fb_max_items )) \
&& continue
fb_filename=`
cat -n "$fb_file_list" \
| awk -F"|" -v l="$fb_line" 'NR==l {print $4}'`
@ -100,7 +105,10 @@ if__command rsync
if__command numfmt
# 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_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_local_dir > $fb_filename"
rsync -a --update --info=progress2 \
rsync -a --update --info=progress2 2>/dev/null \
"$fb_filename" "$fb_local_dir"
chmod -R go+rx "$fb_local_dir"
}
@ -133,21 +141,24 @@ create__list() {
touch "$fb_file_list"
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_time" \
"fb_file"
"fb_time_file"
do
fb_time=`echo $fb_time_file | cut -d' ' -f1`
fb_file=${fb_time_file/$fb_time /}
[[ "$fb_rights" =~ "d" ]] \
&& fb_color="$C_Yellow" \
|| fb_color="$C_Cyan"
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" \
>> "$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"
}

View File

@ -1,29 +1,42 @@
#!/bin/bash
# file: updater
# Folder: /var/lib/upd/scripts/
# Folder: /var/lib/filebox/scripts/
# By echolib
# 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
#======================================================================
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
script__versions
[[ $upd_err ]] \
&& return 1
# Get archive
cd /tmp
@ -32,16 +45,15 @@ curl -L -o ${app_name}-main.tar.gz "$repo_tar" 2>/dev/null
&& 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}/"
tar -xzf "${app_name}-main.tar.gz"
# Check
v_cur=`awk 'NR==2 {print $3}' "/usr/local/bin/$app_name"`
echo "# $app_name updated to: $v_cur"
cd "${app_name}-main"
cp -f "usr/local/bin/$app_name" "/usr/local/bin/$app_name"
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
rm -f ${app_name}-main.tar.gz
upd -v
rm -rf "/tmp/${app_name}-main"
rm -f "/tmp/${app_name}-main.tar.gz"
}