-
-
Save ansarizafar/20572531b06ed8cb6bb52ebf33a47aa7 to your computer and use it in GitHub Desktop.
Automation for installing GunDB as a service (tested on Pi)
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 | |
## Usage: GUN_USER=gun GUN_ROOT=~gun/gun-pi-custom GUN_BRACH=master gun-service.sh | |
# Should be run as root (with sudo or directly) | |
[[ "$(whoami)" == "root" ]] || { echo "Must be run as root"; exit 1; } | |
# Setup default environment | |
[ -z "${GUN_USER}" ] && GUN_USER="pi" | |
GUN_DETECTED_USER_HOME=$(getent passwd ${GUN_USER} | cut -d: -f6) | |
[ -z "${GUN_ROOT}" ] && GUN_ROOT="${GUN_DETECTED_USER_HOME}/gun-service" | |
[ -z "${GUN_BRANCH}" ] && GUN_BRANCH="#manhattan" | |
# Exit on failure | |
set -e | |
# Create gun root folder | |
test -d "${GUN_ROOT}" || sudo -H -u ${GUN_USER} mkdir -vp "${GUN_ROOT}" | |
# Install NPM (only support `apt` for now, easily converted to `yum`, etc) | |
which npm || { apt update && apt install -y npm; } | |
# Install Gun | |
(cd "${GUN_ROOT}" && sudo -H -u ${GUN_USER} npm install "https://github.com/amark/gun.git${GUN_BRANCH}" --save) | |
# Install Service | |
cat << EOF > /etc/systemd/system/gun.service | |
[Unit] | |
Description=GunDB Relay Peer | |
[Service] | |
User=${GUN_USER} | |
Group=${GUN_USER} | |
WorkingDirectory=${GUN_ROOT}/node_modules/gun | |
ExecStart=/usr/bin/npm start | |
[Install] | |
WantedBy=multi-user.target | |
EOF | |
systemctl daemon-reload | |
systemctl enable gun | |
systemctl start gun |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment