migration/deno-v4 #1

Merged
philkunz merged 28 commits from migration/deno-v4 into main 2025-10-19 15:14:04 +00:00
11 changed files with 686 additions and 10928 deletions
Showing only changes of commit df6a44d5d9 - Show all commits

174
.gitea/workflows/README.md Normal file
View File

@@ -0,0 +1,174 @@
# Gitea Actions Workflows
This directory contains automated workflows for NUPST's CI/CD pipeline.
## Workflows
### CI Workflow (`ci.yml`)
**Triggers:**
- Push to `main` branch
- Push to `migration/**` branches
- Pull requests to `main`
**Jobs:**
1. **Type Check & Lint**
- Runs `deno check` for TypeScript validation
- Runs `deno lint` (continues on error)
- Runs `deno fmt --check` (continues on error)
2. **Build Test (Current Platform)**
- Compiles for Linux x86_64 (host platform)
- Tests binary execution (`--version` and `help`)
3. **Build All Platforms** (Main/Tags only)
- Compiles all 5 platform binaries
- Uploads as artifacts (30-day retention)
- Only runs on `main` branch or tags
### Release Workflow (`release.yml`)
**Triggers:**
- Push tags matching `v*` (e.g., `v4.0.0`)
**Jobs:**
1. **Version Verification**
- Extracts version from tag
- Verifies `deno.json` version matches tag
- Fails if mismatch detected
2. **Compilation**
- Compiles binaries for all 5 platforms:
- `nupst-linux-x64` (Linux x86_64)
- `nupst-linux-arm64` (Linux ARM64)
- `nupst-macos-x64` (macOS Intel)
- `nupst-macos-arm64` (macOS Apple Silicon)
- `nupst-windows-x64.exe` (Windows x64)
3. **Checksums**
- Generates SHA256 checksums for all binaries
- Creates `SHA256SUMS.txt`
4. **Release Creation**
- Creates Gitea release with tag
- Extracts release notes from CHANGELOG.md (if exists)
- Uploads all binaries + checksums as release assets
## Creating a Release
### Prerequisites
1. Update version in `deno.json`:
```json
{
"version": "4.0.0"
}
```
2. Update `CHANGELOG.md` with release notes (optional but recommended)
3. Commit all changes:
```bash
git add .
git commit -m "chore: bump version to 4.0.0"
```
### Release Process
1. Create and push a tag matching the version:
```bash
git tag v4.0.0
git push origin v4.0.0
```
2. Gitea Actions will automatically:
- Verify version consistency
- Compile all platform binaries
- Generate checksums
- Create release with binaries attached
3. Monitor the workflow:
- Go to: `https://code.foss.global/serve.zone/nupst/actions`
- Check the "Release" workflow run
### Manual Release (Fallback)
If workflows fail, you can create a release manually:
```bash
# Compile all binaries
bash scripts/compile-all.sh
# Generate checksums
cd dist/binaries
sha256sum * > SHA256SUMS.txt
cd ../..
# Create release on Gitea UI
# Upload binaries manually
```
## Troubleshooting
### Version Mismatch Error
If the release workflow fails with "Version mismatch":
- Ensure `deno.json` version matches the git tag
- Example: tag `v4.0.0` requires `"version": "4.0.0"` in deno.json
### Compilation Errors
If compilation fails:
1. Test locally: `bash scripts/compile-all.sh`
2. Check Deno version compatibility
3. Review TypeScript errors: `deno check mod.ts`
### Upload Failures
If binary upload fails:
1. Check Gitea Actions permissions
2. Verify `GITHUB_TOKEN` secret exists (auto-provided by Gitea)
3. Try manual release creation
## Workflow Secrets
The workflows use the following secrets:
- `GITHUB_TOKEN` - Auto-provided by Gitea Actions (no setup needed)
## Development
### Testing Workflows Locally
You can test compilation locally:
```bash
# Install Deno
curl -fsSL https://deno.land/install.sh | sh
# Test type checking
deno check mod.ts
# Test compilation
bash scripts/compile-all.sh
# Test binary
./dist/binaries/nupst-linux-x64 --version
```
### Modifying Workflows
After modifying workflows:
1. Test syntax: Use a YAML validator
2. Commit changes: `git add .gitea/workflows/`
3. Push to feature branch first to test CI
4. Merge to main once verified
## Links
- Gitea Actions Documentation: https://docs.gitea.com/usage/actions/overview
- Deno Compile Documentation: https://docs.deno.com/runtime/manual/tools/compiler
- NUPST Repository: https://code.foss.global/serve.zone/nupst

