2019-01-14 14:39:01 +01:00
#!/bin/bash
# command info
if [ " $1 " = "-h" ] || [ " $1 " = "-help" ] ; then
echo "small config script to set a passwords A,B,C & D"
2019-01-14 15:47:47 +01:00
echo "blitz.setpassword.sh [?a|b|c|d] [?newpassword] "
2019-04-12 23:16:38 +01:00
echo "or just as a password enter dialog (result as file)"
2019-04-12 23:26:38 +01:00
echo "blitz.setpassword.sh [x] [text] [result-file]"
2019-01-14 18:13:45 +01:00
echo "exits on 0 = needs reboot"
2019-01-14 14:39:01 +01:00
exit 1
fi
2019-01-14 16:05:39 +01:00
# check if sudo
if [ " $EUID " -ne 0 ]
then echo "Please run as root (with sudo)"
exit
fi
2019-01-14 17:05:12 +01:00
# tempfile
_temp = " ./dialog. $$ "
2019-01-14 16:05:39 +01:00
# load raspiblitz config (if available)
2019-02-02 23:49:04 +01:00
source /home/admin/raspiblitz.info
source /mnt/hdd/raspiblitz.conf
2019-01-14 16:25:43 +01:00
if [ ${# network } -eq 0 ] ; then
network = "bitcoin"
fi
if [ ${# chain } -eq 0 ] ; then
chain = "main"
fi
2019-01-14 16:05:39 +01:00
2019-01-14 14:39:01 +01:00
# 1. parameter [?a|b|c|d]
abcd = $1
# 2. parameter [?newpassword]
newPassword = $2
# run interactive if no further parameters
2019-01-14 15:30:01 +01:00
OPTIONS = ( )
2019-01-14 14:39:01 +01:00
if [ ${# abcd } -eq 0 ] ; then
2019-01-14 15:30:01 +01:00
OPTIONS += ( A "Master User Password / SSH" )
2019-01-14 14:51:34 +01:00
OPTIONS += ( B "RPC Password (blockchain/lnd)" )
OPTIONS += ( C "LND Wallet Password" )
OPTIONS += ( D "LND Seed Password" )
2019-01-14 14:39:01 +01:00
CHOICE = $( dialog --clear \
2019-01-14 15:39:50 +01:00
--backtitle "RaspiBlitz" \
--title "Set Password" \
--menu "Which password to change?" \
11 50 7 \
2019-01-14 14:39:01 +01:00
" ${ OPTIONS [@] } " \
2>& 1 >/dev/tty)
clear
case $CHOICE in
A)
abcd = 'a' ;
; ;
B)
abcd = 'b' ;
; ;
C)
abcd = 'c' ;
; ;
D)
abcd = 'd' ;
; ;
esac
fi
2019-01-14 15:47:47 +01:00
echo " Changing Password ${ abcd } ... "
echo ""
2019-01-14 17:42:44 +01:00
############################
2019-01-14 15:47:47 +01:00
# PASSWORD A
if [ " ${ abcd } " = "a" ] ; then
2019-01-14 17:05:12 +01:00
# if no password given by parameter - ask by dialog
if [ ${# newPassword } -eq 0 ] ; then
# ask user for new password A (first time)
dialog --backtitle "RaspiBlitz - Setup" \
2019-02-13 00:47:41 +01:00
--insecure --passwordbox "Set new Master/Admin Password A:\n(min 8chars, 1word, chars+number, no specials)" 10 52 2>$_temp
2019-01-14 17:05:12 +01:00
# get user input
password1 = $( cat $_temp )
shred $_temp
# ask user for new password A (second time)
dialog --backtitle "RaspiBlitz - Setup" \
2019-01-14 17:42:44 +01:00
--insecure --passwordbox "Re-Enter Password A:\n(This is new password to login per SSH)" 10 52 2>$_temp
2019-01-14 17:05:12 +01:00
# get user input
password2 = $( cat $_temp )
shred $_temp
# check if passwords match
if [ " ${ password1 } " != " ${ password2 } " ] ; then
2019-01-14 17:42:44 +01:00
dialog --backtitle "RaspiBlitz - Setup" --msgbox "FAIL -> Passwords dont Match\nPlease try again ..." 6 52
sudo /home/admin/config.scripts/blitz.setpassword.sh a
exit 1
fi
# password zero
if [ ${# password1 } -eq 0 ] ; then
dialog --backtitle "RaspiBlitz - Setup" --msgbox "FAIL -> Password cannot be empty\nPlease try again ..." 6 52
sudo /home/admin/config.scripts/blitz.setpassword.sh a
exit 1
2019-01-14 17:05:12 +01:00
fi
# check that password does not contain bad characters
2019-01-14 17:44:56 +01:00
clearedResult = $( echo " ${ password1 } " | tr -dc '[:alnum:]-.' | tr -d ' ' )
if [ ${# clearedResult } != ${# password1 } ] || [ ${# clearedResult } -eq 0 ] ; then
2019-01-14 17:55:12 +01:00
dialog --backtitle "RaspiBlitz - Setup" --msgbox "FAIL -> Contains bad characters (spaces, special chars)\nPlease try again ..." 6 52
2019-01-14 17:42:44 +01:00
sudo /home/admin/config.scripts/blitz.setpassword.sh a
exit 1
2019-01-14 17:05:12 +01:00
fi
2019-01-14 17:42:44 +01:00
# password longer than 8
if [ ${# password1 } -lt 8 ] ; then
dialog --backtitle "RaspiBlitz - Setup" --msgbox "FAIL -> Password length under 8\nPlease try again ..." 6 52
sudo /home/admin/config.scripts/blitz.setpassword.sh a
exit 1
fi
# use entred password now as parameter
newPassword = " ${ password1 } "
2019-01-14 17:05:12 +01:00
2019-01-14 17:12:01 +01:00
fi
# change user passwords and then change hostname
2019-01-14 17:42:44 +01:00
echo " pi: $newPassword " | sudo chpasswd
echo " root: $newPassword " | sudo chpasswd
echo " bitcoin: $newPassword " | sudo chpasswd
echo " admin: $newPassword " | sudo chpasswd
sleep 1
echo ""
echo "OK - password A changed for user pi, root, admin & bitcoin"
2019-01-14 18:13:45 +01:00
exit 0
2019-01-14 15:47:47 +01:00
2019-01-14 17:42:44 +01:00
############################
2019-01-14 15:47:47 +01:00
# PASSWORD B
elif [ " ${ abcd } " = "b" ] ; then
2019-01-14 17:55:12 +01:00
# if no password given by parameter - ask by dialog
if [ ${# newPassword } -eq 0 ] ; then
# ask user for new password A (first time)
dialog --backtitle "RaspiBlitz - Setup" \
--insecure --passwordbox "Please enter your RPC Password B:\n(min 8chars, 1word, chars+number, no specials)" 10 52 2>$_temp
# get user input
password1 = $( cat $_temp )
shred $_temp
# ask user for new password A (second time)
dialog --backtitle "RaspiBlitz - Setup" \
--insecure --passwordbox "Re-Enter Password B:\n" 10 52 2>$_temp
# get user input
password2 = $( cat $_temp )
shred $_temp
# check if passwords match
if [ " ${ password1 } " != " ${ password2 } " ] ; then
dialog --backtitle "RaspiBlitz - Setup" --msgbox "FAIL -> Passwords dont Match\nPlease try again ..." 6 52
sudo /home/admin/config.scripts/blitz.setpassword.sh b
exit 1
fi
# password zero
if [ ${# password1 } -eq 0 ] ; then
dialog --backtitle "RaspiBlitz - Setup" --msgbox "FAIL -> Password cannot be empty\nPlease try again ..." 6 52
sudo /home/admin/config.scripts/blitz.setpassword.sh b
exit 1
fi
# check that password does not contain bad characters
clearedResult = $( echo " ${ password1 } " | tr -dc '[:alnum:]-.' | tr -d ' ' )
if [ ${# clearedResult } != ${# password1 } ] || [ ${# clearedResult } -eq 0 ] ; then
dialog --backtitle "RaspiBlitz - Setup" --msgbox "FAIL -> Contains bad characters (spaces, special chars)\nPlease try again ..." 6 52
sudo /home/admin/config.scripts/blitz.setpassword.sh b
exit 1
fi
# password longer than 8
if [ ${# password1 } -lt 8 ] ; then
dialog --backtitle "RaspiBlitz - Setup" --msgbox "FAIL -> Password length under 8\nPlease try again ..." 6 52
sudo /home/admin/config.scripts/blitz.setpassword.sh b
exit 1
fi
# use entred password now as parameter
newPassword = " ${ password1 } "
fi
# change in assets (just in case this is used on setup)
sed -i " s/^rpcpassword=.*/rpcpassword= ${ newPassword } /g " /home/admin/assets/${ network } .conf 2>/dev/null
sed -i " s/^ ${ network } d.rpcpass=.*/ ${ network } d.rpcpass= ${ newPassword } /g " /home/admin/assets/lnd.${ network } .conf 2>/dev/null
# change in real configs
sed -i " s/^rpcpassword=.*/rpcpassword= ${ newPassword } /g " /mnt/hdd/${ network } /${ network } .conf 2>/dev/null
sed -i " s/^rpcpassword=.*/rpcpassword= ${ newPassword } /g " /home/admin/.${ network } /${ network } .conf 2>/dev/null
sed -i " s/^ ${ network } d.rpcpass=.*/ ${ network } d.rpcpass= ${ newPassword } /g " /mnt/hdd/lnd/lnd.conf 2>/dev/null
sed -i " s/^ ${ network } d.rpcpass=.*/ ${ network } d.rpcpass= ${ newPassword } /g " /home/admin/.lnd/lnd.conf 2>/dev/null
2020-02-13 12:31:59 +00:00
# RTL - keep settings from current RTL-Config.json
cp /home/admin/RTL/RTL-Config.json /home/admin/RTL/backup-RTL-Config.json
chmod 600 /home/admin/RTL/RTL-Config.json || exit 1
node > /home/admin/RTL/RTL-Config.json <<EOF
//Read data
var data = require( '/home/admin/RTL/backup-RTL-Config.json' ) ;
//Manipulate data
data.multiPass = '$newPassword' ;
//Output data
console.log( JSON.stringify( data, null, 2) ) ;
EOF
rm -f /home/admin/RTL/backup-RTL-Config.json
2020-01-20 11:39:08 +00:00
# electrs
RPC_USER = $( cat /mnt/hdd/bitcoin/bitcoin.conf | grep rpcuser | cut -c 9-)
sed -i " s/^cookie = \" $RPC_USER .*\"/cookie = \" $RPC_USER : ${ newPassword } \"/g " /home/electrs/.electrs/config.toml 2>/dev/null
# BTC-RPC-Explorer
sed -i " s/^BTCEXP_BITCOIND_URI= $network :\/\/ $RPC_USER :.*@127.0.0.1:8332?timeout=10000/BTCEXP_BITCOIND_URI= $network :\/\/ $RPC_USER : ${ newPassword } @127.0.0.1:8332\?timeout=10000/g " /home/bitcoin/.config/btc-rpc-explorer.env 2>/dev/null
sed -i " s/^BTCEXP_BITCOIND_PASS=.*/BTCEXP_BITCOIND_PASS= ${ newPassword } /g " /home/bitcoin/.config/btc-rpc-explorer.env 2>/dev/null
sed -i " s/^BTCEXP_BASIC_AUTH_PASSWORD=.*/BTCEXP_BASIC_AUTH_PASSWORD= ${ newPassword } /g " /home/bitcoin/.config/btc-rpc-explorer.env 2>/dev/null
2020-01-21 04:21:35 +00:00
# BTCPayServer
sed -i " s/^btc.rpc.password=.*/btc.rpc.password= ${ newPassword } /g " /home/btcpay/.nbxplorer/Main/settings.config 2>/dev/null
2019-01-14 17:55:12 +01:00
2019-01-14 17:56:28 +01:00
echo "OK -> RPC Password B changed"
2019-01-14 17:55:12 +01:00
echo "if services are running - reboot is needed to activate new settings"
2019-01-14 18:13:45 +01:00
exit 0
2019-01-14 15:47:47 +01:00
2019-01-14 17:42:44 +01:00
############################
2019-01-14 15:47:47 +01:00
# PASSWORD C
elif [ " ${ abcd } " = "c" ] ; then
2019-01-14 16:32:21 +01:00
if [ ${# newPassword } -gt 0 ] ; then
2019-01-14 16:30:46 +01:00
echo "New password C cannot be set thru paramter .. will start interactive password setting."
echo "PRESS ENTER to continue"
read key
fi
2019-01-14 16:05:39 +01:00
clear
echo ""
echo "****************************************************************************"
2019-01-14 16:25:43 +01:00
echo " Change LND Wallet Password --> lncli --chain= ${ network } --network= ${ chain } net changepassword "
2019-01-14 16:05:39 +01:00
echo "****************************************************************************"
echo "This is your Password C on the RaspiBlitz to unlock your LND wallet."
echo "If you had Auto-Unlock active - you need to re-activate after this."
echo "****************************************************************************"
2019-02-14 14:40:27 +01:00
echo "LND needs to be restarted to lock wallet first .. (please wait)"
2019-02-14 13:42:14 +01:00
sudo systemctl restart lnd
2019-02-14 14:00:12 +01:00
sleep 6
2019-02-14 13:42:14 +01:00
2019-01-14 16:05:39 +01:00
# let LND-CLI handle the password change
2019-01-14 16:32:21 +01:00
sudo -u bitcoin lncli --chain= ${ network } --network= ${ chain } net changepassword
2019-01-14 16:05:39 +01:00
# deactivate AUTO-UNLOCK if activated
2019-01-14 16:36:36 +01:00
echo ""
echo "# Make sure Auto-Unlocks off"
2019-01-14 16:05:39 +01:00
sudo /home/admin/config.scripts/lnd.autounlock.sh off
2019-01-14 15:47:47 +01:00
2019-01-14 16:36:36 +01:00
# final user output
echo ""
echo "OK"
2019-01-14 18:13:45 +01:00
exit 0
2019-01-14 16:36:36 +01:00
2019-01-14 17:42:44 +01:00
############################
2019-01-14 15:47:47 +01:00
# PASSWORD D
elif [ " ${ abcd } " = "d" ] ; then
echo "#### NOTICE ####"
echo "Sorry - the password D cannot be changed. Its the password you set on creating your wallet to protect your seed (the list of words)."
2019-01-14 18:13:45 +01:00
exit 1
2019-01-14 15:47:47 +01:00
2019-04-12 23:16:38 +01:00
############################
# PASSWORD X
2019-04-12 23:26:38 +01:00
elif [ " ${ abcd } " = "x" ] ; then
2019-04-12 23:16:38 +01:00
# second parameter is the flexible text
text = $2
resultFile = $3
shred $3 2>/dev/null
# ask user for new password (first time)
dialog --backtitle "RaspiBlitz" \
--insecure --passwordbox " ${ text } :\n(min 8chars, 1word, chars+number, no specials) " 10 52 2>$_temp
# get user input
password1 = $( cat $_temp )
shred $_temp
# ask user for new password A (second time)
dialog --backtitle "RaspiBlitz - Setup" \
2019-04-13 00:13:24 +01:00
--insecure --passwordbox "Re-Enter the Password:\n(to test if typed in correctly)" 10 52 2>$_temp
2019-04-12 23:16:38 +01:00
# get user input
password2 = $( cat $_temp )
shred $_temp
# check if passwords match
if [ " ${ password1 } " != " ${ password2 } " ] ; then
dialog --backtitle "RaspiBlitz - Setup" --msgbox "FAIL -> Passwords dont Match\nPlease try again ..." 6 52
2019-04-12 23:27:53 +01:00
sudo /home/admin/config.scripts/blitz.setpassword.sh x " $2 " " $3 "
2019-04-12 23:16:38 +01:00
exit 1
fi
# password zero
if [ ${# password1 } -eq 0 ] ; then
dialog --backtitle "RaspiBlitz - Setup" --msgbox "FAIL -> Password cannot be empty\nPlease try again ..." 6 52
2019-04-12 23:27:53 +01:00
sudo /home/admin/config.scripts/blitz.setpassword.sh x " $2 " " $3 "
2019-04-12 23:16:38 +01:00
exit 1
fi
# check that password does not contain bad characters
clearedResult = $( echo " ${ password1 } " | tr -dc '[:alnum:]-.' | tr -d ' ' )
if [ ${# clearedResult } != ${# password1 } ] || [ ${# clearedResult } -eq 0 ] ; then
dialog --backtitle "RaspiBlitz - Setup" --msgbox "FAIL -> Contains bad characters (spaces, special chars)\nPlease try again ..." 6 52
2019-04-12 23:27:53 +01:00
sudo /home/admin/config.scripts/blitz.setpassword.sh x " $2 " " $3 "
2019-04-12 23:16:38 +01:00
exit 1
fi
# password longer than 8
if [ ${# password1 } -lt 8 ] ; then
dialog --backtitle "RaspiBlitz - Setup" --msgbox "FAIL -> Password length under 8\nPlease try again ..." 6 52
2019-04-12 23:27:53 +01:00
sudo /home/admin/config.scripts/blitz.setpassword.sh x " $2 " " $3 "
2019-04-12 23:16:38 +01:00
exit 1
fi
# store result is file
2019-04-12 23:31:21 +01:00
echo " ${ password1 } " > ${ resultFile }
2019-04-12 23:16:38 +01:00
2019-01-14 15:47:47 +01:00
# everything else
else
echo " FAIL: there is no password ' ${ abcd } ' (reminder: use lower case) "
2019-01-14 18:13:45 +01:00
exit 1
fi