I’m working on a module to add OctoPrint status to my zsh prompt, which I’ll probably write about in the future as a bigger post about my prompt customizations.
To start with that though, I need to play around with accessing the API via curl.
So here’s my super alpha version that will request the current status via HTTP and output it:
#!/bin/bash
OCTOPRINT_API="hunter2"
BASE_URL="http://octoprint.example.com"
JOB_ENDPOINT="${BASE_URL}/api/job"
CURL_TIMEOUT="0.5"# Fetch the JSON from OctoPrint
response="$(curl --max-time ${CURL_TIMEOUT} --silent --fail \
--header "X-Api-Key: ${OCTOPRINT_API}" \
"${JOB_ENDPOINT}")"# Extract fields with jq
file_name=$(jq -r '.job.file.display' <<< "$response")
completion=$(jq -r '.progress.completion' <<< "$response")
state=$(jq -r '.state' <<< "$response")
time_elapsed=$(jq -r '.progress.printTime' <<< "$response")
time_left=$(jq -r '.progress.printTimeLeft' <<< "$response")
# Round the completion percentage to two decimals
completion_str=$(printf"%.2f""$completion")
# Convert seconds to H:MM:SSfunctionfmt_time() {
local total_seconds="$1"local hours=$((total_seconds / 3600))
local minutes=$(((total_seconds % 3600) / 60))
local seconds=$((total_seconds % 60))
printf"%02d:%02d:%02d""$hours""$minutes""$seconds"
}
# Convert the times
time_elapsed_str=$(fmt_time "$time_elapsed")
time_left_str=$(fmt_time "$time_left")
# Print a readable summaryecho"File: ${file_name}"echo"State: ${state}"echo"Completion: ${completion_str}%"echo"Time Elapsed: ${time_elapsed_str}"echo"Time Left: ${time_left_str}"Code language:Bash(bash)
I set up a few defaults I like to have for my Pis:
# Updates, new software, and cleanup
sudo apt update && sudo apt upgrade
sudo apt install mc screen ack zsh locate git htop cockpit -y
sudo apt autoremove
# Add dotfile customizations. Sorry, it's currently private :D
git clone git@github.com:emrikol/dotfiles.git
cp -r ~/dotfiles/. ~/
sudo usermod --shell /bin/zsh derrick
zsh
# Set up root access so I can SCP in from Transmit if I need to.
sudo sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
sudo passwd root
# Customize Raspberry Pi settings.
sudo raspi-configCode language:Bash(bash)
After installing cockpit I believe, I had an issue where the MAC address of my Wifi kept changing randomly on each reboot. I had to follow these instructions and add this to my /etc/NetworkManager/NetworkManager.conf:
From here, we should have my default “base” Raspberry Pi setup. And now, we can work on figuring out how to install Pibooth. According to the install docs, we need to run a few commands:
$ sudo apt install "libsdl2-*"
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'libsdl2-mixer-dev'for glob 'libsdl2-*'
Note, selecting 'libsdl2-image-dev'for glob 'libsdl2-*'
Note, selecting 'libsdl2-gfx-dev'for glob 'libsdl2-*'
Note, selecting 'libsdl2-gfx-doc'for glob 'libsdl2-*'
Note, selecting 'libsdl2-mixer-2.0-0'for glob 'libsdl2-*'
Note, selecting 'libsdl2-dbg:armhf'for glob 'libsdl2-*'
Note, selecting 'libsdl2-dev'for glob 'libsdl2-*'
Note, selecting 'libsdl2-doc'for glob 'libsdl2-*'
Note, selecting 'libsdl2-ttf-dev'for glob 'libsdl2-*'
Note, selecting 'libsdl2-net-2.0-0'for glob 'libsdl2-*'
Note, selecting 'libsdl2-net-dev'for glob 'libsdl2-*'
Note, selecting 'libsdl2-image-2.0-0'for glob 'libsdl2-*'
Note, selecting 'libsdl2-2.0-0-dbgsym:armhf'for glob 'libsdl2-*'
Note, selecting 'libsdl2-2.0-0'for glob 'libsdl2-*'
Note, selecting 'libsdl2-gfx-1.0-0'for glob 'libsdl2-*'
Note, selecting 'libsdl2-ttf-2.0-0'for glob 'libsdl2-*'
libsdl2-2.0-0 is already the newest version (2.0.9+dfsg1-1+deb10u1).
libsdl2-2.0-0set to manually installed.
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
libsdl2-2.0-0-dbgsym:armhf : Depends: libsdl2-2.0-0:armhf (= 2.0.9+dfsg1-1+rpt1) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.Code language:JavaScript(javascript)
Meh. Okay. Let’s just install all of them but the trouble package. Hopefully that won’t come back to bite us.