This commit is contained in:
Justin (shocknet) 2024-07-23 14:39:56 -04:00
parent 351b3e16fa
commit 20fed1d457
4 changed files with 108 additions and 82 deletions

View file

@ -36,7 +36,7 @@ get_log_info() {
while [ $(($(date +%s) - START_TIME)) -lt $MAX_WAIT_TIME ]; do while [ $(($(date +%s) - START_TIME)) -lt $MAX_WAIT_TIME ]; do
current_lines=$(wc -l < "$latest_unlocker_log") current_lines=$(wc -l < "$latest_unlocker_log")
if [ $current_lines -gt $initial_lines ]; then if [ $current_lines -gt $initial_lines ]; then
latest_entry=$(tail -n $((current_lines - initial_lines)) "$latest_unlocker_log" | grep "unlocker >>" | tail -n 1) latest_entry=$(tail -n $((current_lines - initial_lines)) "$latest_unlocker_log" | grep -E "unlocker >> (the wallet is already unlocked|created wallet with pub|unlocked wallet with pub)" | tail -n 1)
if [ -n "$latest_entry" ]; then if [ -n "$latest_entry" ]; then
break break
fi fi
@ -49,7 +49,17 @@ get_log_info() {
exit 1 exit 1
fi fi
log "Wallet status: $(echo "$latest_entry" | cut -d' ' -f4-)" if [[ "$latest_entry" == *"the wallet is already unlocked"* ]]; then
log "Wallet status: The wallet is already unlocked"
elif [[ "$latest_entry" == *"created wallet with pub"* ]]; then
log "Wallet status: A new wallet has been created"
elif [[ "$latest_entry" == *"unlocking"* ]]; then
log "Wallet status: The wallet is in the process of unlocking"
elif [[ "$latest_entry" == *"unlocked wallet with pub"* ]]; then
log "Wallet status: The wallet has been successfully unlocked"
else
log "Wallet status: Unknown (unexpected status message)"
fi
log "Retrieving connection information..." log "Retrieving connection information..."

View file

@ -1,7 +1,6 @@
#!/bin/bash #!/bin/bash
set -e set -e
# Function to log errors
log_error() { log_error() {
log "ERROR: $1" log "ERROR: $1"
log "Exiting with status $2" log "Exiting with status $2"
@ -33,8 +32,22 @@ detect_os_arch
if [ "$OS" = "Mac" ]; then if [ "$OS" = "Mac" ]; then
handle_macos handle_macos
else else
install_lnd || log_error "LND installation failed" $? lnd_output=$(install_lnd)
lnd_upgrade_status=$? install_result=$?
if [ $install_result -ne 0 ]; then
log_error "LND installation failed" $install_result
fi
# Extract the LND status from the output
lnd_status=$(echo "$lnd_output" | grep "LND_STATUS:" | cut -d':' -f2)
case $lnd_status in
0) log "LND fresh installation completed successfully." ;;
1) log "LND upgrade completed successfully." ;;
2) log "LND is already up-to-date. No action needed." ;;
*) log "WARNING: Unexpected status from install_lnd: $lnd_status" ;;
esac
install_nodejs || log_error "NodeJS installation failed" $? install_nodejs || log_error "NodeJS installation failed" $?
@ -57,7 +70,8 @@ else
log "Full output: $pub_output" log "Full output: $pub_output"
fi fi
start_services $lnd_upgrade_status $pub_upgrade_status log "Starting services..."
start_services $lnd_status $pub_upgrade_status
get_log_info get_log_info
log "Installation process completed successfully" log "Installation process completed successfully"

View file

