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

1227 lines
40 KiB
Bash
Raw Normal View History

2020-02-10 12:33:03 +01:00
#!/bin/bash
2022-02-10 15:46:12 +00:00
# https://github.com/lnbits/lnbits-legend
2020-02-10 12:33:03 +01:00
2022-09-13 18:16:28 +01:00
# https://github.com/lnbits/lnbits-legend/releases
2022-10-15 11:20:20 +01:00
tag="0.9.4"
VERSION="${tag}"
2022-09-13 18:16:28 +01:00
2020-02-10 12:33:03 +01:00
# command info
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
2022-09-13 18:16:28 +01:00
echo "Config script to switch LNbits on or off."
echo "Installs the version ${VERSION} by default."
2022-09-13 18:16:28 +01:00
echo "Usage:"
2022-12-13 15:28:05 +01:00
echo "bonus.lnbits.sh [install|uninstall] [?GITHUBUSER] [?BRANCH|?TAG]"
echo "bonus.lnbits.sh on [lnd|tlnd|slnd|cl|tcl|scl]"
echo "bonus.lnbits.sh switch [lnd|tlnd|slnd|cl|tcl|scl]"
echo "bonus.lnbits.sh off"
echo "bonus.lnbits.sh status"
echo "bonus.lnbits.sh menu"
2022-09-13 18:16:28 +01:00
echo "bonus.lnbits.sh prestart"
echo "bonus.lnbits.sh repo [githubuser] [branch]"
echo "bonus.lnbits.sh sync"
LNBits Backup and Restore database (#3412) * LNBits Backup and Restore database Add Backup and Restore methods and menu entries * LNBits backup target based on blitz.backupdevice.sh switch backup target to /mnt/backup_manual per default * Add postgresql script Script to install or uninstall postgresql Backup a single database with sql dump file Restore a single database from sql dump file * Unpack backup file only for SQLite For postgresql just use the dedicated script * Support multiple backup files After backup file was written, keep only last 3 backups Restore the recent backup found * improve backup and restore with config and path make use of raspiblitz config to retrieve db state for backup and restore default manual backup path set to /mnt/hdd/app-data/backup * add info command to postgresql script retrieve database directory and database names * update backup path for postgresql script default path is /mnt/hdd/app-data/backup this will survive reflash sd card * improve user feedback * add dialog for restore and improvements dialog with confirm restore process timestamps for backup file names small improvements for user feedback only resume if unpack backup succeed * fix sqlite backup file name * fix restore path and permissions * add dialog to choose backup from a list list all available backups to start restore in a dialog * fix backup list for sqlite * fix restore menu * Update LNBits version with bigint fix for migration if migrate to postgresql, use lnbits version with latest bigint fixes * Update bonus.postgresql.sh * fix postgres backup permissions
2022-12-14 10:40:15 +01:00
echo "bonus.lnbits.sh backup"
echo "bonus.lnbits.sh restore [?FILE]"
#3505 lnbits PostgresSQl migration finalization (#3507) * fix missing dependencies * LNBits SQLite to PostgreSQL migration (#3411) * LNBits SQLite to PostgreSQL migration New installations with PostgreSQL configuration, existent data with SQLite. convert script needs a full start of LNBits prior migrating the old sqlite db's. User can migrate from raspiblitz menu. * only fix postgres if it needs to check for symbolik link of postgres default directory or desired postgres folder btcpayserver and lnbits could use postgresql new script to install or uninstall postgresql * fix typos * silent apt remove * fix removed function postgresConfig call bonus.postgresql.sh to setup PostgreSQL * Support outdated installation old installations should upgrade to new tag first create new data directory /mnt/hdd/app-data/LNBits/data * Improve migration Make it a bit more user friendly and prepare for a worst case to revert the migration if something fails unexpectedly make use of sync method for preparation * Rework migration workflow Cant wait for lnbits to start when ExecStartPre is used. We need a full start of lnbits prior migration, so make use of lsof to check for ports and wait. dont forget to start postgres service after installation. dont forget to stop postgres after uninstall * Dont overwrite the backup file if we start migrate again, the sqlite backup should not be overwritten with postgres data. Keep the backup file. * add migrate message to menu add the hint to revert migration manually after migrate script executed * fix install and data directory lnbits always needs a data directory * clean up lnbits settings for migration even if postgresql is already running, we can extract sqlite backup and start migrate remove migrateMsg duplicate * preserve database for reflash drop database only for migrate, not for regular installations * set blitz config for LNBits fix drop database only for migrate, not for regular installations * Add confirmation dialog and automatic revert User needs to confirm the process, this will eliminate missclicks add a migrate revert function to automatically revert if something unexpected happens let the user call the function manually * check conv.py on success or revert if the conversion script fails, revert automatically * Improve revert message Do not print the revert hint message if current database is SQLite * fix read config LNBitsDB * fix unpack backup Folder LNBits should never block the restore of backup. Happened after multiple migrations and revert. * Wait for lnbits v0.9.5 Set commit version with fix for postgresql database and BIGINT for amounts for migrate Can be set to v0.9.5 tag or above later * improve migrate backup handling revert to the current backup and not to the previous backup. No need for the failed folder state user message with backup file path * check psql version once * supress expected errors if database exists Co-authored-by: /rootzoll <christian@geektank.de> * fix error output on status Co-authored-by: ChuckNorrison <2964146+ChuckNorrison@users.noreply.github.com>
2022-12-10 00:04:15 +01:00
echo "bonus.lnbits.sh migrate"
exit 1
2020-02-10 12:33:03 +01:00
fi
echo "# Running: 'bonus.lnbits.sh $*'"
2020-04-28 18:01:50 +02:00
source /mnt/hdd/raspiblitz.conf
#3505 lnbits PostgresSQl migration finalization (#3507) * fix missing dependencies * LNBits SQLite to PostgreSQL migration (#3411) * LNBits SQLite to PostgreSQL migration New installations with PostgreSQL configuration, existent data with SQLite. convert script needs a full start of LNBits prior migrating the old sqlite db's. User can migrate from raspiblitz menu. * only fix postgres if it needs to check for symbolik link of postgres default directory or desired postgres folder btcpayserver and lnbits could use postgresql new script to install or uninstall postgresql * fix typos * silent apt remove * fix removed function postgresConfig call bonus.postgresql.sh to setup PostgreSQL * Support outdated installation old installations should upgrade to new tag first create new data directory /mnt/hdd/app-data/LNBits/data * Improve migration Make it a bit more user friendly and prepare for a worst case to revert the migration if something fails unexpectedly make use of sync method for preparation * Rework migration workflow Cant wait for lnbits to start when ExecStartPre is used. We need a full start of lnbits prior migration, so make use of lsof to check for ports and wait. dont forget to start postgres service after installation. dont forget to stop postgres after uninstall * Dont overwrite the backup file if we start migrate again, the sqlite backup should not be overwritten with postgres data. Keep the backup file. * add migrate message to menu add the hint to revert migration manually after migrate script executed * fix install and data directory lnbits always needs a data directory * clean up lnbits settings for migration even if postgresql is already running, we can extract sqlite backup and start migrate remove migrateMsg duplicate * preserve database for reflash drop database only for migrate, not for regular installations * set blitz config for LNBits fix drop database only for migrate, not for regular installations * Add confirmation dialog and automatic revert User needs to confirm the process, this will eliminate missclicks add a migrate revert function to automatically revert if something unexpected happens let the user call the function manually * check conv.py on success or revert if the conversion script fails, revert automatically * Improve revert message Do not print the revert hint message if current database is SQLite * fix read config LNBitsDB * fix unpack backup Folder LNBits should never block the restore of backup. Happened after multiple migrations and revert. * Wait for lnbits v0.9.5 Set commit version with fix for postgresql database and BIGINT for amounts for migrate Can be set to v0.9.5 tag or above later * improve migrate backup handling revert to the current backup and not to the previous backup. No need for the failed folder state user message with backup file path * check psql version once * supress expected errors if database exists Co-authored-by: /rootzoll <christian@geektank.de> * fix error output on status Co-authored-by: ChuckNorrison <2964146+ChuckNorrison@users.noreply.github.com>
2022-12-10 00:04:15 +01:00
function postgresConfig() {
sudo /home/admin/config.scripts/bonus.postgresql.sh on || exit 1
echo "# Generate the database lnbits_db"
# migrate clean up
source <(/home/admin/_cache.sh get LNBitsMigrate)
if [ "${LNBitsMigrate}" == "on" ]; then
sudo -u postgres psql -c "drop database lnbits_db;"
sudo -u postgres psql -c "drop user lnbits_user;"
fi
# create database for new installations and keep old
sudo -u postgres psql -c "create database lnbits_db;" 2>/dev/null
sudo -u postgres psql -c "create user lnbits_user with encrypted password 'raspiblitz';" 2>/dev/null
sudo -u postgres psql -c "grant all privileges on database lnbits_db to lnbits_user;" 2>/dev/null
# check
check=$(sudo -u postgres psql -c "SELECT datname FROM pg_database;" | grep lnbits_db)
if [ "$check" = "" ]; then
echo "# postgresConfig failed -> SELECT datname FROM pg_database;"
exit 1
else
echo "# Setup PostgreSQL successful, new database found: $check"
fi
/home/admin/config.scripts/blitz.conf.sh set LNBitsDB "PostgreSQL"
}
function migrateMsg() {
source <(/home/admin/_cache.sh get LNBitsDB)
if [ "${LNBitsDB}" == "PostgreSQL" ]; then
if [ -e /mnt/hdd/app-data/LNBits_sqlitedb_backup.tar ]; then
echo "SUCCESS - A backup file was found. The migrate progress will revert automatically on failure."
echo "For yet unknown reasons, this could be done manually with unpacking the SQLite backup file."
echo
echo "/home/admin/config.scripts/bonus.lnbits.sh migrate revert"
echo
echo "********************************************************"
echo "* *"
echo "* Revert: /mnt/hdd/app-data/LNBits_sqlitedb_backup.tar *"
echo "* *"
echo "********************************************************"
echo
else
echo "You dont have any migration backup files!"
fi
else
echo "ABORT - Your LNBits is still running on old SQLite database."
echo "Check for errors, '.dump' and fix your database manually and try again."
fi
}
function revertMigration() {
source <(/home/admin/_cache.sh get LNBitsMigrate)
if [ "${LNBitsMigrate}" == "on" ]; then
echo "# Revert migration, restore SQLite..."
sudo systemctl stop lnbits
# check current backup
if [ -e /mnt/hdd/app-data/LNBits_sqlitedb_backup.tar ]; then
echo "# Unpack Backup"
cd /mnt/hdd/app-data/
sudo rm -R /mnt/hdd/app-data/LNBits
sudo tar -xf /mnt/hdd/app-data/LNBits_sqlitedb_backup.tar
sudo chown lnbits:lnbits -R /mnt/hdd/app-data/LNBits
else
echo "# No backup file found!"
fi
# update config
echo "# Configure config .env"
# clean up
sudo sed -i "/^LNBITS_DATABASE_URL=/d" /home/lnbits/lnbits/.env
sudo sed -i "/^LNBITS_DATA_FOLDER=/d" /home/lnbits/lnbits/.env
sudo bash -c "echo 'LNBITS_DATA_FOLDER=/mnt/hdd/app-data/LNBits' >> /home/lnbits/lnbits/.env"
# start service
echo "# Start LNBits"
sudo systemctl start lnbits
# set blitz config
/home/admin/config.scripts/blitz.conf.sh set LNBitsMigrate "off"
/home/admin/config.scripts/blitz.conf.sh set LNBitsDB "SQLite"
echo "# OK revert migration done"
else
echo "# No migration started yet, nothing to do."
fi
}
2020-02-10 12:33:03 +01:00
# show info menu
if [ "$1" = "menu" ]; then
2020-07-14 21:04:14 +02:00
# get LNbits status info
2020-02-10 12:33:03 +01:00
echo "# collecting status info ... (please wait)"
source <(sudo /home/admin/config.scripts/bonus.lnbits.sh status)
# display possible problems with IP2TOR setup
if [ ${#ip2torWarn} -gt 0 ]; then
whiptail --title " Warning " \
--yes-button "Back" \
--no-button "Continue Anyway" \
--yesno "Your IP2TOR+LetsEncrypt may have problems:\n${ip2torWarn}\n\nCheck if locally responding: https://${localIP}:${httpsPort}\n\nCheck if service is reachable over Tor:\n${toraddress}" 14 72
if [ "$?" != "1" ]; then
exit 0
fi
fi
# add info on funding source
fundinginfo=""
if [ "${LNBitsFunding}" == "lnd" ] || [ "${LNBitsFunding}" == "tlnd" ] || [ "${LNBitsFunding}" == "slnd" ]; then
fundinginfo="on LND "
elif [ "${LNBitsFunding}" == "cl" ] || [ "${LNBitsFunding}" == "tcl" ] || [ "${LNBitsFunding}" == "scl" ]; then
2022-11-16 11:00:35 -06:00
fundinginfo="on CLN "
fi
text="Local Web Browser: https://${localIP}:${httpsPort}"
2020-07-14 21:04:14 +02:00
if [ ${#publicDomain} -gt 0 ]; then
text="${text}
Public Domain: https://${publicDomain}:${httpsPort}
port forwarding on router needs to be active & may change port"
2020-07-14 21:04:14 +02:00
fi
text="${text}\n
You need to accept self-signed HTTPS cert with SHA1 Fingerprint:
${sslFingerprintIP}"
2020-02-10 12:33:03 +01:00
2020-07-14 21:04:14 +02:00
if [ "${runBehindTor}" = "on" ] && [ ${#toraddress} -gt 0 ]; then
2022-02-13 12:23:34 +00:00
sudo /home/admin/config.scripts/blitz.display.sh qr "${toraddress}"
2020-07-14 21:04:14 +02:00
text="${text}\n
2020-07-14 21:17:05 +02:00
TOR Browser Hidden Service address (QR see LCD):
2020-07-14 21:04:14 +02:00
${toraddress}"
fi
2020-07-14 21:04:14 +02:00
if [ ${#ip2torDomain} -gt 0 ]; then
2020-07-14 23:06:09 +02:00
text="${text}\n
2020-07-14 21:04:14 +02:00
IP2TOR+LetsEncrypt: https://${ip2torDomain}:${ip2torPort}
SHA1 ${sslFingerprintTOR}\n
https://${ip2torDomain}:${ip2torPort} ready for public use"
2020-07-14 21:04:14 +02:00
elif [ ${#ip2torIP} -gt 0 ]; then
2020-07-14 22:56:20 +02:00
text="${text}\n
2020-07-14 21:04:14 +02:00
IP2TOR: https://${ip2torIP}:${ip2torPort}
SHA1 ${sslFingerprintTOR}\n
Consider adding a LetsEncrypt HTTPS Domain under OPTIONS."
# elif [ ${#publicDomain} -eq 0 ]; then
# text="${text}\n
#To enable easy reachability with normal browser from the outside
#Consider adding a IP2TOR Bridge under OPTIONS."
2020-02-10 12:33:03 +01:00
fi
whiptail --title " LNbits ${fundinginfo}" --yes-button "OK" --no-button "OPTIONS" --yesno "${text}" 18 69
result=$?
2022-02-13 12:23:34 +00:00
sudo /home/admin/config.scripts/blitz.display.sh hide
echo "option (${result}) - please wait ..."
# exit when user presses OK to close menu
if [ ${result} -eq 0 ]; then
exit 0
fi
# LNbits OPTIONS menu
OPTIONS=()
# IP2TOR options
#if [ "${ip2torDomain}" != "" ]; then
# # IP2TOR+LetsEncrypt active - offer cancel
# OPTIONS+=(IP2TOR-OFF "Cancel IP2Tor Subscription for LNbits")
#elif [ "${ip2torIP}" != "" ]; then
# # just IP2TOR active - offer cancel or Lets Encrypt
# OPTIONS+=(HTTPS-ON "Add free HTTPS-Certificate for LNbits")
# OPTIONS+=(IP2TOR-OFF "Cancel IP2Tor Subscription for LNbits")
#else
# OPTIONS+=(IP2TOR-ON "Make Public with IP2Tor Subscription")
#fi
# Change Funding Source options (only if available)
if [ "${LNBitsFunding}" == "lnd" ] && [ "${cl}" == "on" ]; then
2022-11-16 11:00:35 -06:00
OPTIONS+=(SWITCH-CL "Switch: Use CLN as funding source")
elif [ "${LNBitsFunding}" == "cl" ] && [ "${lnd}" == "on" ]; then
OPTIONS+=(SWITCH-LND "Switch: Use LND as funding source")
fi
LNBits Backup and Restore database (#3412) * LNBits Backup and Restore database Add Backup and Restore methods and menu entries * LNBits backup target based on blitz.backupdevice.sh switch backup target to /mnt/backup_manual per default * Add postgresql script Script to install or uninstall postgresql Backup a single database with sql dump file Restore a single database from sql dump file * Unpack backup file only for SQLite For postgresql just use the dedicated script * Support multiple backup files After backup file was written, keep only last 3 backups Restore the recent backup found * improve backup and restore with config and path make use of raspiblitz config to retrieve db state for backup and restore default manual backup path set to /mnt/hdd/app-data/backup * add info command to postgresql script retrieve database directory and database names * update backup path for postgresql script default path is /mnt/hdd/app-data/backup this will survive reflash sd card * improve user feedback * add dialog for restore and improvements dialog with confirm restore process timestamps for backup file names small improvements for user feedback only resume if unpack backup succeed * fix sqlite backup file name * fix restore path and permissions * add dialog to choose backup from a list list all available backups to start restore in a dialog * fix backup list for sqlite * fix restore menu * Update LNBits version with bigint fix for migration if migrate to postgresql, use lnbits version with latest bigint fixes * Update bonus.postgresql.sh * fix postgres backup permissions
2022-12-14 10:40:15 +01:00
# Backup database
OPTIONS+=(BACKUP "Backup database")
if [ -d /mnt/hdd/app-data/backup ]; then
OPTIONS+=(RESTORE "Restore database")
fi
#3505 lnbits PostgresSQl migration finalization (#3507) * fix missing dependencies * LNBits SQLite to PostgreSQL migration (#3411) * LNBits SQLite to PostgreSQL migration New installations with PostgreSQL configuration, existent data with SQLite. convert script needs a full start of LNBits prior migrating the old sqlite db's. User can migrate from raspiblitz menu. * only fix postgres if it needs to check for symbolik link of postgres default directory or desired postgres folder btcpayserver and lnbits could use postgresql new script to install or uninstall postgresql * fix typos * silent apt remove * fix removed function postgresConfig call bonus.postgresql.sh to setup PostgreSQL * Support outdated installation old installations should upgrade to new tag first create new data directory /mnt/hdd/app-data/LNBits/data * Improve migration Make it a bit more user friendly and prepare for a worst case to revert the migration if something fails unexpectedly make use of sync method for preparation * Rework migration workflow Cant wait for lnbits to start when ExecStartPre is used. We need a full start of lnbits prior migration, so make use of lsof to check for ports and wait. dont forget to start postgres service after installation. dont forget to stop postgres after uninstall * Dont overwrite the backup file if we start migrate again, the sqlite backup should not be overwritten with postgres data. Keep the backup file. * add migrate message to menu add the hint to revert migration manually after migrate script executed * fix install and data directory lnbits always needs a data directory * clean up lnbits settings for migration even if postgresql is already running, we can extract sqlite backup and start migrate remove migrateMsg duplicate * preserve database for reflash drop database only for migrate, not for regular installations * set blitz config for LNBits fix drop database only for migrate, not for regular installations * Add confirmation dialog and automatic revert User needs to confirm the process, this will eliminate missclicks add a migrate revert function to automatically revert if something unexpected happens let the user call the function manually * check conv.py on success or revert if the conversion script fails, revert automatically * Improve revert message Do not print the revert hint message if current database is SQLite * fix read config LNBitsDB * fix unpack backup Folder LNBits should never block the restore of backup. Happened after multiple migrations and revert. * Wait for lnbits v0.9.5 Set commit version with fix for postgresql database and BIGINT for amounts for migrate Can be set to v0.9.5 tag or above later * improve migrate backup handling revert to the current backup and not to the previous backup. No need for the failed folder state user message with backup file path * check psql version once * supress expected errors if database exists Co-authored-by: /rootzoll <christian@geektank.de> * fix error output on status Co-authored-by: ChuckNorrison <2964146+ChuckNorrison@users.noreply.github.com>
2022-12-10 00:04:15 +01:00
# Migrate SQLite to PostgreSQL
if [ -e /mnt/hdd/app-data/LNBits/database.sqlite3 ]; then
OPTIONS+=(MIGRATE-DB "Migrate SQLite to PostgreSQL database")
fi
WIDTH=66
CHOICE_HEIGHT=$(("${#OPTIONS[@]}/2+1"))
HEIGHT=$((CHOICE_HEIGHT+7))
CHOICE=$(dialog --clear \
--title " LNbits - Options" \
--ok-label "Select" \
--cancel-label "Back" \
--menu "Choose one of the following options:" \
$HEIGHT $WIDTH $CHOICE_HEIGHT \
"${OPTIONS[@]}" \
2>&1 >/dev/tty)
case $CHOICE in
IP2TOR-ON)
python /home/admin/config.scripts/blitz.subscriptions.ip2tor.py create-ssh-dialog LNBITS ${toraddress} 443
exit 0
;;
IP2TOR-OFF)
clear
python /home/admin/config.scripts/blitz.subscriptions.ip2tor.py subscription-cancel ${ip2torID}
echo
echo "OK - PRESS ENTER to continue"
read key
exit 0
;;
HTTPS-ON)
python /home/admin/config.scripts/blitz.subscriptions.letsencrypt.py create-ssh-dialog
exit 0
;;
SWITCH-CL)
clear
/home/admin/config.scripts/bonus.lnbits.sh switch cl
echo "Restarting LNbits ..."
sudo systemctl restart lnbits
echo
echo "OK new funding source for LNbits active."
echo "PRESS ENTER to continue"
read key
exit 0
;;
SWITCH-LND)
clear
/home/admin/config.scripts/bonus.lnbits.sh switch lnd
echo "Restarting LNbits ..."
sudo systemctl restart lnbits
echo
2022-09-13 18:16:28 +01:00
echo "OK new funding source for LNbits active."
echo "PRESS ENTER to continue"
read key
exit 0
;;
LNBits Backup and Restore database (#3412) * LNBits Backup and Restore database Add Backup and Restore methods and menu entries * LNBits backup target based on blitz.backupdevice.sh switch backup target to /mnt/backup_manual per default * Add postgresql script Script to install or uninstall postgresql Backup a single database with sql dump file Restore a single database from sql dump file * Unpack backup file only for SQLite For postgresql just use the dedicated script * Support multiple backup files After backup file was written, keep only last 3 backups Restore the recent backup found * improve backup and restore with config and path make use of raspiblitz config to retrieve db state for backup and restore default manual backup path set to /mnt/hdd/app-data/backup * add info command to postgresql script retrieve database directory and database names * update backup path for postgresql script default path is /mnt/hdd/app-data/backup this will survive reflash sd card * improve user feedback * add dialog for restore and improvements dialog with confirm restore process timestamps for backup file names small improvements for user feedback only resume if unpack backup succeed * fix sqlite backup file name * fix restore path and permissions * add dialog to choose backup from a list list all available backups to start restore in a dialog * fix backup list for sqlite * fix restore menu * Update LNBits version with bigint fix for migration if migrate to postgresql, use lnbits version with latest bigint fixes * Update bonus.postgresql.sh * fix postgres backup permissions
2022-12-14 10:40:15 +01:00
BACKUP)
clear
/home/admin/config.scripts/bonus.lnbits.sh backup
echo
echo "Backup done"
echo "PRESS ENTER to continue"
read key
exit 0
;;
RESTORE)
clear
# check if backup exist
source <(/home/admin/_cache.sh get LNBitsDB)
if [ "${LNBitsDB}" == "PostgreSQL" ]; then
backup_target="/mnt/hdd/app-data/backup/lnbits_db"
backup_file=$(ls -t $backup_target/*.sql | head -n1)
else
backup_target="/mnt/hdd/app-data/backup/lnbits_sqlite"
backup_file=$(ls -t $backup_target/*.tar | head -n1)
fi
if [ "$backup_file" = "" ]; then
echo "ABORT - No Backup found to restore from"
exit 1
else
# build dialog to choose backup file from menu
OPTIONS_RESTORE=()
counter=0
cd $backup_target
for f in `find *.* -maxdepth 1 -type f`; do
[[ -f "$f" ]] || continue
counter=$(($counter+1))
OPTIONS_RESTORE+=($counter "$f")
done
WIDTH_RESTORE=66
CHOICE_HEIGHT_RESTORE=$(("${#OPTIONS_RESTORE[@]}/2+1"))
HEIGHT_RESTORE=$((CHOICE_HEIGHT_RESTORE+7))
CHOICE_RESTORE=$(dialog --clear \
--title " LNbits - Backup restore" \
--ok-label "Select" \
--cancel-label "Back" \
--menu "Choose one of the following backups:" \
$HEIGHT_RESTORE $WIDTH_RESTORE $CHOICE_HEIGHT_RESTORE \
"${OPTIONS_RESTORE[@]}" \
2>&1 >/dev/tty)
# start restore with selected backup
clear
if [ "$CHOICE_RESTORE" != "" ]; then
backup_file=${backup_target}/${OPTIONS_RESTORE[$(($CHOICE_RESTORE*2-1))]}
/home/admin/config.scripts/bonus.lnbits.sh restore "${backup_file}"
echo
echo "Restore done"
echo "PRESS ENTER to continue"
read key
fi
exit 0
fi
;;
#3505 lnbits PostgresSQl migration finalization (#3507) * fix missing dependencies * LNBits SQLite to PostgreSQL migration (#3411) * LNBits SQLite to PostgreSQL migration New installations with PostgreSQL configuration, existent data with SQLite. convert script needs a full start of LNBits prior migrating the old sqlite db's. User can migrate from raspiblitz menu. * only fix postgres if it needs to check for symbolik link of postgres default directory or desired postgres folder btcpayserver and lnbits could use postgresql new script to install or uninstall postgresql * fix typos * silent apt remove * fix removed function postgresConfig call bonus.postgresql.sh to setup PostgreSQL * Support outdated installation old installations should upgrade to new tag first create new data directory /mnt/hdd/app-data/LNBits/data * Improve migration Make it a bit more user friendly and prepare for a worst case to revert the migration if something fails unexpectedly make use of sync method for preparation * Rework migration workflow Cant wait for lnbits to start when ExecStartPre is used. We need a full start of lnbits prior migration, so make use of lsof to check for ports and wait. dont forget to start postgres service after installation. dont forget to stop postgres after uninstall * Dont overwrite the backup file if we start migrate again, the sqlite backup should not be overwritten with postgres data. Keep the backup file. * add migrate message to menu add the hint to revert migration manually after migrate script executed * fix install and data directory lnbits always needs a data directory * clean up lnbits settings for migration even if postgresql is already running, we can extract sqlite backup and start migrate remove migrateMsg duplicate * preserve database for reflash drop database only for migrate, not for regular installations * set blitz config for LNBits fix drop database only for migrate, not for regular installations * Add confirmation dialog and automatic revert User needs to confirm the process, this will eliminate missclicks add a migrate revert function to automatically revert if something unexpected happens let the user call the function manually * check conv.py on success or revert if the conversion script fails, revert automatically * Improve revert message Do not print the revert hint message if current database is SQLite * fix read config LNBitsDB * fix unpack backup Folder LNBits should never block the restore of backup. Happened after multiple migrations and revert. * Wait for lnbits v0.9.5 Set commit version with fix for postgresql database and BIGINT for amounts for migrate Can be set to v0.9.5 tag or above later * improve migrate backup handling revert to the current backup and not to the previous backup. No need for the failed folder state user message with backup file path * check psql version once * supress expected errors if database exists Co-authored-by: /rootzoll <christian@geektank.de> * fix error output on status Co-authored-by: ChuckNorrison <2964146+ChuckNorrison@users.noreply.github.com>
2022-12-10 00:04:15 +01:00
MIGRATE-DB)
clear
dialog --title "MIGRATE LNBITS" --yesno "
Do you want to proceed the migration?
Try to migrate your LNBits SQLite database to PostgreSQL.
This can fail for unknown circumstances. Revert of this process is possible afterwards, a backup will be saved.
" 12 65
if [ $? -eq 0 ]; then
clear
/home/admin/config.scripts/bonus.lnbits.sh migrate
echo
migrateMsg
echo
echo "OK please test your LNBits installation."
echo "PRESS ENTER to continue"
read key
fi
exit 0
LNBits Backup and Restore database (#3412) * LNBits Backup and Restore database Add Backup and Restore methods and menu entries * LNBits backup target based on blitz.backupdevice.sh switch backup target to /mnt/backup_manual per default * Add postgresql script Script to install or uninstall postgresql Backup a single database with sql dump file Restore a single database from sql dump file * Unpack backup file only for SQLite For postgresql just use the dedicated script * Support multiple backup files After backup file was written, keep only last 3 backups Restore the recent backup found * improve backup and restore with config and path make use of raspiblitz config to retrieve db state for backup and restore default manual backup path set to /mnt/hdd/app-data/backup * add info command to postgresql script retrieve database directory and database names * update backup path for postgresql script default path is /mnt/hdd/app-data/backup this will survive reflash sd card * improve user feedback * add dialog for restore and improvements dialog with confirm restore process timestamps for backup file names small improvements for user feedback only resume if unpack backup succeed * fix sqlite backup file name * fix restore path and permissions * add dialog to choose backup from a list list all available backups to start restore in a dialog * fix backup list for sqlite * fix restore menu * Update LNBits version with bigint fix for migration if migrate to postgresql, use lnbits version with latest bigint fixes * Update bonus.postgresql.sh * fix postgres backup permissions
2022-12-14 10:40:15 +01:00
;;
*)
clear
exit 0
esac
2020-02-10 12:33:03 +01:00
exit 0
fi
# status
if [ "$1" = "status" ]; then
echo "version='${VERSION}'"
2020-04-23 23:08:14 +02:00
if [ "${LNBits}" = "on" ]; then
2020-02-10 12:33:03 +01:00
echo "installed=1"
merging pre-1.7.1 (#2462) * fix copychain returns * typo in sync loop * stop services on inconsistent state * calling correct provisioning * apply bitcoin and lncli aliases in all scripts * network.aliases: add CLNETWORK * make cln default plugin dir: cln-plugins-enabled similar to the nginx model make 2 directories for plugins: cln-plugins-enabled - symlinked to ~/.lightning/plugins plugins from here are loaded automatically on cln start cln-plugins-available: plugins are downloaded here to be run until the next cln restart (or stopped with runonce) note the disk is mounted with noexec so plugins can't run from there discuss in: https://github.com/rootzoll/raspiblitz/issues/2295 * move shutdown script * change all place where shutdown script is used * change notify & release * moved shutdown script * moved shutdown scripts * add more debug info * moving github script * remove chain in sync * no longer needed chain in sync * move debug script * patch patch command * make sure setup file is sourced * remove debug output * make sure lnd is put behind tor * change indent * get fresh sync progress * avoid scrolling in menus * use new selfsignedcert if no lnd tls.cert present * sparko: add info and connect menu with own cert https://github.com/rootzoll/raspiblitz/issues/2295 * cln.rest: add connect option for Zeus https://github.com/rootzoll/raspiblitz/issues/2295 * cln: add the backup plugin + options Usage options: cln-plugin.backup.sh [on] [testnet|mainnet|signet] cln-plugin.backup.sh [restore] [testnet|mainnet|signet] [force] cln-plugin.backup.sh [backup-compact] [testnet|mainnet|signet] https://github.com/lightningd/plugins/tree/master/backup Discussed in: https://github.com/rootzoll/raspiblitz/issues/2295 * cln: add cln-plugin.standard.python.sh Install and show the output of the chosen plugin for C-lightning Usage: cln-plugin.standard-python.sh on [plugin-name] [testnet|mainnet|signet] [runonce] tested plugins: summary | helpme | feeadjuster find more at: https://github.com/lightningd/plugins discussed in: https://github.com/rootzoll/raspiblitz/issues/2295 * shellcheck: change all `egrep` to `grep -E` https://github.com/koalaman/shellcheck/wiki/SC2196 * do not resolve aliases, use as variables * lnd: fix lnd.conf for parallel networks discussed in: https://github.com/rootzoll/raspiblitz/issues/2290 * lnd: add LND option for parallel networks * deprecate Testnet in SETTINGS keysend and autopilot only for mainnet due to: https://github.com/rootzoll/raspiblitz/issues/2290 * lnd: autopilot and autounlock for testnet * fix comments * add the SYSTEM menu for parallel chains * RTL update to v0.11.0 make chain specific directory for the config: /home/rtl/${netprefix}RTL/ use ${netprefix}lnd.conf in config override Environmen tvaribales for cln in the systemd service: /etc/systemd/system/${netprefix}${typeprefix}RTL.service discussed in: https://github.com/rootzoll/raspiblitz/issues/2384 * lnd.setname.sh for testnet * display ${CHAIN} in the SYSTEM menu options * keep _aliases file when live patches are applied * all lncli_aliases to be used as variables * default to KIllMode=control-group in services https://www.man7.org/linux/man-pages/man5/systemd.kill.5.html discussed in: https://github.com/rootzoll/raspiblitz/issues/1901 * add cln.hsmtool.sh for hsm_secret handling encrypt | decrypt | autounlock the hsm_secret for C-lightning usage: cln.hsmtool.sh [unlock] [testnet|mainnet|signet] cln.hsmtool.sh [encrypt|decrypt] [testnet|mainnet|signet] cln.hsmtool.sh [autounlock-on|autounlock-off] [testnet|mainnet|signet] discussed in: https://github.com/rootzoll/raspiblitz/issues/2295 * add cln.install-service.sh to set up cln with systemd script to set up or update the CLN systemd service checks for hsm_secret encryption, autounlock and the sparko plugin usage: /home/admin/config.scripts/cln.install-service.sh $CHAIN discussed in: https://github.com/rootzoll/raspiblitz/issues/2295 * use symlink to cln-plugins-enabled for all plugins * keep lnd autopilot and autounlock mainnet only mainnet only settings: lnd autopilot lnd keysend circuibreaker lnd autounlock StaticChannelBackup to DropBox and USB * cln FUNDING fix parsing address * cln.hsmtool: add change-password and lock options * always set password A * cached peer info * fix printing cache * fix check for existing files * handle bitcoind not running * result with newline * test line break * test new line * test new line * two vars on output * #2388 improve online check (less pinging) * used cached peer status * move chache * cach file permissions * allow sudo call * fix cache * remove double scan info * add conf info to sync screen * reorder info * add space * add space * order info * internet suppress error messages * order info * fix offering Blockchain copy * fix hostname * final ready state info * lnd unlock after provision * remove debug exit * harmonize ready state * add status to lnd unlock * update lnd unlock script * edit the unlock * remove debug echo * add debug * add debug * fix if statement * debug output * switch position of source setupdata * #1126 preparing new setup with new c-lightning (#2396) * move debug script * patch patch command * make sure setup file is sourced * remove debug output * make sure lnd is put behind tor * change indent * get fresh sync progress * always set password A * cached peer info * fix printing cache * fix check for existing files * handle bitcoind not running * result with newline * test line break * test new line * test new line * two vars on output * #2388 improve online check (less pinging) * used cached peer status * move chache * cach file permissions * allow sudo call * fix cache * remove double scan info * add conf info to sync screen * reorder info * add space * add space * order info * internet suppress error messages * order info * fix offering Blockchain copy * fix hostname * final ready state info * lnd unlock after provision * remove debug exit * harmonize ready state * add status to lnd unlock * update lnd unlock script * edit the unlock * remove debug echo * add debug * add debug * fix if statement * debug output * switch position of source setupdata * lnd.unlock: fix typo * netwok.monitor.sh debug * cln-plugin.summary: fix paths * rtl: fix permission of config on copy * CASHOUT: use aliases for lnd * rtl: install correctly for paralell chains * use CHAIN in CLN and LND menu * cln: add CASHOUT option * CLOSEALL and CASHOUT: Improve labels and comments Explaining CASHOUT in the label as discussed in: https://github.com/rootzoll/raspiblitz/issues/2358 * cln.install: fix tor config * cln: installthe latest master until the next release * _commands: source _aliases only if exists * network aliases: fall back to 'main' for 'chain' * new setup: keep testnet3 blocks and chainstate * new setup: improve capitalization in menu * improve help and comments * cln: install Sparko if configured, but not present * cln: add new wallet and import seed options * fix peernum * make sure that aliases get created on lnd setup * no error if aliases not yet exist * debug state * fix network alias when not set * fix syntax error * add debug error info * mute unlocking echos * add debug wait * add debug wait * make sure info is uptodate * make alias info as defaults * rename option * update sync info for no lightning * add action string * update sync info * move name dialog * wait for sync progress info * wait for syncprogress info * fix syntax * get fresh data * make sure to disable lnd * add c-lightning to debug * add setup logs to debug output * fix syntax error * add new-force wallet * try fix call hsmtool * hsm output tool * fix output * add seed-force * refactor blitz.mnemonic.py * test seed * debug info * dump object * try check * correct putput * fix syntax * check lnd for valid seed * fix gui * add Suez install script discussed in: https://github.com/rootzoll/raspiblitz/issues/2366 * cln rescue file export * get correct version * add cln export gui * cln.backup.sh cln-import * correct bytesize * generate cln wallet with passwordc * fix syntax * fix syntax * mute not needed error msg * PEERING: correct message on success * cln.install-service: fix sparko check * add Suez to menu for CLN and LND needs to be installed with the bitcoin user to be able to interact with CLN related: https://github.com/rootzoll/raspiblitz/issues/2366 * debug _provison.setup.sh stop bitcoind and restart with new config to avoid rpc password error disable and enable service instead of daemon-reload CLN: don't use passwordC as seedPassword * add cln.setname.sh make lnd.setname.sh work with parallel wallets * improve comments * SYSTEM: add CLNLOG and CLNCONF options * SYSTEM menu fixes * cln: add more aliases cln, clnlog, clnconf * cln: activate the backup plugin on every install * SERVICES menu: fix chantools/CLN switch * cln: load plugins from ${netprefix}cln-plugins-enabled changed the config paths to $lightning-dir/config or /networkname/config plugins are downloaded to the SDcard: /home/bitcoin/cln-plugins-available/ symlinked and loaded automatically from: /home/bitcoin/${netprefix}cln-plugins-enabled Related: #2295 * sparko: don't show logs after install * #2425 Adding experimental Blitz WebUI & API (#2426) * no password C & D when cln * add debug echos * set defaults before * #2228 wider grep to detect nvms (#2427) * cln.hsmtool: init backup with the new wallet * cln.install: fix access to raspiblitz.conf * cln-plugin.backup: fix path to backup-cli * cln: hide unhelpful warnings during setup * remove old jinja template rendering * fix lnd unlock detection * cln: look for files in .lightning dir with sudo * cln: correct lightning name in FInalDialog + typo * cln: make sure .lightning/bitcoin dir exists * FinalDialog: make the 24 words fit * cln.install.sh: create cln config if not present * Simplify localIP detection and improve compatibility (#2432) * show tail info on provision * only show lnd options when activated * fix syntax * only show main lightning impl options for RC1 * cln: always start the lightnind.service * cln: clear before showing summary * start cln on the end of provisioning * exit 0 on cln menu * press key after single actions * remove key press on cln actions * change to none * detect cln running * fix syntax * fix lightniing info * add TODO for CLN * add clnblockheight * zty with user bitcoin * check synced to chain for cln * fix increment * try scanprogress * use cln sync detection and progress * replace LNTYPE * next line * fix spaces * fix spaces * Update README.md (#2456) Fix 404 * Fix FAQ links (#2441) * Fix invalid URL ( (#2440) * support channels (#2382) * use #2370 height optimization * adjust exit codes in menu scripts * adjust password menu exit codes * adapt shutdown for cln * settings adapt to running lightning impl * fix syntax * debug info * add debug * better height * add default values * add config entry if not there yet * change default value * Added exit info for cln * make sure to load config file if available * add sparko to menu * add default for sparko * replace default sparko entry * show sparko installed or not * add more description to sparko option * RTL for clightnign in service menu * main menu item rtl * add RTL description * debug in RTL install * install sparko on recovery * update menu with cln * rework menu options Co-authored-by: openoms <oms@tuta.io> Co-authored-by: openoms <43343391+openoms@users.noreply.github.com> Co-authored-by: rek79 <rek79@users.noreply.github.com> Co-authored-by: Bitpaint <67663265+bitpaint@users.noreply.github.com> Co-authored-by: João Thallis <joaothallis@icloud.com> Co-authored-by: Peter Flock <78184669+peterflock@users.noreply.github.com> Co-authored-by: nyxnor <nyxnor@protonmail.com>
2021-08-04 00:18:30 +02:00
localIP=$(hostname -I | awk '{print $1}')
2020-07-14 20:29:33 +02:00
echo "localIP='${localIP}'"
echo "httpPort='5000'"
2020-07-14 20:29:33 +02:00
echo "httpsPort='5001'"
2022-05-05 10:59:50 +02:00
echo "httpsForced='1'"
echo "httpsSelfsigned='1'" # TODO: change later if IP2Tor+LetsEncrypt is active
echo "authMethod='none'"
2020-07-14 20:29:33 +02:00
echo "publicIP='${publicIP}'"
# check funding source
if [ "${LNBitsFunding}" == "" ]; then
LNBitsFunding="lnd"
fi
echo "LNBitsFunding='${LNBitsFunding}'"
2020-07-14 20:29:33 +02:00
# check for LetsEnryptDomain for DynDns
error=""
#3505 lnbits PostgresSQl migration finalization (#3507) * fix missing dependencies * LNBits SQLite to PostgreSQL migration (#3411) * LNBits SQLite to PostgreSQL migration New installations with PostgreSQL configuration, existent data with SQLite. convert script needs a full start of LNBits prior migrating the old sqlite db's. User can migrate from raspiblitz menu. * only fix postgres if it needs to check for symbolik link of postgres default directory or desired postgres folder btcpayserver and lnbits could use postgresql new script to install or uninstall postgresql * fix typos * silent apt remove * fix removed function postgresConfig call bonus.postgresql.sh to setup PostgreSQL * Support outdated installation old installations should upgrade to new tag first create new data directory /mnt/hdd/app-data/LNBits/data * Improve migration Make it a bit more user friendly and prepare for a worst case to revert the migration if something fails unexpectedly make use of sync method for preparation * Rework migration workflow Cant wait for lnbits to start when ExecStartPre is used. We need a full start of lnbits prior migration, so make use of lsof to check for ports and wait. dont forget to start postgres service after installation. dont forget to stop postgres after uninstall * Dont overwrite the backup file if we start migrate again, the sqlite backup should not be overwritten with postgres data. Keep the backup file. * add migrate message to menu add the hint to revert migration manually after migrate script executed * fix install and data directory lnbits always needs a data directory * clean up lnbits settings for migration even if postgresql is already running, we can extract sqlite backup and start migrate remove migrateMsg duplicate * preserve database for reflash drop database only for migrate, not for regular installations * set blitz config for LNBits fix drop database only for migrate, not for regular installations * Add confirmation dialog and automatic revert User needs to confirm the process, this will eliminate missclicks add a migrate revert function to automatically revert if something unexpected happens let the user call the function manually * check conv.py on success or revert if the conversion script fails, revert automatically * Improve revert message Do not print the revert hint message if current database is SQLite * fix read config LNBitsDB * fix unpack backup Folder LNBits should never block the restore of backup. Happened after multiple migrations and revert. * Wait for lnbits v0.9.5 Set commit version with fix for postgresql database and BIGINT for amounts for migrate Can be set to v0.9.5 tag or above later * improve migrate backup handling revert to the current backup and not to the previous backup. No need for the failed folder state user message with backup file path * check psql version once * supress expected errors if database exists Co-authored-by: /rootzoll <christian@geektank.de> * fix error output on status Co-authored-by: ChuckNorrison <2964146+ChuckNorrison@users.noreply.github.com>
2022-12-10 00:04:15 +01:00
source <(sudo /home/admin/config.scripts/blitz.subscriptions.ip2tor.py ip-by-tor $publicIP 2>/dev/null)
2020-07-14 20:29:33 +02:00
if [ ${#error} -eq 0 ]; then
echo "publicDomain='${domain}'"
fi
2020-07-14 20:35:37 +02:00
sslFingerprintIP=$(openssl x509 -in /mnt/hdd/app-data/nginx/tls.cert -fingerprint -noout 2>/dev/null | cut -d"=" -f2)
2020-07-14 20:29:33 +02:00
echo "sslFingerprintIP='${sslFingerprintIP}'"
toraddress=$(sudo cat /mnt/hdd/tor/lnbits/hostname 2>/dev/null)
echo "toraddress='${toraddress}'"
2020-07-14 20:35:37 +02:00
sslFingerprintTOR=$(openssl x509 -in /mnt/hdd/app-data/nginx/tor_tls.cert -fingerprint -noout 2>/dev/null | cut -d"=" -f2)
2020-07-14 20:29:33 +02:00
echo "sslFingerprintTOR='${sslFingerprintTOR}'"
# check for IP2TOR
error=""
source <(sudo /home/admin/config.scripts/blitz.subscriptions.ip2tor.py ip-by-tor $toraddress)
if [ ${#error} -eq 0 ]; then
echo "ip2torType='${ip2tor-v1}'"
2020-07-14 20:36:04 +02:00
echo "ip2torID='${id}'"
2020-07-14 20:29:33 +02:00
echo "ip2torIP='${ip}'"
echo "ip2torPort='${port}'"
# check for LetsEnryptDomain on IP2TOR
error=""
source <(sudo /home/admin/config.scripts/blitz.subscriptions.letsencrypt.py domain-by-ip $ip)
if [ ${#error} -eq 0 ]; then
echo "ip2torDomain='${domain}'"
domainWarning=$(sudo /home/admin/config.scripts/blitz.subscriptions.letsencrypt.py subscription-detail ${domain} ${port} | jq -r ".warning")
if [ ${#domainWarning} -gt 0 ]; then
echo "ip2torWarn='${domainWarning}'"
fi
2020-07-14 20:29:33 +02:00
fi
fi
2020-02-10 12:33:03 +01:00
# check for error
isDead=$(sudo systemctl status lnbits | grep -c 'inactive (dead)')
if [ ${isDead} -eq 1 ]; then
echo "error='Service Failed'"
2022-05-05 10:59:50 +02:00
exit 0
2020-02-10 12:33:03 +01:00
fi
else
echo "installed=0"
fi
exit 0
fi
##########################
# PRESTART
# - will be called as prestart by systemd service (as user lnbits)
#########################
if [ "$1" = "prestart" ]; then
# users need to be `lnbits` so that it can be run by systemd as prestart (no SUDO available)
if [ "$USER" != "lnbits" ]; then
echo "# FAIL: run as user lnbits"
2020-02-10 12:33:03 +01:00
exit 1
fi
# get if its for lnd or cl service
echo "## lnbits.service PRESTART CONFIG"
echo "# --> /home/lnbits/lnbits/.env"
# set values based in funding source in raspiblitz config
2022-11-16 11:00:35 -06:00
# portprefix is "" | 1 | 3
LNBitsNetwork="bitcoin"
LNBitsChain=""
LNBitsLightning=""
if [ "${LNBitsFunding}" == "" ] || [ "${LNBitsFunding}" == "lnd" ]; then
LNBitsFunding="lnd"
LNBitsLightning="lnd"
LNBitsChain="main"
2022-11-16 11:00:35 -06:00
portprefix=""
elif [ "${LNBitsFunding}" == "tlnd" ]; then
LNBitsLightning="lnd"
LNBitsChain="test"
2022-11-16 11:00:35 -06:00
portprefix="1"
elif [ "${LNBitsFunding}" == "slnd" ]; then
LNBitsLightning="lnd"
LNBitsChain="sig"
2022-11-16 11:00:35 -06:00
portprefix="3"
elif [ "${LNBitsFunding}" == "cl" ]; then
LNBitsLightning="cl"
LNBitsChain="main"
elif [ "${LNBitsFunding}" == "tcl" ]; then
LNBitsLightning="cl"
LNBitsChain="test"
elif [ "${LNBitsFunding}" == "scl" ]; then
LNBitsLightning="cl"
LNBitsChain="sig"
else
echo "# FAIL: Unknown LNBitsFunding=${LNBitsFunding}"
exit 1
2020-05-01 11:15:32 +02:00
fi
echo "# LNBitsFunding(${LNBitsFunding}) --> network(${LNBitsNetwork}) chain(${LNBitsChain}) lightning(${LNBitsLightning})"
# set lnd config
if [ "${LNBitsLightning}" == "lnd" ]; then
echo "# setting lnd config fresh ..."
# check if lnbits user has read access on lnd data files
checkReadAccess=$(cat /mnt/hdd/app-data/lnd/data/chain/${LNBitsNetwork}/${LNBitsChain}net/admin.macaroon | grep -c "lnd")
if [ "${checkReadAccess}" != "1" ]; then
echo "# FAIL: missing lnd data in '/mnt/hdd/app-data/lnd' or missing access rights for lnbits user"
exit 1
fi
echo "# Updating LND TLS & macaroon data fresh for LNbits config ..."
# set tls.cert path (use | as separator to avoid escaping file path slashes)
sed -i "s|^LND_REST_CERT=.*|LND_REST_CERT=/mnt/hdd/app-data/lnd/tls.cert|g" /home/lnbits/lnbits/.env
# set macaroon path info in .env - USING HEX IMPORT
chmod 600 /home/lnbits/lnbits/.env
macaroonAdminHex=$(xxd -ps -u -c 1000 /mnt/hdd/app-data/lnd/data/chain/${LNBitsNetwork}/${LNBitsChain}net/admin.macaroon)
macaroonInvoiceHex=$(xxd -ps -u -c 1000 /mnt/hdd/app-data/lnd/data/chain/${LNBitsNetwork}/${LNBitsChain}net/invoice.macaroon)
macaroonReadHex=$(xxd -ps -u -c 1000 /mnt/hdd/app-data/lnd/data/chain/${LNBitsNetwork}/${LNBitsChain}net/readonly.macaroon)
sed -i "s/^LND_REST_ADMIN_MACAROON=.*/LND_REST_ADMIN_MACAROON=${macaroonAdminHex}/g" /home/lnbits/lnbits/.env
sed -i "s/^LND_REST_INVOICE_MACAROON=.*/LND_REST_INVOICE_MACAROON=${macaroonInvoiceHex}/g" /home/lnbits/lnbits/.env
sed -i "s/^LND_REST_READ_MACAROON=.*/LND_REST_READ_MACAROON=${macaroonReadHex}/g" /home/lnbits/lnbits/.env
2022-11-16 11:00:35 -06:00
sed -i "s/^LND_REST_ENDPOINT=.*/LND_REST_ENDPOINT=https://127.0.0.1:${portprefix}8080/g" /home/lnbits/lnbits/.env
elif [ "${LNBitsLightning}" == "cl" ]; then
isUsingCL=$(cat /home/lnbits/lnbits/.env | grep -c "LNBITS_BACKEND_WALLET_CLASS=CLightningWallet")
if [ "${isUsingCL}" != "1" ]; then
2022-11-16 11:00:35 -06:00
echo "# FAIL: /home/lnbits/lnbits/.env not set to CLN"
exit 1
fi
2022-11-16 11:00:35 -06:00
echo "# everything looks OK for lnbits config on CLN on ${LNBitsChain}net"
else
echo "# FAIL: missing or not supported LNBitsLightning=${LNBitsLightning}"
exit 1
fi
echo "# OK: prestart finished"
exit 0 # exit with clean code
2020-02-10 12:33:03 +01:00
fi
if [ "$1" = "repo" ]; then
# get github parameters
githubUser="$2"
if [ ${#githubUser} -eq 0 ]; then
echo "echo='missing parameter'"
exit 1
fi
githubBranch="$3"
if [ ${#githubBranch} -eq 0 ]; then
githubBranch="main"
fi
# check if repo exists
githubRepo="https://github.com/${githubUser}/lnbits"
2022-09-13 18:16:28 +01:00
httpcode=$(curl -s -o /dev/null -w "%{http_code}" ${githubRepo})
if [ "${httpcode}" != "200" ]; then
echo "# tested github repo: ${githubRepo}"
echo "error='repo for user does not exist'"
exit 1
fi
2022-10-15 11:20:20 +01:00
# fix permissions
sudo chown -R lnbits:lnbits /home/lnbits/lnbits
# change origin repo of lnbits code
echo "# changing LNbits github repo(${githubUser}) branch(${githubBranch})"
2022-10-15 11:20:20 +01:00
cd /home/lnbits/lnbits || exit 1
2022-09-13 18:16:28 +01:00
sudo -u lnbits git remote remove origin
sudo -u lnbits git remote add origin ${githubRepo}
sudo -u lnbits git fetch
sudo -u lnbits git checkout ${githubBranch}
sudo -u lnbits git branch --set-upstream-to=origin/${githubBranch} ${githubBranch}
fi
if [ "$1" = "sync" ] || [ "$1" = "repo" ]; then
echo "# pull all changes from github repo"
2022-10-15 11:20:20 +01:00
# fix permissions
sudo chown -R lnbits:lnbits /home/lnbits/lnbits
# output basic info
2022-10-15 11:20:20 +01:00
cd /home/lnbits/lnbits || exit 1
2022-09-13 18:16:28 +01:00
sudo -u lnbits git remote -v
sudo -u lnbits git branch -v
# pull latest code
2022-09-13 18:16:28 +01:00
sudo -u lnbits git pull
# install
sudo -u lnbits python3 -m venv venv
sudo -u lnbits ./venv/bin/pip install -r requirements.txt
sudo -u lnbits ./venv/bin/pip install pylightning
sudo -u lnbits ./venv/bin/pip install secp256k1
sudo -u lnbits ./venv/bin/pip install pyln-client
#3505 lnbits PostgresSQl migration finalization (#3507) * fix missing dependencies * LNBits SQLite to PostgreSQL migration (#3411) * LNBits SQLite to PostgreSQL migration New installations with PostgreSQL configuration, existent data with SQLite. convert script needs a full start of LNBits prior migrating the old sqlite db's. User can migrate from raspiblitz menu. * only fix postgres if it needs to check for symbolik link of postgres default directory or desired postgres folder btcpayserver and lnbits could use postgresql new script to install or uninstall postgresql * fix typos * silent apt remove * fix removed function postgresConfig call bonus.postgresql.sh to setup PostgreSQL * Support outdated installation old installations should upgrade to new tag first create new data directory /mnt/hdd/app-data/LNBits/data * Improve migration Make it a bit more user friendly and prepare for a worst case to revert the migration if something fails unexpectedly make use of sync method for preparation * Rework migration workflow Cant wait for lnbits to start when ExecStartPre is used. We need a full start of lnbits prior migration, so make use of lsof to check for ports and wait. dont forget to start postgres service after installation. dont forget to stop postgres after uninstall * Dont overwrite the backup file if we start migrate again, the sqlite backup should not be overwritten with postgres data. Keep the backup file. * add migrate message to menu add the hint to revert migration manually after migrate script executed * fix install and data directory lnbits always needs a data directory * clean up lnbits settings for migration even if postgresql is already running, we can extract sqlite backup and start migrate remove migrateMsg duplicate * preserve database for reflash drop database only for migrate, not for regular installations * set blitz config for LNBits fix drop database only for migrate, not for regular installations * Add confirmation dialog and automatic revert User needs to confirm the process, this will eliminate missclicks add a migrate revert function to automatically revert if something unexpected happens let the user call the function manually * check conv.py on success or revert if the conversion script fails, revert automatically * Improve revert message Do not print the revert hint message if current database is SQLite * fix read config LNBitsDB * fix unpack backup Folder LNBits should never block the restore of backup. Happened after multiple migrations and revert. * Wait for lnbits v0.9.5 Set commit version with fix for postgresql database and BIGINT for amounts for migrate Can be set to v0.9.5 tag or above later * improve migrate backup handling revert to the current backup and not to the previous backup. No need for the failed folder state user message with backup file path * check psql version once * supress expected errors if database exists Co-authored-by: /rootzoll <christian@geektank.de> * fix error output on status Co-authored-by: ChuckNorrison <2964146+ChuckNorrison@users.noreply.github.com>
2022-12-10 00:04:15 +01:00
sudo -u lnbits ./venv/bin/pip install psycopg2 # conv.py postgres migration dependency
2022-09-13 18:16:28 +01:00
# build
sudo -u lnbits ./venv/bin/python build.py
# restart lnbits service
sudo systemctl restart lnbits
echo "# server is restarting ... maybe takes some seconds until available"
exit 0
fi
2020-02-10 12:33:03 +01:00
# stop service
sudo systemctl stop lnbits 2>/dev/null
2022-12-13 15:28:05 +01:00
# install (code & compile)
if [ "$1" = "install" ]; then
# check if already installed
isInstalled=$(compgen -u | grep -c lnbits)
if [ "${isInstalled}" != "0" ]; then
echo "result='already installed'"
exit 0
fi
echo "# *** INSTALL THUNDERHUB ***"
# add lnbits user
echo "*** Add the 'lnbits' user ***"
sudo adduser --disabled-password --gecos "" lnbits
# get optional github parameter
githubUser="lnbits"
if [ "$2" != "" ]; then
githubUser="$2"
fi
if [ "$3" != "" ]; then
tag="$3"
fi
# install from GitHub
echo "# get the github code user(${githubUser}) branch(${tag})"
sudo rm -r /home/lnbits/lnbits 2>/dev/null
cd /home/lnbits || exit 1
sudo -u lnbits git clone https://github.com/${githubUser}/lnbits-legend lnbits
cd /home/lnbits/lnbits || exit 1
sudo -u lnbits git checkout ${tag} || exit 1
# to the install
echo "# installing application dependencies"
cd /home/lnbits/lnbits || exit 1
# do install like this
sudo -u lnbits python3 -m venv venv
sudo -u lnbits ./venv/bin/pip install -r requirements.txt
sudo -u lnbits ./venv/bin/pip install pylightning
sudo -u lnbits ./venv/bin/pip install secp256k1
sudo -u lnbits ./venv/bin/pip install pyln-client
sudo -u lnbits ./venv/bin/pip install psycopg2 # conv.py postgres migration dependency
# build
sudo -u lnbits ./venv/bin/python build.py
exit 0
fi
# remove from system
if [ "$1" = "uninstall" ]; then
# check if still active
isActive=$(sudo ls /etc/systemd/system/lnbits.service 2>/dev/null | grep -c 'lnbits.service')
if [ "${isActive}" != "0" ]; then
echo "result='still in use'"
exit 1
fi
echo "# *** UNINSTALL LNBITS ***"
# always delete user and home directory
sudo userdel -rf lnbits
exit 0
fi
# install
2020-02-10 12:33:03 +01:00
if [ "$1" = "1" ] || [ "$1" = "on" ]; then
2022-12-13 15:28:05 +01:00
# check if code is already installed
isInstalled=$(compgen -u | grep -c lnbits)
if [ "${isInstalled}" == "0" ]; then
echo "# Installing code base & dependencies first .."
/home/admin/config.scripts/bonus.lnbits.sh install || exit 1
fi
# check if already active
isActive=$(sudo ls /etc/systemd/system/lnbits.service 2>/dev/null | grep -c 'lnbits.service')
if [ "${isActive}" == "1" ]; then
echo "# FAIL: already installed"
exit 1
fi
2020-02-10 12:33:03 +01:00
# get funding source and check that its available
fundingsource="$2"
2020-04-28 09:27:03 +01:00
2022-05-05 10:59:50 +02:00
# run with default funding source if not given as parameter
if [ "${fundingsource}" == "" ]; then
echo "# running with default lightning as funing source: ${lightning}"
fundingsource="${lightning}"
fi
if [ "${fundingsource}" == "lnd" ]; then
if [ "${lnd}" != "on" ]; then
2022-01-11 14:55:06 +00:00
echo "# FAIL: lnd mainnet needs to be activated"
exit 1
fi
elif [ "${fundingsource}" == "tlnd" ]; then
if [ "${tlnd}" != "on" ]; then
2022-01-11 14:55:06 +00:00
echo "# FAIL: lnd testnet needs to be activated"
exit 1
fi
elif [ "${fundingsource}" == "slnd" ]; then
if [ "${slnd}" != "on" ]; then
2022-01-11 14:55:06 +00:00
echo "# FAIL: lnd signet needs to be activated"
exit 1
fi
2020-02-10 12:33:03 +01:00
elif [ "${fundingsource}" == "cl" ]; then
if [ "${cl}" != "on" ]; then
2022-11-16 11:00:35 -06:00
echo "# FAIL: CLN mainnet needs to be activated"
exit 1
fi
2020-02-10 21:07:24 +01:00
elif [ "${fundingsource}" == "tcl" ]; then
if [ "${tcl}" != "on" ]; then
2022-11-16 11:00:35 -06:00
echo "# FAIL: CLN testnet needs to be activated"
exit 1
fi
2020-02-10 12:33:03 +01:00
elif [ "${fundingsource}" == "scl" ]; then
if [ "${scl}" != "on" ]; then
2022-11-16 11:00:35 -06:00
echo "# FAIL: CLN signet needs to be activated"
exit 1
fi
else
2022-01-11 14:55:06 +00:00
echo "# FAIL: invalid funding source parameter"
exit 1
fi
# prepare .env file
echo "# preparing env file"
sudo rm /home/lnbits/lnbits/.env 2>/dev/null
sudo -u lnbits touch /home/lnbits/lnbits/.env
sudo bash -c "echo 'LNBITS_FORCE_HTTPS=0' >> /home/lnbits/lnbits/.env"
#3505 lnbits PostgresSQl migration finalization (#3507) * fix missing dependencies * LNBits SQLite to PostgreSQL migration (#3411) * LNBits SQLite to PostgreSQL migration New installations with PostgreSQL configuration, existent data with SQLite. convert script needs a full start of LNBits prior migrating the old sqlite db's. User can migrate from raspiblitz menu. * only fix postgres if it needs to check for symbolik link of postgres default directory or desired postgres folder btcpayserver and lnbits could use postgresql new script to install or uninstall postgresql * fix typos * silent apt remove * fix removed function postgresConfig call bonus.postgresql.sh to setup PostgreSQL * Support outdated installation old installations should upgrade to new tag first create new data directory /mnt/hdd/app-data/LNBits/data * Improve migration Make it a bit more user friendly and prepare for a worst case to revert the migration if something fails unexpectedly make use of sync method for preparation * Rework migration workflow Cant wait for lnbits to start when ExecStartPre is used. We need a full start of lnbits prior migration, so make use of lsof to check for ports and wait. dont forget to start postgres service after installation. dont forget to stop postgres after uninstall * Dont overwrite the backup file if we start migrate again, the sqlite backup should not be overwritten with postgres data. Keep the backup file. * add migrate message to menu add the hint to revert migration manually after migrate script executed * fix install and data directory lnbits always needs a data directory * clean up lnbits settings for migration even if postgresql is already running, we can extract sqlite backup and start migrate remove migrateMsg duplicate * preserve database for reflash drop database only for migrate, not for regular installations * set blitz config for LNBits fix drop database only for migrate, not for regular installations * Add confirmation dialog and automatic revert User needs to confirm the process, this will eliminate missclicks add a migrate revert function to automatically revert if something unexpected happens let the user call the function manually * check conv.py on success or revert if the conversion script fails, revert automatically * Improve revert message Do not print the revert hint message if current database is SQLite * fix read config LNBitsDB * fix unpack backup Folder LNBits should never block the restore of backup. Happened after multiple migrations and revert. * Wait for lnbits v0.9.5 Set commit version with fix for postgresql database and BIGINT for amounts for migrate Can be set to v0.9.5 tag or above later * improve migrate backup handling revert to the current backup and not to the previous backup. No need for the failed folder state user message with backup file path * check psql version once * supress expected errors if database exists Co-authored-by: /rootzoll <christian@geektank.de> * fix error output on status Co-authored-by: ChuckNorrison <2964146+ChuckNorrison@users.noreply.github.com>
2022-12-10 00:04:15 +01:00
if [ ! -e /mnt/hdd/app-data/LNBits/database.sqlite3 ]; then
echo "# install database: PostgreSQL"
# POSTGRES
postgresConfig
# new data directory
sudo mkdir -p /mnt/hdd/app-data/LNBits/data
# config update
# example: postgres://<user>:<password>@<host>/<database>
sudo bash -c "echo 'LNBITS_DATABASE_URL=postgres://lnbits_user:raspiblitz@localhost:5432/lnbits_db' >> /home/lnbits/lnbits/.env"
sudo bash -c "echo 'LNBITS_DATA_FOLDER=/mnt/hdd/app-data/LNBits/data' >> /home/lnbits/lnbits/.env"
else
echo "# install database: SQLite"
/home/admin/config.scripts/blitz.conf.sh set LNBitsDB "SQLite"
# new data directory
sudo mkdir -p /mnt/hdd/app-data/LNBits
# config update
sudo bash -c "echo 'LNBITS_DATA_FOLDER=/mnt/hdd/app-data/LNBits' >> /home/lnbits/lnbits/.env"
fi
sudo chown lnbits:lnbits -R /mnt/hdd/app-data/LNBits
2022-09-13 18:16:28 +01:00
# let switch command part do the detail config
/home/admin/config.scripts/bonus.lnbits.sh switch ${fundingsource}
2022-10-15 11:20:20 +01:00
cd /home/lnbits/lnbits || exit 1
# open firewall
echo
echo "*** Updating Firewall ***"
sudo ufw allow 5000 comment 'lnbits HTTP'
sudo ufw allow 5001 comment 'lnbits HTTPS'
2022-10-15 11:20:20 +01:00
echo
2020-02-10 12:33:03 +01:00
#3505 lnbits PostgresSQl migration finalization (#3507) * fix missing dependencies * LNBits SQLite to PostgreSQL migration (#3411) * LNBits SQLite to PostgreSQL migration New installations with PostgreSQL configuration, existent data with SQLite. convert script needs a full start of LNBits prior migrating the old sqlite db's. User can migrate from raspiblitz menu. * only fix postgres if it needs to check for symbolik link of postgres default directory or desired postgres folder btcpayserver and lnbits could use postgresql new script to install or uninstall postgresql * fix typos * silent apt remove * fix removed function postgresConfig call bonus.postgresql.sh to setup PostgreSQL * Support outdated installation old installations should upgrade to new tag first create new data directory /mnt/hdd/app-data/LNBits/data * Improve migration Make it a bit more user friendly and prepare for a worst case to revert the migration if something fails unexpectedly make use of sync method for preparation * Rework migration workflow Cant wait for lnbits to start when ExecStartPre is used. We need a full start of lnbits prior migration, so make use of lsof to check for ports and wait. dont forget to start postgres service after installation. dont forget to stop postgres after uninstall * Dont overwrite the backup file if we start migrate again, the sqlite backup should not be overwritten with postgres data. Keep the backup file. * add migrate message to menu add the hint to revert migration manually after migrate script executed * fix install and data directory lnbits always needs a data directory * clean up lnbits settings for migration even if postgresql is already running, we can extract sqlite backup and start migrate remove migrateMsg duplicate * preserve database for reflash drop database only for migrate, not for regular installations * set blitz config for LNBits fix drop database only for migrate, not for regular installations * Add confirmation dialog and automatic revert User needs to confirm the process, this will eliminate missclicks add a migrate revert function to automatically revert if something unexpected happens let the user call the function manually * check conv.py on success or revert if the conversion script fails, revert automatically * Improve revert message Do not print the revert hint message if current database is SQLite * fix read config LNBitsDB * fix unpack backup Folder LNBits should never block the restore of backup. Happened after multiple migrations and revert. * Wait for lnbits v0.9.5 Set commit version with fix for postgresql database and BIGINT for amounts for migrate Can be set to v0.9.5 tag or above later * improve migrate backup handling revert to the current backup and not to the previous backup. No need for the failed folder state user message with backup file path * check psql version once * supress expected errors if database exists Co-authored-by: /rootzoll <christian@geektank.de> * fix error output on status Co-authored-by: ChuckNorrison <2964146+ChuckNorrison@users.noreply.github.com>
2022-12-10 00:04:15 +01:00
# install service
echo "*** Install systemd ***"
cat <<EOF | sudo tee /etc/systemd/system/lnbits.service >/dev/null
2020-02-10 18:16:55 +01:00
# systemd unit for lnbits
2020-02-10 12:33:03 +01:00
[Unit]
Description=lnbits
Wants=bitcoind.service
After=bitcoind.service
2020-02-10 12:33:03 +01:00
[Service]
2020-04-28 09:27:03 +01:00
WorkingDirectory=/home/lnbits/lnbits
ExecStartPre=/home/admin/config.scripts/bonus.lnbits.sh prestart
ExecStart=/home/lnbits/lnbits/venv/bin/uvicorn lnbits.__main__:app --port 5000
2020-04-28 09:27:03 +01:00
User=lnbits
2020-02-10 12:33:03 +01:00
Restart=always
TimeoutSec=120
RestartSec=30
StandardOutput=journal
2020-02-10 12:33:03 +01:00
StandardError=journal
2020-02-10 18:40:53 +01:00
merging pre-1.7.1 (#2462) * fix copychain returns * typo in sync loop * stop services on inconsistent state * calling correct provisioning * apply bitcoin and lncli aliases in all scripts * network.aliases: add CLNETWORK * make cln default plugin dir: cln-plugins-enabled similar to the nginx model make 2 directories for plugins: cln-plugins-enabled - symlinked to ~/.lightning/plugins plugins from here are loaded automatically on cln start cln-plugins-available: plugins are downloaded here to be run until the next cln restart (or stopped with runonce) note the disk is mounted with noexec so plugins can't run from there discuss in: https://github.com/rootzoll/raspiblitz/issues/2295 * move shutdown script * change all place where shutdown script is used * change notify & release * moved shutdown script * moved shutdown scripts * add more debug info * moving github script * remove chain in sync * no longer needed chain in sync * move debug script * patch patch command * make sure setup file is sourced * remove debug output * make sure lnd is put behind tor * change indent * get fresh sync progress * avoid scrolling in menus * use new selfsignedcert if no lnd tls.cert present * sparko: add info and connect menu with own cert https://github.com/rootzoll/raspiblitz/issues/2295 * cln.rest: add connect option for Zeus https://github.com/rootzoll/raspiblitz/issues/2295 * cln: add the backup plugin + options Usage options: cln-plugin.backup.sh [on] [testnet|mainnet|signet] cln-plugin.backup.sh [restore] [testnet|mainnet|signet] [force] cln-plugin.backup.sh [backup-compact] [testnet|mainnet|signet] https://github.com/lightningd/plugins/tree/master/backup Discussed in: https://github.com/rootzoll/raspiblitz/issues/2295 * cln: add cln-plugin.standard.python.sh Install and show the output of the chosen plugin for C-lightning Usage: cln-plugin.standard-python.sh on [plugin-name] [testnet|mainnet|signet] [runonce] tested plugins: summary | helpme | feeadjuster find more at: https://github.com/lightningd/plugins discussed in: https://github.com/rootzoll/raspiblitz/issues/2295 * shellcheck: change all `egrep` to `grep -E` https://github.com/koalaman/shellcheck/wiki/SC2196 * do not resolve aliases, use as variables * lnd: fix lnd.conf for parallel networks discussed in: https://github.com/rootzoll/raspiblitz/issues/2290 * lnd: add LND option for parallel networks * deprecate Testnet in SETTINGS keysend and autopilot only for mainnet due to: https://github.com/rootzoll/raspiblitz/issues/2290 * lnd: autopilot and autounlock for testnet * fix comments * add the SYSTEM menu for parallel chains * RTL update to v0.11.0 make chain specific directory for the config: /home/rtl/${netprefix}RTL/ use ${netprefix}lnd.conf in config override Environmen tvaribales for cln in the systemd service: /etc/systemd/system/${netprefix}${typeprefix}RTL.service discussed in: https://github.com/rootzoll/raspiblitz/issues/2384 * lnd.setname.sh for testnet * display ${CHAIN} in the SYSTEM menu options * keep _aliases file when live patches are applied * all lncli_aliases to be used as variables * default to KIllMode=control-group in services https://www.man7.org/linux/man-pages/man5/systemd.kill.5.html discussed in: https://github.com/rootzoll/raspiblitz/issues/1901 * add cln.hsmtool.sh for hsm_secret handling encrypt | decrypt | autounlock the hsm_secret for C-lightning usage: cln.hsmtool.sh [unlock] [testnet|mainnet|signet] cln.hsmtool.sh [encrypt|decrypt] [testnet|mainnet|signet] cln.hsmtool.sh [autounlock-on|autounlock-off] [testnet|mainnet|signet] discussed in: https://github.com/rootzoll/raspiblitz/issues/2295 * add cln.install-service.sh to set up cln with systemd script to set up or update the CLN systemd service checks for hsm_secret encryption, autounlock and the sparko plugin usage: /home/admin/config.scripts/cln.install-service.sh $CHAIN discussed in: https://github.com/rootzoll/raspiblitz/issues/2295 * use symlink to cln-plugins-enabled for all plugins * keep lnd autopilot and autounlock mainnet only mainnet only settings: lnd autopilot lnd keysend circuibreaker lnd autounlock StaticChannelBackup to DropBox and USB * cln FUNDING fix parsing address * cln.hsmtool: add change-password and lock options * always set password A * cached peer info * fix printing cache * fix check for existing files * handle bitcoind not running * result with newline * test line break * test new line * test new line * two vars on output * #2388 improve online check (less pinging) * used cached peer status * move chache * cach file permissions * allow sudo call * fix cache * remove double scan info * add conf info to sync screen * reorder info * add space * add space * order info * internet suppress error messages * order info * fix offering Blockchain copy * fix hostname * final ready state info * lnd unlock after provision * remove debug exit * harmonize ready state * add status to lnd unlock * update lnd unlock script * edit the unlock * remove debug echo * add debug * add debug * fix if statement * debug output * switch position of source setupdata * #1126 preparing new setup with new c-lightning (#2396) * move debug script * patch patch command * make sure setup file is sourced * remove debug output * make sure lnd is put behind tor * change indent * get fresh sync progress * always set password A * cached peer info * fix printing cache * fix check for existing files * handle bitcoind not running * result with newline * test line break * test new line * test new line * two vars on output * #2388 improve online check (less pinging) * used cached peer status * move chache * cach file permissions * allow sudo call * fix cache * remove double scan info * add conf info to sync screen * reorder info * add space * add space * order info * internet suppress error messages * order info * fix offering Blockchain copy * fix hostname * final ready state info * lnd unlock after provision * remove debug exit * harmonize ready state * add status to lnd unlock * update lnd unlock script * edit the unlock * remove debug echo * add debug * add debug * fix if statement * debug output * switch position of source setupdata * lnd.unlock: fix typo * netwok.monitor.sh debug * cln-plugin.summary: fix paths * rtl: fix permission of config on copy * CASHOUT: use aliases for lnd * rtl: install correctly for paralell chains * use CHAIN in CLN and LND menu * cln: add CASHOUT option * CLOSEALL and CASHOUT: Improve labels and comments Explaining CASHOUT in the label as discussed in: https://github.com/rootzoll/raspiblitz/issues/2358 * cln.install: fix tor config * cln: installthe latest master until the next release * _commands: source _aliases only if exists * network aliases: fall back to 'main' for 'chain' * new setup: keep testnet3 blocks and chainstate * new setup: improve capitalization in menu * improve help and comments * cln: install Sparko if configured, but not present * cln: add new wallet and import seed options * fix peernum * make sure that aliases get created on lnd setup * no error if aliases not yet exist * debug state * fix network alias when not set * fix syntax error * add debug error info * mute unlocking echos * add debug wait * add debug wait * make sure info is uptodate * make alias info as defaults * rename option * update sync info for no lightning * add action string * update sync info * move name dialog * wait for sync progress info * wait for syncprogress info * fix syntax * get fresh data * make sure to disable lnd * add c-lightning to debug * add setup logs to debug output * fix syntax error * add new-force wallet * try fix call hsmtool * hsm output tool * fix output * add seed-force * refactor blitz.mnemonic.py * test seed * debug info * dump object * try check * correct putput * fix syntax * check lnd for valid seed * fix gui * add Suez install script discussed in: https://github.com/rootzoll/raspiblitz/issues/2366 * cln rescue file export * get correct version * add cln export gui * cln.backup.sh cln-import * correct bytesize * generate cln wallet with passwordc * fix syntax * fix syntax * mute not needed error msg * PEERING: correct message on success * cln.install-service: fix sparko check * add Suez to menu for CLN and LND needs to be installed with the bitcoin user to be able to interact with CLN related: https://github.com/rootzoll/raspiblitz/issues/2366 * debug _provison.setup.sh stop bitcoind and restart with new config to avoid rpc password error disable and enable service instead of daemon-reload CLN: don't use passwordC as seedPassword * add cln.setname.sh make lnd.setname.sh work with parallel wallets * improve comments * SYSTEM: add CLNLOG and CLNCONF options * SYSTEM menu fixes * cln: add more aliases cln, clnlog, clnconf * cln: activate the backup plugin on every install * SERVICES menu: fix chantools/CLN switch * cln: load plugins from ${netprefix}cln-plugins-enabled changed the config paths to $lightning-dir/config or /networkname/config plugins are downloaded to the SDcard: /home/bitcoin/cln-plugins-available/ symlinked and loaded automatically from: /home/bitcoin/${netprefix}cln-plugins-enabled Related: #2295 * sparko: don't show logs after install * #2425 Adding experimental Blitz WebUI & API (#2426) * no password C & D when cln * add debug echos * set defaults before * #2228 wider grep to detect nvms (#2427) * cln.hsmtool: init backup with the new wallet * cln.install: fix access to raspiblitz.conf * cln-plugin.backup: fix path to backup-cli * cln: hide unhelpful warnings during setup * remove old jinja template rendering * fix lnd unlock detection * cln: look for files in .lightning dir with sudo * cln: correct lightning name in FInalDialog + typo * cln: make sure .lightning/bitcoin dir exists * FinalDialog: make the 24 words fit * cln.install.sh: create cln config if not present * Simplify localIP detection and improve compatibility (#2432) * show tail info on provision * only show lnd options when activated * fix syntax * only show main lightning impl options for RC1 * cln: always start the lightnind.service * cln: clear before showing summary * start cln on the end of provisioning * exit 0 on cln menu * press key after single actions * remove key press on cln actions * change to none * detect cln running * fix syntax * fix lightniing info * add TODO for CLN * add clnblockheight * zty with user bitcoin * check synced to chain for cln * fix increment * try scanprogress * use cln sync detection and progress * replace LNTYPE * next line * fix spaces * fix spaces * Update README.md (#2456) Fix 404 * Fix FAQ links (#2441) * Fix invalid URL ( (#2440) * support channels (#2382) * use #2370 height optimization * adjust exit codes in menu scripts * adjust password menu exit codes * adapt shutdown for cln * settings adapt to running lightning impl * fix syntax * debug info * add debug * better height * add default values * add config entry if not there yet * change default value * Added exit info for cln * make sure to load config file if available * add sparko to menu * add default for sparko * replace default sparko entry * show sparko installed or not * add more description to sparko option * RTL for clightnign in service menu * main menu item rtl * add RTL description * debug in RTL install * install sparko on recovery * update menu with cln * rework menu options Co-authored-by: openoms <oms@tuta.io> Co-authored-by: openoms <43343391+openoms@users.noreply.github.com> Co-authored-by: rek79 <rek79@users.noreply.github.com> Co-authored-by: Bitpaint <67663265+bitpaint@users.noreply.github.com> Co-authored-by: João Thallis <joaothallis@icloud.com> Co-authored-by: Peter Flock <78184669+peterflock@users.noreply.github.com> Co-authored-by: nyxnor <nyxnor@protonmail.com>
2021-08-04 00:18:30 +02:00
# Hardening measures
PrivateTmp=true
ProtectSystem=full
NoNewPrivileges=true
PrivateDevices=true
2020-02-10 18:40:53 +01:00
[Install]
WantedBy=multi-user.target
2020-02-10 12:33:03 +01:00
EOF
#3505 lnbits PostgresSQl migration finalization (#3507) * fix missing dependencies * LNBits SQLite to PostgreSQL migration (#3411) * LNBits SQLite to PostgreSQL migration New installations with PostgreSQL configuration, existent data with SQLite. convert script needs a full start of LNBits prior migrating the old sqlite db's. User can migrate from raspiblitz menu. * only fix postgres if it needs to check for symbolik link of postgres default directory or desired postgres folder btcpayserver and lnbits could use postgresql new script to install or uninstall postgresql * fix typos * silent apt remove * fix removed function postgresConfig call bonus.postgresql.sh to setup PostgreSQL * Support outdated installation old installations should upgrade to new tag first create new data directory /mnt/hdd/app-data/LNBits/data * Improve migration Make it a bit more user friendly and prepare for a worst case to revert the migration if something fails unexpectedly make use of sync method for preparation * Rework migration workflow Cant wait for lnbits to start when ExecStartPre is used. We need a full start of lnbits prior migration, so make use of lsof to check for ports and wait. dont forget to start postgres service after installation. dont forget to stop postgres after uninstall * Dont overwrite the backup file if we start migrate again, the sqlite backup should not be overwritten with postgres data. Keep the backup file. * add migrate message to menu add the hint to revert migration manually after migrate script executed * fix install and data directory lnbits always needs a data directory * clean up lnbits settings for migration even if postgresql is already running, we can extract sqlite backup and start migrate remove migrateMsg duplicate * preserve database for reflash drop database only for migrate, not for regular installations * set blitz config for LNBits fix drop database only for migrate, not for regular installations * Add confirmation dialog and automatic revert User needs to confirm the process, this will eliminate missclicks add a migrate revert function to automatically revert if something unexpected happens let the user call the function manually * check conv.py on success or revert if the conversion script fails, revert automatically * Improve revert message Do not print the revert hint message if current database is SQLite * fix read config LNBitsDB * fix unpack backup Folder LNBits should never block the restore of backup. Happened after multiple migrations and revert. * Wait for lnbits v0.9.5 Set commit version with fix for postgresql database and BIGINT for amounts for migrate Can be set to v0.9.5 tag or above later * improve migrate backup handling revert to the current backup and not to the previous backup. No need for the failed folder state user message with backup file path * check psql version once * supress expected errors if database exists Co-authored-by: /rootzoll <christian@geektank.de> * fix error output on status Co-authored-by: ChuckNorrison <2964146+ChuckNorrison@users.noreply.github.com>
2022-12-10 00:04:15 +01:00
sudo systemctl enable lnbits
2020-07-19 17:56:00 +02:00
#3505 lnbits PostgresSQl migration finalization (#3507) * fix missing dependencies * LNBits SQLite to PostgreSQL migration (#3411) * LNBits SQLite to PostgreSQL migration New installations with PostgreSQL configuration, existent data with SQLite. convert script needs a full start of LNBits prior migrating the old sqlite db's. User can migrate from raspiblitz menu. * only fix postgres if it needs to check for symbolik link of postgres default directory or desired postgres folder btcpayserver and lnbits could use postgresql new script to install or uninstall postgresql * fix typos * silent apt remove * fix removed function postgresConfig call bonus.postgresql.sh to setup PostgreSQL * Support outdated installation old installations should upgrade to new tag first create new data directory /mnt/hdd/app-data/LNBits/data * Improve migration Make it a bit more user friendly and prepare for a worst case to revert the migration if something fails unexpectedly make use of sync method for preparation * Rework migration workflow Cant wait for lnbits to start when ExecStartPre is used. We need a full start of lnbits prior migration, so make use of lsof to check for ports and wait. dont forget to start postgres service after installation. dont forget to stop postgres after uninstall * Dont overwrite the backup file if we start migrate again, the sqlite backup should not be overwritten with postgres data. Keep the backup file. * add migrate message to menu add the hint to revert migration manually after migrate script executed * fix install and data directory lnbits always needs a data directory * clean up lnbits settings for migration even if postgresql is already running, we can extract sqlite backup and start migrate remove migrateMsg duplicate * preserve database for reflash drop database only for migrate, not for regular installations * set blitz config for LNBits fix drop database only for migrate, not for regular installations * Add confirmation dialog and automatic revert User needs to confirm the process, this will eliminate missclicks add a migrate revert function to automatically revert if something unexpected happens let the user call the function manually * check conv.py on success or revert if the conversion script fails, revert automatically * Improve revert message Do not print the revert hint message if current database is SQLite * fix read config LNBitsDB * fix unpack backup Folder LNBits should never block the restore of backup. Happened after multiple migrations and revert. * Wait for lnbits v0.9.5 Set commit version with fix for postgresql database and BIGINT for amounts for migrate Can be set to v0.9.5 tag or above later * improve migrate backup handling revert to the current backup and not to the previous backup. No need for the failed folder state user message with backup file path * check psql version once * supress expected errors if database exists Co-authored-by: /rootzoll <christian@geektank.de> * fix error output on status Co-authored-by: ChuckNorrison <2964146+ChuckNorrison@users.noreply.github.com>
2022-12-10 00:04:15 +01:00
source <(/home/admin/_cache.sh get state)
if [ "${state}" == "ready" ]; then
echo "# OK - lnbits service is enabled, system is on ready so starting lnbits service"
sudo systemctl start lnbits
else
echo "# OK - lnbits service is enabled, but needs reboot or manual starting: sudo systemctl start lnbits"
fi
2020-02-10 12:33:03 +01:00
2020-05-23 22:34:03 +01:00
# setup nginx symlinks
if ! [ -f /etc/nginx/sites-available/lnbits_ssl.conf ]; then
sudo cp /home/admin/assets/nginx/sites-available/lnbits_ssl.conf /etc/nginx/sites-available/lnbits_ssl.conf
fi
if ! [ -f /etc/nginx/sites-available/lnbits_tor.conf ]; then
sudo cp /home/admin/assets/nginx/sites-available/lnbits_tor.conf /etc/nginx/sites-available/lnbits_tor.conf
fi
if ! [ -f /etc/nginx/sites-available/lnbits_tor_ssl.conf ]; then
sudo cp /home/admin/assets/nginx/sites-available/lnbits_tor_ssl.conf /etc/nginx/sites-available/lnbits_tor_ssl.conf
fi
sudo ln -sf /etc/nginx/sites-available/lnbits_ssl.conf /etc/nginx/sites-enabled/
sudo ln -sf /etc/nginx/sites-available/lnbits_tor.conf /etc/nginx/sites-enabled/
sudo ln -sf /etc/nginx/sites-available/lnbits_tor_ssl.conf /etc/nginx/sites-enabled/
2020-05-23 22:34:03 +01:00
sudo nginx -t
sudo systemctl reload nginx
2020-02-10 12:33:03 +01:00
# setting value in raspi blitz config
/home/admin/config.scripts/blitz.conf.sh set LNBits "on"
2020-02-10 14:29:28 +01:00
# Hidden Service if Tor is active
2020-02-10 12:33:03 +01:00
source /mnt/hdd/raspiblitz.conf
if [ "${runBehindTor}" = "on" ]; then
# make sure to keep in sync with tor.network.sh script
/home/admin/config.scripts/tor.onion-service.sh lnbits 80 5002 443 5003
2020-02-10 12:33:03 +01:00
fi
echo "# OK install done ... might need to restart or call: sudo systemctl start lnbits"
2022-09-13 18:16:28 +01:00
# needed for API/WebUI as signal that install ran thru
2022-05-05 10:59:50 +02:00
echo "result='OK'"
exit 0
fi
2022-11-16 11:00:35 -06:00
# config for a special funding source (e.g lnd or CLN as backend)
if [ "$1" = "switch" ]; then
echo "## bonus.lnbits.sh switch $2"
# get funding source and check that its available
fundingsource="$2"
clrpcsubdir=""
if [ "${fundingsource}" == "lnd" ]; then
if [ "${lnd}" != "on" ]; then
echo "#FAIL: lnd mainnet not installed or running"
exit 1
fi
elif [ "${fundingsource}" == "tlnd" ]; then
if [ "${tlnd}" != "on" ]; then
echo "# FAIL: lnd testnet not installed or running"
exit 1
fi
elif [ "${fundingsource}" == "slnd" ]; then
if [ "${slnd}" != "on" ]; then
echo "# FAIL: lnd signet not installed or running"
exit 1
fi
elif [ "${fundingsource}" == "cl" ]; then
if [ "${cl}" != "on" ]; then
2022-11-16 11:00:35 -06:00
echo "# FAIL: CLN mainnet not installed or running"
exit 1
fi
elif [ "${fundingsource}" == "tcl" ]; then
clrpcsubdir="/testnet"
if [ "${tcl}" != "on" ]; then
2022-11-16 11:00:35 -06:00
echo "# FAIL: CLN testnet not installed or running"
exit 1
fi
elif [ "${fundingsource}" == "scl" ]; then
clrpcsubdir="/signet"
if [ "${scl}" != "on" ]; then
2022-11-16 11:00:35 -06:00
echo "# FAIL: CLN signet not installed or running"
exit 1
fi
else
echo "# FAIL: unvalid fundig source parameter"
exit 1
fi
echo "##############"
echo "# NOTE: If you switch the funding source of a running LNbits instance all sub account will keep balance."
echo "# Make sure that the new funding source has enough sats to cover the LNbits bookeeping of sub accounts."
echo "##############"
# remove all old possible settings for former funding source (clean state)
sudo sed -i "/^LNBITS_BACKEND_WALLET_CLASS=/d" /home/lnbits/lnbits/.env 2>/dev/null
sudo sed -i "/^LND_REST_ENDPOINT=/d" /home/lnbits/lnbits/.env 2>/dev/null
sudo sed -i "/^LND_REST_CERT=/d" /home/lnbits/lnbits/.env 2>/dev/null
sudo sed -i "/^LND_REST_ADMIN_MACAROON=/d" /home/lnbits/lnbits/.env 2>/dev/null
sudo sed -i "/^LND_REST_INVOICE_MACAROON=/d" /home/lnbits/lnbits/.env 2>/dev/null
sudo sed -i "/^LND_REST_READ_MACAROON=/d" /home/lnbits/lnbits/.env 2>/dev/null
sudo /usr/sbin/usermod -G lnbits lnbits
sudo sed -i "/^CLIGHTNING_RPC=/d" /home/lnbits/lnbits/.env 2>/dev/null
# LND CONFIG
if [ "${fundingsource}" == "lnd" ] || [ "${fundingsource}" == "tlnd" ] || [ "${fundingsource}" == "slnd" ]; then
# make sure lnbits user can access LND credentials
echo "# adding lnbits user is member of lndreadonly, lndinvoice, lndadmin"
sudo /usr/sbin/usermod --append --groups lndinvoice lnbits
sudo /usr/sbin/usermod --append --groups lndreadonly lnbits
sudo /usr/sbin/usermod --append --groups lndadmin lnbits
# prepare config entries in lnbits config for lnd
echo "# preparing lnbits config for lnd"
sudo bash -c "echo 'LNBITS_BACKEND_WALLET_CLASS=LndRestWallet' >> /home/lnbits/lnbits/.env"
sudo bash -c "echo 'LND_REST_ENDPOINT=https://127.0.0.1:8080' >> /home/lnbits/lnbits/.env"
sudo bash -c "echo 'LND_REST_CERT=' >> /home/lnbits/lnbits/.env"
sudo bash -c "echo 'LND_REST_ADMIN_MACAROON=' >> /home/lnbits/lnbits/.env"
sudo bash -c "echo 'LND_REST_INVOICE_MACAROON=' >> /home/lnbits/lnbits/.env"
sudo bash -c "echo 'LND_REST_READ_MACAROON=' >> /home/lnbits/lnbits/.env"
2022-09-13 18:16:28 +01:00
fi
if [ "${fundingsource}" == "cl" ] || [ "${fundingsource}" == "tcl" ] || [ "${fundingsource}" == "scl" ]; then
2022-09-13 18:16:28 +01:00
echo "# add the 'lnbits' user to the 'bitcoin' group"
sudo /usr/sbin/usermod --append --groups bitcoin lnbits
echo "# check user"
id lnbits
echo "# allowing lnbits user as part of the bitcoin group to RW RPC hook"
sudo chmod 770 /home/bitcoin/.lightning/bitcoin${clrpcsubdir}
sudo chmod 660 /home/bitcoin/.lightning/bitcoin${clrpcsubdir}/lightning-rpc
if [ "${fundingsource}" == "cl" ]; then
CLCONF="/home/bitcoin/.lightning/config"
else
CLCONF="/home/bitcoin/.lightning${clrpcsubdir}/config"
fi
# https://github.com/rootzoll/raspiblitz/issues/3007
if [ "$(sudo cat ${CLCONF} | grep -c "^rpc-file-mode=0660")" -eq 0 ]; then
echo "rpc-file-mode=0660" | sudo tee -a ${CLCONF}
fi
2022-11-16 11:00:35 -06:00
echo "# preparing lnbits config for CLN"
sudo bash -c "echo 'LNBITS_BACKEND_WALLET_CLASS=CLightningWallet' >> /home/lnbits/lnbits/.env"
sudo bash -c "echo 'CLIGHTNING_RPC=/home/bitcoin/.lightning/bitcoin${clrpcsubdir}/lightning-rpc' >> /home/lnbits/lnbits/.env"
fi
# set raspiblitz config value for funding
2021-12-18 00:38:49 +01:00
/home/admin/config.scripts/blitz.conf.sh set LNBitsFunding "${fundingsource}"
echo "##############"
echo "# OK new funding source set - does need restart or call: sudo systemctl restart lnbits"
echo "##############"
2020-02-10 12:33:03 +01:00
exit 0
fi
# switch off
if [ "$1" = "0" ] || [ "$1" = "off" ]; then
2020-07-24 02:00:47 +02:00
# check for second parameter: should data be deleted?
deleteData=0
if [ "$2" = "--delete-data" ]; then
deleteData=1
elif [ "$2" = "--keep-data" ]; then
deleteData=0
else
if (whiptail --title " DELETE DATA? " --yesno "Do you want to delete\nthe LNbits Server Data?" 8 30); then
2020-07-24 02:00:47 +02:00
deleteData=1
else
deleteData=0
fi
fi
echo "# deleteData(${deleteData})"
2022-01-31 10:24:54 +00:00
echo "*** REMOVING LNbits ***"
2020-07-24 02:00:47 +02:00
2022-01-31 10:24:54 +00:00
isInstalled=$(sudo ls /etc/systemd/system/lnbits.service 2>/dev/null | grep -c 'lnbits.service')
if [ ${isInstalled} -eq 1 ] || [ "${LNBits}" == "on" ]; then
sudo systemctl stop lnbits
sudo systemctl disable lnbits
sudo rm /etc/systemd/system/lnbits.service
echo "OK lnbits.service removed."
else
echo "lnbits.service is not installed."
fi
2020-02-10 12:33:03 +01:00
2022-10-15 11:20:20 +01:00
echo "Cleaning up LNbits install ..."
sudo ufw delete allow 5000
sudo ufw delete allow 5001
2022-10-15 11:20:20 +01:00
2020-05-23 22:34:03 +01:00
# remove nginx symlinks
sudo rm -f /etc/nginx/sites-enabled/lnbits_ssl.conf
sudo rm -f /etc/nginx/sites-enabled/lnbits_tor.conf
sudo rm -f /etc/nginx/sites-enabled/lnbits_tor_ssl.conf
2020-06-26 22:57:12 +02:00
sudo rm -f /etc/nginx/sites-available/lnbits_ssl.conf
sudo rm -f /etc/nginx/sites-available/lnbits_tor.conf
sudo rm -f /etc/nginx/sites-available/lnbits_tor_ssl.conf
2020-05-23 22:34:03 +01:00
sudo nginx -t
sudo systemctl reload nginx
# Hidden Service if Tor is active
if [ "${runBehindTor}" = "on" ]; then
/home/admin/config.scripts/tor.onion-service.sh off lnbits
fi
2022-01-31 10:24:54 +00:00
if [ ${deleteData} -eq 1 ]; then
echo "# deleting data"
#3505 lnbits PostgresSQl migration finalization (#3507) * fix missing dependencies * LNBits SQLite to PostgreSQL migration (#3411) * LNBits SQLite to PostgreSQL migration New installations with PostgreSQL configuration, existent data with SQLite. convert script needs a full start of LNBits prior migrating the old sqlite db's. User can migrate from raspiblitz menu. * only fix postgres if it needs to check for symbolik link of postgres default directory or desired postgres folder btcpayserver and lnbits could use postgresql new script to install or uninstall postgresql * fix typos * silent apt remove * fix removed function postgresConfig call bonus.postgresql.sh to setup PostgreSQL * Support outdated installation old installations should upgrade to new tag first create new data directory /mnt/hdd/app-data/LNBits/data * Improve migration Make it a bit more user friendly and prepare for a worst case to revert the migration if something fails unexpectedly make use of sync method for preparation * Rework migration workflow Cant wait for lnbits to start when ExecStartPre is used. We need a full start of lnbits prior migration, so make use of lsof to check for ports and wait. dont forget to start postgres service after installation. dont forget to stop postgres after uninstall * Dont overwrite the backup file if we start migrate again, the sqlite backup should not be overwritten with postgres data. Keep the backup file. * add migrate message to menu add the hint to revert migration manually after migrate script executed * fix install and data directory lnbits always needs a data directory * clean up lnbits settings for migration even if postgresql is already running, we can extract sqlite backup and start migrate remove migrateMsg duplicate * preserve database for reflash drop database only for migrate, not for regular installations * set blitz config for LNBits fix drop database only for migrate, not for regular installations * Add confirmation dialog and automatic revert User needs to confirm the process, this will eliminate missclicks add a migrate revert function to automatically revert if something unexpected happens let the user call the function manually * check conv.py on success or revert if the conversion script fails, revert automatically * Improve revert message Do not print the revert hint message if current database is SQLite * fix read config LNBitsDB * fix unpack backup Folder LNBits should never block the restore of backup. Happened after multiple migrations and revert. * Wait for lnbits v0.9.5 Set commit version with fix for postgresql database and BIGINT for amounts for migrate Can be set to v0.9.5 tag or above later * improve migrate backup handling revert to the current backup and not to the previous backup. No need for the failed folder state user message with backup file path * check psql version once * supress expected errors if database exists Co-authored-by: /rootzoll <christian@geektank.de> * fix error output on status Co-authored-by: ChuckNorrison <2964146+ChuckNorrison@users.noreply.github.com>
2022-12-10 00:04:15 +01:00
sudo -u postgres psql -c "drop database lnbits_db;"
sudo -u postgres psql -c "drop user lnbits_user;"
2022-01-31 10:24:54 +00:00
sudo rm -R /mnt/hdd/app-data/LNBits
else
2022-01-31 10:24:54 +00:00
echo "# keeping data"
2020-02-10 12:33:03 +01:00
fi
2022-01-31 10:24:54 +00:00
# setting value in raspi blitz config
/home/admin/config.scripts/blitz.conf.sh set LNBits "off"
2022-09-13 18:16:28 +01:00
# needed for API/WebUI as signal that install ran thru
2022-05-05 10:59:50 +02:00
echo "result='OK'"
2020-02-10 12:33:03 +01:00
exit 0
fi
LNBits Backup and Restore database (#3412) * LNBits Backup and Restore database Add Backup and Restore methods and menu entries * LNBits backup target based on blitz.backupdevice.sh switch backup target to /mnt/backup_manual per default * Add postgresql script Script to install or uninstall postgresql Backup a single database with sql dump file Restore a single database from sql dump file * Unpack backup file only for SQLite For postgresql just use the dedicated script * Support multiple backup files After backup file was written, keep only last 3 backups Restore the recent backup found * improve backup and restore with config and path make use of raspiblitz config to retrieve db state for backup and restore default manual backup path set to /mnt/hdd/app-data/backup * add info command to postgresql script retrieve database directory and database names * update backup path for postgresql script default path is /mnt/hdd/app-data/backup this will survive reflash sd card * improve user feedback * add dialog for restore and improvements dialog with confirm restore process timestamps for backup file names small improvements for user feedback only resume if unpack backup succeed * fix sqlite backup file name * fix restore path and permissions * add dialog to choose backup from a list list all available backups to start restore in a dialog * fix backup list for sqlite * fix restore menu * Update LNBits version with bigint fix for migration if migrate to postgresql, use lnbits version with latest bigint fixes * Update bonus.postgresql.sh * fix postgres backup permissions
2022-12-14 10:40:15 +01:00
# backup
if [ "$1" = "backup" ]; then
source <(/home/admin/_cache.sh get LNBitsDB)
echo "# Start Backup LNBits ${LNBitsDB} database"
if [ "${LNBitsDB}" == "PostgreSQL" ]; then
# postgresql backup
sudo /home/admin/config.scripts/bonus.postgresql.sh backup lnbits_db
else
# sqlite backup
backup_target="/mnt/hdd/app-data/backup/lnbits_sqlite"
backup_file="lnbits_sqlite_`date +%d`-`date +%m`-`date +%Y`_`date +%H`-`date +%M`_fs.tar"
if [ ! -d $backup_target ]; then
sudo mkdir -p $backup_target 1>&2
fi
# Delete old backups (keep last 3 backups)
sudo chown -R admin:admin $backup_target
ls -tp $backup_target/*.tar | grep -v '/$' | tail -n +4 | tr '\n' '\0' | xargs -0 rm -- 2>/dev/null
cd $backup_target
sudo tar -cf $backup_file -C "/mnt/hdd/app-data" LNBits/
echo "OK - Backup finished, file saved as ${backup_target}/${backup_file}"
fi
sudo systemctl start lnbits
exit 0
fi
# restore
if [ "$1" = "restore" ]; then
source <(/home/admin/_cache.sh get LNBitsDB)
if [ "${LNBitsDB}" == "PostgreSQL" ]; then
echo "# Restore PostgreSQL database"
if [ "$2" != "" ]; then
backup_file=$2
sudo /home/admin/config.scripts/bonus.postgresql.sh restore lnbits_db lnbits_user raspiblitz "${backup_file}"
else
sudo /home/admin/config.scripts/bonus.postgresql.sh restore lnbits_db lnbits_user raspiblitz
fi
else
backup_target="/mnt/hdd/app-data/backup/lnbits_sqlite"
if [ ! -d $backup_target ]; then
echo "# ABORT - No backups found"
exit 1
else
echo "# Restore SQLite database"
cd $backup_target
if [ "$2" != "" ]; then
if [ -e $2 ]; then
backup_file=$2
else
echo "ABORT - File not found (${2})"
exit 1
fi
else
# find recent backup
backup_file=$(ls -t $backup_target/*.tar | head -n1)
fi
echo "Start restore from backup ${backup_file}"
# unpack backup file
sudo tar -xf $backup_file || exit 1
echo "Unpack backup successful, backup current db now ..."
# backup current db
/home/admin/config.scripts/bonus.lnbits.sh backup
# apply backup data
sudo rm -R /mnt/hdd/app-data/LNBits/
sudo chown -R lnbits:lnbits LNBits/
sudo mv LNBits/ /mnt/hdd/app-data/
echo "Remove restored backup file"
sudo rm -f $backup_file
echo "OK - Apply backup data successful"
fi
fi
sudo systemctl start lnbits
exit 0
fi
# revert migrate to postgresql
#3505 lnbits PostgresSQl migration finalization (#3507) * fix missing dependencies * LNBits SQLite to PostgreSQL migration (#3411) * LNBits SQLite to PostgreSQL migration New installations with PostgreSQL configuration, existent data with SQLite. convert script needs a full start of LNBits prior migrating the old sqlite db's. User can migrate from raspiblitz menu. * only fix postgres if it needs to check for symbolik link of postgres default directory or desired postgres folder btcpayserver and lnbits could use postgresql new script to install or uninstall postgresql * fix typos * silent apt remove * fix removed function postgresConfig call bonus.postgresql.sh to setup PostgreSQL * Support outdated installation old installations should upgrade to new tag first create new data directory /mnt/hdd/app-data/LNBits/data * Improve migration Make it a bit more user friendly and prepare for a worst case to revert the migration if something fails unexpectedly make use of sync method for preparation * Rework migration workflow Cant wait for lnbits to start when ExecStartPre is used. We need a full start of lnbits prior migration, so make use of lsof to check for ports and wait. dont forget to start postgres service after installation. dont forget to stop postgres after uninstall * Dont overwrite the backup file if we start migrate again, the sqlite backup should not be overwritten with postgres data. Keep the backup file. * add migrate message to menu add the hint to revert migration manually after migrate script executed * fix install and data directory lnbits always needs a data directory * clean up lnbits settings for migration even if postgresql is already running, we can extract sqlite backup and start migrate remove migrateMsg duplicate * preserve database for reflash drop database only for migrate, not for regular installations * set blitz config for LNBits fix drop database only for migrate, not for regular installations * Add confirmation dialog and automatic revert User needs to confirm the process, this will eliminate missclicks add a migrate revert function to automatically revert if something unexpected happens let the user call the function manually * check conv.py on success or revert if the conversion script fails, revert automatically * Improve revert message Do not print the revert hint message if current database is SQLite * fix read config LNBitsDB * fix unpack backup Folder LNBits should never block the restore of backup. Happened after multiple migrations and revert. * Wait for lnbits v0.9.5 Set commit version with fix for postgresql database and BIGINT for amounts for migrate Can be set to v0.9.5 tag or above later * improve migrate backup handling revert to the current backup and not to the previous backup. No need for the failed folder state user message with backup file path * check psql version once * supress expected errors if database exists Co-authored-by: /rootzoll <christian@geektank.de> * fix error output on status Co-authored-by: ChuckNorrison <2964146+ChuckNorrison@users.noreply.github.com>
2022-12-10 00:04:15 +01:00
if [ "$1" = "migrate" ] && [ "$2" = "revert" ]; then
/home/admin/config.scripts/blitz.conf.sh set LNBitsMigrate "on"
revertMigration
exit 0
fi
LNBits Backup and Restore database (#3412) * LNBits Backup and Restore database Add Backup and Restore methods and menu entries * LNBits backup target based on blitz.backupdevice.sh switch backup target to /mnt/backup_manual per default * Add postgresql script Script to install or uninstall postgresql Backup a single database with sql dump file Restore a single database from sql dump file * Unpack backup file only for SQLite For postgresql just use the dedicated script * Support multiple backup files After backup file was written, keep only last 3 backups Restore the recent backup found * improve backup and restore with config and path make use of raspiblitz config to retrieve db state for backup and restore default manual backup path set to /mnt/hdd/app-data/backup * add info command to postgresql script retrieve database directory and database names * update backup path for postgresql script default path is /mnt/hdd/app-data/backup this will survive reflash sd card * improve user feedback * add dialog for restore and improvements dialog with confirm restore process timestamps for backup file names small improvements for user feedback only resume if unpack backup succeed * fix sqlite backup file name * fix restore path and permissions * add dialog to choose backup from a list list all available backups to start restore in a dialog * fix backup list for sqlite * fix restore menu * Update LNBits version with bigint fix for migration if migrate to postgresql, use lnbits version with latest bigint fixes * Update bonus.postgresql.sh * fix postgres backup permissions
2022-12-14 10:40:15 +01:00
# migrate
#3505 lnbits PostgresSQl migration finalization (#3507) * fix missing dependencies * LNBits SQLite to PostgreSQL migration (#3411) * LNBits SQLite to PostgreSQL migration New installations with PostgreSQL configuration, existent data with SQLite. convert script needs a full start of LNBits prior migrating the old sqlite db's. User can migrate from raspiblitz menu. * only fix postgres if it needs to check for symbolik link of postgres default directory or desired postgres folder btcpayserver and lnbits could use postgresql new script to install or uninstall postgresql * fix typos * silent apt remove * fix removed function postgresConfig call bonus.postgresql.sh to setup PostgreSQL * Support outdated installation old installations should upgrade to new tag first create new data directory /mnt/hdd/app-data/LNBits/data * Improve migration Make it a bit more user friendly and prepare for a worst case to revert the migration if something fails unexpectedly make use of sync method for preparation * Rework migration workflow Cant wait for lnbits to start when ExecStartPre is used. We need a full start of lnbits prior migration, so make use of lsof to check for ports and wait. dont forget to start postgres service after installation. dont forget to stop postgres after uninstall * Dont overwrite the backup file if we start migrate again, the sqlite backup should not be overwritten with postgres data. Keep the backup file. * add migrate message to menu add the hint to revert migration manually after migrate script executed * fix install and data directory lnbits always needs a data directory * clean up lnbits settings for migration even if postgresql is already running, we can extract sqlite backup and start migrate remove migrateMsg duplicate * preserve database for reflash drop database only for migrate, not for regular installations * set blitz config for LNBits fix drop database only for migrate, not for regular installations * Add confirmation dialog and automatic revert User needs to confirm the process, this will eliminate missclicks add a migrate revert function to automatically revert if something unexpected happens let the user call the function manually * check conv.py on success or revert if the conversion script fails, revert automatically * Improve revert message Do not print the revert hint message if current database is SQLite * fix read config LNBitsDB * fix unpack backup Folder LNBits should never block the restore of backup. Happened after multiple migrations and revert. * Wait for lnbits v0.9.5 Set commit version with fix for postgresql database and BIGINT for amounts for migrate Can be set to v0.9.5 tag or above later * improve migrate backup handling revert to the current backup and not to the previous backup. No need for the failed folder state user message with backup file path * check psql version once * supress expected errors if database exists Co-authored-by: /rootzoll <christian@geektank.de> * fix error output on status Co-authored-by: ChuckNorrison <2964146+ChuckNorrison@users.noreply.github.com>
2022-12-10 00:04:15 +01:00
if [ "$1" = "migrate" ]; then
if [ -e /mnt/hdd/app-data/LNBits/database.sqlite3 ]; then
echo "# Backup SQLite database"
# backup current database, but dont overwrite last backup
if [ -e /mnt/hdd/app-data/LNBits_sqlitedb_backup.tar ]; then
if [ -e /mnt/hdd/app-data/LNBits_sqlitedb_backup.tar.old ]; then
echo "# Remove old backup file"
sudo rm -f /mnt/hdd/app-data/LNBits_sqlitedb_backup.tar.old
fi
# keep the last backup as old backup
sudo mv /mnt/hdd/app-data/LNBits_sqlitedb_backup.tar /mnt/hdd/app-data/LNBits_sqlitedb_backup.tar.old
fi
# create new backup
sudo tar -cf /mnt/hdd/app-data/LNBits_sqlitedb_backup.tar -C /mnt/hdd/app-data LNBits/
# update to expected tag
cd /home/lnbits/lnbits || exit 1
# remove existent config for database
sudo sed -i "/^LNBITS_DATABASE_URL=/d" /home/lnbits/lnbits/.env 2>/dev/null
sudo sed -i "/^LNBITS_DATA_FOLDER=/d" /home/lnbits/lnbits/.env 2>/dev/null
# restore sqlite database config
sudo bash -c "echo 'LNBITS_DATA_FOLDER=/mnt/hdd/app-data/LNBits' >> /home/lnbits/lnbits/.env"
#sudo -u lnbits git checkout ${tag}
LNBits Backup and Restore database (#3412) * LNBits Backup and Restore database Add Backup and Restore methods and menu entries * LNBits backup target based on blitz.backupdevice.sh switch backup target to /mnt/backup_manual per default * Add postgresql script Script to install or uninstall postgresql Backup a single database with sql dump file Restore a single database from sql dump file * Unpack backup file only for SQLite For postgresql just use the dedicated script * Support multiple backup files After backup file was written, keep only last 3 backups Restore the recent backup found * improve backup and restore with config and path make use of raspiblitz config to retrieve db state for backup and restore default manual backup path set to /mnt/hdd/app-data/backup * add info command to postgresql script retrieve database directory and database names * update backup path for postgresql script default path is /mnt/hdd/app-data/backup this will survive reflash sd card * improve user feedback * add dialog for restore and improvements dialog with confirm restore process timestamps for backup file names small improvements for user feedback only resume if unpack backup succeed * fix sqlite backup file name * fix restore path and permissions * add dialog to choose backup from a list list all available backups to start restore in a dialog * fix backup list for sqlite * fix restore menu * Update LNBits version with bigint fix for migration if migrate to postgresql, use lnbits version with latest bigint fixes * Update bonus.postgresql.sh * fix postgres backup permissions
2022-12-14 10:40:15 +01:00
sudo -u lnbits git reset --hard 4f05c6c12e284d4a322a9041d19f66d01afa205b # good tested after BIGINT fix (#1135)
#3505 lnbits PostgresSQl migration finalization (#3507) * fix missing dependencies * LNBits SQLite to PostgreSQL migration (#3411) * LNBits SQLite to PostgreSQL migration New installations with PostgreSQL configuration, existent data with SQLite. convert script needs a full start of LNBits prior migrating the old sqlite db's. User can migrate from raspiblitz menu. * only fix postgres if it needs to check for symbolik link of postgres default directory or desired postgres folder btcpayserver and lnbits could use postgresql new script to install or uninstall postgresql * fix typos * silent apt remove * fix removed function postgresConfig call bonus.postgresql.sh to setup PostgreSQL * Support outdated installation old installations should upgrade to new tag first create new data directory /mnt/hdd/app-data/LNBits/data * Improve migration Make it a bit more user friendly and prepare for a worst case to revert the migration if something fails unexpectedly make use of sync method for preparation * Rework migration workflow Cant wait for lnbits to start when ExecStartPre is used. We need a full start of lnbits prior migration, so make use of lsof to check for ports and wait. dont forget to start postgres service after installation. dont forget to stop postgres after uninstall * Dont overwrite the backup file if we start migrate again, the sqlite backup should not be overwritten with postgres data. Keep the backup file. * add migrate message to menu add the hint to revert migration manually after migrate script executed * fix install and data directory lnbits always needs a data directory * clean up lnbits settings for migration even if postgresql is already running, we can extract sqlite backup and start migrate remove migrateMsg duplicate * preserve database for reflash drop database only for migrate, not for regular installations * set blitz config for LNBits fix drop database only for migrate, not for regular installations * Add confirmation dialog and automatic revert User needs to confirm the process, this will eliminate missclicks add a migrate revert function to automatically revert if something unexpected happens let the user call the function manually * check conv.py on success or revert if the conversion script fails, revert automatically * Improve revert message Do not print the revert hint message if current database is SQLite * fix read config LNBitsDB * fix unpack backup Folder LNBits should never block the restore of backup. Happened after multiple migrations and revert. * Wait for lnbits v0.9.5 Set commit version with fix for postgresql database and BIGINT for amounts for migrate Can be set to v0.9.5 tag or above later * improve migrate backup handling revert to the current backup and not to the previous backup. No need for the failed folder state user message with backup file path * check psql version once * supress expected errors if database exists Co-authored-by: /rootzoll <christian@geektank.de> * fix error output on status Co-authored-by: ChuckNorrison <2964146+ChuckNorrison@users.noreply.github.com>
2022-12-10 00:04:15 +01:00
/home/admin/config.scripts/bonus.lnbits.sh sync || exit 1
# stop after sync was done
sudo systemctl stop lnbits
/home/admin/config.scripts/blitz.conf.sh set LNBitsMigrate "on"
# POSTGRES
postgresConfig
# example: postgres://<user>:<password>@<host>/<database>
# add new postgres config
sudo bash -c "echo 'LNBITS_DATABASE_URL=postgres://lnbits_user:raspiblitz@localhost:5432/lnbits_db' >> /home/lnbits/lnbits/.env"
# clean start on new postgres db prior migration
echo "# LNBits first start with clean PostgreSQL"
sudo systemctl start lnbits
# execStartPre is not enough, wait for lnbits is finally running
count=0
count_max=30
while ! nc -zv 127.0.0.1 5000 2>/dev/null;
do
count=`expr $count + 1`
echo "wait for LNBIts to start (${count}s/${count_max}s)"
sleep 1
if [ $count = $count_max ]; then
sudo systemctl status lnbits
echo "# FAIL - LNBits service was not able to start"
revertMigration
exit 1
fi
done
# wait a sec for "✔ All migrations done." (TODO make it pretty)
sleep 5
echo "# LNBits service looks good"
sudo systemctl stop lnbits
echo "# Start convert old SQLite to new PostgreSQL"
if ! sudo -u lnbits ./venv/bin/python tools/conv.py; then
echo "FAIL - Convert failed, revert migration process"
revertMigration
exit 1
else
LNBits Backup and Restore database (#3412) * LNBits Backup and Restore database Add Backup and Restore methods and menu entries * LNBits backup target based on blitz.backupdevice.sh switch backup target to /mnt/backup_manual per default * Add postgresql script Script to install or uninstall postgresql Backup a single database with sql dump file Restore a single database from sql dump file * Unpack backup file only for SQLite For postgresql just use the dedicated script * Support multiple backup files After backup file was written, keep only last 3 backups Restore the recent backup found * improve backup and restore with config and path make use of raspiblitz config to retrieve db state for backup and restore default manual backup path set to /mnt/hdd/app-data/backup * add info command to postgresql script retrieve database directory and database names * update backup path for postgresql script default path is /mnt/hdd/app-data/backup this will survive reflash sd card * improve user feedback * add dialog for restore and improvements dialog with confirm restore process timestamps for backup file names small improvements for user feedback only resume if unpack backup succeed * fix sqlite backup file name * fix restore path and permissions * add dialog to choose backup from a list list all available backups to start restore in a dialog * fix backup list for sqlite * fix restore menu * Update LNBits version with bigint fix for migration if migrate to postgresql, use lnbits version with latest bigint fixes * Update bonus.postgresql.sh * fix postgres backup permissions
2022-12-14 10:40:15 +01:00
echo "# OK - Convert successful"
#3505 lnbits PostgresSQl migration finalization (#3507) * fix missing dependencies * LNBits SQLite to PostgreSQL migration (#3411) * LNBits SQLite to PostgreSQL migration New installations with PostgreSQL configuration, existent data with SQLite. convert script needs a full start of LNBits prior migrating the old sqlite db's. User can migrate from raspiblitz menu. * only fix postgres if it needs to check for symbolik link of postgres default directory or desired postgres folder btcpayserver and lnbits could use postgresql new script to install or uninstall postgresql * fix typos * silent apt remove * fix removed function postgresConfig call bonus.postgresql.sh to setup PostgreSQL * Support outdated installation old installations should upgrade to new tag first create new data directory /mnt/hdd/app-data/LNBits/data * Improve migration Make it a bit more user friendly and prepare for a worst case to revert the migration if something fails unexpectedly make use of sync method for preparation * Rework migration workflow Cant wait for lnbits to start when ExecStartPre is used. We need a full start of lnbits prior migration, so make use of lsof to check for ports and wait. dont forget to start postgres service after installation. dont forget to stop postgres after uninstall * Dont overwrite the backup file if we start migrate again, the sqlite backup should not be overwritten with postgres data. Keep the backup file. * add migrate message to menu add the hint to revert migration manually after migrate script executed * fix install and data directory lnbits always needs a data directory * clean up lnbits settings for migration even if postgresql is already running, we can extract sqlite backup and start migrate remove migrateMsg duplicate * preserve database for reflash drop database only for migrate, not for regular installations * set blitz config for LNBits fix drop database only for migrate, not for regular installations * Add confirmation dialog and automatic revert User needs to confirm the process, this will eliminate missclicks add a migrate revert function to automatically revert if something unexpected happens let the user call the function manually * check conv.py on success or revert if the conversion script fails, revert automatically * Improve revert message Do not print the revert hint message if current database is SQLite * fix read config LNBitsDB * fix unpack backup Folder LNBits should never block the restore of backup. Happened after multiple migrations and revert. * Wait for lnbits v0.9.5 Set commit version with fix for postgresql database and BIGINT for amounts for migrate Can be set to v0.9.5 tag or above later * improve migrate backup handling revert to the current backup and not to the previous backup. No need for the failed folder state user message with backup file path * check psql version once * supress expected errors if database exists Co-authored-by: /rootzoll <christian@geektank.de> * fix error output on status Co-authored-by: ChuckNorrison <2964146+ChuckNorrison@users.noreply.github.com>
2022-12-10 00:04:15 +01:00
fi
# cleanup old sqlite data directory
echo "# Cleanup old data directory"
sudo rm -R /mnt/hdd/app-data/LNBits/
# new data directory
sudo mkdir -p /mnt/hdd/app-data/LNBits/data
sudo chown lnbits:lnbits -R /mnt/hdd/app-data/LNBits/
echo "# Configure .env"
sudo sed -i "/^LNBITS_DATA_FOLDER=/d" /home/lnbits/lnbits/.env 2>/dev/null
sudo bash -c "echo 'LNBITS_DATA_FOLDER=/mnt/hdd/app-data/LNBits/data' >> /home/lnbits/lnbits/.env"
# setting value in raspi blitz config
/home/admin/config.scripts/blitz.conf.sh set LNBitsMigrate "off"
LNBits Backup and Restore database (#3412) * LNBits Backup and Restore database Add Backup and Restore methods and menu entries * LNBits backup target based on blitz.backupdevice.sh switch backup target to /mnt/backup_manual per default * Add postgresql script Script to install or uninstall postgresql Backup a single database with sql dump file Restore a single database from sql dump file * Unpack backup file only for SQLite For postgresql just use the dedicated script * Support multiple backup files After backup file was written, keep only last 3 backups Restore the recent backup found * improve backup and restore with config and path make use of raspiblitz config to retrieve db state for backup and restore default manual backup path set to /mnt/hdd/app-data/backup * add info command to postgresql script retrieve database directory and database names * update backup path for postgresql script default path is /mnt/hdd/app-data/backup this will survive reflash sd card * improve user feedback * add dialog for restore and improvements dialog with confirm restore process timestamps for backup file names small improvements for user feedback only resume if unpack backup succeed * fix sqlite backup file name * fix restore path and permissions * add dialog to choose backup from a list list all available backups to start restore in a dialog * fix backup list for sqlite * fix restore menu * Update LNBits version with bigint fix for migration if migrate to postgresql, use lnbits version with latest bigint fixes * Update bonus.postgresql.sh * fix postgres backup permissions
2022-12-14 10:40:15 +01:00
echo "# OK - migration done"
#3505 lnbits PostgresSQl migration finalization (#3507) * fix missing dependencies * LNBits SQLite to PostgreSQL migration (#3411) * LNBits SQLite to PostgreSQL migration New installations with PostgreSQL configuration, existent data with SQLite. convert script needs a full start of LNBits prior migrating the old sqlite db's. User can migrate from raspiblitz menu. * only fix postgres if it needs to check for symbolik link of postgres default directory or desired postgres folder btcpayserver and lnbits could use postgresql new script to install or uninstall postgresql * fix typos * silent apt remove * fix removed function postgresConfig call bonus.postgresql.sh to setup PostgreSQL * Support outdated installation old installations should upgrade to new tag first create new data directory /mnt/hdd/app-data/LNBits/data * Improve migration Make it a bit more user friendly and prepare for a worst case to revert the migration if something fails unexpectedly make use of sync method for preparation * Rework migration workflow Cant wait for lnbits to start when ExecStartPre is used. We need a full start of lnbits prior migration, so make use of lsof to check for ports and wait. dont forget to start postgres service after installation. dont forget to stop postgres after uninstall * Dont overwrite the backup file if we start migrate again, the sqlite backup should not be overwritten with postgres data. Keep the backup file. * add migrate message to menu add the hint to revert migration manually after migrate script executed * fix install and data directory lnbits always needs a data directory * clean up lnbits settings for migration even if postgresql is already running, we can extract sqlite backup and start migrate remove migrateMsg duplicate * preserve database for reflash drop database only for migrate, not for regular installations * set blitz config for LNBits fix drop database only for migrate, not for regular installations * Add confirmation dialog and automatic revert User needs to confirm the process, this will eliminate missclicks add a migrate revert function to automatically revert if something unexpected happens let the user call the function manually * check conv.py on success or revert if the conversion script fails, revert automatically * Improve revert message Do not print the revert hint message if current database is SQLite * fix read config LNBitsDB * fix unpack backup Folder LNBits should never block the restore of backup. Happened after multiple migrations and revert. * Wait for lnbits v0.9.5 Set commit version with fix for postgresql database and BIGINT for amounts for migrate Can be set to v0.9.5 tag or above later * improve migrate backup handling revert to the current backup and not to the previous backup. No need for the failed folder state user message with backup file path * check psql version once * supress expected errors if database exists Co-authored-by: /rootzoll <christian@geektank.de> * fix error output on status Co-authored-by: ChuckNorrison <2964146+ChuckNorrison@users.noreply.github.com>
2022-12-10 00:04:15 +01:00
else
LNBits Backup and Restore database (#3412) * LNBits Backup and Restore database Add Backup and Restore methods and menu entries * LNBits backup target based on blitz.backupdevice.sh switch backup target to /mnt/backup_manual per default * Add postgresql script Script to install or uninstall postgresql Backup a single database with sql dump file Restore a single database from sql dump file * Unpack backup file only for SQLite For postgresql just use the dedicated script * Support multiple backup files After backup file was written, keep only last 3 backups Restore the recent backup found * improve backup and restore with config and path make use of raspiblitz config to retrieve db state for backup and restore default manual backup path set to /mnt/hdd/app-data/backup * add info command to postgresql script retrieve database directory and database names * update backup path for postgresql script default path is /mnt/hdd/app-data/backup this will survive reflash sd card * improve user feedback * add dialog for restore and improvements dialog with confirm restore process timestamps for backup file names small improvements for user feedback only resume if unpack backup succeed * fix sqlite backup file name * fix restore path and permissions * add dialog to choose backup from a list list all available backups to start restore in a dialog * fix backup list for sqlite * fix restore menu * Update LNBits version with bigint fix for migration if migrate to postgresql, use lnbits version with latest bigint fixes * Update bonus.postgresql.sh * fix postgres backup permissions
2022-12-14 10:40:15 +01:00
echo "# ABORT - No SQLite data found to migrate from"
#3505 lnbits PostgresSQl migration finalization (#3507) * fix missing dependencies * LNBits SQLite to PostgreSQL migration (#3411) * LNBits SQLite to PostgreSQL migration New installations with PostgreSQL configuration, existent data with SQLite. convert script needs a full start of LNBits prior migrating the old sqlite db's. User can migrate from raspiblitz menu. * only fix postgres if it needs to check for symbolik link of postgres default directory or desired postgres folder btcpayserver and lnbits could use postgresql new script to install or uninstall postgresql * fix typos * silent apt remove * fix removed function postgresConfig call bonus.postgresql.sh to setup PostgreSQL * Support outdated installation old installations should upgrade to new tag first create new data directory /mnt/hdd/app-data/LNBits/data * Improve migration Make it a bit more user friendly and prepare for a worst case to revert the migration if something fails unexpectedly make use of sync method for preparation * Rework migration workflow Cant wait for lnbits to start when ExecStartPre is used. We need a full start of lnbits prior migration, so make use of lsof to check for ports and wait. dont forget to start postgres service after installation. dont forget to stop postgres after uninstall * Dont overwrite the backup file if we start migrate again, the sqlite backup should not be overwritten with postgres data. Keep the backup file. * add migrate message to menu add the hint to revert migration manually after migrate script executed * fix install and data directory lnbits always needs a data directory * clean up lnbits settings for migration even if postgresql is already running, we can extract sqlite backup and start migrate remove migrateMsg duplicate * preserve database for reflash drop database only for migrate, not for regular installations * set blitz config for LNBits fix drop database only for migrate, not for regular installations * Add confirmation dialog and automatic revert User needs to confirm the process, this will eliminate missclicks add a migrate revert function to automatically revert if something unexpected happens let the user call the function manually * check conv.py on success or revert if the conversion script fails, revert automatically * Improve revert message Do not print the revert hint message if current database is SQLite * fix read config LNBitsDB * fix unpack backup Folder LNBits should never block the restore of backup. Happened after multiple migrations and revert. * Wait for lnbits v0.9.5 Set commit version with fix for postgresql database and BIGINT for amounts for migrate Can be set to v0.9.5 tag or above later * improve migrate backup handling revert to the current backup and not to the previous backup. No need for the failed folder state user message with backup file path * check psql version once * supress expected errors if database exists Co-authored-by: /rootzoll <christian@geektank.de> * fix error output on status Co-authored-by: ChuckNorrison <2964146+ChuckNorrison@users.noreply.github.com>
2022-12-10 00:04:15 +01:00
fi
sudo systemctl start lnbits
exit 0
fi
2020-02-10 12:33:03 +01:00
echo "FAIL - Unknown Parameter $1"
LNBits Backup and Restore database (#3412) * LNBits Backup and Restore database Add Backup and Restore methods and menu entries * LNBits backup target based on blitz.backupdevice.sh switch backup target to /mnt/backup_manual per default * Add postgresql script Script to install or uninstall postgresql Backup a single database with sql dump file Restore a single database from sql dump file * Unpack backup file only for SQLite For postgresql just use the dedicated script * Support multiple backup files After backup file was written, keep only last 3 backups Restore the recent backup found * improve backup and restore with config and path make use of raspiblitz config to retrieve db state for backup and restore default manual backup path set to /mnt/hdd/app-data/backup * add info command to postgresql script retrieve database directory and database names * update backup path for postgresql script default path is /mnt/hdd/app-data/backup this will survive reflash sd card * improve user feedback * add dialog for restore and improvements dialog with confirm restore process timestamps for backup file names small improvements for user feedback only resume if unpack backup succeed * fix sqlite backup file name * fix restore path and permissions * add dialog to choose backup from a list list all available backups to start restore in a dialog * fix backup list for sqlite * fix restore menu * Update LNBits version with bigint fix for migration if migrate to postgresql, use lnbits version with latest bigint fixes * Update bonus.postgresql.sh * fix postgres backup permissions
2022-12-14 10:40:15 +01:00
exit 1