mirror of
https://github.com/fankes/komari-agent.git
synced 2025-10-19 02:59:23 +08:00
feat: 指定安装版本
This commit is contained in:
23
install.ps1
23
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
|
||||
$versionToInstall = ""
|
||||
if ($InstallVersion -ne "") {
|
||||
Log-Info "Attempting to install specified version: $InstallVersion"
|
||||
$versionToInstall = $InstallVersion
|
||||
}
|
||||
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
|
||||
$latestVersion = $release.tag_name
|
||||
$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
|
||||
|
29
install.sh
29
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)
|
||||
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..."
|
||||
latest_version=$(curl -s "$api_url" | grep "tag_name" | cut -d'"' -f4)
|
||||
if [ -z "$latest_version" ]; then
|
||||
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: ${GREEN}$latest_version${NC}"
|
||||
log_success "Latest version fetched: ${GREEN}$current_version${NC}"
|
||||
fi
|
||||
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}"
|
||||
|
Reference in New Issue
Block a user