85
.gitea/workflows/ci.yml Normal file
View File

@@ -0,0 +1,85 @@
name: CI
on:
push:
branches:
- main
- 'migration/**'
pull_request:
branches:
- main
jobs:
check:
name: Type Check & Lint
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Deno
uses: denoland/setup-deno@v1
with:
deno-version: v1.x
- name: Check TypeScript types
run: deno check mod.ts
- name: Lint code
run: deno lint
continue-on-error: true
- name: Format check
run: deno fmt --check
continue-on-error: true
build:
name: Build Test (Current Platform)
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Deno
uses: denoland/setup-deno@v1
with:
deno-version: v1.x
- name: Compile for current platform
run: |
echo "Testing compilation for Linux x86_64..."
deno compile --allow-all --no-check \
--output nupst-test \
--target x86_64-unknown-linux-gnu mod.ts
- name: Test binary execution
run: |
chmod +x nupst-test
./nupst-test --version
./nupst-test help
build-all:
name: Build All Platforms (Tag/Main only)
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Deno
uses: denoland/setup-deno@v1
with:
deno-version: v1.x
- name: Compile all platform binaries
run: bash scripts/compile-all.sh
- name: Upload binaries as artifacts
uses: actions/upload-artifact@v4
with:
name: nupst-binaries
path: dist/binaries/*
retention-days: 30

View File

@@ -0,0 +1,182 @@
name: Release
on:
push:
tags:
- 'v*'
jobs:
build-and-release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Deno
uses: denoland/setup-deno@v1
with:
deno-version: v1.x
- name: Get version from tag
id: version
run: |
VERSION=${GITHUB_REF#refs/tags/}
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "version_number=${VERSION#v}" >> $GITHUB_OUTPUT
echo "Building version: $VERSION"
- name: Verify deno.json version matches tag
run: |
DENO_VERSION=$(grep -o '"version": "[^"]*"' deno.json | cut -d'"' -f4)
TAG_VERSION="${{ steps.version.outputs.version_number }}"
echo "deno.json version: $DENO_VERSION"
echo "Tag version: $TAG_VERSION"
if [ "$DENO_VERSION" != "$TAG_VERSION" ]; then
echo "ERROR: Version mismatch!"
echo "deno.json has version $DENO_VERSION but tag is $TAG_VERSION"
exit 1
fi
- name: Compile binaries for all platforms
run: |
echo "================================================"
echo " NUPST Release Compilation"
echo " Version: ${{ steps.version.outputs.version }}"
echo "================================================"
echo ""
mkdir -p dist/binaries
# Linux x86_64
echo "→ Compiling for Linux x86_64..."
deno compile --allow-all --no-check \
--output dist/binaries/nupst-linux-x64 \
--target x86_64-unknown-linux-gnu mod.ts
echo " ✓ Linux x86_64 complete"
# Linux ARM64
echo "→ Compiling for Linux ARM64..."
deno compile --allow-all --no-check \
--output dist/binaries/nupst-linux-arm64 \
--target aarch64-unknown-linux-gnu mod.ts
echo " ✓ Linux ARM64 complete"
# macOS x86_64
echo "→ Compiling for macOS x86_64..."
deno compile --allow-all --no-check \
--output dist/binaries/nupst-macos-x64 \
--target x86_64-apple-darwin mod.ts
echo " ✓ macOS x86_64 complete"
# macOS ARM64
echo "→ Compiling for macOS ARM64..."
deno compile --allow-all --no-check \
--output dist/binaries/nupst-macos-arm64 \
--target aarch64-apple-darwin mod.ts
echo " ✓ macOS ARM64 complete"
# Windows x86_64
echo "→ Compiling for Windows x86_64..."
deno compile --allow-all --no-check \
--output dist/binaries/nupst-windows-x64.exe \
--target x86_64-pc-windows-msvc mod.ts
echo " ✓ Windows x86_64 complete"
echo ""
echo "All binaries compiled successfully!"
ls -lh dist/binaries/
- name: Generate SHA256 checksums
run: |
cd dist/binaries
sha256sum * > SHA256SUMS.txt
cat SHA256SUMS.txt
cd ../..
- name: Extract changelog for this version
id: changelog
run: |
VERSION="${{ steps.version.outputs.version }}"
# Check if CHANGELOG.md exists
if [ ! -f CHANGELOG.md ]; then
echo "No CHANGELOG.md found, using default release notes"
cat > /tmp/release_notes.md << EOF
## NUPST $VERSION
Pre-compiled binaries for multiple platforms.
### Installation
Use the installation script:
\`\`\`bash
curl -sSL https://code.foss.global/serve.zone/nupst/raw/branch/main/install.sh | sudo bash
\`\`\`
Or download the binary for your platform and make it executable.
### Supported Platforms
- Linux x86_64 (x64)
- Linux ARM64 (aarch64)
- macOS x86_64 (Intel)
- macOS ARM64 (Apple Silicon)
- Windows x86_64
### Checksums
SHA256 checksums are provided in SHA256SUMS.txt
EOF
else
# Try to extract section for this version from CHANGELOG.md
# This is a simple extraction - adjust based on your CHANGELOG format
awk "/## \[$VERSION\]/,/## \[/" CHANGELOG.md | sed '$d' > /tmp/release_notes.md || cat > /tmp/release_notes.md << EOF
## NUPST $VERSION
See CHANGELOG.md for full details.
### Installation
Use the installation script:
\`\`\`bash
curl -sSL https://code.foss.global/serve.zone/nupst/raw/branch/main/install.sh | sudo bash
\`\`\`
EOF
fi
echo "Release notes:"
cat /tmp/release_notes.md
- name: Create Gitea Release
uses: actions/gitea-release-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag_name: ${{ steps.version.outputs.version }}
name: NUPST ${{ steps.version.outputs.version }}
body_path: /tmp/release_notes.md
draft: false
prerelease: false
files: |
dist/binaries/nupst-linux-x64
dist/binaries/nupst-linux-arm64
dist/binaries/nupst-macos-x64
dist/binaries/nupst-macos-arm64
dist/binaries/nupst-windows-x64.exe
dist/binaries/SHA256SUMS.txt
- name: Release Summary
run: |
echo "================================================"
echo " Release ${{ steps.version.outputs.version }} Complete!"
echo "================================================"
echo ""
echo "Binaries published:"
ls -lh dist/binaries/
echo ""
echo "Release URL:"
echo "https://code.foss.global/serve.zone/nupst/releases/tag/${{ steps.version.outputs.version }}"
echo ""
echo "Installation command:"
echo "curl -sSL https://code.foss.global/serve.zone/nupst/raw/branch/main/install.sh | sudo bash"
echo ""

20
.gitignore vendored
View File

@@ -1,15 +1,18 @@
# Build
dist*/
# Compiled Deno binaries (built by scripts/compile-all.sh)
dist/binaries/
# Dependencies
# Deno cache and lock file
.deno/
deno.lock
# Legacy Node.js artifacts (v3.x and earlier - kept for safety)
node_modules/
# Bundled Node.js binaries
vendor/
dist_ts/
npm-debug.log*
# Logs
*.log
npm-debug.log*
# Environment
.env
@@ -18,8 +21,5 @@ npm-debug.log*
.DS_Store
Thumbs.db
# Development
.nogit/
# Deno
.deno/
deno.lock

