dont overwrite units

This commit is contained in:
shocknet-justin 2025-08-31 14:54:55 -04:00
parent 343b730624
commit 845e180a66
2 changed files with 44 additions and 44 deletions

View file

@ -76,33 +76,6 @@ install_lightning_pub() {
mv "$EXTRACT_DIR" "$INSTALL_DIR" 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 elif [ -d "$INSTALL_DIR" ]; then
# --- CONFLICT/UNSAFE PATH --- # --- CONFLICT/UNSAFE PATH ---
# This handles the case where the directory exists but is not a valid install (e.g., a git clone). # This handles the case where the directory exists but is not a valid install (e.g., a git clone).
@ -149,6 +122,34 @@ install_lightning_pub() {
return 1 return 1
fi 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 # Store the commit hash for future update checks
# Note: LATEST_COMMIT will be empty on a fresh install, which is fine. # 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. # 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" touch "$INSTALL_DIR/.installed_commit"
fi fi
rm -rf "$BACKUP_DIR" rm -rf "$BACKUP_DIR" 2>/dev/null || true
return $upgrade_status return $upgrade_status
} }

View file

@ -17,25 +17,24 @@ start_services() {
if [ "$SYSTEMCTL_AVAILABLE" = true ]; then if [ "$SYSTEMCTL_AVAILABLE" = true ]; then
mkdir -p "$UNIT_DIR" 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" 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" ]; then
if [ ! -f "$LND_UNIT" ] || [ "$(cat "$LND_UNIT")" != "$NEW_LND_CONTENT" ]; 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" echo -e "$NEW_LND_CONTENT" > "$LND_UNIT"
$SYSTEMCTL_CMD daemon-reload $SYSTEMCTL_CMD daemon-reload
$SYSTEMCTL_CMD enable lnd >/dev/null 2>&1
fi 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" 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" ]; then
if [ ! -f "$PUB_UNIT" ] || [ "$(cat "$PUB_UNIT")" != "$NEW_PUB_CONTENT" ]; 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" echo -e "$NEW_PUB_CONTENT" > "$PUB_UNIT"
$SYSTEMCTL_CMD daemon-reload $SYSTEMCTL_CMD daemon-reload
$SYSTEMCTL_CMD enable lightning_pub >/dev/null 2>&1
fi 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 # Only start/restart LND if it was freshly installed or upgraded
if [ "$LND_STATUS" = "0" ] || [ "$LND_STATUS" = "1" ]; then if [ "$LND_STATUS" = "0" ] || [ "$LND_STATUS" = "1" ]; then
if $SYSTEMCTL_CMD is-active --quiet lnd; 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..." log "${PRIMARY_COLOR}Starting${RESET_COLOR} ${SECONDARY_COLOR}LND${RESET_COLOR} service..."
$SYSTEMCTL_CMD start lnd $SYSTEMCTL_CMD start lnd
fi 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 else
log "${SECONDARY_COLOR}LND${RESET_COLOR} not updated, service status unchanged." log "${SECONDARY_COLOR}LND${RESET_COLOR} not updated, service status unchanged."
fi 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" = "0" ] || [ "$PUB_UPGRADE" = "100" ]; then
if [ "$PUB_UPGRADE" = "100" ]; then if [ "$PUB_UPGRADE" = "100" ]; then
log "${PRIMARY_COLOR}Restarting${RESET_COLOR} ${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR} service after upgrade..." log "${PRIMARY_COLOR}Restarting${RESET_COLOR} ${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR} service after upgrade..."