Use specific exit codes in addon scripts

Replace generic exit 1 with specific exit codes across multiple addon scripts to improve error signaling and handling. Files updated: tools/addon/add-netbird-lxc.sh (exit 238 on unsupported distro), tools/addon/add-tailscale-lxc.sh (treat user cancel as exit 0), tools/addon/glances.sh (exit 233 when not installed), tools/addon/komodo.sh (distinct exits for missing compose, legacy DB, backup/download failures, docker checks), tools/addon/netdata.sh (distinct exits for unsupported PVE versions, OS/codename detection, repo lookups), and tools/addon/phpmyadmin.sh (distinct exits for unsupported OS, network/download issues, package install/start failures, and invalid input). These changes make failures easier to identify and automate recovery or reporting.
This commit is contained in:
CanbiZ (MickLesk)
2026-03-02 09:59:23 +01:00
parent 4f735a9a23
commit 3aba5f3209
6 changed files with 25 additions and 25 deletions

View File

@@ -73,7 +73,7 @@ fi
DISTRO=$(pct exec "$CTID" -- cat /etc/os-release | grep -w "ID" | cut -d'=' -f2 | tr -d '"')
if [[ "$DISTRO" != "debian" && "$DISTRO" != "ubuntu" ]]; then
msg "\e[1;31m Error: This script only supports Debian or Ubuntu LXC containers. Detected: $DISTRO. Aborting...\e[0m"
exit 1
exit 238
fi
CTID_CONFIG_PATH=/etc/pve/lxc/${CTID}.conf

View File

@@ -32,7 +32,7 @@ header_info
if ! command -v pveversion &>/dev/null; then
msg_error "This script must be run on the Proxmox VE host (not inside an LXC container)"
exit 1
exit 232
fi
while true; do
@@ -64,7 +64,7 @@ while [[ -z "${CTID}" ]]; do
CTID=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "Containers on $NODE" --radiolist \
"\nSelect a container to add Tailscale to:\n" \
16 $((MSG_MAX_LENGTH + 23)) 6 \
"${CTID_MENU[@]}" 3>&1 1>&2 2>&3) || exit 1
"${CTID_MENU[@]}" 3>&1 1>&2 2>&3) || exit 0
done
CTID_CONFIG_PATH="/etc/pve/lxc/${CTID}.conf"

View File

