Browse Source

Fix up unlock script to handle missing files. Also fix up docker-compose error. Work towards #1

patch-1
nolim1t 5 years ago
parent
commit
b3e904887d
No known key found for this signature in database GPG Key ID: F6287B82CC84BCBD
  1. 45
      build/lnd-unlock/unlock.sh
  2. 2
      docker-compose.yml

45
build/lnd-unlock/unlock.sh

@ -2,11 +2,11 @@
HOST=localhost:8080
TLS_CERT=/lnd/tls.cert
MACAROON="$(xxd -p /run/secrets/lnd-admin | tr -d '\n')"
PASS="$(cat /run/secrets/lnd-password | tr -d '\n' | base64 | tr -d '\n')"
UNLOCK_PAYLOAD="$(jq -nc --arg wallet_password ${PASS} '{$wallet_password}')"
LNDPASSWORD_PATH=/secrets/lnd-password.txt
MACAROON_PATH=/lnd/data/chain/bitcoin/mainnet/admin.macaroon
lncurl() {
MACAROON="$(xxd -p /lnd/data/chain/bitcoin/mainnet/admin.macaroon | tr -d '\n')"
url_path=$1
data=$2
@ -27,20 +27,31 @@ while true; do
# Wait a bit more in case the port was just opened
sleep 1
>&2 echo "Trying ${HOST}/getinfo…"
INFO=$(lncurl getinfo)
if [ "$?" = "0" ]; then
>&2 echo "Response: ${INFO}"
alias="$(echo "${INFO}" | jq '.alias')"
>&2 echo "Wallet for ${alias} unlocked!"
exit 0
if [[ -f $LNDPASSWORD_PATH ]]; then
if [[ -f $MACAROON_PATH ]]; then
>&2 echo "Password and macaroon file file exists"
PASS="$(cat /secrets/lnd-password.txt | tr -d '\n' | base64 | tr -d '\n')"
UNLOCK_PAYLOAD="$(jq -nc --arg wallet_password ${PASS} '{$wallet_password}')"
# Try getinfo then unlock
>&2 echo "Trying ${HOST}/getinfo…"
INFO=$(lncurl getinfo)
if [ "$?" = "0" ]; then
>&2 echo "Response: ${INFO}"
alias="$(echo "${INFO}" | jq '.alias')"
>&2 echo "Wallet for ${alias} unlocked!"
exit 0
fi
>&2 echo "${HOST}/getinfo FAILED, out=${INFO}"
>&2 echo "Trying ${HOST}/unlockwallet…"
RESULT=$(lncurl unlockwallet "${UNLOCK_PAYLOAD}")
>&2 echo "${HOST}/unlockwallet completed with: exit-code=$?, out=${RESULT}"
else
>&2 echo "macaroon file doesn't exist"
fi
else
>&2 echo "password file doesn't exist"
fi
>&2 echo "${HOST}/getinfo FAILED, out=${INFO}"
>&2 echo "Trying ${HOST}/unlockwallet…"
RESULT=$(lncurl unlockwallet "${UNLOCK_PAYLOAD}")
>&2 echo "${HOST}/unlockwallet completed with: exit-code=$?, out=${RESULT}"
sleep 16
sleep 30
done

2
docker-compose.yml

@ -40,5 +40,5 @@ services:
logging: *default-logging
volumes:
- "${HOME}/lnd:/lnd"
- "${HOME}/secrets"
- "${HOME}/secrets:/secrets"
network_mode: host

Loading…
Cancel
Save