From 845e180a6688623055341972188c4cb1eed26f86 Mon Sep 17 00:00:00 2001 From: shocknet-justin Date: Sun, 31 Aug 2025 14:54:55 -0400 Subject: [PATCH] dont overwrite units --- scripts/install_lightning_pub.sh | 59 ++++++++++++++++---------------- scripts/start_services.sh | 29 ++++++++-------- 2 files changed, 44 insertions(+), 44 deletions(-) diff --git a/scripts/install_lightning_pub.sh b/scripts/install_lightning_pub.sh index 3df75c2e..7bc70069 100755 --- a/scripts/install_lightning_pub.sh +++ b/scripts/install_lightning_pub.sh @@ -76,33 +76,6 @@ install_lightning_pub() { mv "$EXTRACT_DIR" "$INSTALL_DIR" - log "Restoring user data..." - cp "$BACKUP_DIR"/*.sqlite "$INSTALL_DIR/" 2>/dev/null || true - cp "$BACKUP_DIR"/.env "$INSTALL_DIR/" 2>/dev/null || true - cp -r "$BACKUP_DIR"/logs "$INSTALL_DIR/" 2>/dev/null || true - cp -r "$BACKUP_DIR"/metric_cache "$INSTALL_DIR/" 2>/dev/null || true - cp "$BACKUP_DIR"/.jwt_secret "$INSTALL_DIR/" 2>/dev/null || true - cp "$BACKUP_DIR"/.wallet_secret "$INSTALL_DIR/" 2>/dev/null || true - cp "$BACKUP_DIR"/.installed_commit "$INSTALL_DIR/" 2>/dev/null || true - cp "$BACKUP_DIR"/admin.npub "$INSTALL_DIR/" 2>/dev/null || true - cp "$BACKUP_DIR"/app.nprofile "$INSTALL_DIR/" 2>/dev/null || true - cp "$BACKUP_DIR"/admin.connect "$INSTALL_DIR/" 2>/dev/null || true - cp "$BACKUP_DIR"/admin.enroll "$INSTALL_DIR/" 2>/dev/null || true - - # Ensure correct ownership post-restore (fixes potential mismatches) - chown -R "$USER_NAME:$USER_NAME" "$INSTALL_DIR/" 2>/dev/null || true - # Secure DB files (as before) - chmod 600 "$INSTALL_DIR/db.sqlite" 2>/dev/null || true - chmod 600 "$INSTALL_DIR/metrics.sqlite" 2>/dev/null || true - chmod 600 "$INSTALL_DIR/.jwt_secret" 2>/dev/null || true - chmod 600 "$INSTALL_DIR/.wallet_secret" 2>/dev/null || true - chmod 600 "$INSTALL_DIR/admin.connect" 2>/dev/null || true - chmod 600 "$INSTALL_DIR/admin.enroll" 2>/dev/null || true - # Ensure log/metric dirs are writable (dirs need execute for traversal) - chmod 755 "$INSTALL_DIR/logs" 2>/dev/null || true - chmod 755 "$INSTALL_DIR/logs/"*/ 2>/dev/null || true # Subdirs like apps/ - chmod 755 "$INSTALL_DIR/metric_cache" 2>/dev/null || true - elif [ -d "$INSTALL_DIR" ]; then # --- CONFLICT/UNSAFE PATH --- # This handles the case where the directory exists but is not a valid install (e.g., a git clone). @@ -148,7 +121,35 @@ install_lightning_pub() { return 1 fi - + + # Restore user data AFTER successful NPM install + log "Restoring user data..." + cp "$BACKUP_DIR"/*.sqlite "$INSTALL_DIR/" 2>/dev/null || true + cp "$BACKUP_DIR"/.env "$INSTALL_DIR/" 2>/dev/null || true + cp -r "$BACKUP_DIR"/logs "$INSTALL_DIR/" 2>/dev/null || true + cp -r "$BACKUP_DIR"/metric_cache "$INSTALL_DIR/" 2>/dev/null || true + cp "$BACKUP_DIR"/.jwt_secret "$INSTALL_DIR/" 2>/dev/null || true + cp "$BACKUP_DIR"/.wallet_secret "$INSTALL_DIR/" 2>/dev/null || true + cp "$BACKUP_DIR"/.installed_commit "$INSTALL_DIR/" 2>/dev/null || true + cp "$BACKUP_DIR"/admin.npub "$INSTALL_DIR/" 2>/dev/null || true + cp "$BACKUP_DIR"/app.nprofile "$INSTALL_DIR/" 2>/dev/null || true + cp "$BACKUP_DIR"/admin.connect "$INSTALL_DIR/" 2>/dev/null || true + cp "$BACKUP_DIR"/admin.enroll "$INSTALL_DIR/" 2>/dev/null || true + + # Ensure correct ownership post-restore (fixes potential mismatches) + chown -R "$USER_NAME:$USER_NAME" "$INSTALL_DIR/" 2>/dev/null || true + # Secure DB files (as before) + chmod 600 "$INSTALL_DIR/db.sqlite" 2>/dev/null || true + chmod 600 "$INSTALL_DIR/metrics.sqlite" 2>/dev/null || true + chmod 600 "$INSTALL_DIR/.jwt_secret" 2>/dev/null || true + chmod 600 "$INSTALL_DIR/.wallet_secret" 2>/dev/null || true + chmod 600 "$INSTALL_DIR/admin.connect" 2>/dev/null || true + chmod 600 "$INSTALL_DIR/admin.enroll" 2>/dev/null || true + # Ensure log/metric dirs are writable (dirs need execute for traversal) + chmod 755 "$INSTALL_DIR/logs" 2>/dev/null || true + chmod 755 "$INSTALL_DIR/logs/"*/ 2>/dev/null || true # Subdirs like apps/ + chmod 755 "$INSTALL_DIR/metric_cache" 2>/dev/null || true + # Store the commit hash for future update checks # Note: LATEST_COMMIT will be empty on a fresh install, which is fine. # The file will be created, and the next run will be an upgrade. @@ -158,7 +159,7 @@ install_lightning_pub() { touch "$INSTALL_DIR/.installed_commit" fi - rm -rf "$BACKUP_DIR" + rm -rf "$BACKUP_DIR" 2>/dev/null || true return $upgrade_status } \ No newline at end of file diff --git a/scripts/start_services.sh b/scripts/start_services.sh index 519208e6..a1d50470 100755 --- a/scripts/start_services.sh +++ b/scripts/start_services.sh @@ -17,25 +17,24 @@ start_services() { if [ "$SYSTEMCTL_AVAILABLE" = true ]; then mkdir -p "$UNIT_DIR" - # Check and create lnd.service if needed + # Check and create lnd.service if needed (only if it doesn't exist) LND_UNIT="$UNIT_DIR/lnd.service" - NEW_LND_CONTENT="[Unit]\nDescription=LND Service\nAfter=network.target\n\n[Service]\nExecStart=${USER_HOME}/lnd/lnd\nRestart=always\n\n[Install]\nWantedBy=default.target" - if [ ! -f "$LND_UNIT" ] || [ "$(cat "$LND_UNIT")" != "$NEW_LND_CONTENT" ]; then + if [ ! -f "$LND_UNIT" ]; then + NEW_LND_CONTENT="[Unit]\nDescription=LND Service\nAfter=network.target\n\n[Service]\nExecStart=${USER_HOME}/lnd/lnd\nRestart=always\n\n[Install]\nWantedBy=default.target" echo -e "$NEW_LND_CONTENT" > "$LND_UNIT" $SYSTEMCTL_CMD daemon-reload + $SYSTEMCTL_CMD enable lnd >/dev/null 2>&1 fi - # Check and create lightning_pub.service if needed + # Check and create lightning_pub.service if needed (only if it doesn't exist) PUB_UNIT="$UNIT_DIR/lightning_pub.service" - NEW_PUB_CONTENT="[Unit]\nDescription=Lightning.Pub Service\nAfter=network.target\n\n[Service]\nExecStart=/bin/bash -c 'source ${NVM_DIR}/nvm.sh && npm start'\nWorkingDirectory=${INSTALL_DIR}\nRestart=always\n\n[Install]\nWantedBy=default.target" - if [ ! -f "$PUB_UNIT" ] || [ "$(cat "$PUB_UNIT")" != "$NEW_PUB_CONTENT" ]; then + if [ ! -f "$PUB_UNIT" ]; then + NEW_PUB_CONTENT="[Unit]\nDescription=Lightning.Pub Service\nAfter=network.target\n\n[Service]\nExecStart=/bin/bash -c 'source ${NVM_DIR}/nvm.sh && npm start'\nWorkingDirectory=${INSTALL_DIR}\nRestart=always\n\n[Install]\nWantedBy=default.target" echo -e "$NEW_PUB_CONTENT" > "$PUB_UNIT" $SYSTEMCTL_CMD daemon-reload + $SYSTEMCTL_CMD enable lightning_pub >/dev/null 2>&1 fi - $SYSTEMCTL_CMD enable lnd >/dev/null 2>&1 - $SYSTEMCTL_CMD enable lightning_pub >/dev/null 2>&1 - # Only start/restart LND if it was freshly installed or upgraded if [ "$LND_STATUS" = "0" ] || [ "$LND_STATUS" = "1" ]; then if $SYSTEMCTL_CMD is-active --quiet lnd; then @@ -45,16 +44,16 @@ start_services() { log "${PRIMARY_COLOR}Starting${RESET_COLOR} ${SECONDARY_COLOR}LND${RESET_COLOR} service..." $SYSTEMCTL_CMD start lnd fi + + # Check LND status after attempting to start/restart + if ! $SYSTEMCTL_CMD is-active --quiet lnd; then + log "Failed to start or restart ${SECONDARY_COLOR}LND${RESET_COLOR}. Please check the logs." + exit 1 + fi else log "${SECONDARY_COLOR}LND${RESET_COLOR} not updated, service status unchanged." fi - # Check LND status after attempting to start/restart - if ! $SYSTEMCTL_CMD is-active --quiet lnd; then - log "Failed to start or restart ${SECONDARY_COLOR}LND${RESET_COLOR}. Please check the logs." - exit 1 - fi - if [ "$PUB_UPGRADE" = "0" ] || [ "$PUB_UPGRADE" = "100" ]; then if [ "$PUB_UPGRADE" = "100" ]; then log "${PRIMARY_COLOR}Restarting${RESET_COLOR} ${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR} service after upgrade..."