From f5ab6597210b932577f553338f690eda3a3fca98 Mon Sep 17 00:00:00 2001 From: Peter Cai Date: Sat, 13 Jul 2024 18:07:07 -0400 Subject: [PATCH 1/2] Improve rmfile command --- bambu.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bambu.sh b/bambu.sh index 08faff8..4e03f65 100755 --- a/bambu.sh +++ b/bambu.sh @@ -98,7 +98,7 @@ function bambu_upload() { function bambu_rmfile() { local file="$(preprocess_file_path "$1")" - curl_ftps_command "$file" -Q "DELE /$file" + curl_ftps_command "" -Q "DELE /$file" > /dev/null 2>&1 || echo "Failed to delete file $file" } function bambu_print() { From 83f2a98d79014b6715847ecef87e44d14e0915f3 Mon Sep 17 00:00:00 2001 From: Peter Cai Date: Sat, 13 Jul 2024 18:15:16 -0400 Subject: [PATCH 2/2] Split file commands into a subcommand and support listing files --- bambu.sh | 60 ++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/bambu.sh b/bambu.sh index 4e03f65..0e63e36 100755 --- a/bambu.sh +++ b/bambu.sh @@ -86,9 +86,51 @@ function bambu_status() { mqtt_command '{"pushing": { "sequence_id": 1, "command": "pushall"}, "user_id":"1234567890"}' } -function bambu_lsdir() { - local directory="$(preprocess_directory_path "$1")" - curl_ftps_command "$directory" +function bambu_file() { + local subcommand="$1" + shift + + case "$subcommand" in + ls) + bambu_ls "$@" + ;; + upload) + bambu_upload "$@" + ;; + rm) + bambu_rm "$@" + ;; + *) + die "Unknown subcommand $subcommand" + ;; + esac +} + +function bambu_ls() { + local is_file="false" + local path="" + + while [ ! -z "$1" ]; do + case "$1" in + -f|--file) + is_file="true" + shift + ;; + *) + path="$1" + shift + break + ;; + esac + done + + if [ "$is_file" == "true" ]; then + path="$(preprocess_file_path "$path")" + curl_ftps_command "$(preprocess_directory_path "$(dirname "$path")")" -s | grep "$(basename "$path")" + else + path="$(preprocess_directory_path "$path")" + curl_ftps_command "$(preprocess_directory_path "$path")" + fi } function bambu_upload() { @@ -96,7 +138,7 @@ function bambu_upload() { curl_ftps_command "$directory" -T "$1" } -function bambu_rmfile() { +function bambu_rm() { local file="$(preprocess_file_path "$1")" curl_ftps_command "" -Q "DELE /$file" > /dev/null 2>&1 || echo "Failed to delete file $file" } @@ -225,14 +267,8 @@ case "$command" in status) bambu_status "$@" ;; - lsdir) - bambu_lsdir "$@" - ;; - upload) - bambu_upload "$@" - ;; - rmfile) - bambu_rmfile "$@" + file) + bambu_file "$@" ;; print) bambu_print "$@"