feat(install): add proper update/migration support for existing installations
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:
84
install.sh
84
install.sh
@@ -213,8 +213,24 @@ echo "Download URL: $DOWNLOAD_URL"
|
|||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# Check if installation directory exists
|
# Check if installation directory exists
|
||||||
|
SERVICE_WAS_RUNNING=0
|
||||||
|
OLD_NODE_INSTALL=0
|
||||||
|
|
||||||
if [ -d "$INSTALL_DIR" ]; then
|
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 [ $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 "Installation directory already exists: $INSTALL_DIR"
|
||||||
echo "Do you want to update/reinstall? (Y/n): "
|
echo "Do you want to update/reinstall? (Y/n): "
|
||||||
read -r update_confirm
|
read -r update_confirm
|
||||||
@@ -226,6 +242,28 @@ if [ -d "$INSTALL_DIR" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Updating existing installation at $INSTALL_DIR..."
|
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
|
else
|
||||||
if [ $AUTO_YES -eq 0 ] && [ $INTERACTIVE -eq 1 ]; then
|
if [ $AUTO_YES -eq 0 ] && [ $INTERACTIVE -eq 1 ]; then
|
||||||
echo "NUPST will be installed to: $INSTALL_DIR"
|
echo "NUPST will be installed to: $INSTALL_DIR"
|
||||||
@@ -301,18 +339,54 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo ""
|
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 "================================================"
|
||||||
echo " NUPST Installation Complete!"
|
echo " NUPST Installation Complete!"
|
||||||
echo "================================================"
|
echo "================================================"
|
||||||
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 "Installation details:"
|
||||||
echo " Binary location: $BINARY_PATH"
|
echo " Binary location: $BINARY_PATH"
|
||||||
echo " Symlink location: $BIN_DIR/nupst"
|
echo " Symlink location: $BIN_DIR/nupst"
|
||||||
echo " Version: $VERSION"
|
echo " Version: $VERSION"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Get started:"
|
|
||||||
echo " nupst --version"
|
# Check if configuration exists
|
||||||
echo " nupst help"
|
if [ -f "/etc/nupst/config.json" ]; then
|
||||||
echo " nupst ups add # Add a UPS device"
|
echo "Configuration: /etc/nupst/config.json (preserved)"
|
||||||
echo " nupst service enable # Enable systemd service"
|
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 ""
|
echo ""
|
||||||
|
Reference in New Issue
Block a user