From 9665e86df14fbfbfca4f941fdf55de98d8513714 Mon Sep 17 00:00:00 2001 From: Pulse Monitor Date: Sun, 17 Aug 2025 11:11:26 +0000 Subject: [PATCH] feat: add command line arguments to install script (addresses #324) The install script now accepts arguments that work with piped execution: - --rc or --pre: Install latest RC/pre-release - --stable: Force stable version (default) - --version VERSION: Install specific version - --help: Show usage This allows users to update to RC versions with: curl -fsSL .../install.sh | bash -s -- --rc --- install.sh | 106 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 78 insertions(+), 28 deletions(-) diff --git a/install.sh b/install.sh index 7e49c46a6..c693d40a3 100755 --- a/install.sh +++ b/install.sh @@ -146,37 +146,49 @@ backup_existing() { download_pulse() { print_info "Downloading Pulse..." - # Check if user has RC channel configured - UPDATE_CHANNEL="stable" - - # Allow override via environment variable - if [[ "${PULSE_UPDATE_CHANNEL:-}" == "rc" ]]; then - UPDATE_CHANNEL="rc" - print_info "RC channel requested via environment variable" - elif [[ -f "$CONFIG_DIR/system.json" ]]; then - CONFIGURED_CHANNEL=$(cat "$CONFIG_DIR/system.json" 2>/dev/null | grep -o '"updateChannel"[[:space:]]*:[[:space:]]*"[^"]*"' | sed 's/.*"\([^"]*\)"$/\1/') - if [[ "$CONFIGURED_CHANNEL" == "rc" ]]; then - UPDATE_CHANNEL="rc" - print_info "RC channel detected in configuration" + # Check for forced version first + if [[ -n "${FORCE_VERSION}" ]]; then + LATEST_RELEASE="${FORCE_VERSION}" + print_info "Installing specific version: $LATEST_RELEASE" + + # Verify the version exists + if ! curl -fsS "https://api.github.com/repos/$GITHUB_REPO/releases/tags/$LATEST_RELEASE" > /dev/null 2>&1; then + print_error "Version $LATEST_RELEASE not found" + exit 1 fi - fi - - # Get appropriate release based on channel - if [[ "$UPDATE_CHANNEL" == "rc" ]]; then - # Get all releases and find the latest (including pre-releases) - LATEST_RELEASE=$(curl -s https://api.github.com/repos/$GITHUB_REPO/releases | grep '"tag_name":' | head -1 | sed -E 's/.*"([^"]+)".*/\1/') else - # Get latest stable release only - LATEST_RELEASE=$(curl -s https://api.github.com/repos/$GITHUB_REPO/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') + # Check if user has RC channel configured + UPDATE_CHANNEL="stable" + + # Allow override via command line + if [[ -n "${FORCE_CHANNEL}" ]]; then + UPDATE_CHANNEL="${FORCE_CHANNEL}" + print_info "Using $UPDATE_CHANNEL channel from command line" + elif [[ -f "$CONFIG_DIR/system.json" ]]; then + CONFIGURED_CHANNEL=$(cat "$CONFIG_DIR/system.json" 2>/dev/null | grep -o '"updateChannel"[[:space:]]*:[[:space:]]*"[^"]*"' | sed 's/.*"\([^"]*\)"$/\1/') + if [[ "$CONFIGURED_CHANNEL" == "rc" ]]; then + UPDATE_CHANNEL="rc" + print_info "RC channel detected in configuration" + fi + fi + + # Get appropriate release based on channel + if [[ "$UPDATE_CHANNEL" == "rc" ]]; then + # Get all releases and find the latest (including pre-releases) + LATEST_RELEASE=$(curl -s https://api.github.com/repos/$GITHUB_REPO/releases | grep '"tag_name":' | head -1 | sed -E 's/.*"([^"]+)".*/\1/') + else + # Get latest stable release only + LATEST_RELEASE=$(curl -s https://api.github.com/repos/$GITHUB_REPO/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') + fi + + if [[ -z "$LATEST_RELEASE" ]]; then + print_error "Could not determine latest release" + exit 1 + fi + + print_info "Latest version: $LATEST_RELEASE" fi - if [[ -z "$LATEST_RELEASE" ]]; then - print_error "Could not determine latest release" - exit 1 - fi - - print_info "Latest version: $LATEST_RELEASE" - # Detect architecture ARCH=$(uname -m) case $ARCH in @@ -392,5 +404,43 @@ main() { fi } +# Parse command line arguments +FORCE_VERSION="" +FORCE_CHANNEL="" + +while [[ $# -gt 0 ]]; do + case $1 in + --rc|--pre|--prerelease) + FORCE_CHANNEL="rc" + shift + ;; + --stable) + FORCE_CHANNEL="stable" + shift + ;; + --version) + FORCE_VERSION="$2" + shift 2 + ;; + -h|--help) + echo "Usage: $0 [OPTIONS]" + echo "Options:" + echo " --rc, --pre Install latest RC/pre-release version" + echo " --stable Install latest stable version (default)" + echo " --version VERSION Install specific version (e.g., v4.4.0-rc.1)" + echo " -h, --help Show this help message" + exit 0 + ;; + *) + print_error "Unknown option: $1" + echo "Use --help for usage information" + exit 1 + ;; + esac +done + +# Export for use in download_pulse function +export FORCE_VERSION FORCE_CHANNEL + # Run main function -main "$@" \ No newline at end of file +main \ No newline at end of file