Compare commits
No commits in common. "4d5053a101c63ed324e4f58d1d584d713f52bb6c" and "726d20b8f73f07fd0ca23dd17e8975a0a1239744" have entirely different histories.
4d5053a101
...
726d20b8f7
1 changed files with 4 additions and 104 deletions
108
bambu.sh
108
bambu.sh
|
@ -1,56 +1,10 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
CONFIG_PATH="${XDG_CONFIG_HOME:-$HOME/.config}/bambu.conf.sh"
|
|
||||||
|
|
||||||
function usage() {
|
|
||||||
cat <<EOF
|
|
||||||
Command: $0 [--debug] [--raw-output] <subcommand> [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 <path> 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 <path> is assumed
|
|
||||||
to be a file, and it is listed on its own instead of
|
|
||||||
trying to list its children.
|
|
||||||
get [-o|--output <output_directory>] <remote_file>
|
|
||||||
- Download <remote_file> to <output_directory> (\$PWD by default)
|
|
||||||
put <local_file> <remote_directory>
|
|
||||||
- Upload <local_file> to <remote_directory>
|
|
||||||
rm [-r|--recursive] <path>
|
|
||||||
- Delete the remote <path> on the printer.
|
|
||||||
If "-r" is specified, assume <path> is a directory and
|
|
||||||
delete all of its children, including itself.
|
|
||||||
print
|
|
||||||
start [--timelapse] [--no-bed-leveling] [--no-vibration-calibration]
|
|
||||||
[--flow-calibration] <remote_file>
|
|
||||||
- Start a print job with <remote_file>. 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() {
|
function die() {
|
||||||
echo "$1" >&2
|
echo "$1" >&2
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CONFIG_PATH="${XDG_CONFIG_HOME:-$HOME/.config}/bambu.conf.sh"
|
||||||
[ ! -f "$CONFIG_PATH" ] && die "Config file $CONFIG_PATH not found"
|
[ ! -f "$CONFIG_PATH" ] && die "Config file $CONFIG_PATH not found"
|
||||||
|
|
||||||
source "$CONFIG_PATH"
|
source "$CONFIG_PATH"
|
||||||
|
@ -140,7 +94,7 @@ function bambu_file() {
|
||||||
ls)
|
ls)
|
||||||
bambu_ls "$@"
|
bambu_ls "$@"
|
||||||
;;
|
;;
|
||||||
put)
|
put])
|
||||||
bambu_put "$@"
|
bambu_put "$@"
|
||||||
;;
|
;;
|
||||||
rm)
|
rm)
|
||||||
|
@ -157,7 +111,6 @@ function bambu_file() {
|
||||||
|
|
||||||
function bambu_ls() {
|
function bambu_ls() {
|
||||||
local is_file="false"
|
local is_file="false"
|
||||||
local extra_curl_args=""
|
|
||||||
local path=""
|
local path=""
|
||||||
|
|
||||||
while [ ! -z "$1" ]; do
|
while [ ! -z "$1" ]; do
|
||||||
|
@ -166,13 +119,6 @@ function bambu_ls() {
|
||||||
is_file="true"
|
is_file="true"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--list-only)
|
|
||||||
extra_curl_args+="--list-only"
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
-*)
|
|
||||||
die "Unknown option $1"
|
|
||||||
;;
|
|
||||||
*)
|
*)
|
||||||
path="$1"
|
path="$1"
|
||||||
shift
|
shift
|
||||||
|
@ -183,10 +129,10 @@ function bambu_ls() {
|
||||||
|
|
||||||
if [ "$is_file" == "true" ]; then
|
if [ "$is_file" == "true" ]; then
|
||||||
path="$(preprocess_file_path "$path")"
|
path="$(preprocess_file_path "$path")"
|
||||||
curl_ftps_command "$(preprocess_directory_path "$(dirname "$path")")" -s | grep "$(basename "$path")" $extra_curl_args
|
curl_ftps_command "$(preprocess_directory_path "$(dirname "$path")")" -s | grep "$(basename "$path")"
|
||||||
else
|
else
|
||||||
path="$(preprocess_directory_path "$path")"
|
path="$(preprocess_directory_path "$path")"
|
||||||
curl_ftps_command "$(preprocess_directory_path "$path")" $extra_curl_args
|
curl_ftps_command "$(preprocess_directory_path "$path")"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,53 +142,10 @@ function bambu_put() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function bambu_rm() {
|
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")"
|
local file="$(preprocess_file_path "$1")"
|
||||||
curl_ftps_command "" -Q "DELE /$file" > /dev/null 2>&1 || echo "Failed to delete file $file"
|
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() {
|
function bambu_get() {
|
||||||
local file=""
|
local file=""
|
||||||
local output_path="$PWD"
|
local output_path="$PWD"
|
||||||
|
@ -399,9 +302,6 @@ case "$command" in
|
||||||
print)
|
print)
|
||||||
bambu_print "$@"
|
bambu_print "$@"
|
||||||
;;
|
;;
|
||||||
help)
|
|
||||||
usage
|
|
||||||
;;
|
|
||||||
*)
|
*)
|
||||||
die "Unknown command $command"
|
die "Unknown command $command"
|
||||||
;;
|
;;
|
||||||
|
|
Loading…
Add table
Reference in a new issue