View File

@@ -1,96 +0,0 @@
#!/bin/bash
# NUPST Launcher Script
# This script detects architecture and OS, then runs NUPST with the appropriate Node.js binary
# First, handle symlinks correctly
REAL_SCRIPT_PATH=$(readlink -f "${BASH_SOURCE[0]}")
SCRIPT_DIR=$(dirname "$REAL_SCRIPT_PATH")
# For debugging
# echo "Script path: $REAL_SCRIPT_PATH"
# echo "Script dir: $SCRIPT_DIR"
# If we're run via symlink from /usr/local/bin, use the hardcoded installation path
if [[ "$SCRIPT_DIR" == "/usr/local/bin" ]]; then
PROJECT_ROOT="/opt/nupst"
else
# Otherwise, use relative path from script location
PROJECT_ROOT="$( cd "$SCRIPT_DIR/.." &> /dev/null && pwd )"
fi
# For debugging
# echo "Project root: $PROJECT_ROOT"
# Detect architecture and OS
ARCH=$(uname -m)
OS=$(uname -s)
# Determine Node.js binary location based on architecture and OS
NODE_BIN=""
case "$OS" in
Linux)
case "$ARCH" in
x86_64)
NODE_BIN="$PROJECT_ROOT/vendor/node-linux-x64/bin/node"
;;
aarch64|arm64)
NODE_BIN="$PROJECT_ROOT/vendor/node-linux-arm64/bin/node"
;;
*)
# Use system Node as fallback for other architectures
if command -v node &> /dev/null; then
NODE_BIN="node"
echo "Using system Node.js installation for unsupported architecture: $ARCH"
fi
;;
esac
;;
Darwin)
case "$ARCH" in
x86_64)
NODE_BIN="$PROJECT_ROOT/vendor/node-darwin-x64/bin/node"
;;
arm64)
NODE_BIN="$PROJECT_ROOT/vendor/node-darwin-arm64/bin/node"
;;
*)
# Use system Node as fallback for other architectures
if command -v node &> /dev/null; then
NODE_BIN="node"
echo "Using system Node.js installation for unsupported architecture: $ARCH"
fi
;;
esac
;;
*)
# Use system Node as fallback for other operating systems
if command -v node &> /dev/null; then
NODE_BIN="node"
echo "Using system Node.js installation for unsupported OS: $OS"
fi
;;
esac
# If binary doesn't exist, try system Node as fallback
if [ -z "$NODE_BIN" ] || [ ! -f "$NODE_BIN" ]; then
if command -v node &> /dev/null; then
NODE_BIN="node"
echo "Using system Node.js installation"
else
echo "Error: Node.js binary not found for $OS-$ARCH"
echo "Please run the setup script or install Node.js manually."
exit 1
fi
fi
# Run NUPST with the Node.js binary
if [ -f "$PROJECT_ROOT/dist_ts/index.js" ]; then
exec "$NODE_BIN" "$PROJECT_ROOT/dist_ts/index.js" "$@"
elif [ -f "$PROJECT_ROOT/dist/index.js" ]; then
exec "$NODE_BIN" "$PROJECT_ROOT/dist/index.js" "$@"
else
echo "Error: Could not find NUPST's index.js file."
echo "Please run the setup script to download the required files."
exit 1
fi

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 ""

