Last active
May 7, 2016 03:08
-
-
Save karrots/e0d6ae1432d7f2130273 to your computer and use it in GitHub Desktop.
Self install script for RaspberryPi-Gateway. Copy to base Jessie or Jessie Lite install. Change permissions and run as root.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#rsyslog config to redirect moteino-gateway logs to the home directory. | |
#Place this file in /etc/rsyslog.d/ then restart the rsyslog daemon. | |
if $programname == 'moteino-gateway' then /home/pi/gateway/logs/gateway.log | |
& ~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Installs NodeJS 4.3.x, RaspberryPi-Gateway, and a systemd service file. | |
# Created by Jonathan Karras jkarras @ karras.net | |
# https://gist.github.com/karrots/e0d6ae1432d7f2130273 | |
NODEVERSION='v4.4.4' | |
NODEARCH=$(uname -m) | |
NODEDOWNLOAD="https://nodejs.org/dist/${NODEVERSION}/node-${NODEVERSION}-linux-${NODEARCH}.tar.xz" | |
NODEDIR='/opt/nodejs' | |
APPSRVDIR='/home/pi/gateway/' | |
BRANCH='ExpressJS-dev' | |
REPO='https://github.com/LowPowerLab/RaspberryPi-Gateway' | |
function setupPreReq() | |
{ | |
apt-get update -m | |
apt-get install -y git apache2-utils build-essential | |
} | |
function installNodeJSviaTZX() | |
{ | |
mkdir -p $NODEDIR | |
cd $NODEDIR || exit | |
echo "Download & extract node.js version: ${NODEVERSION} arch: ${NODEARCH}..." | |
curl -#L "$NODEDOWNLOAD" | tar Jx --strip-components 1 | |
echo 'Creating symbolic link to node in /usr/bin/' | |
ln -sf $NODEDIR/bin/node /usr/bin/node | |
echo 'Creating symbolic link to nodejs in /usr/bin/' | |
ln -sf $NODEDIR/bin/node /usr/bin/nodejs | |
echo 'Creating symbolic link to npm in /usr/bin/' | |
ln -sf $NODEDIR/bin/npm /usr/bin/npm | |
} | |
function installNodeJSviaAPT() | |
{ | |
curl -#L https://deb.nodesource.com/setup_4.x | sudo -E bash - | |
sudo apt-get install -y nodejs | |
} | |
function installMoteinoGW() | |
{ | |
mkdir -p $APPSRVDIR | |
cd $APPSRVDIR || exit | |
echo "Clone branch ${BRANCH} from repo ${REPO} RaspberryPi-Gateway repository from github." | |
git clone --depth=1 --branch=$BRANCH $REPO . | |
chown -R pi:pi $APPSRVDIR | |
npm install --unsafe-perm --production | |
} | |
function setupHTTPUser() | |
{ | |
echo "Setting up default web credentials." | |
echo "username: admin" | |
echo "password: raspberry" | |
echo "Change using \"htpassword $APPSRVDIR/data/secure/.htpasswd admin\"." | |
htpasswd -bc $APPSRVDIR/data/secure/.htpasswd admin raspberry | |
} | |
function installSystemdUnitFile() | |
{ | |
#Install Systemd unit file | |
echo "Copy systemd service file to /etc/systemd/system/" | |
cp $APPSRVDIR/_piConfigs/moteino-gateway.service /etc/systemd/system/ | |
#Enable service to start at boot. | |
echo 'To enable at boot run "systemctl enable moteino-gateway.service" after creating htaccess file' | |
} | |
#Install packages needed to complete this install as well as build the node_modules | |
setupPreReq | |
#Install the correct node version for the box its installed on. Choosing LTS 4.3.x | |
if [[ "$NODEARCH" == "armv6l" ]] ; then | |
#arm6l isn't in the apt repo install the tzx file manually. | |
installNodeJSviaTZX | |
else | |
#arm7+ is in the apt repo as well as i386/i686 so install from there. | |
installNodeJSviaAPT | |
fi | |
#Install the gateaway node source code via a git clone. | |
installMoteinoGW | |
#Setup a initial HTTP user account. Currently password is hard set. | |
#This could be generated at a future date. | |
setupHTTPUser | |
#Install the systemd unit file to start the node program as needed. | |
installSystemdUnitFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
journalctl --since '3 days ago' -u moteino-gateway.service --no-pager | tar jvf fileofyourchoice.txz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Dang, I probably need a commit hook to keep me from doing that.