feat(install): add proper update/migration support for existing installations
Some checks failed
CI / Build All Platforms (Tag/Main only) (push) Has been skipped
CI / Type Check & Lint (push) Failing after 41s
CI / Build Test (Current Platform) (push) Successful in 40s

Enhanced install.sh to properly handle updates and migrations:

**Update Detection & Service Management:**
- Detect old Node.js-based installations (v3.x) via package.json/node_modules
- Stop running service before updating binary
- Restart service after successful update if it was running
- Preserve /etc/nupst/config.json during updates

**Migration from v3.x to v4.0:**
- Clean up old Node.js installation files:
  - node_modules/, vendor/, dist_ts/ directories
  - package.json, package-lock.json, pnpm-lock.yaml
  - tsconfig.json, setup.sh, bin/ directory
- Inform user about migration with helpful feedback
- Link to migration guide documentation

**User Experience Improvements:**
- Show different messages for new installs vs updates
- Inform about v3.x → v4.0 migration when detected
- Display migration guide link for old installations
- Show service restart status
- Provide context-aware next steps based on config presence

**Safety Features:**
- Ask for confirmation before replacing existing installation (interactive mode)
- Preserve user configuration in /etc/nupst/
- Handle service state properly (stop → update → restart)
- Graceful cleanup with error suppression (|| true)

This ensures seamless updates from any version (including v3.x Node.js installs)
to v4.0+ Deno-based binaries without manual intervention or data loss.
This commit is contained in:
2025-10-19 10:23:14 +00:00
parent c2d39cc19a
commit 4faa10c494

View File

@@ -213,8 +213,24 @@ echo "Download URL: $DOWNLOAD_URL"
echo ""
# Check if installation directory exists
SERVICE_WAS_RUNNING=0
OLD_NODE_INSTALL=0
if [ -d "$INSTALL_DIR" ]; then
# Check if this is an old Node.js-based installation
if [ -f "$INSTALL_DIR/package.json" ] || [ -d "$INSTALL_DIR/node_modules" ]; then
OLD_NODE_INSTALL=1
echo "Detected old Node.js-based NUPST installation (v3.x or earlier)"
echo "This installer will migrate to the new Deno-based binary version (v4.0+)"
echo ""
fi
if [ $AUTO_YES -eq 0 ] && [ $INTERACTIVE -eq 1 ]; then
if [ $OLD_NODE_INSTALL -eq 1 ]; then
echo "This will replace your Node.js installation with a pre-compiled binary."
echo "Your configuration in /etc/nupst/config.json will be preserved."
echo ""
fi
echo "Installation directory already exists: $INSTALL_DIR"
echo "Do you want to update/reinstall? (Y/n): "
read -r update_confirm
@@ -226,6 +242,28 @@ if [ -d "$INSTALL_DIR" ]; then
fi
echo "Updating existing installation at $INSTALL_DIR..."
# Check if service is running and stop it
if systemctl is-active --quiet nupst 2>/dev/null; then
echo "Stopping NUPST service..."
systemctl stop nupst
SERVICE_WAS_RUNNING=1
fi
# Clean up old Node.js installation files
if [ $OLD_NODE_INSTALL -eq 1 ]; then
echo "Cleaning up old Node.js installation files..."
rm -rf "$INSTALL_DIR/node_modules" 2>/dev/null || true
rm -rf "$INSTALL_DIR/vendor" 2>/dev/null || true
rm -rf "$INSTALL_DIR/dist_ts" 2>/dev/null || true
rm -f "$INSTALL_DIR/package.json" 2>/dev/null || true
rm -f "$INSTALL_DIR/package-lock.json" 2>/dev/null || true
rm -f "$INSTALL_DIR/pnpm-lock.yaml" 2>/dev/null || true
rm -f "$INSTALL_DIR/tsconfig.json" 2>/dev/null || true
rm -f "$INSTALL_DIR/setup.sh" 2>/dev/null || true
rm -rf "$INSTALL_DIR/bin" 2>/dev/null || true
echo "Old installation files removed."
fi
else
if [ $AUTO_YES -eq 0 ] && [ $INTERACTIVE -eq 1 ]; then
echo "NUPST will be installed to: $INSTALL_DIR"
@@ -301,18 +339,54 @@ else
fi
echo ""
# Restart service if it was running before update
if [ $SERVICE_WAS_RUNNING -eq 1 ]; then
echo "Restarting NUPST service..."
systemctl start nupst
echo "Service restarted successfully."
echo ""
fi
echo "================================================"
echo " NUPST Installation Complete!"
echo "================================================"
echo ""
if [ $OLD_NODE_INSTALL -eq 1 ]; then
echo "Migration from v3.x to v4.0 successful!"
echo ""
echo "What changed:"
echo " • Node.js runtime removed (now a self-contained binary)"
echo " • Faster startup and lower memory usage"
echo " • CLI commands now use subcommand structure"
echo " (old commands still work with deprecation warnings)"
echo ""
echo "Migration guide: https://code.foss.global/serve.zone/nupst/src/branch/main/MIGRATION.md"
echo ""
fi
echo "Installation details:"
echo " Binary location: $BINARY_PATH"
echo " Symlink location: $BIN_DIR/nupst"
echo " Version: $VERSION"
echo ""
echo "Get started:"
echo " nupst --version"
echo " nupst help"
echo " nupst ups add # Add a UPS device"
echo " nupst service enable # Enable systemd service"
# Check if configuration exists
if [ -f "/etc/nupst/config.json" ]; then
echo "Configuration: /etc/nupst/config.json (preserved)"
echo ""
echo "Your existing configuration has been preserved."
if [ $SERVICE_WAS_RUNNING -eq 1 ]; then
echo "The service has been restarted with your current settings."
else
echo "Start the service with: sudo nupst service start"
fi
else
echo "Get started:"
echo " nupst --version"
echo " nupst help"
echo " nupst ups add # Add a UPS device"
echo " nupst service enable # Enable systemd service"
fi
echo ""