Skip to content

Instantly share code, notes, and snippets.

View dimo414's full-sized avatar
🦀
Playing with Rust

Michael Diamond dimo414

🦀
Playing with Rust
View GitHub Profile
@dimo414
dimo414 / heartbeat.sh
Last active March 27, 2024 20:21
Basic Server Heartbeat Script
#!/bin/bash
# Source: https://gist.github.com/dimo414/10d6f162fb6d72f517a041d28d92314f
#
# This is a basic heartbeat monitoring script suitible for adding to
# a machine's crontab to receive alerts (via https://healthchecks.io)
# when the machine is unhealthy.
#
# I use it to keep an eye on my headless Raspberry Pi, but it should
# work for most Linux machines.
#
@dimo414
dimo414 / health-blink.sh
Last active April 3, 2021 18:42
Healthchecks.io + blink(1)
@dimo414
dimo414 / getopts.sh
Last active March 14, 2022 12:25
getopts function helper
#!/bin/bash
#
# Helper utility to simplify using Bash's getopts utility, and make it usable with functions.
#
# Example usage:
# foo() {
# local _usage=... # optional usage string
# eval "$(parse_opts 'ab:f:v')" # provide a standard getopts optstring
# echo "f is $f" # opts are now local variables
# if (( a )); then # check boolean flags with (( ... ))
@dimo414
dimo414 / build.md
Last active April 30, 2020 07:04
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
@dimo414
dimo414 / _README.md
Last active November 28, 2022 07:25
Bash array expansion patterns for use with -u

Expanding Bash arrays safely with set -u

Prior to Bash 4.4 set -u treated empty arrays as "unset", and terminates the process. There are a number of possible workarounds using array parameter expansion, however almost all of them fail in certain Bash versions.

This gist is a supplement to this StackOverflow post.

@dimo414
dimo414 / health-plex.sh
Last active April 3, 2021 18:42
Plex Healthcheck
#!/bin/bash
# Checks that a Plex server is up. For devices on a local network your
# router may have created [hostname].local or [hostname].lan DNS entries;
# otherwise you can pass an IP address or ensure your server is remotely
# accessible (https://support.plex.tv/articles/200931138/).
#
# See also
# https://old.reddit.com/r/PleX/comments/7qolre/what_do_others_do_to_monitor_plex_health/
# https://support.plex.tv/articles/201638786-plex-media-server-url-commands/
#
@dimo414
dimo414 / README.md
Last active June 5, 2023 06:53
Raspberry Pi Camera + mjpg-streamer systemd setup

This article includes setup instructions for the Raspberry Pi camera, but doesn't capture setting it up as a service (even though a few lines up it sets up OctoPrint as a service), and instead provides a pair of relatively-complex scripts to be run at startup via /etc/rc.local.

Setup

  • copy webcam.sh to the mjpg-streamer directory (or wherever you'd like, just update the MJPG_DIR variable)
  • copy pi-webcam.service to /etc/systemd/system/ (requires sudo), ensure ExecStart points to the correct path