This commit is contained in:
Justin (shocknet) 2024-07-23 01:01:56 -04:00
parent 3a726f583e
commit 8b1cbbbe8e
5 changed files with 94 additions and 25 deletions

View file

@ -49,8 +49,10 @@ get_log_info() {
log "Creating wallet..." log "Creating wallet..."
elif echo "$latest_entry" | grep -q "unlocker >> wallet is locked, unlocking"; then elif echo "$latest_entry" | grep -q "unlocker >> wallet is locked, unlocking"; then
log "Unlocking wallet..." log "Unlocking wallet..."
else elif echo "$latest_entry" | grep -q "unlocker >> the wallet is already unlocked"; then
log "Wallet is already unlocked." log "Wallet is already unlocked."
else
log "Unknown wallet status."
fi fi
while [ $ATTEMPT -lt $MAX_ATTEMPTS ]; do while [ $ATTEMPT -lt $MAX_ATTEMPTS ]; do
@ -76,5 +78,5 @@ get_log_info() {
exit 1 exit 1
fi fi
log "Paste this string into ShockWallet to connect to the node: $latest_nprofile_key" log "Paste this admin string into ShockWallet to manage the node: $latest_nprofile_key"
} }

View file

@ -1,7 +1,8 @@
#!/bin/bash #!/bin/bash
set -e set -e
BASE_URL="https://raw.githubusercontent.com/shocknet/Lightning.Pub/master/scripts/" #BASE_URL="https://raw.githubusercontent.com/shocknet/Lightning.Pub/master/scripts/"
BASE_URL="https://bolt12.info/deploy"
modules=( modules=(
"utils" "utils"
"check_homebrew" "check_homebrew"
@ -37,8 +38,9 @@ if [ "$OS" = "Mac" ]; then
handle_macos handle_macos
else else
install_lnd install_lnd
LND_UPGRADE=$?
install_nodejs install_nodejs
install_lightning_pub PUB_UPGRADE_STATUS=$(install_lightning_pub)
start_services start_services $LND_UPGRADE $PUB_UPGRADE_STATUS
get_log_info get_log_info
fi fi

View file

@ -44,6 +44,13 @@ install_lightning_pub() {
fi fi
fi fi
if [ -d "$USER_HOME/lightning_pub" ]; then
log "${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR} is already installed. Upgrading..."
PUB_UPGRADE=true
else
PUB_UPGRADE=false
fi
# Merge if upgrade # Merge if upgrade
rsync -av --exclude='*.sqlite' --exclude='.env' --exclude='logs' --exclude='node_modules' --exclude='.jwt_secret' --exclude='.wallet_secret' --exclude='admin.npub' --exclude='app.nprofile' --exclude='.admin_connect' --exclude='.admin_enroll' lightning_pub_temp/ lightning_pub/ > /dev/null 2>&1 rsync -av --exclude='*.sqlite' --exclude='.env' --exclude='logs' --exclude='node_modules' --exclude='.jwt_secret' --exclude='.wallet_secret' --exclude='admin.npub' --exclude='app.nprofile' --exclude='.admin_connect' --exclude='.admin_enroll' lightning_pub_temp/ lightning_pub/ > /dev/null 2>&1
rm -rf lightning_pub_temp rm -rf lightning_pub_temp
@ -61,5 +68,13 @@ install_lightning_pub() {
exit 1 exit 1
} }
log "${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR} installation completed." if [ "$PUB_UPGRADE" = true ]; then
PUB_UPGRADE_STATUS=1
else
PUB_UPGRADE_STATUS=0
fi
log "PUB_UPGRADE_STATUS set to $PUB_UPGRADE_STATUS"
echo $PUB_UPGRADE_STATUS
} }

View file

@ -17,21 +17,23 @@ install_lnd() {
CURRENT_VERSION=$("$USER_HOME/lnd/lnd" --version | grep -oP 'version \K[^\s]+') CURRENT_VERSION=$("$USER_HOME/lnd/lnd" --version | grep -oP 'version \K[^\s]+')
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 return 0
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
;; ;;
*) *)
log "$(date '+%Y-%m-%d %H:%M:%S') Upgrade cancelled." log "$(date '+%Y-%m-%d %H:%M:%S') Upgrade cancelled."
return return 0
;; ;;
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
fi fi
fi fi
fi fi
@ -77,4 +79,11 @@ 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
} }

View file

@ -1,6 +1,11 @@
#!/bin/bash #!/bin/bash
start_services() { start_services() {
LND_UPGRADE=$1
PUB_UPGRADE=$2
log "Entered start_services with LND_UPGRADE=$LND_UPGRADE and PUB_UPGRADE=$PUB_UPGRADE"
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,6 +14,8 @@ start_services() {
USER_NAME=$(whoami) USER_NAME=$(whoami)
fi fi
log "USER_HOME: $USER_HOME, USER_NAME: $USER_NAME"
if [ "$OS" = "Linux" ]; then if [ "$OS" = "Linux" ]; then
if [ "$SYSTEMCTL_AVAILABLE" = true ]; then if [ "$SYSTEMCTL_AVAILABLE" = true ]; then
sudo bash -c "cat > /etc/systemd/system/lnd.service <<EOF sudo bash -c "cat > /etc/systemd/system/lnd.service <<EOF
@ -44,30 +51,64 @@ 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" = true ]; then
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
log "LND restarted successfully using systemd."
else
log "Failed to restart ${SECONDARY_COLOR}LND${RESET_COLOR} using systemd."
exit 1
fi
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=$! lnd_pid=$!
wait $lnd_pid wait $lnd_pid
if systemctl is-active --quiet lnd; then if systemctl is-active --quiet lnd; then
log "${SECONDARY_COLOR}LND${RESET_COLOR} started successfully using systemd." log "LND started successfully using systemd."
else else
log "Failed to start ${SECONDARY_COLOR}LND${RESET_COLOR} using systemd." log "Failed to start ${SECONDARY_COLOR}LND${RESET_COLOR} using systemd."
exit 1 exit 1
fi 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
if [ "$PUB_UPGRADE" = "1" ]; then
log "${PRIMARY_COLOR}Restarting${RESET_COLOR} ${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR} service..."
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
log "Failed to restart ${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR} using systemd."
exit 1
fi
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=$! lightning_pub_pid=$!
wait $lightning_pub_pid wait $lightning_pub_pid
if systemctl is-active --quiet lightning_pub; then if systemctl is-active --quiet lightning_pub; then
log "${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR} started successfully using systemd." log "Lightning.Pub started successfully using systemd."
else else
log "Failed to start ${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR} using systemd." log "Failed to start ${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR} using systemd."
exit 1 exit 1
fi fi
fi
log "Checking status of ${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR} service..."
if sudo systemctl is-active lightning_pub >/dev/null 2>&1; then
log "Lightning.Pub is started"
else
log "Lightning.Pub is not started"
fi
else else
create_start_script create_start_script
log "systemctl not available. Created start.sh. Please use this script to start the services manually." log "systemctl not available. Created start.sh. Please use this script to start the services manually."