#!/bin/bash set -e REPO="fosrl/newt" INSTALL_DIR="/opt/newt" SERVICE_NAME="PVE-MGNT" SYMLINK="${INSTALL_DIR}/newt_latest" SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service" UPDATER_SERVICE="/etc/systemd/system/newt-updater.service" UPDATER_TIMER="/etc/systemd/system/newt-updater.timer" GREEN='\033[0;32m' YELLOW='\033[1;33m' RED='\033[0;31m' NC='\033[0m' info() { echo -e "${GREEN}[INFO]${NC} $1"; } warn() { echo -e "${YELLOW}[WARN]${NC} $1"; } error() { echo -e "${RED}[ERROR]${NC} $1"; exit 1; } get_latest_version() { curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" | grep -Po '"tag_name": *"\K[^"]+' } download_newt() { local version="$1" local arch=$(uname -m) local file="" case "$arch" in x86_64) file="newt_linux_amd64" ;; aarch64) file="newt_linux_arm64" ;; armv7l) file="newt_linux_arm32" ;; *) error "Unsupported architecture: $arch" ;; esac local url="https://github.com/${REPO}/releases/download/${version}/${file}" local target="${INSTALL_DIR}/newt_${version}" mkdir -p "$INSTALL_DIR" info "โฌ‡๏ธ Downloading $url โ€ฆ" curl -fsSL "$url" -o "${target}.tmp" || error "Download failed." chmod +x "${target}.tmp" mv "${target}.tmp" "$target" ln -sf "$target" "$SYMLINK" info "โœ… Installed newt ${version} at ${target}" } setup_systemd_service() { echo "๐Ÿ†” Please enter the Pangolin ID: " read -r PANGOLIN_ID echo "๐Ÿ”‘ Please enter the Secret: " read -r PANGOLIN_SECRET echo "๐ŸŒ Please enter the Endpoint (e.g. https://pangolin.domain.com): " read -r PANGOLIN_ENDPOINT cat > "$SERVICE_FILE" < "$UPDATER_SERVICE" < "$UPDATER_TIMER" </dev/null || true rm -f "$SERVICE_FILE" # Remove updater if systemctl is-active --quiet newt-updater.timer; then systemctl stop newt-updater.timer fi systemctl disable newt-updater.timer 2>/dev/null || true rm -f "$UPDATER_SERVICE" "$UPDATER_TIMER" systemctl daemon-reload # Delete installation dir (ask first) if [ -d "$INSTALL_DIR" ]; then read -p "โ“ Do you want to remove ${INSTALL_DIR} and all versions? (y/N): " yn case $yn in [Yy]*) rm -rf "$INSTALL_DIR"; info "๐Ÿ“‚ ${INSTALL_DIR} was removed." ;; *) warn "๐Ÿ“‚ ${INSTALL_DIR} was NOT removed." ;; esac fi info "๐Ÿงน Uninstallation completed!" } main() { case "$1" in --install|"") mode_install ;; --update) mode_update ;; --reinstall) mode_reinstall ;; --uninstall) mode_uninstall ;; *) error "โŒ Unknown parameter: $1 (use --install, --update, --reinstall or --uninstall)" ;; esac } main "$@"