feat: complete migration to Deno with automated releases

- Remove old Node.js infrastructure (package.json, tsconfig.json, bin/nupst launcher, setup.sh)
- Update install.sh to download pre-compiled binaries from Gitea releases
- Add Gitea Actions CI/CD workflows:
  - ci.yml: Type checking, linting, and build verification
  - release.yml: Automated binary compilation and release on tags
- Update .gitignore for Deno-focused project structure
- Binary-based distribution requires no dependencies or build steps
This commit is contained in:
2025-10-18 13:20:23 +00:00
parent 9efcc4b437
commit df6a44d5d9
11 changed files with 686 additions and 10928 deletions

View File

@@ -1,23 +1,41 @@
#!/bin/bash
# NUPST Installer Script
# Downloads and installs NUPST globally on the system
# Can be used directly with curl:
# Without auto-installing dependencies:
# curl -sSL https://code.foss.global/serve.zone/nupst/raw/branch/main/install.sh | sudo bash
# With auto-installing dependencies:
# curl -sSL https://code.foss.global/serve.zone/nupst/raw/branch/main/install.sh | sudo bash -s -- -y
#
# NUPST Installer Script (v4.0+)
# Downloads and installs pre-compiled NUPST binary from Gitea releases
#
# Usage:
# Direct piped installation (recommended):
# curl -sSL https://code.foss.global/serve.zone/nupst/raw/branch/main/install.sh | sudo bash
#
# With version specification:
# curl -sSL https://code.foss.global/serve.zone/nupst/raw/branch/main/install.sh | sudo bash -s -- --version v4.0.0
#
# Non-interactive mode (auto-confirm):
# curl -sSL https://code.foss.global/serve.zone/nupst/raw/branch/main/install.sh | sudo bash -s -- -y
#
# Downloaded script:
# curl -sSL https://code.foss.global/serve.zone/nupst/raw/branch/main/install.sh -o nupst-install.sh
# sudo bash nupst-install.sh
#
# Options:
# -y, --yes Automatically answer yes to all prompts
# -h, --help Show this help message
# -y, --yes Automatically answer yes to all prompts
# -h, --help Show this help message
# --version VERSION Install specific version (e.g., v4.0.0)
# --install-dir DIR Installation directory (default: /opt/nupst)
# Parse command line arguments
set -e
# Default values
AUTO_YES=0
SHOW_HELP=0
SPECIFIED_VERSION=""
INSTALL_DIR="/opt/nupst"
GITEA_BASE_URL="https://code.foss.global"
GITEA_REPO="serve.zone/nupst"
for arg in "$@"; do
case $arg in
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
-y|--yes)
AUTO_YES=1
shift
@@ -26,19 +44,43 @@ for arg in "$@"; do
SHOW_HELP=1
shift
;;
--version)
SPECIFIED_VERSION="$2"
shift 2
;;
--install-dir)
INSTALL_DIR="$2"
shift 2
;;
*)
# Unknown option
echo "Unknown option: $1"
echo "Use -h or --help for usage information"
exit 1
;;
esac
done
if [ $SHOW_HELP -eq 1 ]; then
echo "NUPST Installer Script"
echo "NUPST Installer Script (v4.0+)"
echo "Downloads and installs pre-compiled NUPST binary"
echo ""
echo "Usage: $0 [options]"
echo ""
echo "Options:"
echo " -y, --yes Automatically answer yes to all prompts"
echo " -h, --help Show this help message"
echo " -y, --yes Automatically answer yes to all prompts"
echo " -h, --help Show this help message"
echo " --version VERSION Install specific version (e.g., v4.0.0)"
echo " --install-dir DIR Installation directory (default: /opt/nupst)"
echo ""
echo "Examples:"
echo " # Install latest version"
echo " curl -sSL https://code.foss.global/serve.zone/nupst/raw/branch/main/install.sh | sudo bash"
echo ""
echo " # Install specific version"
echo " curl -sSL https://code.foss.global/serve.zone/nupst/raw/branch/main/install.sh | sudo bash -s -- --version v4.0.0"
echo ""
echo " # Non-interactive installation"
echo " curl -sSL https://code.foss.global/serve.zone/nupst/raw/branch/main/install.sh | sudo bash -s -- -y"
exit 0
fi
@@ -49,35 +91,23 @@ if [ "$EUID" -ne 0 ]; then
fi
# Detect if script is being piped or run directly
PIPED=0
INTERACTIVE=1
if [ ! -t 0 ]; then
# Being piped, need to clone the repo
PIPED=1
fi
# Check if stdin is a terminal
if [ ! -t 0 ] || [ ! -t 1 ]; then
# Either stdin or stdout is not a terminal, check if -y was provided
# Either stdin or stdout is not a terminal
if [ $AUTO_YES -ne 1 ]; then
echo "Script detected it's running in a non-interactive environment without -y flag."
echo "Attempting to find a controlling terminal for interactive prompts..."
# Try to use a controlling terminal for user input
if [ -t 1 ]; then
# Stdout is a terminal, use it
exec < /dev/tty 2>/dev/null || INTERACTIVE=0
else
# Try to find controlling terminal
exec < /dev/tty 2>/dev/null || INTERACTIVE=0
fi
exec < /dev/tty 2>/dev/null || INTERACTIVE=0
if [ $INTERACTIVE -eq 0 ]; then
echo "ERROR: No controlling terminal available for interactive prompts."
echo ""
echo "For interactive installation (RECOMMENDED):"
echo " curl -sSL https://code.foss.global/serve.zone/nupst/raw/branch/main/install.sh -o nupst-install.sh"
echo " sudo bash nupst-install.sh"
echo ""
echo "For non-interactive installation with automatic dependency installation:"
echo "For non-interactive installation with auto-confirm:"
echo " curl -sSL https://code.foss.global/serve.zone/nupst/raw/branch/main/install.sh | sudo bash -s -- -y"
exit 1
else
@@ -86,211 +116,203 @@ if [ ! -t 0 ] || [ ! -t 1 ]; then
fi
fi
# Helper function to detect OS type
detect_os() {
if [ -f /etc/os-release ]; then
. /etc/os-release
OS=$ID
elif type lsb_release >/dev/null 2>&1; then
OS=$(lsb_release -si | tr '[:upper:]' '[:lower:]')
elif [ -f /etc/lsb-release ]; then
. /etc/lsb-release
OS=$DISTRIB_ID
elif [ -f /etc/debian_version ]; then
OS="debian"
elif [ -f /etc/redhat-release ]; then
if grep -q "CentOS" /etc/redhat-release; then
OS="centos"
elif grep -q "Fedora" /etc/redhat-release; then
OS="fedora"
else
OS="rhel"
fi
else
OS=$(uname -s)
fi
echo $OS
}
# Helper function to detect OS and architecture
detect_platform() {
local os=$(uname -s)
local arch=$(uname -m)
# Helper function to install git
install_git() {
OS=$(detect_os)
echo "Detected OS: $OS"
case "$OS" in
ubuntu|debian|pop|mint|elementary|kali|zorin)
echo "Installing git using apt..."
apt-get update && apt-get install -y git
# Map OS
case "$os" in
Linux)
os_name="linux"
;;
fedora|rhel|centos|almalinux|rocky)
echo "Installing git using dnf/yum..."
if command -v dnf &> /dev/null; then
dnf install -y git
else
yum install -y git
fi
Darwin)
os_name="macos"
;;
arch|manjaro|endeavouros|garuda)
echo "Installing git using pacman..."
pacman -Sy --noconfirm git
;;
opensuse*|suse|sles)
echo "Installing git using zypper..."
zypper install -y git
;;
alpine)
echo "Installing git using apk..."
apk add git
MINGW*|MSYS*|CYGWIN*)
os_name="windows"
;;
*)
echo "Unsupported OS: $OS"
echo "Please install git manually and run the installer again."
echo "Error: Unsupported operating system: $os"
echo "Supported: Linux, macOS, Windows"
exit 1
;;
esac
# Check if git was installed successfully
if ! command -v git &> /dev/null; then
echo "Failed to install git. Please install git manually and run the installer again."
exit 1
# Map architecture
case "$arch" in
x86_64|amd64)
arch_name="x64"
;;
aarch64|arm64)
arch_name="arm64"
;;
*)
echo "Error: Unsupported architecture: $arch"
echo "Supported: x86_64/amd64 (x64), aarch64/arm64 (arm64)"
exit 1
;;
esac
# Construct binary name
if [ "$os_name" = "windows" ]; then
echo "nupst-${os_name}-${arch_name}.exe"
else
echo "nupst-${os_name}-${arch_name}"
fi
echo "Git installed successfully."
}
# Define installation directory
INSTALL_DIR="/opt/nupst"
REPO_URL="https://code.foss.global/serve.zone/nupst.git"
# Get latest release version from Gitea API
get_latest_version() {
echo "Fetching latest release version from Gitea..." >&2
# Check if git is installed - needed for both piped and direct execution
if ! command -v git &> /dev/null; then
echo "Git is required but not installed."
if [ $AUTO_YES -eq 1 ]; then
echo "Auto-installing git (-y flag provided)..."
install_git
elif [ $INTERACTIVE -eq 1 ]; then
# If interactive and no -y flag, ask the user
echo "Would you like to install git now? (y/N): "
read -r install_git_prompt
if [[ "$install_git_prompt" =~ ^[Yy]$ ]]; then
install_git
else
echo "Git installation skipped. Please install git manually and run the installer again."
echo "Alternatively, you can run the installer with -y flag to automatically install git:"
echo " sudo bash install.sh -y"
exit 1
fi
else
# Non-interactive mode without -y flag
echo "Error: Git is required but not installed."
echo "In non-interactive mode, use -y flag to auto-install dependencies:"
echo " curl -sSL https://code.foss.global/serve.zone/nupst/raw/branch/main/install.sh | sudo bash -s -- -y"
local api_url="${GITEA_BASE_URL}/api/v1/repos/${GITEA_REPO}/releases/latest"
local response=$(curl -sSL "$api_url" 2>/dev/null)
if [ $? -ne 0 ] || [ -z "$response" ]; then
echo "Error: Failed to fetch latest release information from Gitea API" >&2
echo "URL: $api_url" >&2
exit 1
fi
fi
if [ $PIPED -eq 1 ]; then
echo "Installing NUPST from remote repository..."
# Check if installation directory exists
if [ -d "$INSTALL_DIR" ] && [ -d "$INSTALL_DIR/.git" ]; then
echo "Existing installation found at $INSTALL_DIR. Updating..."
cd "$INSTALL_DIR"
# Try to update the repository
git fetch origin
git reset --hard origin/main
if [ $? -ne 0 ]; then
echo "Failed to update repository. Reinstalling..."
cd /
rm -rf "$INSTALL_DIR"
mkdir -p "$INSTALL_DIR"
git clone --depth 1 $REPO_URL "$INSTALL_DIR"
else
echo "Repository updated successfully."
fi
else
# Fresh installation
if [ -d "$INSTALL_DIR" ]; then
echo "Removing previous installation at $INSTALL_DIR..."
rm -rf "$INSTALL_DIR"
fi
# Create installation directory
mkdir -p "$INSTALL_DIR"
# Clone the repository
echo "Cloning NUPST repository to $INSTALL_DIR..."
git clone --depth 1 $REPO_URL "$INSTALL_DIR"
fi
if [ $? -ne 0 ]; then
echo "Failed to clone/update repository. Please check your internet connection."
# Extract tag_name from JSON response
local version=$(echo "$response" | grep -o '"tag_name":"[^"]*"' | cut -d'"' -f4)
if [ -z "$version" ]; then
echo "Error: Could not determine latest version from API response" >&2
exit 1
fi
# Set script directory to the cloned repo
SCRIPT_DIR="$INSTALL_DIR"
echo "$version"
}
# Main installation process
echo "================================================"
echo " NUPST Installation Script (v4.0+)"
echo "================================================"
echo ""
# Detect platform
BINARY_NAME=$(detect_platform)
echo "Detected platform: $BINARY_NAME"
echo ""
# Determine version to install
if [ -n "$SPECIFIED_VERSION" ]; then
VERSION="$SPECIFIED_VERSION"
echo "Installing specified version: $VERSION"
else
# Running directly from within the repo or downloaded script
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
# When running from a downloaded script in a different location
# we need to clone the repository first
if [ ! -f "$SCRIPT_DIR/setup.sh" ]; then
echo "Running installer from downloaded script outside repository."
echo "Will clone the repository to $INSTALL_DIR..."
# Create installation directory if needed
if [ -d "$INSTALL_DIR" ]; then
echo "Removing previous installation at $INSTALL_DIR..."
rm -rf "$INSTALL_DIR"
VERSION=$(get_latest_version)
echo "Installing latest version: $VERSION"
fi
echo ""
# Construct download URL
DOWNLOAD_URL="${GITEA_BASE_URL}/${GITEA_REPO}/releases/download/${VERSION}/${BINARY_NAME}"
echo "Download URL: $DOWNLOAD_URL"
echo ""
# Check if installation directory exists
if [ -d "$INSTALL_DIR" ]; then
if [ $AUTO_YES -eq 0 ] && [ $INTERACTIVE -eq 1 ]; then
echo "Installation directory already exists: $INSTALL_DIR"
echo "Do you want to update/reinstall? (Y/n): "
read -r update_confirm
if [[ "$update_confirm" =~ ^[Nn]$ ]]; then
echo "Installation cancelled."
exit 0
fi
mkdir -p "$INSTALL_DIR"
# Clone the repository
echo "Cloning NUPST repository to $INSTALL_DIR..."
git clone --depth 1 $REPO_URL "$INSTALL_DIR"
if [ $? -ne 0 ]; then
echo "Failed to clone repository. Please check your internet connection."
exit 1
fi
# Update script directory to use the cloned repo
SCRIPT_DIR="$INSTALL_DIR"
fi
echo "Updating existing installation at $INSTALL_DIR..."
else
if [ $AUTO_YES -eq 0 ] && [ $INTERACTIVE -eq 1 ]; then
echo "NUPST will be installed to: $INSTALL_DIR"
echo "Continue? (Y/n): "
read -r install_confirm
if [[ "$install_confirm" =~ ^[Nn]$ ]]; then
echo "Installation cancelled."
exit 0
fi
fi
echo "Creating installation directory: $INSTALL_DIR"
mkdir -p "$INSTALL_DIR"
fi
# Run setup script
echo "Running setup script..."
if [ ! -f "$SCRIPT_DIR/setup.sh" ]; then
echo "ERROR: Setup script not found at $SCRIPT_DIR/setup.sh"
echo "Current directory: $(pwd)"
echo "Script directory: $SCRIPT_DIR"
ls -la "$SCRIPT_DIR"
# Download binary
echo "Downloading NUPST binary..."
TEMP_FILE="$INSTALL_DIR/nupst.download"
curl -sSL "$DOWNLOAD_URL" -o "$TEMP_FILE"
if [ $? -ne 0 ]; then
echo "Error: Failed to download binary from $DOWNLOAD_URL"
echo ""
echo "Please check:"
echo " 1. Your internet connection"
echo " 2. The specified version exists: ${GITEA_BASE_URL}/${GITEA_REPO}/releases"
echo " 3. The platform binary is available for this release"
rm -f "$TEMP_FILE"
exit 1
fi
bash "$SCRIPT_DIR/setup.sh"
# Install globally
echo "Installing NUPST globally..."
ln -sf "$SCRIPT_DIR/bin/nupst" /usr/local/bin/nupst
# Installation completed
if [ $PIPED -eq 1 ]; then
echo "NUPST has been installed globally at $INSTALL_DIR"
else
echo "NUPST has been installed globally."
# Check if download was successful (file exists and not empty)
if [ ! -s "$TEMP_FILE" ]; then
echo "Error: Downloaded file is empty or does not exist"
rm -f "$TEMP_FILE"
exit 1
fi
echo "You can now run 'nupst' from anywhere."
# Move to final location
BINARY_PATH="$INSTALL_DIR/nupst"
mv "$TEMP_FILE" "$BINARY_PATH"
# Make executable
chmod +x "$BINARY_PATH"
echo "Binary installed successfully to: $BINARY_PATH"
echo ""
echo "To get started, try:"
# Check if /usr/local/bin is in PATH
if [[ ":$PATH:" == *":/usr/local/bin:"* ]]; then
BIN_DIR="/usr/local/bin"
else
BIN_DIR="/usr/bin"
fi
# Create symlink for global access
if [ $AUTO_YES -eq 0 ] && [ $INTERACTIVE -eq 1 ]; then
echo "Create symlink in $BIN_DIR for global access? (Y/n): "
read -r symlink_confirm
if [[ ! "$symlink_confirm" =~ ^[Nn]$ ]]; then
ln -sf "$BINARY_PATH" "$BIN_DIR/nupst"
echo "Symlink created: $BIN_DIR/nupst -> $BINARY_PATH"
else
echo "Symlink creation skipped."
echo "To use NUPST, run: $BINARY_PATH"
echo "Or manually create symlink: sudo ln -sf $BINARY_PATH $BIN_DIR/nupst"
fi
else
ln -sf "$BINARY_PATH" "$BIN_DIR/nupst"
echo "Symlink created: $BIN_DIR/nupst -> $BINARY_PATH"
fi
echo ""
echo "================================================"
echo " NUPST Installation Complete!"
echo "================================================"
echo ""
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 setup # To configure your UPS connection"
echo " nupst ups add # Add a UPS device"
echo " nupst service enable # Enable systemd service"
echo ""