From 55c040df8280339356adf99c0c8f1fd595fe14d8 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Tue, 25 Mar 2025 13:08:28 +0000 Subject: [PATCH] fix(install): Improve interactive mode detection and non-interactive installation handling in install.sh --- changelog.md | 8 ++++++++ install.sh | 36 ++++++++++++++++++++++++++++++++++-- readme.md | 5 +++++ ts/00_commitinfo_data.ts | 2 +- 4 files changed, 48 insertions(+), 3 deletions(-) diff --git a/changelog.md b/changelog.md index 6f6e301..980f8ba 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,13 @@ # Changelog +## 2025-03-25 - 2.4.4 - fix(install) +Improve interactive mode detection and non-interactive installation handling in install.sh + +- Detect and warn when running without a controlling terminal +- Attempt to use /dev/tty for user input when possible +- Update prompts and error messages for auto-installation of dependencies +- Clarify installation instructions in readme for interactive and non-interactive modes + ## 2025-03-25 - 2.4.3 - fix(readme) Update Quick Install command syntax in readme for auto-yes installation diff --git a/install.sh b/install.sh index 9945a0d..e974a0b 100644 --- a/install.sh +++ b/install.sh @@ -50,11 +50,35 @@ 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 + if [ $AUTO_YES -ne 1 ]; then + echo "Warning: Running in non-interactive mode without -y flag." + echo "Will ask for confirmation via controlling terminal." + # 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 + + if [ $INTERACTIVE -eq 0 ]; then + echo "No controlling terminal available. To run non-interactively, use:" + echo " curl -sSL https://code.foss.global/serve.zone/nupst/raw/branch/main/install.sh | sudo bash -s -- -y" + exit 1 + fi + fi +fi + # Helper function to detect OS type detect_os() { if [ -f /etc/os-release ]; then @@ -141,8 +165,10 @@ if [ $PIPED -eq 1 ]; then if [ $AUTO_YES -eq 1 ]; then echo "Auto-installing git (-y flag provided)..." install_git - else - read -p "Would you like to install git now? (y/N): " install_git_prompt + 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 @@ -152,6 +178,12 @@ if [ $PIPED -eq 1 ]; then 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" + exit 1 fi fi diff --git a/readme.md b/readme.md index 79bd9cf..91764be 100644 --- a/readme.md +++ b/readme.md @@ -20,6 +20,11 @@ NUPST is a command-line tool that monitors SNMP-enabled UPS devices and initiate ```bash # Install directly without cloning the repository (requires root privileges) +# This will interactively prompt for installing any dependencies +curl -sSL https://code.foss.global/serve.zone/nupst/raw/branch/main/install.sh | sudo bash + +# Install with auto-yes for dependencies (will install git automatically if needed) +# Use this for automated/non-interactive installations curl -sSL https://code.foss.global/serve.zone/nupst/raw/branch/main/install.sh | sudo bash -c "bash -s -- -y" ``` diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index d5fb6de..2ca5ab3 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@serve.zone/nupst', - version: '2.4.3', + version: '2.4.4', description: 'Node.js UPS Shutdown Tool for SNMP-enabled UPS devices' }