@@ -93,7 +93,7 @@ EOF
update_glances_debian() {
if [[ ! -d /opt/glances/.venv ]]; then
msg_error "$APP is not installed"
exit 1
exit 233
fi
msg_info "Updating $APP"
cd /opt/glances
@@ -160,7 +160,7 @@ EOF
update_glances_alpine() {
if [[ ! -d /opt/glances/.venv ]]; then
msg_error "$APP is not installed"
exit 1
exit 233
fi
msg_info "Updating $APP"
cd /opt/glances

View File

@@ -37,7 +37,7 @@ function find_compose_file() {
COMPOSE_FILE=$(find "$INSTALL_PATH" -maxdepth 1 -type f -name '*.compose.yaml' ! -name 'compose.env' | head -n1)
if [[ -z "${COMPOSE_FILE:-}" ]]; then
msg_error "No valid compose file found in ${INSTALL_PATH}!"
exit 1
exit 233
fi
COMPOSE_BASENAME=$(basename "$COMPOSE_FILE")
}
@@ -48,7 +48,7 @@ function check_legacy_db() {
echo -e "${YW}This configuration is no longer supported since Komodo v1.18.0.${CL}"
echo -e "${YW}Please follow the migration guide:${CL}"
echo -e "${BGN}https://github.com/community-scripts/ProxmoxVE/discussions/5689${CL}\n"
exit 1
exit 238
fi
}
@@ -79,14 +79,14 @@ function update() {
BACKUP_FILE="${INSTALL_PATH}/${COMPOSE_BASENAME}.bak_$(date +%Y%m%d_%H%M%S)"
cp "$COMPOSE_FILE" "$BACKUP_FILE" || {
msg_error "Failed to create backup of ${COMPOSE_BASENAME}!"
exit 1
exit 235
}
GITHUB_URL="https://raw.githubusercontent.com/moghtech/komodo/main/compose/${COMPOSE_BASENAME}"
if ! curl -fsSL "$GITHUB_URL" -o "$COMPOSE_FILE"; then
msg_error "Failed to download ${COMPOSE_BASENAME} from GitHub!"
mv "$BACKUP_FILE" "$COMPOSE_FILE"
exit 1
exit 115
fi
if ! grep -qxF 'COMPOSE_KOMODO_BACKUPS_PATH=/etc/komodo/backups' "$COMPOSE_ENV"; then
@@ -129,7 +129,7 @@ function check_or_install_docker() {
msg_ok "Docker Compose is available"
else
msg_error "Docker Compose plugin is not available. Please install it."
exit 1
exit 10
fi
return
fi
@@ -139,7 +139,7 @@ function check_or_install_docker() {
read -r install_docker_prompt
if [[ ! "${install_docker_prompt,,}" =~ ^(y|yes)$ ]]; then
msg_error "Docker is required for ${APP}. Exiting."
exit 1
exit 10
fi
msg_info "Installing Docker"
@@ -239,7 +239,7 @@ if [[ "${type:-}" == "update" ]]; then
update
else
msg_error "${APP} is not installed. Nothing to update."
exit 1
exit 233
fi
exit 0
fi

View File

@@ -58,7 +58,7 @@ pve_check() {
if ((MINOR < 0 || MINOR > 9)); then
msg_error "This version of Proxmox VE is not supported."
msg_error "Supported: Proxmox VE version 8.0 8.9"
exit 1
exit 105
fi
return 0
fi
@@ -69,7 +69,7 @@ pve_check() {
if ((MINOR < 0 || MINOR > 1)); then
msg_error "This version of Proxmox VE is not yet supported."
msg_error "Supported: Proxmox VE version 9.09.1.x"
exit 1
exit 105
fi
return 0
fi
@@ -77,19 +77,19 @@ pve_check() {
# All other unsupported versions
msg_error "This version of Proxmox VE is not supported."
msg_error "Supported versions: Proxmox VE 8.0 8.9 or 9.09.1.x"
exit 1
exit 105
}
detect_codename() {
source /etc/os-release
if [[ "$ID" != "debian" ]]; then
msg_error "Unsupported base OS: $ID (only Proxmox VE / Debian supported)."
exit 1
exit 238
fi
CODENAME="${VERSION_CODENAME:-}"
if [[ -z "$CODENAME" ]]; then
msg_error "Could not detect Debian codename."
exit 1
exit 71
fi
echo "$CODENAME"
}
@@ -124,7 +124,7 @@ install() {
PKG=$(get_latest_repo_pkg "$REPO_URL")
if [[ -z "$PKG" ]]; then
msg_error "Could not find netdata-repo package for Debian $CODENAME"
exit 1
exit 237
fi
curl -fsSL "${REPO_URL}${PKG}" -o "$PKG"
$STD dpkg -i "$PKG"

View File

@@ -52,7 +52,7 @@ elif [[ -f "/etc/debian_version" ]]; then
INSTALL_DIR="$INSTALL_DIR_DEBIAN"
else
echo -e "${CROSS} Unsupported OS detected. Exiting."
exit 1
exit 238
fi
header_info
@@ -72,7 +72,7 @@ function check_internet() {
msg_ok "Internet connectivity OK"
else
msg_error "Internet connectivity or GitHub unreachable (Status $HTTP_CODE). Exiting."
exit 1
exit 115
fi
}
@@ -105,7 +105,7 @@ function install_php_and_modules() {
msg_info "Installing missing PHP packages: ${MISSING_PACKAGES[*]}"
if ! apt-get update &>/dev/null || ! apt-get install -y "${MISSING_PACKAGES[@]}" &>/dev/null; then
msg_error "Failed to install required PHP modules. Exiting."
exit 1
exit 237
fi
msg_ok "Installed missing PHP packages"
else
@@ -132,7 +132,7 @@ function install_phpmyadmin() {
msg_info "Downloading ${TARBALL_URL}"
if ! curl -fsSL "$TARBALL_URL" -o /tmp/phpmyadmin.tar.gz; then
msg_error "Download failed: $TARBALL_URL"
exit 1
exit 115
fi
mkdir -p "$INSTALL_DIR"
@@ -188,7 +188,7 @@ EOF
msg_ok "Started PHP-FPM service: $PHP_FPM_SERVICE"
else
msg_error "Failed to start PHP-FPM service: $PHP_FPM_SERVICE"
exit 1
exit 150
fi
$STD rc-service lighttpd start
@@ -237,7 +237,7 @@ function update_phpmyadmin() {
if ! curl -fsSL "$TARBALL_URL" -o /tmp/phpmyadmin.tar.gz; then
msg_error "Download failed: $TARBALL_URL"
exit 1
exit 115
fi
BACKUP_DIR="/tmp/phpmyadmin-backup-$(date +%Y%m%d-%H%M%S)"
@@ -280,7 +280,7 @@ if is_phpmyadmin_installed; then
;;
*)
echo -e "${YW}⚠️ Invalid input. Exiting.${CL}"
exit 1
exit 112
;;
esac
else