Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
a87710144c | |||
23fd5cc5cd |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@serve.zone/nupst",
|
||||
"version": "4.0.4",
|
||||
"version": "4.0.5",
|
||||
"exports": "./mod.ts",
|
||||
"tasks": {
|
||||
"dev": "deno run --allow-all mod.ts",
|
||||
|
92
install.sh
92
install.sh
@@ -10,15 +10,7 @@
|
||||
# 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
|
||||
# --version VERSION Install specific version (e.g., v4.0.0)
|
||||
# --install-dir DIR Installation directory (default: /opt/nupst)
|
||||
@@ -26,7 +18,6 @@
|
||||
set -e
|
||||
|
||||
# Default values
|
||||
AUTO_YES=0
|
||||
SHOW_HELP=0
|
||||
SPECIFIED_VERSION=""
|
||||
INSTALL_DIR="/opt/nupst"
|
||||
@@ -36,10 +27,6 @@ GITEA_REPO="serve.zone/nupst"
|
||||
# Parse command line arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
-y|--yes)
|
||||
AUTO_YES=1
|
||||
shift
|
||||
;;
|
||||
-h|--help)
|
||||
SHOW_HELP=1
|
||||
shift
|
||||
@@ -67,7 +54,6 @@ if [ $SHOW_HELP -eq 1 ]; then
|
||||
echo "Usage: $0 [options]"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
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)"
|
||||
@@ -78,9 +64,6 @@ if [ $SHOW_HELP -eq 1 ]; then
|
||||
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
|
||||
|
||||
@@ -90,36 +73,6 @@ if [ "$EUID" -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Detect if script is being piped or run directly
|
||||
INTERACTIVE=1
|
||||
if [ ! -t 0 ] || [ ! -t 1 ]; then
|
||||
# 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 exec < /dev/tty 2>/dev/null && [ -t 0 ]; then
|
||||
INTERACTIVE=1
|
||||
else
|
||||
INTERACTIVE=0
|
||||
fi
|
||||
|
||||
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 auto-confirm:"
|
||||
echo " curl -sSL https://code.foss.global/serve.zone/nupst/raw/branch/main/install.sh | sudo bash -s -- -y"
|
||||
exit 1
|
||||
else
|
||||
echo "Interactive terminal found, continuing with prompts..."
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# Helper function to detect OS and architecture
|
||||
detect_platform() {
|
||||
local os=$(uname -s)
|
||||
@@ -229,22 +182,6 @@ if [ -d "$INSTALL_DIR" ]; then
|
||||
echo ""
|
||||
fi
|
||||
|
||||
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 "Do you want to update/reinstall? (Y/n): "
|
||||
read -r update_confirm
|
||||
|
||||
if [[ "$update_confirm" =~ ^[Nn]$ ]]; then
|
||||
echo "Installation cancelled."
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Updating existing installation at $INSTALL_DIR..."
|
||||
|
||||
# Check if service exists (enabled or running) and stop it if active
|
||||
@@ -273,17 +210,6 @@ if [ -d "$INSTALL_DIR" ]; then
|
||||
echo "Old installation files removed."
|
||||
fi
|
||||
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
|
||||
@@ -329,22 +255,8 @@ else
|
||||
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
|
||||
ln -sf "$BINARY_PATH" "$BIN_DIR/nupst"
|
||||
echo "Symlink created: $BIN_DIR/nupst -> $BINARY_PATH"
|
||||
|
||||
echo ""
|
||||
|
||||
|
16
readme.md
16
readme.md
@@ -29,15 +29,8 @@ dependencies.
|
||||
The easiest way to install NUPST is using the automated installer:
|
||||
|
||||
```bash
|
||||
# Download and run installer (most reliable)
|
||||
curl -sSL https://code.foss.global/serve.zone/nupst/raw/branch/main/install.sh -o nupst-install.sh
|
||||
sudo bash nupst-install.sh
|
||||
rm nupst-install.sh
|
||||
```
|
||||
|
||||
```bash
|
||||
# One-line installation (non-interactive with auto-confirm)
|
||||
curl -sSL https://code.foss.global/serve.zone/nupst/raw/branch/main/install.sh | sudo bash -s -- -y
|
||||
# One-line installation
|
||||
curl -sSL https://code.foss.global/serve.zone/nupst/raw/branch/main/install.sh | sudo bash
|
||||
```
|
||||
|
||||
The installer will:
|
||||
@@ -76,7 +69,6 @@ sudo mv nupst /usr/local/bin/nupst
|
||||
The installer script (`install.sh`) supports the following options:
|
||||
|
||||
```
|
||||
-y, --yes Automatically answer yes to all prompts
|
||||
-h, --help Show help message
|
||||
--version VERSION Install specific version (e.g., --version v4.0.0)
|
||||
--install-dir DIR Custom installation directory (default: /opt/nupst)
|
||||
@@ -373,7 +365,7 @@ sudo nupst service disable
|
||||
Re-run the installer to update to the latest version:
|
||||
|
||||
```bash
|
||||
curl -sSL https://code.foss.global/serve.zone/nupst/raw/branch/main/install.sh | sudo bash -s -- -y
|
||||
curl -sSL https://code.foss.global/serve.zone/nupst/raw/branch/main/install.sh | sudo bash
|
||||
```
|
||||
|
||||
The installer will:
|
||||
@@ -461,7 +453,7 @@ The installer script automatically handles the entire migration while preserving
|
||||
|
||||
```bash
|
||||
# Run the installer (handles stop/update/restart automatically)
|
||||
curl -sSL https://code.foss.global/serve.zone/nupst/raw/branch/main/install.sh | sudo bash -s -- -y
|
||||
curl -sSL https://code.foss.global/serve.zone/nupst/raw/branch/main/install.sh | sudo bash
|
||||
|
||||
# Verify
|
||||
nupst service status
|
||||
|
@@ -44,17 +44,30 @@ export class MigrationV3ToV4 extends BaseMigration {
|
||||
readonly toVersion = '4.0';
|
||||
|
||||
async shouldRun(config: any): Promise<boolean> {
|
||||
// V3 format has upsList instead of upsDevices
|
||||
return !!config.upsList && !config.upsDevices;
|
||||
// V3 format has upsList OR has upsDevices with flat structure (host at top level)
|
||||
if (config.upsList && !config.upsDevices) {
|
||||
return true; // Classic v3 with upsList
|
||||
}
|
||||
|
||||
// Check if upsDevices exists but has flat structure (v3 format)
|
||||
if (config.upsDevices && config.upsDevices.length > 0) {
|
||||
const firstDevice = config.upsDevices[0];
|
||||
// V3 has host at top level, v4 has it nested in snmp object
|
||||
return !!firstDevice.host && !firstDevice.snmp;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
async migrate(config: any): Promise<any> {
|
||||
logger.info(`${this.getName()}: Migrating v3 config to v4 format...`);
|
||||
logger.dim(` - Renaming upsList → upsDevices`);
|
||||
logger.dim(` - Restructuring UPS devices (flat → nested snmp config)`);
|
||||
|
||||
// Get devices from either upsList or upsDevices (for partially migrated configs)
|
||||
const sourceDevices = config.upsList || config.upsDevices;
|
||||
|
||||
// Transform each UPS device from v3 flat structure to v4 nested structure
|
||||
const transformedDevices = config.upsList.map((device: any) => {
|
||||
const transformedDevices = sourceDevices.map((device: any) => {
|
||||
// Build SNMP config object
|
||||
const snmpConfig: any = {
|
||||
host: device.host,
|
||||
|
Reference in New Issue
Block a user