@ -1,6 +1,10 @@
#!/bin/bash #!/bin/bash
install_lnd() { install_lnd() {
local lnd_status=0
log "Starting LND installation/check process..."
if [ "$EUID" -eq 0 ]; then if [ "$EUID" -eq 0 ]; then
USER_HOME=$(getent passwd ${SUDO_USER} | cut -d: -f6) USER_HOME=$(getent passwd ${SUDO_USER} | cut -d: -f6)
USER_NAME=$SUDO_USER USER_NAME=$SUDO_USER
@ -9,35 +13,44 @@ install_lnd() {
USER_NAME=$(whoami) USER_NAME=$(whoami)
fi fi
log "Checking latest LND version..."
LND_VERSION=$(wget -qO- https://api.github.com/repos/lightningnetwork/lnd/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")') LND_VERSION=$(wget -qO- https://api.github.com/repos/lightningnetwork/lnd/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")')
log "Latest LND version: $LND_VERSION"
LND_URL="https://github.com/lightningnetwork/lnd/releases/download/${LND_VERSION}/lnd-${OS}-${ARCH}-${LND_VERSION}.tar.gz" LND_URL="https://github.com/lightningnetwork/lnd/releases/download/${LND_VERSION}/lnd-${OS}-${ARCH}-${LND_VERSION}.tar.gz"
# Check if LND is already installed # Check if LND is already installed
if [ -d "$USER_HOME/lnd" ]; then if [ -d "$USER_HOME/lnd" ]; then
log "LND directory found. Checking current version..."
CURRENT_VERSION=$("$USER_HOME/lnd/lnd" --version | grep -oP 'version \K[^\s]+') CURRENT_VERSION=$("$USER_HOME/lnd/lnd" --version | grep -oP 'version \K[^\s]+')
log "Current LND version: $CURRENT_VERSION"
if [ "$CURRENT_VERSION" == "${LND_VERSION#v}" ]; then if [ "$CURRENT_VERSION" == "${LND_VERSION#v}" ]; then
log "${SECONDARY_COLOR}LND${RESET_COLOR} is already up-to-date (version $CURRENT_VERSION)." log "${SECONDARY_COLOR}LND${RESET_COLOR} is already up-to-date (version $CURRENT_VERSION)."
return 0 lnd_status=2 # Set status to 2 to indicate no action needed
else else
if [ "$SKIP_PROMPT" != true ]; then if [ "$SKIP_PROMPT" != true ]; then
read -p "LND version $CURRENT_VERSION is installed. Do you want to upgrade to version $LND_VERSION? (y/N): " response read -p "LND version $CURRENT_VERSION is installed. Do you want to upgrade to version $LND_VERSION? (y/N): " response
case "$response" in case "$response" in
[yY][eE][sS]|[yY]) [yY][eE][sS]|[yY])
log "${PRIMARY_COLOR}Upgrading${RESET_COLOR} ${SECONDARY_COLOR}LND${RESET_COLOR} from version $CURRENT_VERSION to $LND_VERSION..." log "${PRIMARY_COLOR}Upgrading${RESET_COLOR} ${SECONDARY_COLOR}LND${RESET_COLOR} from version $CURRENT_VERSION to $LND_VERSION..."
PERFORM_UPGRADE=true lnd_status=1 # Set status to 1 to indicate upgrade
;; ;;
*) *)
log "$(date '+%Y-%m-%d %H:%M:%S') Upgrade cancelled." log "$(date '+%Y-%m-%d %H:%M:%S') Upgrade cancelled."
return 0 lnd_status=2 # Set status to 2 to indicate no action needed
;; ;;
esac esac
else else
log "${PRIMARY_COLOR}Upgrading${RESET_COLOR} ${SECONDARY_COLOR}LND${RESET_COLOR} from version $CURRENT_VERSION to $LND_VERSION..." log "${PRIMARY_COLOR}Upgrading${RESET_COLOR} ${SECONDARY_COLOR}LND${RESET_COLOR} from version $CURRENT_VERSION to $LND_VERSION..."
PERFORM_UPGRADE=true lnd_status=1 # Set status to 1 to indicate upgrade
fi fi
fi fi
else
log "LND not found. Proceeding with fresh installation..."
fi fi
if [ $lnd_status -eq 0 ] || [ $lnd_status -eq 1 ]; then
log "${PRIMARY_COLOR}Downloading${RESET_COLOR} ${SECONDARY_COLOR}LND${RESET_COLOR}..." log "${PRIMARY_COLOR}Downloading${RESET_COLOR} ${SECONDARY_COLOR}LND${RESET_COLOR}..."
# Start the download # Start the download
@ -79,11 +92,10 @@ EOF"
fi fi
log "${SECONDARY_COLOR}LND${RESET_COLOR} installation and configuration completed." log "${SECONDARY_COLOR}LND${RESET_COLOR} installation and configuration completed."
# Return 1 if it was an upgrade, 0 otherwise
if [ "$PERFORM_UPGRADE" = true ]; then
return 1
else
return 0
fi fi
log "LND installation/check process complete. Status: $lnd_status"
# Echo the LND status
echo "LND_STATUS:$lnd_status"
return 0 # Always return 0 to indicate success
} }

