Skip to content

Commit

Permalink
Don't use RatOS provided configurator helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
miklschmidt committed Jan 2, 2024
1 parent 2225815 commit 1bacbe0
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions scripts/ratos-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,36 @@ install_beacon()

# update link to beacon.py
echo "beacon: registering beacon with the configurator."
register_klippy_extension "beacon" "$BEACON_DIR" "beacon.py"
_register_klippy_extension "beacon" "$BEACON_DIR" "beacon.py"

}

_register_klippy_extension() {
EXT_NAME=$1
EXT_PATH=$2
EXT_FILE=$3
ERROR_IF_EXISTS=$4
[[ "$ERROR_IF_EXISTS" == "false" ]] && ERROR_IF_EXISTS="false" || ERROR_IF_EXISTS="true"

report_status "Registering klippy extension '$EXT_NAME' with the RatOS Configurator..."
if [ ! -e "$EXT_PATH/$EXT_FILE" ]
then
echo "ERROR: The file you're trying to register does not exist"
exit 1
fi


if curl --fail -X POST 'http://localhost:3000/configure/api/trpc/klippy-extensions.register' \
-H 'content-type: application/json' \
--data-raw "{\"json\":{\"extensionName\":\"$EXT_NAME\",\"path\":\"$EXT_PATH\",\"fileName\":\"$EXT_FILE\",\"errorIfExists\":$ERROR_IF_EXISTS}}"
then
echo "Registered $EXT_NAME successfully."
else
echo "ERROR: Failed to register $EXT_NAME. Is the RatOS configurator running?"
exit 1
fi
}

regenerate_config() {
report_status "Regenerating RatOS configuration via RatOS Configurator..."

Expand All @@ -67,7 +93,7 @@ register_gcode_shell_command()
EXT_NAME="gcode_shell_extension"
EXT_PATH=$(realpath "$SCRIPT_DIR"/../klippy)
EXT_FILE="gcode_shell_command.py"
register_klippy_extension $EXT_NAME "$EXT_PATH" $EXT_FILE
_register_klippy_extension $EXT_NAME "$EXT_PATH" $EXT_FILE
}

register_ratos_homing()
Expand All @@ -76,7 +102,7 @@ register_ratos_homing()
EXT_PATH=$(realpath "$SCRIPT_DIR"/../klippy)
EXT_FILE="ratos_homing.py"
# Don't error if extension is already registered
register_klippy_extension $EXT_NAME "$EXT_PATH" $EXT_FILE "false"
_register_klippy_extension $EXT_NAME "$EXT_PATH" $EXT_FILE "false"
}

install_hooks()
Expand Down

0 comments on commit 1bacbe0

Please sign in to comment.