Skip to content

Instantly share code, notes, and snippets.

@dimo414
Last active April 30, 2020 07:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dimo414/62f88a1b0917bd5e3a6bfe51c58ccca2 to your computer and use it in GitHub Desktop.
Save dimo414/62f88a1b0917bd5e3a6bfe51c58ccca2 to your computer and use it in GitHub Desktop.
Run Slack Dogebot on Raspberry Pi

Build the Luit/dogebot binary (I prefer to do so in a Docker container) for ARM:

$ docker run -v /tmp:/mnt/tmp -it debian:testing
docker$ apt-get update && apt-get install -y git golang
# Ensure build dependencies are available locally
docker$ go get github.com/Luit/dogebot/src/dogebot
docker$ git clone https://github.com/Luit/dogebot
docker$ cd dogebot/src/dogebot
# Build a Raspberry Pi binary
# https://www.thepolyglotdeveloper.com/2017/04/cross-compiling-golang-applications-raspberry-pi/
docker$ env GOOS=linux GOARCH=arm GOARM=5 go build
docker$ cp dogebot /mnt/tmp/
docker$ exit
$ scp /tmp/dogebot pi@hostname:

Then copy dogebot.sh to ~ (you'll need to tweak the script if you want it/the binary to live somewhere other than your home directory), and add the following to your crontab:

*/5      * * * * bash /home/pi/dogebot.sh [YOUR SLACK API KEY]
#!/bin/bash
# Crontab wrapper for the dogebot binary, to safely restart it if it crashes
if pgrep dogebot >/dev/null; then
# already running
exit
fi
key=${1:?API key}
logfile=/tmp/dogebot.log
date >> "$logfile"
SLACK_TOKEN=$key exec ~/dogebot >> "$logfile" 2>&1
@dimo414
Copy link
Author

dimo414 commented Apr 30, 2020

http://mywiki.wooledge.org/ProcessManagement suggests some better alternatives to scheduled polling with cron. Even the while-loop approach would probably be sufficient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment