Skip to content

Commit

Permalink
Merge pull request #1301 from dennisreimann/kindle-display
Browse files Browse the repository at this point in the history
Add bonus script: kindle-display
  • Loading branch information
rootzoll authored Jul 4, 2020
2 parents b6b25cf + 46bb6bc commit 9d40258
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ There are further Services that can be switched on:
* **ThunderHub** (Lightning Node Manager WebUI) [details](https://www.thunderhub.io/)
* **Faraday** (Channel Analysis & Recommendations CLI) [details](https://github.com/lightninglabs/faraday/blob/master/README.md)
* **Balance Of Satoshis** (Commands for working with LND balances) [details](https://github.com/alexbosworth/balanceofsatoshis/blob/master/README.md)
* **Kindle Display** (Bitcoin Status Display made with a jailbroken Kindle) [details](https://github.com/dennisreimann/kindle-display)

You can connect the following Wallet-Apps to your RaspiBlitz:

Expand Down
9 changes: 9 additions & 0 deletions home.admin/_bootstrap.provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,15 @@ else
echo "Provisioning letsencrypt - keep default" >> ${logFile}
fi

# kindle-display
if [ "${kindleDisplay}" = "on" ]; then
echo "Provisioning kindle-display - run config script" >> ${logFile}
sudo sed -i "s/^message=.*/message='Setup kindle-display'/g" ${infoFile}
sudo -u admin /home/admin/config.scripts/bonus.kindle-display.sh on >> ${logFile} 2>&1
else
echo "Provisioning kindle-display - keep default" >> ${logFile}
fi



# replay backup LND conf & tlscerts
Expand Down
171 changes: 171 additions & 0 deletions home.admin/config.scripts/bonus.kindle-display.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
#!/bin/bash

# https://github.com/dennisreimann/kindle-display

USERNAME=kindledisplay
SERVER_PORT=3030
APP_DATA_DIR=/mnt/hdd/app-data/kindle-display
HOME_DIR=/home/$USERNAME
CONFIG_FILE=$APP_DATA_DIR/.env
APP_ROOT_DIR=$HOME_DIR/kindle-display
APP_SERVER_DIR=$APP_ROOT_DIR/server
CRON_FILE=$APP_SERVER_DIR/cron.sh
APP_VERSION=0.2.1

# command info
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
echo "small config script to switch kindle-display on or off"
echo "bonus.kindle-display.sh [on|off]"
exit 1
fi

source /mnt/hdd/raspiblitz.conf

# switch on
if [ "$1" = "1" ] || [ "$1" = "on" ]; then
echo "*** INSTALL KINDLE-DISPLAY ***"

isInstalled=$(sudo ls $HOME_DIR 2>/dev/null | grep -c 'kindle-display')
if [ ${isInstalled} -eq 0 ]; then
# install dependencies
sudo apt install -y firefox-esr pngcrush jo

# install nodeJS
/home/admin/config.scripts/bonus.nodejs.sh on

# add user
sudo adduser --disabled-password --gecos "" $USERNAME

# install kindle-display
cd $HOME_DIR
sudo -u $USERNAME wget https://github.com/dennisreimann/kindle-display/archive/v$APP_VERSION.tar.gz
sudo -u $USERNAME tar -xzf v$APP_VERSION.tar.gz kindle-display-$APP_VERSION/server
sudo -u $USERNAME mv kindle-display{-$APP_VERSION,}
sudo -u $USERNAME rm v$APP_VERSION.tar.gz
cd kindle-display/server
sudo -u $USERNAME npm install

# setup kindle-display config
RPC_USER=$(sudo cat /mnt/hdd/${network}/${network}.conf | grep rpcuser | cut -c 9-)
RPC_PASS=$(sudo cat /mnt/hdd/${network}/${network}.conf | grep rpcpassword | cut -c 13-)

sudo mkdir -p $APP_DATA_DIR
sudo chown $USERNAME:$USERNAME $APP_DATA_DIR

if [[ ! -f "$CONFIG_FILE" ]]; then
configFile=/home/admin/kindle-display.env
touch $configFile
sudo chmod 600 $configFile || exit 1
cat > $configFile <<EOF
# Server port
DISPLAY_SERVER_PORT=$SERVER_PORT
DISPLAY_BITCOIN_RPC_USER="$RPC_USER"
DISPLAY_BITCOIN_RPC_PASS="$RPC_PASS"
# BTCPay Settings for rate fetching – omit these setting to use Bitstamp as a fallback
# Generate API via Store > Access Tokens > Legacy API Keys
# BTCPAY_HOST="https://my.btcpayserver.com"
# BTCPAY_API_TOKEN="myBtcPayLegacyApiKey"
EOF
sudo mv $configFile $CONFIG_FILE
fi

sudo chown $USERNAME:$USERNAME $CONFIG_FILE

# link config to app
sudo -u $USERNAME ln -s $CONFIG_FILE $APP_SERVER_DIR/.env

# generate initial data
sudo -u $USERNAME $APP_SERVER_DIR/data.sh

# open firewall
sudo ufw allow $SERVER_PORT comment 'kindle-display HTTP'

# install service
cat > /home/admin/kindle-display.service <<EOF
# systemd unit for kindle-display
[Unit]
Description=kindle-display
Wants=${network}d.service
After=${network}d.service
[Service]
WorkingDirectory=${APP_SERVER_DIR}
ExecStart=/usr/bin/npm start
User=$USERNAME
# Restart on failure but no more than 2 time every 10 minutes (600 seconds). Otherwise stop
Restart=on-failure
StartLimitIntervalSec=600
StartLimitBurst=2
[Install]
WantedBy=multi-user.target
EOF
sudo mv /home/admin/kindle-display.service /etc/systemd/system/kindle-display.service
sudo systemctl enable kindle-display
sudo systemctl start kindle-display

# generate initial screenshot
sudo -u $USERNAME $CRON_FILE

echo "OK - the KINDLE-DISPLAY script is now installed."
echo ""
echo "Switch to the '$USERNAME' user and adapt the settings in $CONFIG_FILE"

# setting value in raspi blitz config
sudo sed -i "s/^kindleDisplay=.*/kindleDisplay=on/g" /mnt/hdd/raspiblitz.conf
else
echo "KINDLE-DISPLAY already installed."
fi

cron_count=$(sudo -u $USERNAME crontab -l | grep "$CRON_FILE" -c)
if [ "${cron_count}" = "0" ]; then
echo ""
echo "You might want to set up a cronjob to run the script in regular intervals."
echo "As the '$USERNAME' user you can run the 'crontab -e' command."
echo ""
echo "Here is an example for updating every five minutes ..."
echo ""
echo "SHELL=/bin/bash"
echo "PATH=/bin:/usr/bin:/usr/local/bin"
echo "*/5 * * * * /bin/bash $CRON_FILE > /dev/null 2>&1 || true"
fi

exit 0
fi

# switch off
if [ "$1" = "0" ] || [ "$1" = "off" ]; then
echo "*** UNINSTALL KINDLE-DISPLAY ***"
isInstalled=$(sudo ls $HOME_DIR 2>/dev/null | grep -c 'kindle-display')

if [ ${isInstalled} -eq 1 ]; then
echo "*** REMOVING KINDLE-DISPLAY ***"

# setting value in raspi blitz config
sudo sed -i "s/^kindleDisplay=.*/kindleDisplay=off/g" /mnt/hdd/raspiblitz.conf

# uninstall service
sudo systemctl disable kindle-display
sudo rm /etc/systemd/system/kindle-display.service

# close port on firewall
sudo ufw deny $SERVER_PORT

# remove config
sudo rm -rf $APP_DATA_DIR

# delete user and home directory
sudo userdel -rf $USERNAME

echo "OK KINDLE-DISPLAY removed."
else
echo "KINDLE-DISPLAY is not installed."
fi

exit 0
fi

echo "FAIL - Unknown Parameter $1"
exit 1

0 comments on commit 9d40258

Please sign in to comment.