#!/bin/bash # NUPST Uninstaller Script # Completely removes NUPST from the system. # Shipped as a release asset and installed to /opt/nupst/uninstall.sh by install.sh. # Check if running as root if [ "$EUID" -ne 0 ]; then echo "Please run as root (sudo nupst uninstall or sudo ./uninstall.sh)" exit 1 fi # This script can be called directly or through the CLI # When called through the CLI, environment variables are set # REMOVE_CONFIG=yes|no - whether to remove configuration files # REMOVE_REPO=yes|no - whether to remove the installation directory # If not set through CLI, use defaults REMOVE_CONFIG=${REMOVE_CONFIG:-"no"} REMOVE_REPO=${REMOVE_REPO:-"no"} echo "NUPST Uninstaller" echo "=================" echo "This will completely remove NUPST from your system." # Find the directory where this script is located SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" # Installation directory of the binary install (overridable for custom --install-dir installs) INSTALL_DIR=${NUPST_INSTALL_DIR:-"/opt/nupst"} if [ -f "$SCRIPT_DIR/nupst" ]; then INSTALL_DIR="$SCRIPT_DIR" fi # Step 1: Stop and disable the systemd service if it exists if [ -f "/etc/systemd/system/nupst.service" ]; then echo "Stopping NUPST service..." systemctl stop nupst.service 2>/dev/null echo "Disabling NUPST service..." systemctl disable nupst.service 2>/dev/null echo "Removing systemd service file..." rm -f /etc/systemd/system/nupst.service echo "Reloading systemd daemon..." systemctl daemon-reload fi # Step 2: Remove global symlinks created by install.sh for symlink_dir in /usr/local/bin /usr/bin; do if [ -L "$symlink_dir/nupst" ]; then echo "Removing global symlink: $symlink_dir/nupst" rm -f "$symlink_dir/nupst" fi done # Step 3: Remove configuration if requested if [ "$REMOVE_CONFIG" = "yes" ]; then echo "Removing configuration files..." rm -rf /etc/nupst else # If not called through CLI, ask user if [ -z "$NUPST_CLI_CALL" ]; then read -p "Do you want to remove the NUPST configuration files? (y/N) " -n 1 -r echo if [[ $REPLY =~ ^[Yy]$ ]]; then echo "Removing configuration files..." rm -rf /etc/nupst fi fi fi # Step 4: Remove the installation directory if requested # Covers both the binary install (/opt/nupst with the nupst binary) and the # legacy git checkout used by NUPST v3 and earlier. if [ "$REMOVE_REPO" != "yes" ] && [ -z "$NUPST_CLI_CALL" ] && [ -d "$INSTALL_DIR" ]; then read -p "Do you want to remove the NUPST installation directory ($INSTALL_DIR)? (y/N) " -n 1 -r echo if [[ $REPLY =~ ^[Yy]$ ]]; then REMOVE_REPO="yes" fi fi if [ "$REMOVE_REPO" = "yes" ]; then if [ -d "$INSTALL_DIR" ] && { [ -f "$INSTALL_DIR/nupst" ] || [ -d "$INSTALL_DIR/.git" ]; }; then echo "Removing NUPST installation directory: $INSTALL_DIR" if [ "$INSTALL_DIR" = "$SCRIPT_DIR" ]; then # The uninstaller lives inside the directory that is being removed, so the # removal has to happen after this script exits. CLEANUP_SCRIPT=$(mktemp) { echo "#!/bin/bash" echo "sleep 1" echo "rm -rf \"$INSTALL_DIR\"" echo "rm -f \"\$0\"" echo "echo \"NUPST installation directory has been removed.\"" } > "$CLEANUP_SCRIPT" chmod +x "$CLEANUP_SCRIPT" nohup "$CLEANUP_SCRIPT" > /dev/null 2>&1 & echo "NUPST installation directory will be removed after the uninstaller exits." else rm -rf "$INSTALL_DIR" echo "NUPST installation directory removed." fi else echo "No NUPST installation directory found at $INSTALL_DIR." fi else # If not requested, just display info if [ -d "$INSTALL_DIR" ]; then echo echo "NUPST installation directory at $INSTALL_DIR will remain intact." fi fi # Check for npm global installation NODE_PATH=$(which node 2>/dev/null) if [ -n "$NODE_PATH" ]; then NPM_PATH=$(dirname "$NODE_PATH")/npm if [ -x "$NPM_PATH" ]; then echo echo "If you installed NUPST via npm, you may want to uninstall it with:" echo " npm uninstall -g @serve.zone/nupst" fi fi echo echo "NUPST has been uninstalled from your system."