Skip to content

Instantly share code, notes, and snippets.

@kiwi-cam
Created June 12, 2020 02:13
Show Gist options
  • Save kiwi-cam/555df8c730d5881686ce66635ab37843 to your computer and use it in GitHub Desktop.
Save kiwi-cam/555df8c730d5881686ce66635ab37843 to your computer and use it in GitHub Desktop.
A simple bash script to email details of your Homebridge setup for backup/archiving. Takes a single argument, the email destination. Uses sendmail so some configuration may be required. Also assumes config.json is in /var/homebridge
#!/bin/bash
if ! [[ "$1" =~ ^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$ ]]
then
echo "Email address $1 is invalid."
exit 1
fi
npm=`npm list -g --depth=0 | sed 's/$/<br \/>/'`
config=`cat /var/homebridge/config.json | sed 's/$/<br \/>/'`
subject="Homebridge Backup"
from="[email protected]"
recipients="$1"
message="Below is a record of your Homebridge installation and configuration"
mail="subject:$subject\nfrom:$from\nto:$1\nContent-Type: text/html\nMIME-Version: 1.0\n\n<HTML><BODY>$message<br /><br /><b>NPM:</b><br />$npm<br /><b>Config:</b><br />$config</BODY></HTML>"
echo -e $mail | /usr/sbin/sendmail -t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment