bitcore/scripts/debian/postinst

38 lines
1.0 KiB
Bash

#!/bin/bash
set -e
set -o pipefail
# add group
if ! getent group | grep -q "^bitcore:" ; then
echo "Creating system group: bitcore"
groupadd --system bitcore
fi
# add user
if ! getent passwd | grep -q "^bitcore:"; then
echo "Creating bitcore system user"
useradd --gid "bitcore" --system -m bitcore
fi
# build nodejs addons
cd "/usr/opt/bitcore"
SKIP_BITCOIN_DOWNLOAD=1 npm rebuild
# setup data directory
mkdir -p "/home/bitcore/.bitcore/data"
chown -R bitcore:bitcore "/home/bitcore/.bitcore"
# start bitcore
if hash service 2> /dev/null; then
service bitcore start || echo "bitcore could not be registered or started"
elif hash start 2> /dev/null; then
start bitcore || echo "bitcore could not be registered or started"
elif hash systemctl 2> /dev/null; then
{
systemctl enable "bitcore.service" && \
systemctl start "bitcore.service"
} || echo "bitcore could not be registered or started"
else
echo 'Your system does not appear to use upstart or systemd, so bitcore could not be started'
fi