View file

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
start_services() { start_services() {
LND_UPGRADE=$1 LND_STATUS=$1
PUB_UPGRADE=$2 PUB_UPGRADE=$2
if [ "$EUID" -eq 0 ]; then if [ "$EUID" -eq 0 ]; then
@ -47,55 +47,45 @@ EOF"
sudo systemctl enable lnd >/dev/null 2>&1 sudo systemctl enable lnd >/dev/null 2>&1
sudo systemctl enable lightning_pub >/dev/null 2>&1 sudo systemctl enable lightning_pub >/dev/null 2>&1
if [ "$LND_UPGRADE" = "1" ]; then # Always attempt to start or restart LND
log "${PRIMARY_COLOR}Restarting${RESET_COLOR} ${SECONDARY_COLOR}LND${RESET_COLOR} service..."
sudo systemctl restart lnd &
lnd_pid=$!
wait $lnd_pid
if systemctl is-active --quiet lnd; then if systemctl is-active --quiet lnd; then
log "LND restarted successfully using systemd." if [ "$LND_STATUS" = "1" ]; then
log "${PRIMARY_COLOR}Restarting${RESET_COLOR} ${SECONDARY_COLOR}LND${RESET_COLOR} service..."
sudo systemctl restart lnd
else else
log "Failed to restart ${SECONDARY_COLOR}LND${RESET_COLOR} using systemd." log "${SECONDARY_COLOR}LND${RESET_COLOR} service is already running."
exit 1
fi fi
else else
log "${PRIMARY_COLOR}Starting${RESET_COLOR} ${SECONDARY_COLOR}LND${RESET_COLOR} service..." log "${PRIMARY_COLOR}Starting${RESET_COLOR} ${SECONDARY_COLOR}LND${RESET_COLOR} service..."
sudo systemctl start lnd & sudo systemctl start lnd
lnd_pid=$!
wait $lnd_pid
if systemctl is-active --quiet lnd; then
log "LND started successfully using systemd."
else
log "Failed to start ${SECONDARY_COLOR}LND${RESET_COLOR} using systemd."
exit 1
fi fi
# Check LND status after attempting to start/restart
if ! systemctl is-active --quiet lnd; then
log "Failed to start or restart ${SECONDARY_COLOR}LND${RESET_COLOR}. Please check the logs."
exit 1
fi fi
log "Giving ${SECONDARY_COLOR}LND${RESET_COLOR} a few seconds to start before starting ${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR}..." log "Giving ${SECONDARY_COLOR}LND${RESET_COLOR} a few seconds to start before starting ${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR}..."
sleep 10 sleep 10
# Always attempt to start or restart Lightning.Pub
if systemctl is-active --quiet lightning_pub; then
if [ "$PUB_UPGRADE" = "100" ]; then if [ "$PUB_UPGRADE" = "100" ]; then
log "${PRIMARY_COLOR}Restarting${RESET_COLOR} ${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR} service..." log "${PRIMARY_COLOR}Restarting${RESET_COLOR} ${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR} service..."
sudo systemctl restart lightning_pub & sudo systemctl restart lightning_pub
lightning_pub_pid=$!
wait $lightning_pub_pid
if systemctl is-active --quiet lightning_pub; then
log "Lightning.Pub restarted successfully using systemd."
else else
log "Failed to restart ${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR} using systemd." log "${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR} service is already running."
exit 1
fi fi
else else
log "${PRIMARY_COLOR}Starting${RESET_COLOR} ${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR} service..." log "${PRIMARY_COLOR}Starting${RESET_COLOR} ${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR} service..."
sudo systemctl start lightning_pub & sudo systemctl start lightning_pub
lightning_pub_pid=$!
wait $lightning_pub_pid
if systemctl is-active --quiet lightning_pub; then
log "Lightning.Pub started successfully using systemd."
else
log "Failed to start ${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR} using systemd."
exit 1
fi fi
# Check Lightning.Pub status after attempting to start/restart
if ! systemctl is-active --quiet lightning_pub; then
log "Failed to start or restart ${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR}. Please check the logs."
exit 1
fi fi
else else