raspiblitz/home.admin/config.scripts/bonus.bos.sh

119 lines
3.5 KiB
Bash
Raw Normal View History

2020-05-18 15:25:39 +01:00
#!/bin/bash
# https://github.com/alexbosworth/balanceofsatoshis/blob/master/package.json#L81
BOSVERSION="10.7.8"
2021-03-16 22:49:13 +00:00
2020-05-18 15:25:39 +01:00
# command info
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
2020-06-01 11:32:28 +01:00
echo "config script to install, update or uninstall Balance of Satoshis"
echo "bonus.bos.sh [on|off|menu|update]"
2021-03-16 22:49:13 +00:00
echo "installs the version $BOSVERSION by default"
2020-05-18 15:25:39 +01:00
exit 1
fi
source /mnt/hdd/raspiblitz.conf
# show info menu
if [ "$1" = "menu" ]; then
dialog --title " Info Balance of Satoshis " --msgbox "
Balance of Satoshis is a command line tool.
Type: 'bos' in the command line to switch to the dedicated user.
Then see 'bos help' for the options.
2020-05-18 15:25:39 +01:00
Usage: https://github.com/alexbosworth/balanceofsatoshis/blob/master/README.md
" 10 75
2020-05-18 15:25:39 +01:00
exit 0
fi
2020-05-18 15:25:39 +01:00
# install
if [ "$1" = "1" ] || [ "$1" = "on" ]; then
2020-07-24 21:49:06 +02:00
if [ $(sudo ls /home/bos/.npmrc 2>/dev/null | grep -c ".npmrc") -gt 0 ]; then
2020-05-18 15:25:39 +01:00
echo "# FAIL - bos already installed"
sleep 3
exit 1
fi
echo "*** INSTALL BALANCE OF SATOSHIS ***"
# check and install NodeJS
2020-05-29 15:21:38 +01:00
/home/admin/config.scripts/bonus.nodejs.sh on
2020-05-18 15:25:39 +01:00
# create bos user
sudo adduser --disabled-password --gecos "" bos
echo "# Create data folder on the disk"
# move old data if present
sudo mv /home/bos/.bos /mnt/hdd/app-data/ 2>/dev/null
echo "# make sure the data directory exists"
sudo mkdir -p /mnt/hdd/app-data/.bos
echo "# symlink"
sudo rm -rf /home/bos/.bos # not a symlink.. delete it silently
sudo ln -s /mnt/hdd/app-data/.bos/ /home/bos/.bos
sudo chown bos:bos -R /mnt/hdd/app-data/.bos
2020-05-18 15:25:39 +01:00
# set up npm-global
sudo -u bos mkdir /home/bos/.npm-global
sudo -u bos npm config set prefix '/home/bos/.npm-global'
sudo bash -c "echo 'PATH=$PATH:/home/bos/.npm-global/bin' >> /home/bos/.bashrc"
# download source code
sudo -u bos git clone https://github.com/alexbosworth/balanceofsatoshis.git /home/bos/balanceofsatoshis
cd /home/bos/balanceofsatoshis
# make sure symlink to central app-data directory exists ***"
sudo rm -rf /home/bos/.lnd # not a symlink.. delete it silently
# create symlink
sudo ln -s "/mnt/hdd/app-data/lnd/" "/home/bos/.lnd"
2020-08-19 14:52:33 +01:00
# add user to group with admin access to lnd
2020-05-18 15:25:39 +01:00
sudo /usr/sbin/usermod --append --groups lndadmin bos
# install bos
2020-07-16 10:48:49 +01:00
# check latest version:
# https://github.com/alexbosworth/balanceofsatoshis/blob/master/package.json#L70
2021-03-16 22:49:13 +00:00
sudo -u bos npm install -g balanceofsatoshis@$BOSVERSION
if ! [ $? -eq 0 ]; then
echo "FAIL - npm install did not run correctly, aborting"
exit 1
fi
2020-05-18 15:25:39 +01:00
2021-04-14 20:20:29 +01:00
# add cli autocompletion https://www.npmjs.com/package/caporal/v/0.7.0#if-you-are-using-bash
sudo -u bos bash -c 'echo "source <(bos completion bash)" >> /home/bos/.bashrc'
2020-05-18 15:25:39 +01:00
# setting value in raspi blitz config
/home/admin/config.scripts/blitz.conf.sh set bos "on"
2020-05-18 15:25:39 +01:00
echo "# Usage: https://github.com/alexbosworth/balanceofsatoshis/blob/master/README.md"
echo "# To start type: 'sudo su bos' in the command line."
echo "# Then see 'bos help' for options."
echo "# To exit the user - type 'exit' and press ENTER"
exit 0
fi
2020-05-18 15:25:39 +01:00
# switch off
if [ "$1" = "0" ] || [ "$1" = "off" ]; then
# setting value in raspi blitz config
/home/admin/config.scripts/blitz.conf.sh set bos "off"
2020-05-18 15:25:39 +01:00
echo "*** REMOVING BALANCE OF SATOSHIS ***"
sudo userdel -rf bos
echo "# OK, bos is removed."
exit 0
fi
2020-06-01 11:32:28 +01:00
# update
if [ "$1" = "update" ]; then
echo "*** UPDATING BALANCE OF SATOSHIS ***"
sudo -u bos npm i -g balanceofsatoshis
2020-06-01 11:53:09 +01:00
echo "*** Updated to the latest in https://github.com/alexbosworth/balanceofsatoshis ***"
2020-06-01 11:32:28 +01:00
exit 0
fi
2020-05-18 15:25:39 +01:00
echo "FAIL - Unknown Parameter $1"
2021-04-14 20:20:29 +01:00
exit