mirror of
https://github.com/fankes/komari-agent.git
synced 2025-10-19 02:59:23 +08:00
feat: 指定安装版本
This commit is contained in:
37
install.ps1
37
install.ps1
@@ -13,6 +13,7 @@ $InstallDir = Join-Path $Env:ProgramFiles "Komari"
|
|||||||
$ServiceName = "komari-agent"
|
$ServiceName = "komari-agent"
|
||||||
$GitHubProxy = ""
|
$GitHubProxy = ""
|
||||||
$KomariArgs = @()
|
$KomariArgs = @()
|
||||||
|
$InstallVersion = ""
|
||||||
|
|
||||||
# Parse script arguments
|
# Parse script arguments
|
||||||
for ($i = 0; $i -lt $args.Count; $i++) {
|
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-dir" { $InstallDir = $args[$i + 1]; $i++; continue }
|
||||||
"--install-service-name" { $ServiceName = $args[$i + 1]; $i++; continue }
|
"--install-service-name" { $ServiceName = $args[$i + 1]; $i++; continue }
|
||||||
"--install-ghproxy" { $GitHubProxy = $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] }
|
Default { $KomariArgs += $args[$i] }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -158,6 +160,11 @@ Log-Config "Service name: $ServiceName"
|
|||||||
Log-Config "Install directory: $InstallDir"
|
Log-Config "Install directory: $InstallDir"
|
||||||
Log-Config "GitHub proxy: $ProxyDisplay"
|
Log-Config "GitHub proxy: $ProxyDisplay"
|
||||||
Log-Config "Agent arguments: $($KomariArgs -join ' ')"
|
Log-Config "Agent arguments: $($KomariArgs -join ' ')"
|
||||||
|
if ($InstallVersion -ne "") {
|
||||||
|
Log-Config "Specified agent version: $InstallVersion"
|
||||||
|
} else {
|
||||||
|
Log-Config "Agent version: Latest"
|
||||||
|
}
|
||||||
|
|
||||||
# Paths
|
# Paths
|
||||||
$BinaryName = "komari-agent-windows-$arch.exe"
|
$BinaryName = "komari-agent-windows-$arch.exe"
|
||||||
@@ -198,21 +205,29 @@ function Uninstall-Previous {
|
|||||||
}
|
}
|
||||||
Uninstall-Previous
|
Uninstall-Previous
|
||||||
|
|
||||||
# Fetch latest release version
|
$versionToInstall = ""
|
||||||
$ApiUrl = "https://api.github.com/repos/komari-monitor/komari-agent/releases/latest"
|
if ($InstallVersion -ne "") {
|
||||||
try {
|
Log-Info "Attempting to install specified version: $InstallVersion"
|
||||||
$release = Invoke-RestMethod -Uri $ApiUrl -UseBasicParsing
|
$versionToInstall = $InstallVersion
|
||||||
$latestVersion = $release.tag_name
|
|
||||||
}
|
}
|
||||||
catch {
|
else {
|
||||||
Log-Error "Failed to fetch latest version: $_"
|
$ApiUrl = "https://api.github.com/repos/komari-monitor/komari-agent/releases/latest"
|
||||||
exit 1
|
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
|
# Construct download URL
|
||||||
$BinaryName = "komari-agent-windows-$arch.exe"
|
$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
|
# Download and install
|
||||||
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
|
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-Success "Komari Agent installation completed!"
|
||||||
Log-Config "Service name: $ServiceName"
|
Log-Config "Service name: $ServiceName"
|
||||||
Log-Config "Arguments: $argString"
|
Log-Config "Arguments: $argString"
|
37
install.sh
37
install.sh
@@ -39,6 +39,7 @@ log_config() {
|
|||||||
service_name="komari-agent"
|
service_name="komari-agent"
|
||||||
target_dir="/opt/komari"
|
target_dir="/opt/komari"
|
||||||
github_proxy=""
|
github_proxy=""
|
||||||
|
install_version="" # New parameter for specifying version
|
||||||
|
|
||||||
# Parse install-specific arguments
|
# Parse install-specific arguments
|
||||||
komari_args=""
|
komari_args=""
|
||||||
@@ -56,6 +57,10 @@ while [[ $# -gt 0 ]]; do
|
|||||||
github_proxy="$2"
|
github_proxy="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
|
--install-version)
|
||||||
|
install_version="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
--install*)
|
--install*)
|
||||||
log_warning "Unknown install parameter: $1"
|
log_warning "Unknown install parameter: $1"
|
||||||
shift
|
shift
|
||||||
@@ -87,6 +92,11 @@ log_config " Service name: ${GREEN}$service_name${NC}"
|
|||||||
log_config " Install directory: ${GREEN}$target_dir${NC}"
|
log_config " Install directory: ${GREEN}$target_dir${NC}"
|
||||||
log_config " GitHub proxy: ${GREEN}${github_proxy:-"(direct)"}${NC}"
|
log_config " GitHub proxy: ${GREEN}${github_proxy:-"(direct)"}${NC}"
|
||||||
log_config " Binary arguments: ${GREEN}$komari_args${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 ""
|
echo ""
|
||||||
|
|
||||||
# Function to uninstall the previous installation
|
# Function to uninstall the previous installation
|
||||||
@@ -176,25 +186,30 @@ case $arch in
|
|||||||
esac
|
esac
|
||||||
log_info "Detected architecture: ${GREEN}$arch${NC}"
|
log_info "Detected architecture: ${GREEN}$arch${NC}"
|
||||||
|
|
||||||
# Get latest release version (API always uses direct access)
|
current_version=""
|
||||||
api_url="https://api.github.com/repos/komari-monitor/komari-agent/releases/latest"
|
if [ -n "$install_version" ]; then
|
||||||
|
log_info "Attempting to install specified version: ${GREEN}$install_version${NC}"
|
||||||
log_step "Fetching latest version from GitHub API..."
|
current_version="$install_version"
|
||||||
latest_version=$(curl -s "$api_url" | grep "tag_name" | cut -d'"' -f4)
|
else
|
||||||
if [ -z "$latest_version" ]; then
|
api_url="https://api.github.com/repos/komari-monitor/komari-agent/releases/latest"
|
||||||
log_error "Could not fetch latest version"
|
log_step "Fetching latest version from GitHub API..."
|
||||||
exit 1
|
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
|
fi
|
||||||
log_success "Latest version: ${GREEN}$latest_version${NC}"
|
log_success "Installing Komari Agent version: ${GREEN}$current_version${NC}"
|
||||||
|
|
||||||
# Construct download URL
|
# Construct download URL
|
||||||
file_name="komari-agent-linux-${arch}"
|
file_name="komari-agent-linux-${arch}"
|
||||||
if [ -n "$github_proxy" ]; then
|
if [ -n "$github_proxy" ]; then
|
||||||
# Use proxy for GitHub releases
|
# 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
|
else
|
||||||
# Direct access to GitHub releases
|
# 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
|
fi
|
||||||
|
|
||||||
log_step "Creating installation directory: ${GREEN}$target_dir${NC}"
|
log_step "Creating installation directory: ${GREEN}$target_dir${NC}"
|
||||||
|
Reference in New Issue
Block a user