feat: add support for vnstat installation based on --month-rotate flag

This commit is contained in:
akizon77
2025-08-04 11:48:14 +08:00
parent 1583a54ea4
commit 8a78e4a2b0

View File

@@ -40,6 +40,7 @@ service_name="komari-agent"
target_dir="/opt/komari" target_dir="/opt/komari"
github_proxy="" github_proxy=""
install_version="" # New parameter for specifying version install_version="" # New parameter for specifying version
need_vnstat=false # Flag to indicate if vnstat is needed
# Detect OS # Detect OS
os_type=$(uname -s) os_type=$(uname -s)
@@ -82,6 +83,11 @@ while [[ $# -gt 0 ]]; do
install_version="$2" install_version="$2"
shift 2 shift 2
;; ;;
--month-rotate)
need_vnstat=true
komari_args="$komari_args $1"
shift
;;
--install*) --install*)
log_warning "Unknown install parameter: $1" log_warning "Unknown install parameter: $1"
shift shift
@@ -126,6 +132,11 @@ if [ -n "$install_version" ]; then
else else
log_config " Agent version: ${GREEN}Latest${NC}" log_config " Agent version: ${GREEN}Latest${NC}"
fi fi
if [ "$need_vnstat" = true ]; then
log_config " vnstat installation: ${GREEN}Required (--month-rotate detected)${NC}"
else
log_config " vnstat installation: ${GREEN}Not required${NC}"
fi
echo "" echo ""
# Function to uninstall the previous installation # Function to uninstall the previous installation
@@ -221,9 +232,69 @@ install_dependencies() {
fi fi
} }
# Function to install vnstat if needed
install_vnstat() {
if [ "$need_vnstat" = true ]; then
log_step "Checking and installing vnstat for --month-rotate functionality..."
if command -v vnstat >/dev/null 2>&1; then
log_success "vnstat is already installed"
return
fi
log_info "vnstat not found, installing..."
# Install vnstat based on package manager
if command -v apt >/dev/null 2>&1; then
log_info "Using apt to install vnstat..."
apt update
apt install -y vnstat
elif command -v yum >/dev/null 2>&1; then
log_info "Using yum to install vnstat..."
yum install -y vnstat
elif command -v dnf >/dev/null 2>&1; then
log_info "Using dnf to install vnstat..."
dnf install -y vnstat
elif command -v apk >/dev/null 2>&1; then
log_info "Using apk to install vnstat..."
apk add vnstat
elif command -v brew >/dev/null 2>&1; then
log_info "Using Homebrew to install vnstat..."
brew install vnstat
elif command -v pacman >/dev/null 2>&1; then
log_info "Using pacman to install vnstat..."
pacman -S --noconfirm vnstat
else
log_error "No supported package manager found for vnstat installation"
log_error "Please install vnstat manually to use --month-rotate functionality"
exit 1
fi
# Verify installation
if command -v vnstat >/dev/null 2>&1; then
log_success "vnstat installed successfully"
# Start vnstat daemon if systemd is available
if command -v systemctl >/dev/null 2>&1; then
log_info "Starting vnstat daemon..."
systemctl enable vnstat
systemctl start vnstat
elif [ "$os_name" = "darwin" ] && command -v launchctl >/dev/null 2>&1; then
log_info "vnstat daemon management varies on macOS, please check vnstat documentation"
fi
else
log_error "Failed to install vnstat"
exit 1
fi
fi
}
# Install dependencies # Install dependencies
install_dependencies install_dependencies
# Install vnstat if needed for month-rotate
install_vnstat
arch=$(uname -m) arch=$(uname -m)
case $arch in case $arch in
x86_64) x86_64)