update
This commit is contained in:
parent
c84485d5f4
commit
601250feee
@ -176,6 +176,7 @@ EOF
|
|||||||
|
|
||||||
# Create update script
|
# Create update script
|
||||||
msg_info "Creating update script"
|
msg_info "Creating update script"
|
||||||
|
ensure_usr_local_bin_persist
|
||||||
cat <<'UPDATEEOF' >/usr/local/bin/update_pihole-exporter
|
cat <<'UPDATEEOF' >/usr/local/bin/update_pihole-exporter
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# pihole-exporter Update Script
|
# pihole-exporter Update Script
|
||||||
|
|||||||
@ -8,17 +8,28 @@
|
|||||||
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/core.func)
|
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/core.func)
|
||||||
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/tools.func)
|
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/tools.func)
|
||||||
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/build.func)
|
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/build.func)
|
||||||
|
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/error_handler.func)
|
||||||
|
load_functions
|
||||||
|
|
||||||
|
# Enable error handling
|
||||||
|
set -Eeuo pipefail
|
||||||
|
trap 'error_handler' ERR
|
||||||
|
|
||||||
|
# ==============================================================================
|
||||||
|
# CONFIGURATION
|
||||||
|
# ==============================================================================
|
||||||
VERBOSE=${var_verbose:-no}
|
VERBOSE=${var_verbose:-no}
|
||||||
APP="qbittorrent-exporter"
|
APP="qbittorrent-exporter"
|
||||||
APP_TYPE="tools"
|
APP_TYPE="tools"
|
||||||
INSTALL_PATH="/opt/qbittorrent-exporter/src/qbittorrent-exporter"
|
INSTALL_PATH="/opt/qbittorrent-exporter"
|
||||||
CONFIG_PATH="/opt/qbittorrent-exporter.env"
|
CONFIG_PATH="/opt/qbittorrent-exporter.env"
|
||||||
header_info
|
header_info
|
||||||
ensure_usr_local_bin_persist
|
ensure_usr_local_bin_persist
|
||||||
get_current_ip &>/dev/null
|
get_current_ip &>/dev/null
|
||||||
|
|
||||||
# OS Detection
|
# ==============================================================================
|
||||||
|
# OS DETECTION
|
||||||
|
# ==============================================================================
|
||||||
if [[ -f "/etc/alpine-release" ]]; then
|
if [[ -f "/etc/alpine-release" ]]; then
|
||||||
OS="Alpine"
|
OS="Alpine"
|
||||||
SERVICE_PATH="/etc/init.d/qbittorrent-exporter"
|
SERVICE_PATH="/etc/init.d/qbittorrent-exporter"
|
||||||
@ -30,108 +41,118 @@ else
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Existing installation
|
# ==============================================================================
|
||||||
if [[ -f "$INSTALL_PATH" ]]; then
|
# UNINSTALL
|
||||||
echo -e "${YW}⚠️ qbittorrent-exporter is already installed.${CL}"
|
# ==============================================================================
|
||||||
echo -n "Uninstall ${APP}? (y/N): "
|
function uninstall() {
|
||||||
read -r uninstall_prompt
|
msg_info "Uninstalling qBittorrent-Exporter"
|
||||||
if [[ "${uninstall_prompt,,}" =~ ^(y|yes)$ ]]; then
|
if [[ "$OS" == "Alpine" ]]; then
|
||||||
msg_info "Uninstalling qbittorrent-exporter"
|
rc-service qbittorrent-exporter stop &>/dev/null
|
||||||
if [[ "$OS" == "Debian" ]]; then
|
rc-update del qbittorrent-exporter &>/dev/null
|
||||||
systemctl disable --now qbittorrent-exporter.service &>/dev/null
|
rm -f "$SERVICE_PATH"
|
||||||
rm -f "$SERVICE_PATH"
|
|
||||||
else
|
|
||||||
rc-service qbittorrent-exporter stop &>/dev/null
|
|
||||||
rc-update del qbittorrent-exporter &>/dev/null
|
|
||||||
rm -f "$SERVICE_PATH"
|
|
||||||
fi
|
|
||||||
rm -f "$INSTALL_PATH" "$CONFIG_PATH" ~/.qbittorrent-exporter
|
|
||||||
msg_ok "${APP} has been uninstalled."
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo -n "Update qbittorrent-exporter? (y/N): "
|
|
||||||
read -r update_prompt
|
|
||||||
if [[ "${update_prompt,,}" =~ ^(y|yes)$ ]]; then
|
|
||||||
if check_for_gh_release "qbittorrent-exporter" "martabal/qbittorrent-exporter"; then
|
|
||||||
fetch_and_deploy_gh_release "qbittorrent-exporter" "martabal/qbittorrent-exporter"
|
|
||||||
setup_go
|
|
||||||
msg_info "Updating qbittorrent-exporter"
|
|
||||||
cd /opt/qbittorrent-exporter/src
|
|
||||||
$STD /usr/local/bin/go build -o ./qbittorrent-exporter
|
|
||||||
msg_ok "Updated Successfully!"
|
|
||||||
fi
|
|
||||||
exit 0
|
|
||||||
else
|
else
|
||||||
echo -e "${YW}⚠️ Update skipped. Exiting.${CL}"
|
systemctl disable -q --now qbittorrent-exporter
|
||||||
exit 0
|
rm -f "$SERVICE_PATH"
|
||||||
fi
|
fi
|
||||||
fi
|
rm -rf "$INSTALL_PATH" "$CONFIG_PATH"
|
||||||
|
rm -f "/usr/local/bin/update_qbittorrent-exporter"
|
||||||
|
rm -f "$HOME/.qbittorrent-exporter"
|
||||||
|
msg_ok "qBittorrent-Exporter has been uninstalled"
|
||||||
|
}
|
||||||
|
|
||||||
echo -e "${YW}⚠️ qbittorrent-exporter is not installed.${CL}"
|
# ==============================================================================
|
||||||
echo -n "Enter URL of qbittorrent, example: (http://127.0.0.1:8080): "
|
# UPDATE
|
||||||
read -er QBITTORRENT_BASE_URL
|
# ==============================================================================
|
||||||
|
function update() {
|
||||||
|
if check_for_gh_release "qbittorrent-exporter" "martabal/qbittorrent-exporter"; then
|
||||||
|
msg_info "Stopping service"
|
||||||
|
if [[ "$OS" == "Alpine" ]]; then
|
||||||
|
rc-service qbittorrent-exporter stop &>/dev/null
|
||||||
|
else
|
||||||
|
systemctl stop qbittorrent-exporter
|
||||||
|
fi
|
||||||
|
msg_ok "Stopped service"
|
||||||
|
|
||||||
echo -n "Enter qbittorrent username: "
|
fetch_and_deploy_gh_release "qbittorrent-exporter" "martabal/qbittorrent-exporter" "tarball" "latest"
|
||||||
read -er QBITTORRENT_USERNAME
|
setup_go
|
||||||
|
|
||||||
echo -n "Enter qbittorrent password: "
|
msg_info "Building qBittorrent-Exporter"
|
||||||
read -rs QBITTORRENT_PASSWORD
|
cd /opt/qbittorrent-exporter/src
|
||||||
echo
|
$STD /usr/local/bin/go build -o ../qbittorrent-exporter
|
||||||
|
msg_ok "Built qBittorrent-Exporter"
|
||||||
|
|
||||||
echo -n "Install qbittorrent-exporter? (y/n): "
|
msg_info "Starting service"
|
||||||
read -r install_prompt
|
if [[ "$OS" == "Alpine" ]]; then
|
||||||
if ! [[ "${install_prompt,,}" =~ ^(y|yes)$ ]]; then
|
rc-service qbittorrent-exporter start &>/dev/null
|
||||||
echo -e "${YW}⚠️ Installation skipped. Exiting.${CL}"
|
else
|
||||||
exit 0
|
systemctl start qbittorrent-exporter
|
||||||
fi
|
fi
|
||||||
|
msg_ok "Started service"
|
||||||
|
msg_ok "Updated successfully"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
fetch_and_deploy_gh_release "qbittorrent-exporter" "martabal/qbittorrent-exporter" "tarball" "latest"
|
# ==============================================================================
|
||||||
setup_go
|
# INSTALL
|
||||||
msg_info "Installing qbittorrent-exporter on ${OS}"
|
# ==============================================================================
|
||||||
cd /opt/qbittorrent-exporter/src
|
function install() {
|
||||||
$STD /usr/local/bin/go build -o ./qbittorrent-exporter
|
read -erp "Enter URL of qBittorrent, example: (http://127.0.0.1:8080): " QBITTORRENT_BASE_URL
|
||||||
msg_ok "Installed qbittorrent-exporter"
|
read -erp "Enter qBittorrent username: " QBITTORRENT_USERNAME
|
||||||
|
read -rsp "Enter qBittorrent password: " QBITTORRENT_PASSWORD
|
||||||
|
printf "\n"
|
||||||
|
|
||||||
msg_info "Creating configuration"
|
fetch_and_deploy_gh_release "qbittorrent-exporter" "martabal/qbittorrent-exporter" "tarball" "latest"
|
||||||
cat <<EOF >"$CONFIG_PATH"
|
setup_go
|
||||||
|
msg_info "Building qBittorrent-Exporter on ${OS}"
|
||||||
|
cd /opt/qbittorrent-exporter/src
|
||||||
|
$STD /usr/local/bin/go build -o ../qbittorrent-exporter
|
||||||
|
msg_ok "Built qBittorrent-Exporter"
|
||||||
|
|
||||||
|
msg_info "Creating configuration"
|
||||||
|
cat <<EOF >"$CONFIG_PATH"
|
||||||
# https://github.com/martabal/qbittorrent-exporter?tab=readme-ov-file#parameters
|
# https://github.com/martabal/qbittorrent-exporter?tab=readme-ov-file#parameters
|
||||||
QBITTORRENT_BASE_URL="${QBITTORRENT_BASE_URL}"
|
QBITTORRENT_BASE_URL="${QBITTORRENT_BASE_URL}"
|
||||||
QBITTORRENT_USERNAME="${QBITTORRENT_USERNAME}"
|
QBITTORRENT_USERNAME="${QBITTORRENT_USERNAME}"
|
||||||
QBITTORRENT_PASSWORD="${QBITTORRENT_PASSWORD}"
|
QBITTORRENT_PASSWORD="${QBITTORRENT_PASSWORD}"
|
||||||
EOF
|
EOF
|
||||||
msg_ok "Created configuration"
|
msg_ok "Created configuration"
|
||||||
|
|
||||||
msg_info "Creating service"
|
msg_info "Creating service"
|
||||||
if [[ "$OS" == "Debian" ]]; then
|
if [[ "$OS" == "Debian" ]]; then
|
||||||
cat <<EOF >"$SERVICE_PATH"
|
cat <<EOF >"$SERVICE_PATH"
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=qbittorrent-exporter
|
Description=qbittorrent-exporter
|
||||||
After=network.target
|
After=network.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
User=root
|
User=root
|
||||||
WorkingDirectory=/opt/qbittorrent-exporter/src
|
WorkingDirectory=/opt/qbittorrent-exporter
|
||||||
EnvironmentFile=$CONFIG_PATH
|
EnvironmentFile=$CONFIG_PATH
|
||||||
ExecStart=/opt/qbittorrent-exporter/src/qbittorrent-exporter
|
ExecStart=/opt/qbittorrent-exporter/qbittorrent-exporter
|
||||||
Restart=always
|
Restart=always
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
EOF
|
EOF
|
||||||
systemctl enable -q --now qbittorrent-exporter
|
systemctl daemon-reload
|
||||||
else
|
systemctl enable -q --now qbittorrent-exporter
|
||||||
cat <<EOF >"$SERVICE_PATH"
|
else
|
||||||
|
cat <<EOF >"$SERVICE_PATH"
|
||||||
#!/sbin/openrc-run
|
#!/sbin/openrc-run
|
||||||
|
|
||||||
command="$INSTALL_PATH"
|
name="qbittorrent-exporter"
|
||||||
command_args=""
|
description="qBittorrent Exporter for Prometheus"
|
||||||
|
command="${INSTALL_PATH}/qbittorrent-exporter"
|
||||||
command_background=true
|
command_background=true
|
||||||
directory="/opt/qbittorrent-exporter/src"
|
directory="/opt/qbittorrent-exporter"
|
||||||
pidfile="/opt/qbittorrent-exporter/src/pidfile"
|
pidfile="/run/\${RC_SVCNAME}.pid"
|
||||||
|
output_log="/var/log/qbittorrent-exporter.log"
|
||||||
|
error_log="/var/log/qbittorrent-exporter.log"
|
||||||
|
|
||||||
depend() {
|
depend() {
|
||||||
need net
|
need net
|
||||||
|
after firewall
|
||||||
}
|
}
|
||||||
|
|
||||||
start_pre() {
|
start_pre() {
|
||||||
@ -140,10 +161,83 @@ start_pre() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
chmod +x "$SERVICE_PATH"
|
chmod +x "$SERVICE_PATH"
|
||||||
rc-update add qbittorrent-exporter default &>/dev/null
|
$STD rc-update add qbittorrent-exporter default
|
||||||
rc-service qbittorrent-exporter start &>/dev/null
|
$STD rc-service qbittorrent-exporter start
|
||||||
fi
|
fi
|
||||||
msg_ok "Service created successfully"
|
msg_ok "Created and started service"
|
||||||
|
|
||||||
echo -e "${CM} ${GN}${APP} is reachable at: ${BL}http://$CURRENT_IP:8090/metrics${CL}"
|
# Create update script
|
||||||
|
msg_info "Creating update script"
|
||||||
|
ensure_usr_local_bin_persist
|
||||||
|
cat <<'UPDATEEOF' >/usr/local/bin/update_qbittorrent-exporter
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
# qbittorrent-exporter Update Script
|
||||||
|
type=update bash -c "$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/tools/addon/qbittorrent-exporter.sh)"
|
||||||
|
UPDATEEOF
|
||||||
|
chmod +x /usr/local/bin/update_qbittorrent-exporter
|
||||||
|
msg_ok "Created update script (/usr/local/bin/update_qbittorrent-exporter)"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
msg_ok "qBittorrent-Exporter installed successfully"
|
||||||
|
msg_ok "Metrics: ${BL}http://${CURRENT_IP}:8090/metrics${CL}"
|
||||||
|
msg_ok "Config: ${BL}${CONFIG_PATH}${CL}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# ==============================================================================
|
||||||
|
# MAIN
|
||||||
|
# ==============================================================================
|
||||||
|
header_info
|
||||||
|
ensure_usr_local_bin_persist
|
||||||
|
get_current_ip &>/dev/null
|
||||||
|
|
||||||
|
# Handle type=update (called from update script)
|
||||||
|
if [[ "${type:-}" == "update" ]]; then
|
||||||
|
if [[ -d "$INSTALL_PATH" && -f "$INSTALL_PATH/qbittorrent-exporter" ]]; then
|
||||||
|
update
|
||||||
|
else
|
||||||
|
msg_error "qBittorrent-Exporter is not installed. Nothing to update."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if already installed
|
||||||
|
if [[ -d "$INSTALL_PATH" && -f "$INSTALL_PATH/qbittorrent-exporter" ]]; then
|
||||||
|
msg_warn "qBittorrent-Exporter is already installed."
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo -n "${TAB}Uninstall qBittorrent-Exporter? (y/N): "
|
||||||
|
read -r uninstall_prompt
|
||||||
|
if [[ "${uninstall_prompt,,}" =~ ^(y|yes)$ ]]; then
|
||||||
|
uninstall
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -n "${TAB}Update qBittorrent-Exporter? (y/N): "
|
||||||
|
read -r update_prompt
|
||||||
|
if [[ "${update_prompt,,}" =~ ^(y|yes)$ ]]; then
|
||||||
|
update
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
msg_warn "No action selected. Exiting."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Fresh installation
|
||||||
|
msg_warn "qBittorrent-Exporter is not installed."
|
||||||
|
echo ""
|
||||||
|
echo -e "${TAB}${INFO} This will install:"
|
||||||
|
echo -e "${TAB} - qBittorrent Exporter (Go binary)"
|
||||||
|
echo -e "${TAB} - Systemd/OpenRC service"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo -n "${TAB}Install qBittorrent-Exporter? (y/N): "
|
||||||
|
read -r install_prompt
|
||||||
|
if [[ "${install_prompt,,}" =~ ^(y|yes)$ ]]; then
|
||||||
|
install
|
||||||
|
else
|
||||||
|
msg_warn "Installation cancelled. Exiting."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user