From 9967ab2b24025a16345bd4ecffd8b96be4a816b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Fernando=20S=C3=A1nchez?= Date: Wed, 28 Dec 2016 01:14:36 +0100 Subject: [PATCH] --- octo.sh | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/octo.sh b/octo.sh index 80d34e4..b31c239 100644 --- a/octo.sh +++ b/octo.sh @@ -1,18 +1,16 @@ #!/bin/bash -# Starting Octoprint's CLI takes **very long**. -# So long that it's useless for LIRC (remote) control. -# This script uses the CLI only once, to retrieve the API. -# It's a bit hacky, but it works for LIRC (infrared remote) -KEY_FILE=$HOME/.octokey -if [ ! -f "$KEY_FILE" ]; +CONF_FILE=$HOME/.octo.conf +if [ ! -f "$CONF_FILE" ]; then - OctoPrint/venv/bin/octoprint config get api.key | tr -d "'" > $KEY_FILE + echo OCTO_API_KEY=$(OctoPrint/venv/bin/octoprint config get api.key | tr -d "'") > $CONF_FILE + echo OCTO_PORT=$(OctoPrint/venv/bin/octoprint config get server.port | tr -d "'") >> $CONF_FILE + echo OCTO_HOST=$(OctoPrint/venv/bin/octoprint config get server.host | tr -d "'") >> $CONF_FILE echo 'Retrieved API key' fi -OCTO_API_KEY=$(cat $KEY_FILE) +source $CONF_FILE function send_octo() { - curl -H "X-Api-Key: $OCTO_API_KEY" -H 'Content-Type: application/json' --data "$1" http://localhost:5000/api/printer/printhead + curl -H "X-Api-Key: $OCTO_API_KEY" -H 'Content-Type: application/json' --data "$1" http://$OCTO_HOST:$OCTO_PORT/api/printer/printhead } case $1 in