From 59b86e7217d311ac358d9345f95213e27f4b4326 Mon Sep 17 00:00:00 2001 From: Peter Cai Date: Sat, 13 Jul 2024 19:10:15 -0400 Subject: [PATCH 1/3] Add missing case --- bambu.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bambu.sh b/bambu.sh index d410dd0..d971dd0 100755 --- a/bambu.sh +++ b/bambu.sh @@ -119,6 +119,9 @@ function bambu_ls() { is_file="true" shift ;; + -*) + die "Unknown option $1" + ;; *) path="$1" shift From c23282c0aa4da6989809c3d4912727fa60f78550 Mon Sep 17 00:00:00 2001 From: Peter Cai Date: Sat, 13 Jul 2024 21:04:48 -0400 Subject: [PATCH 2/3] Implement deleting directories --- bambu.sh | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/bambu.sh b/bambu.sh index d971dd0..1a18827 100755 --- a/bambu.sh +++ b/bambu.sh @@ -111,6 +111,7 @@ function bambu_file() { function bambu_ls() { local is_file="false" + local extra_curl_args="" local path="" while [ ! -z "$1" ]; do @@ -119,6 +120,10 @@ function bambu_ls() { is_file="true" shift ;; + --list-only) + extra_curl_args+="--list-only" + shift + ;; -*) die "Unknown option $1" ;; @@ -132,10 +137,10 @@ function bambu_ls() { if [ "$is_file" == "true" ]; then path="$(preprocess_file_path "$path")" - curl_ftps_command "$(preprocess_directory_path "$(dirname "$path")")" -s | grep "$(basename "$path")" + curl_ftps_command "$(preprocess_directory_path "$(dirname "$path")")" -s | grep "$(basename "$path")" $extra_curl_args else path="$(preprocess_directory_path "$path")" - curl_ftps_command "$(preprocess_directory_path "$path")" + curl_ftps_command "$(preprocess_directory_path "$path")" $extra_curl_args fi } @@ -145,10 +150,53 @@ function bambu_put() { } function bambu_rm() { + local is_dir="false" + local name="" + + while [ ! -z "$1" ]; do + case "$1" in + -r|--recursive) + is_dir=true + shift + ;; + -*) + die "Unknown option $1" + ;; + *) + name="$1" + shift + break + ;; + esac + done + + [ -z "$name" ] && die "Please specify file/directory to delete" + + if [ "$is_dir" == "true" ]; then + bambu_rm_dir "$name" + else + bambu_rm_file "$name" + fi +} + +function bambu_rm_file() { local file="$(preprocess_file_path "$1")" curl_ftps_command "" -Q "DELE /$file" > /dev/null 2>&1 || echo "Failed to delete file $file" } +function bambu_rm_dir() { + local dir="$(preprocess_directory_path "$1")" + [ -z "$dir" ] && die "Please specify directory to be deleted" + local content="$(bambu_ls --list-only "$dir" 2> /dev/null)" + + while read file; do + echo "Deleting $dir$file" + bambu_rm_file "$dir$file" + done <<< "$content" + + curl_ftps_command "" -Q "RMD /$dir" > /dev/null 2>&1 || echo "Failed to delete directory $dir" +} + function bambu_get() { local file="" local output_path="$PWD" From 4d5053a101c63ed324e4f58d1d584d713f52bb6c Mon Sep 17 00:00:00 2001 From: Peter Cai Date: Sat, 13 Jul 2024 21:21:47 -0400 Subject: [PATCH 3/3] Add help string --- bambu.sh | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/bambu.sh b/bambu.sh index 1a18827..d05e2c9 100755 --- a/bambu.sh +++ b/bambu.sh @@ -1,10 +1,56 @@ #!/usr/bin/env bash +CONFIG_PATH="${XDG_CONFIG_HOME:-$HOME/.config}/bambu.conf.sh" + +function usage() { + cat < [args] ... +Command line client for controlling Bambu Labs 3D printers. + +This script relies on a configuration file located at $CONFIG_PATH. +The configuration file should be a Bash script that sets the following variables: + +BAMBU_IP +BAMBU_SERIAL +BAMBU_ACCESS_CODE + +Subcommands: + help - Print this help message + status - Display current status of the printer + file + ls [--list-only] [--file] [path] + - List on the printer's SD card. + If "--list-only" is specified, only print out the names + of files without metadata (timestamp, etc.). + If "--file" is specified, then is assumed + to be a file, and it is listed on its own instead of + trying to list its children. + get [-o|--output ] + - Download to (\$PWD by default) + put + - Upload to + rm [-r|--recursive] + - Delete the remote on the printer. + If "-r" is specified, assume is a directory and + delete all of its children, including itself. + print + start [--timelapse] [--no-bed-leveling] [--no-vibration-calibration] + [--flow-calibration] + - Start a print job with . Only single-plate 3mf + files are supported. + pause|resume|stop + - As names suggest. + check + - Check the current print status from the printer and output + any potential error codes. + +EOF +} + function die() { echo "$1" >&2 exit 1 } -CONFIG_PATH="${XDG_CONFIG_HOME:-$HOME/.config}/bambu.conf.sh" [ ! -f "$CONFIG_PATH" ] && die "Config file $CONFIG_PATH not found" source "$CONFIG_PATH" @@ -94,7 +140,7 @@ function bambu_file() { ls) bambu_ls "$@" ;; - put]) + put) bambu_put "$@" ;; rm) @@ -353,6 +399,9 @@ case "$command" in print) bambu_print "$@" ;; + help) + usage + ;; *) die "Unknown command $command" ;;