View File

@@ -1 +0,0 @@
{}

View File

@@ -1,61 +0,0 @@
{
"name": "@serve.zone/nupst",
"version": "3.1.2",
"description": "Node.js UPS Shutdown Tool for SNMP-enabled UPS devices",
"main": "dist/index.js",
"bin": {
"nupst": "bin/nupst"
},
"type": "module",
"scripts": {
"build": "tsbuild tsfolders --allowimplicitany",
"start": "bin/nupst",
"setup": "bash setup.sh",
"test": "tstest test/",
"install-global": "sudo bash install.sh",
"uninstall": "sudo bash uninstall.sh"
},
"keywords": [
"ups",
"snmp",
"shutdown",
"node",
"cli"
],
"files": [
"ts/**/*",
"ts_web/**/*",
"dist/**/*",
"dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
"npmextra.json",
"readme.md"
],
"author": "",
"license": "MIT",
"dependencies": {
"net-snmp": "3.20.0"
},
"devDependencies": {
"@git.zone/tsbuild": "^2.3.2",
"@git.zone/tsrun": "^1.3.3",
"@git.zone/tstest": "^1.0.96",
"@push.rocks/qenv": "^6.1.0",
"@push.rocks/tapbundle": "^5.6.0",
"@types/node": "^20.11.0"
},
"engines": {
"node": ">=16.0.0"
},
"pnpm": {
"onlyBuiltDependencies": [
"esbuild",
"mongodb-memory-server",
"puppeteer"
]
},
"packageManager": "pnpm@10.7.0+sha512.6b865ad4b62a1d9842b61d674a393903b871d9244954f652b8842c2b553c72176b278f64c463e52d40fff8aba385c235c8c9ecf5cc7de4fd78b8bb6d49633ab6"
}

