From 1f1d2998f52340dbcb2f78f5ea3a3f5d8c74aa46 Mon Sep 17 00:00:00 2001 From: Pulse Monitor Date: Thu, 11 Sep 2025 16:29:42 +0000 Subject: [PATCH] fix: handle --main flag properly for existing installations (addresses #448) The install script now correctly builds from source when --main is specified, even if Pulse is already installed. Previously it would go into the update prompt instead of building from source. --- install.sh | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/install.sh b/install.sh index 4af25e0bc..5529f65e2 100755 --- a/install.sh +++ b/install.sh @@ -1717,6 +1717,87 @@ main() { # Check for existing installation FIRST before asking for configuration if check_existing_installation; then + # If building from source was requested, skip the update prompt + if [[ "$BUILD_FROM_SOURCE" == "true" ]]; then + print_info "Building Pulse from source (branch: $SOURCE_BRANCH)..." + + # Install build dependencies + print_info "Installing build dependencies..." + if ! (apt-get update >/dev/null 2>&1 && apt-get install -y git make nodejs npm wget >/dev/null 2>&1); then + print_error "Failed to install build dependencies" + exit 1 + fi + + # Check for Go installation + if ! command -v go &> /dev/null; then + print_info "Go is not installed. Installing Go 1.23..." + install_go + else + GO_VERSION=$(go version | grep -oP 'go\K[0-9]+\.[0-9]+') + if awk "BEGIN {exit !($GO_VERSION < 1.23)}"; then + print_info "Go version $GO_VERSION is too old. Installing Go 1.23..." + install_go + else + print_info "Go version $GO_VERSION is installed" + fi + fi + + # Clone and build + print_info "Cloning repository..." + TEMP_BUILD_DIR=$(mktemp -d) + cd "$TEMP_BUILD_DIR" + + if ! git clone -b "$SOURCE_BRANCH" "https://github.com/$GITHUB_REPO.git" pulse-src >/dev/null 2>&1; then + print_error "Failed to clone repository" + rm -rf "$TEMP_BUILD_DIR" + exit 1 + fi + + cd pulse-src + + print_info "Building Pulse..." + if ! make build >/dev/null 2>&1; then + print_error "Build failed" + cd / + rm -rf "$TEMP_BUILD_DIR" + exit 1 + fi + + # Detect service name before stopping + SERVICE_NAME=$(detect_service_name) + + # Stop existing service if running + if systemctl is-active --quiet $SERVICE_NAME 2>/dev/null; then + print_info "Stopping existing Pulse service..." + systemctl stop $SERVICE_NAME + fi + + # Install the built binary + print_info "Installing Pulse..." + create_user + setup_directories + + # Copy the built binary + cp bin/pulse "$INSTALL_DIR/bin/pulse" + chmod +x "$INSTALL_DIR/bin/pulse" + chown pulse:pulse "$INSTALL_DIR/bin/pulse" + + # Create symlink for backward compatibility + ln -sf "$INSTALL_DIR/bin/pulse" /usr/local/bin/pulse + + # Setup update command and service + setup_update_command + install_systemd_service + start_pulse + create_marker_file + + # Clean up + cd / + rm -rf "$TEMP_BUILD_DIR" + + print_completion + exit 0 + fi # If a specific version was requested, just update to it if [[ -n "${FORCE_VERSION}" ]]; then # Determine if this is an upgrade, downgrade, or reinstall