From dff6cdc1e2259a8b95ec630f72b6dc1ea6591fe4 Mon Sep 17 00:00:00 2001 From: Akizon77 Date: Fri, 27 Jun 2025 12:26:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8C=87=E5=AE=9A=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install.ps1 | 37 ++++++++++++++++++++++++++----------- install.sh | 37 ++++++++++++++++++++++++++----------- 2 files changed, 52 insertions(+), 22 deletions(-) diff --git a/install.ps1 b/install.ps1 index 469c98a..a5869ba 100644 --- a/install.ps1 +++ b/install.ps1 @@ -13,6 +13,7 @@ $InstallDir = Join-Path $Env:ProgramFiles "Komari" $ServiceName = "komari-agent" $GitHubProxy = "" $KomariArgs = @() +$InstallVersion = "" # Parse script arguments for ($i = 0; $i -lt $args.Count; $i++) { @@ -20,6 +21,7 @@ for ($i = 0; $i -lt $args.Count; $i++) { "--install-dir" { $InstallDir = $args[$i + 1]; $i++; continue } "--install-service-name" { $ServiceName = $args[$i + 1]; $i++; continue } "--install-ghproxy" { $GitHubProxy = $args[$i + 1]; $i++; continue } + "--install-version" { $InstallVersion = $args[$i + 1]; $i++; continue } Default { $KomariArgs += $args[$i] } } } @@ -158,6 +160,11 @@ Log-Config "Service name: $ServiceName" Log-Config "Install directory: $InstallDir" Log-Config "GitHub proxy: $ProxyDisplay" Log-Config "Agent arguments: $($KomariArgs -join ' ')" +if ($InstallVersion -ne "") { + Log-Config "Specified agent version: $InstallVersion" +} else { + Log-Config "Agent version: Latest" +} # Paths $BinaryName = "komari-agent-windows-$arch.exe" @@ -198,21 +205,29 @@ function Uninstall-Previous { } Uninstall-Previous -# Fetch latest release version -$ApiUrl = "https://api.github.com/repos/komari-monitor/komari-agent/releases/latest" -try { - $release = Invoke-RestMethod -Uri $ApiUrl -UseBasicParsing - $latestVersion = $release.tag_name +$versionToInstall = "" +if ($InstallVersion -ne "") { + Log-Info "Attempting to install specified version: $InstallVersion" + $versionToInstall = $InstallVersion } -catch { - Log-Error "Failed to fetch latest version: $_" - exit 1 +else { + $ApiUrl = "https://api.github.com/repos/komari-monitor/komari-agent/releases/latest" + try { + Log-Step "Fetching latest release version from GitHub API..." + $release = Invoke-RestMethod -Uri $ApiUrl -UseBasicParsing + $versionToInstall = $release.tag_name + Log-Success "Latest version fetched: $versionToInstall" + } + catch { + Log-Error "Failed to fetch latest version: $_" + exit 1 + } } -Log-Success "Latest version: $latestVersion" +Log-Success "Installing Komari Agent version: $versionToInstall" # Construct download URL $BinaryName = "komari-agent-windows-$arch.exe" -$DownloadUrl = if ($GitHubProxy) { "$GitHubProxy/https://github.com/komari-monitor/komari-agent/releases/download/$latestVersion/$BinaryName" } else { "https://github.com/komari-monitor/komari-agent/releases/download/$latestVersion/$BinaryName" } +$DownloadUrl = if ($GitHubProxy) { "$GitHubProxy/https://github.com/komari-monitor/komari-agent/releases/download/$versionToInstall/$BinaryName" } else { "https://github.com/komari-monitor/komari-agent/releases/download/$versionToInstall/$BinaryName" } # Download and install New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null @@ -243,4 +258,4 @@ Log-Success "Service $ServiceName installed and started using nssm." Log-Success "Komari Agent installation completed!" Log-Config "Service name: $ServiceName" -Log-Config "Arguments: $argString" +Log-Config "Arguments: $argString" \ No newline at end of file diff --git a/install.sh b/install.sh index 97081d2..c0d92c1 100644 --- a/install.sh +++ b/install.sh @@ -39,6 +39,7 @@ log_config() { service_name="komari-agent" target_dir="/opt/komari" github_proxy="" +install_version="" # New parameter for specifying version # Parse install-specific arguments komari_args="" @@ -56,6 +57,10 @@ while [[ $# -gt 0 ]]; do github_proxy="$2" shift 2 ;; + --install-version) + install_version="$2" + shift 2 + ;; --install*) log_warning "Unknown install parameter: $1" shift @@ -87,6 +92,11 @@ log_config " Service name: ${GREEN}$service_name${NC}" log_config " Install directory: ${GREEN}$target_dir${NC}" log_config " GitHub proxy: ${GREEN}${github_proxy:-"(direct)"}${NC}" log_config " Binary arguments: ${GREEN}$komari_args${NC}" +if [ -n "$install_version" ]; then + log_config " Specified agent version: ${GREEN}$install_version${NC}" +else + log_config " Agent version: ${GREEN}Latest${NC}" +fi echo "" # Function to uninstall the previous installation @@ -176,25 +186,30 @@ case $arch in esac log_info "Detected architecture: ${GREEN}$arch${NC}" -# Get latest release version (API always uses direct access) -api_url="https://api.github.com/repos/komari-monitor/komari-agent/releases/latest" - -log_step "Fetching latest version from GitHub API..." -latest_version=$(curl -s "$api_url" | grep "tag_name" | cut -d'"' -f4) -if [ -z "$latest_version" ]; then - log_error "Could not fetch latest version" - exit 1 +current_version="" +if [ -n "$install_version" ]; then + log_info "Attempting to install specified version: ${GREEN}$install_version${NC}" + current_version="$install_version" +else + api_url="https://api.github.com/repos/komari-monitor/komari-agent/releases/latest" + log_step "Fetching latest version from GitHub API..." + current_version=$(curl -s "$api_url" | grep "tag_name" | cut -d'"' -f4) + if [ -z "$current_version" ]; then + log_error "Could not fetch latest version" + exit 1 + fi + log_success "Latest version fetched: ${GREEN}$current_version${NC}" fi -log_success "Latest version: ${GREEN}$latest_version${NC}" +log_success "Installing Komari Agent version: ${GREEN}$current_version${NC}" # Construct download URL file_name="komari-agent-linux-${arch}" if [ -n "$github_proxy" ]; then # Use proxy for GitHub releases - download_url="${github_proxy}/https://github.com/komari-monitor/komari-agent/releases/download/${latest_version}/${file_name}" + download_url="${github_proxy}/https://github.com/komari-monitor/komari-agent/releases/download/${current_version}/${file_name}" else # Direct access to GitHub releases - download_url="https://github.com/komari-monitor/komari-agent/releases/download/${latest_version}/${file_name}" + download_url="https://github.com/komari-monitor/komari-agent/releases/download/${current_version}/${file_name}" fi log_step "Creating installation directory: ${GREEN}$target_dir${NC}"