10204
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

328
setup.sh
View File

@@ -1,328 +0,0 @@
#!/bin/bash
# NUPST Setup Script
# Downloads the appropriate Node.js binary for the current platform
# and installs production dependencies
# Parse command line arguments
FORCE_UPDATE=0
for arg in "$@"; do
case $arg in
--force|-f)
FORCE_UPDATE=1
shift
;;
*)
# Unknown option
;;
esac
done
# Find the directory where this script is located
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
# Create vendor directory if it doesn't exist
mkdir -p "$SCRIPT_DIR/vendor"
# Get the latest LTS Node.js version
echo "Determining latest LTS Node.js version..."
NODE_VERSIONS_JSON=$(curl -s https://nodejs.org/dist/index.json)
if [ $? -ne 0 ]; then
echo "Warning: Could not fetch latest Node.js versions. Using fallback version."
NODE_VERSION="20.11.1" # Fallback to a recent LTS version
else
# Extract the latest LTS version (those marked with lts field)
NODE_VERSION=$(echo "$NODE_VERSIONS_JSON" | grep -o '"version":"v[0-9.]*".*"lts":[^,]*' | grep -v '"lts":false' | grep -o 'v[0-9.]*' | head -1 | cut -c 2-)
if [ -z "$NODE_VERSION" ]; then
echo "Warning: Could not determine latest LTS version. Using fallback version."
NODE_VERSION="20.11.1" # Fallback to a recent LTS version
else
echo "Latest Node.js LTS version: $NODE_VERSION"
fi
fi
# Detect architecture
ARCH=$(uname -m)
OS=$(uname -s)
# Map architecture and OS to Node.js download URL
NODE_URL=""
NODE_DIR=""
case "$OS" in
Linux)
case "$ARCH" in
x86_64)
NODE_URL="https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.gz"
NODE_DIR="node-linux-x64"
;;
aarch64|arm64)
NODE_URL="https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-arm64.tar.gz"
NODE_DIR="node-linux-arm64"
;;
*)
echo "Unsupported architecture: $ARCH. Please install Node.js manually."
exit 1
;;
esac
;;
Darwin)
case "$ARCH" in
x86_64)
NODE_URL="https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-darwin-x64.tar.gz"
NODE_DIR="node-darwin-x64"
;;
arm64)
NODE_URL="https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-darwin-arm64.tar.gz"
NODE_DIR="node-darwin-arm64"
;;
*)
echo "Unsupported architecture: $ARCH. Please install Node.js manually."
exit 1
;;
esac
;;
*)
echo "Unsupported operating system: $OS. Please install Node.js manually."
exit 1
;;
esac
# Check if we already have the Node.js binary
if [ -f "$SCRIPT_DIR/vendor/$NODE_DIR/bin/node" ] && [ $FORCE_UPDATE -eq 0 ]; then
echo "Node.js binary already exists for $OS-$ARCH. Skipping download."
echo "Use --force or -f to force update Node.js."
else
echo "Downloading Node.js v$NODE_VERSION for $OS-$ARCH..."
# Download and extract Node.js
TMP_FILE="$SCRIPT_DIR/vendor/node.tar.gz"
curl -L "$NODE_URL" -o "$TMP_FILE"
if [ $? -ne 0 ]; then
echo "Error downloading Node.js. Please check your internet connection and try again."
exit 1
fi
# Create target directory
mkdir -p "$SCRIPT_DIR/vendor/$NODE_DIR"
# Extract Node.js
tar -xzf "$TMP_FILE" -C "$SCRIPT_DIR/vendor"
# Move extracted files to the target directory
NODE_EXTRACT_DIR=$(find "$SCRIPT_DIR/vendor" -maxdepth 1 -name "node-v*" -type d | head -n 1)
if [ -d "$NODE_EXTRACT_DIR" ]; then
cp -R "$NODE_EXTRACT_DIR"/* "$SCRIPT_DIR/vendor/$NODE_DIR/"
rm -rf "$NODE_EXTRACT_DIR"
else
echo "Error extracting Node.js. Please try again."
exit 1
fi
# Clean up
rm "$TMP_FILE"
echo "Node.js v$NODE_VERSION for $OS-$ARCH has been downloaded and extracted."
fi
# Remove any existing dist_ts directory
if [ -d "$SCRIPT_DIR/dist_ts" ]; then
echo "Removing existing dist_ts directory..."
rm -rf "$SCRIPT_DIR/dist_ts"
fi
# Download dist_ts from npm registry
echo "Downloading dist_ts from npm registry..."
# Create temp directory
TEMP_DIR=$(mktemp -d)
# Get version from package.json
if [ -f "$SCRIPT_DIR/package.json" ]; then
echo "Reading version from package.json..."
# Extract version using grep and cut
VERSION=$(grep -o '"version": "[^"]*"' "$SCRIPT_DIR/package.json" | cut -d'"' -f4)
if [ -z "$VERSION" ]; then
echo "Error: Could not determine version from package.json."
rm -rf "$TEMP_DIR"
exit 1
fi
echo "Package version is $VERSION. Downloading matching package tarball..."
else
echo "Warning: package.json not found. Getting latest version from npm registry..."
VERSION=$(curl -s https://registry.npmjs.org/@serve.zone/nupst | grep -o '"latest":"[^"]*"' | cut -d'"' -f4)
if [ -z "$VERSION" ]; then
echo "Error: Could not determine version from npm registry."
rm -rf "$TEMP_DIR"
exit 1
fi
echo "Latest version is $VERSION. Using as fallback."
fi
# First try to download with the version from package.json
TARBALL_URL="https://registry.npmjs.org/@serve.zone/nupst/-/nupst-$VERSION.tgz"
TARBALL_PATH="$TEMP_DIR/nupst.tgz"
echo "Attempting to download version $VERSION from $TARBALL_URL..."
curl -sL "$TARBALL_URL" -o "$TARBALL_PATH"
# If download fails or file is empty, try to get the latest version from npm
if [ $? -ne 0 ] || [ ! -s "$TARBALL_PATH" ]; then
echo "Package version $VERSION not found on npm registry."
echo "Fetching latest version information from npm registry..."
# Get latest version from npm registry
NPM_REGISTRY_INFO=$(curl -s https://registry.npmjs.org/@serve.zone/nupst)
if [ $? -ne 0 ]; then
echo "Error: Could not connect to npm registry."
echo "Will attempt to build from source instead."
rm -rf "$TEMP_DIR"
mkdir -p "$SCRIPT_DIR/dist_ts"
BUILD_FROM_SOURCE=1
return 0
fi
# Extract latest version
LATEST_VERSION=$(echo "$NPM_REGISTRY_INFO" | grep -o '"latest":"[^"]*"' | cut -d'"' -f4)
if [ -z "$LATEST_VERSION" ]; then
echo "Error: Could not determine latest version from npm registry."
echo "Will attempt to build from source instead."
rm -rf "$TEMP_DIR"
mkdir -p "$SCRIPT_DIR/dist_ts"
BUILD_FROM_SOURCE=1
return 0
fi
echo "Found latest version: $LATEST_VERSION. Downloading..."
TARBALL_URL="https://registry.npmjs.org/@serve.zone/nupst/-/nupst-$LATEST_VERSION.tgz"
TARBALL_PATH="$TEMP_DIR/nupst.tgz"
curl -sL "$TARBALL_URL" -o "$TARBALL_PATH"
if [ $? -ne 0 ] || [ ! -s "$TARBALL_PATH" ]; then
echo "Error: Failed to download any package version from npm registry."
echo "Installation cannot continue without the dist_ts directory."
rm -rf "$TEMP_DIR"
exit 1
fi
fi
# Extract the tarball
mkdir -p "$TEMP_DIR/extract"
tar -xzf "$TARBALL_PATH" -C "$TEMP_DIR/extract"
# Copy dist_ts to the installation directory
if [ -d "$TEMP_DIR/extract/package/dist_ts" ]; then
echo "Copying dist_ts directory to installation..."
mkdir -p "$SCRIPT_DIR/dist_ts"
cp -R "$TEMP_DIR/extract/package/dist_ts/"* "$SCRIPT_DIR/dist_ts/"
else
echo "Error: dist_ts directory not found in the downloaded npm package."
rm -rf "$TEMP_DIR"
exit 1
fi
# Clean up
rm -rf "$TEMP_DIR"
echo "dist_ts directory successfully downloaded from npm registry."
# Make launcher script executable
chmod +x "$SCRIPT_DIR/bin/nupst"
# Set up Node.js binary path
NODE_BIN_DIR="$SCRIPT_DIR/vendor/$NODE_DIR/bin"
NODE_BIN="$NODE_BIN_DIR/node"
NPM_CLI_JS="$NODE_BIN_DIR/../lib/node_modules/npm/bin/npm-cli.js"
# Ensure we have executable permissions
chmod +x "$NODE_BIN"
# Make sure the npm-cli.js exists
if [ ! -f "$NPM_CLI_JS" ]; then
# Try to find npm-cli.js
NPM_CLI_JS=$(find "$NODE_BIN_DIR/.." -name "npm-cli.js" | head -1)
if [ -z "$NPM_CLI_JS" ]; then
echo "Warning: Could not find npm-cli.js, npm commands may fail"
# Set to a fallback value so code can continue
NPM_CLI_JS="$NODE_BIN_DIR/npm"
else
echo "Found npm-cli.js at: $NPM_CLI_JS"
fi
fi
# Display which binaries we're using
echo "Using Node binary: $NODE_BIN"
echo "Using NPM CLI JS: $NPM_CLI_JS"
# Remove existing node_modules directory and package files
echo "Cleaning up existing installation..."
rm -rf "$SCRIPT_DIR/node_modules"
rm -f "$SCRIPT_DIR/package-lock.json"
# Back up existing package.json if it exists
if [ -f "$SCRIPT_DIR/package.json" ]; then
echo "Backing up existing package.json..."
cp "$SCRIPT_DIR/package.json" "$SCRIPT_DIR/package.json.bak"
fi
# Create a clean minimal package.json with ONLY net-snmp dependency
echo "Creating minimal package.json with only net-snmp dependency..."
VERSION=$(grep -o '"version": "[^"]*"' "$SCRIPT_DIR/package.json.bak" | head -1 | cut -d'"' -f4 || echo "2.6.3")
echo '{
"name": "@serve.zone/nupst",
"version": "'$VERSION'",
"description": "Node.js UPS Shutdown Tool for SNMP-enabled UPS devices",
"main": "dist_ts/index.js",
"type": "module",
"bin": {
"nupst": "bin/nupst"
},
"dependencies": {
"net-snmp": "3.20.0"
},
"engines": {
"node": ">=16.0.0"
},
"private": true
}' > "$SCRIPT_DIR/package.json"
# Install ONLY net-snmp
echo "Installing ONLY net-snmp dependency (+ 2 subdependencies)..."
echo "Node version: $("$NODE_BIN" --version)"
echo "Executing NPM directly with Node.js"
# Execute npm-cli.js directly with our Node.js binary
"$NODE_BIN" "$NPM_CLI_JS" --prefix "$SCRIPT_DIR" install --no-audit --no-fund
INSTALL_STATUS=$?
if [ $INSTALL_STATUS -ne 0 ]; then
echo "Error: Failed to install net-snmp dependency. NUPST may not function correctly."
echo "Restoring original package.json..."
mv "$SCRIPT_DIR/package.json.bak" "$SCRIPT_DIR/package.json"
exit 1
else
echo "net-snmp dependency installed successfully."
# Show what's actually installed
echo "Installed modules:"
find "$SCRIPT_DIR/node_modules" -maxdepth 1 -type d | grep -v "^$SCRIPT_DIR/node_modules$" | sort
# Remove backup if successful
rm -f "$SCRIPT_DIR/package.json.bak"
fi
# No temporary files to clean up
echo "NUPST setup completed successfully."
echo "You can now run NUPST using: $SCRIPT_DIR/bin/nupst"
echo "To install NUPST globally, run: sudo ln -s $SCRIPT_DIR/bin/nupst /usr/local/bin/nupst"

View File

@@ -1,15 +0,0 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"verbatimModuleSyntax": true
},
"exclude": [
"dist_*/**/*.d.ts"
]
}