Skip to content

Instantly share code, notes, and snippets.

@rocktronica
Created June 21, 2017 17:28
Show Gist options
  • Save rocktronica/7fa8865a643476b4e049c61992684b14 to your computer and use it in GitHub Desktop.
Save rocktronica/7fa8865a643476b4e049c61992684b14 to your computer and use it in GitHub Desktop.
#!/bin/bash
{
filename="$1"
user="pi"
host="octopi.local"
destination="~/.octoprint/uploads"
bandwidth_limit="1000" # prevents stalling on large files; kbit/s
function upload() {
echo "Uploading $filename"
scp -C -l "$bandwidth_limit" "$filename" "$user@$host:$destination"
echo
}
function stop_octoprint() {
echo 'Stopping OctoPrint'
ssh "$user@$host" 'sudo service octoprint stop'
echo
}
function start_octoprint() {
echo 'Starting OctoPrint'
ssh "$user@$host" 'sudo service octoprint start'
}
if [[ -z "$filename" ]]; then
echo 'No filename found'
exit 1
fi
stop_octoprint
upload "$filename"
start_octoprint
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment