Files
ProxmoxVE/tools/addon/copyparty.sh
CanbiZ (MickLesk) 5dc244a8c1 core: standardize exit codes and add mappings (#12467)
* Standardize exit codes and add mappings

Replace generic exit 1 usages with specific numeric exit codes and add corresponding explanations to the error lookup. This commit updates multiple misc/* scripts to return distinct codes for validation, Proxmox/LXC, networking, download and curl errors (e.g. 103-123, 64, 107-120, 206, 0 for explicit user cancels). It also updates curl error handling to propagate the original curl exit code and adds new entries in explain_exit_code and the error handler to improve diagnostics.

* Set exit code 115 for update_os errors

Change exit status from 6 to 115 in misc/alpine-install.func's update_os() error handlers when failing to download tools.func or when the expected functions are missing. This gives a distinct exit code for these specific failure cases.

* Add tools/addon exit codes and use them

Introduce exit codes 232-238 for Tools & Addon scripts in misc/api.func and misc/error_handler.func. Update addon scripts (tools/addon/adguardhome-sync.sh, tools/addon/copyparty.sh, tools/addon/cronmaster.sh) to return specific codes instead of generic exit 1: 238 for unsupported OS and 233 when the application is not installed/upgrade prerequisites are missing. This makes failures more descriptive and aligns scripts with the central error explanations.

* Standardize exit codes in exporter addons

Unify exit codes across exporter addon scripts: return 238 for unsupported OS detections and 233 when an update is requested but the exporter is not installed. Applied to nextcloud-exporter.sh, pihole-exporter.sh, prometheus-paperless-ngx-exporter.sh, and qbittorrent-exporter.sh to make failure modes distinguishable for callers/automation.

* Use specific exit codes in addon scripts

Replace generic exit 1 with distinct exit codes across multiple addon scripts to enable finer-grained error handling in automation. Exit codes introduced: 10 for Docker/Compose missing or user-declined Docker install, 233 for "nothing to update" cases, and 238 for unsupported OS cases. Affected files: tools/addon/arcane.sh, coolify.sh, dockge.sh, dokploy.sh, filebrowser-quantum.sh, filebrowser.sh, immich-public-proxy.sh, jellystat.sh, runtipi.sh.

* 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.

* Use specific exit codes in PVE scripts

Replace generic exit 1 with distinct exit codes across tools/pve scripts to provide clearer failure signals for callers. post-pve-install.sh now returns 105 for unsupported Proxmox versions; pve-privilege-converter.sh uses 104 for non-root, 234 when no containers, and 235 for backup/conversion failures; update-apps.sh maps backup failures to 235, missing containers/selections to 234 (and UI cancellations to 0), missing backup storage to 119, and returns the actual container update exit code on failure. These changes improve diagnostics and allow external tooling to react to specific error conditions.

* Standardize exit codes and behaviors

Adjust exit codes and abort handling across multiple PVE helper scripts to provide clearer outcomes for automation and interactive flows. Changes include:

- container-restore-from-backup.sh, core-restore-from-backup.sh: return 235 when no backups found (was 1).
- fstrim.sh: treat user cancellation of non-ext4 warning as non-error (exit 0 instead of 1).
- kernel-clean.sh: treat no selection or user abort as non-error (exit 0 instead of 1).
- lxc-delete.sh: return 234 when no containers are present; treat no selection as non-error (exit 0).
- nic-offloading-fix.sh: use specific non-zero codes for root check and tool install failures (exit 104, 237) and 236 when no matching interfaces (was 1).
- pbs_microcode.sh, post-pmg-install.sh, post-pbs-install.sh: use distinct exit codes (232 and 105) for detected VM/PVE/unsupported distro conditions instead of generic 1.

These modifications make scripts return distinct codes for different failure modes and ensure user-initiated aborts or benign conditions exit with 0 where appropriate.

* Use exit 105 for unsupported PVE versions

Standardize error handling by replacing generic exit 1 with exit 105 in pve_check() across multiple VM template scripts to indicate unsupported Proxmox VE versions. Also add API exit code 226 message for "Proxmox: VM disk import or post-creation setup failed" in misc/api.func. Affected files include misc/api.func and various vm/*-vm.sh scripts.

* Use specific exit codes in VM scripts

Replace generic exit 1 with distinct exit codes across vm/*.sh to make failures more actionable for callers. Changes include: use 226 for missing imported-disk references, 237 for pv installation failures, 115 for download/extract/ISO-related failures, 214 for insufficient disk space during FreeBSD decompression, and 119 for missing storage detection. Updated scripts: archlinux-vm.sh, docker-vm.sh, haos-vm.sh, openwrt-vm.sh, opnsense-vm.sh, truenas-vm.sh, umbrel-os-vm.sh.
2026-03-02 10:55:20 +01:00

366 lines
10 KiB
Bash

#!/usr/bin/env bash
# Copyright (c) 2021-2026 community-scripts ORG
# Author: MickLesk
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
# Source: https://github.com/9001/copyparty
if ! command -v curl &>/dev/null; then
printf "\r\e[2K%b" '\033[93m Setup Source \033[m' >&2
apt-get update >/dev/null 2>&1
apt-get install -y curl >/dev/null 2>&1
fi
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/core.func)
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/tools.func)
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/error_handler.func)
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/api.func) 2>/dev/null || true
# Enable error handling
set -Eeuo pipefail
trap 'error_handler' ERR
load_functions
init_tool_telemetry "" "addon"
# ==============================================================================
# CONFIGURATION
# ==============================================================================
VERBOSE=${var_verbose:-no}
APP="CopyParty"
APP_TYPE="addon"
BIN_PATH="/usr/local/bin/copyparty-sfx.py"
CONF_PATH="/etc/copyparty.conf"
LOG_PATH="/var/log/copyparty"
DATA_PATH="/var/lib/copyparty"
SVC_USER="copyparty"
SVC_GROUP="copyparty"
SRC_URL="https://github.com/9001/copyparty/releases/latest/download/copyparty-sfx.py"
DEFAULT_PORT=3923
# ==============================================================================
# OS DETECTION
# ==============================================================================
if [[ -f "/etc/alpine-release" ]]; then
OS="Alpine"
PKG_MANAGER="apk add --no-cache"
SERVICE_PATH="/etc/init.d/copyparty"
elif grep -qE 'ID=debian|ID=ubuntu' /etc/os-release; then
OS="Debian"
PKG_MANAGER="apt-get install -y"
SERVICE_PATH="/etc/systemd/system/copyparty.service"
else
msg_error "Unsupported OS detected. Exiting."
exit 238
fi
# ==============================================================================
# HEADER
# ==============================================================================
function header_info() {
clear
cat <<"EOF"
______ ____ __
/ ____/___ ____ __ __/ __ \____ ______/ /___ __
/ / / __ \/ __ \/ / / / /_/ / __ `/ ___/ __/ / / /
/ /___/ /_/ / /_/ / /_/ / ____/ /_/ / / / /_/ /_/ /
\____/\____/ .___/\__, /_/ \__,_/_/ \__/\__, /
/_/ /____/ /____/
EOF
}
# ==============================================================================
# HELPER FUNCTIONS
# ==============================================================================
# ==============================================================================
# HELPER FUNCTIONS
# ==============================================================================
function setup_user_and_dirs() {
msg_info "Creating $SVC_USER user and directories"
if ! id "$SVC_USER" &>/dev/null; then
if [[ "$OS" == "Debian" ]]; then
useradd -r -s /sbin/nologin -d "$DATA_PATH" "$SVC_USER"
else
addgroup -S "$SVC_GROUP" 2>/dev/null || true
adduser -S -D -H -G "$SVC_GROUP" -h "$DATA_PATH" -s /sbin/nologin "$SVC_USER" 2>/dev/null || true
fi
fi
mkdir -p "$DATA_PATH" "$LOG_PATH"
chown -R "$SVC_USER:$SVC_GROUP" "$DATA_PATH" "$LOG_PATH"
chmod 755 "$DATA_PATH" "$LOG_PATH"
msg_ok "User/Group/Dirs ready"
}
# ==============================================================================
# UNINSTALL
# ==============================================================================
function uninstall() {
msg_info "Uninstalling ${APP}"
if [[ "$OS" == "Alpine" ]]; then
rc-service copyparty stop &>/dev/null || true
rc-update del copyparty &>/dev/null || true
rm -f "$SERVICE_PATH"
else
systemctl disable --now copyparty.service &>/dev/null || true
rm -f "$SERVICE_PATH"
fi
rm -f "$BIN_PATH" "$CONF_PATH"
rm -rf "$DATA_PATH" "$LOG_PATH"
userdel "$SVC_USER" 2>/dev/null || true
groupdel "$SVC_GROUP" 2>/dev/null || true
rm -f "/usr/local/bin/update_copyparty"
rm -f "$HOME/.copyparty"
msg_ok "${APP} has been uninstalled"
}
# ==============================================================================
# UPDATE
# ==============================================================================
function update() {
if check_for_gh_release "copyparty-sfx.py" "9001/copyparty"; then
msg_info "Stopping service"
if [[ "$OS" == "Alpine" ]]; then
rc-service copyparty stop &>/dev/null || true
else
systemctl stop copyparty.service &>/dev/null || true
fi
msg_ok "Stopped service"
msg_info "Updating ${APP}"
curl -fsSL "$SRC_URL" -o "$BIN_PATH"
chmod +x "$BIN_PATH"
chown "$SVC_USER:$SVC_GROUP" "$BIN_PATH"
msg_ok "Updated ${APP}"
msg_info "Starting service"
if [[ "$OS" == "Alpine" ]]; then
rc-service copyparty start
else
systemctl start copyparty.service
fi
msg_ok "Started service"
msg_ok "Updated successfully!"
exit
fi
}
# ==============================================================================
# INSTALL
# ==============================================================================
function install() {
local port data_path enable_auth admin_user admin_pass
echo ""
read -rp "${TAB}Enter port for ${APP} [${DEFAULT_PORT}]: " port
port=${port:-$DEFAULT_PORT}
read -rp "${TAB}Set data directory [${DATA_PATH}]: " data_path
data_path=${data_path:-$DATA_PATH}
echo -n "${TAB}Enable authentication? (Y/n): "
read -r enable_auth
if [[ "${enable_auth,,}" =~ ^(n|no)$ ]]; then
admin_user=""
admin_pass=""
msg_ok "Configured without authentication"
else
read -rp "${TAB}Set admin username [admin]: " admin_user
admin_user=${admin_user:-admin}
read -rsp "${TAB}Set admin password [helper-scripts.com]: " admin_pass
echo ""
admin_pass=${admin_pass:-helper-scripts.com}
msg_ok "Configured with admin user: ${admin_user}"
fi
msg_info "Installing dependencies"
if [[ "$OS" == "Debian" ]]; then
$STD $PKG_MANAGER python3 python3-pil ffmpeg curl
else
$STD $PKG_MANAGER python3 py3-pillow ffmpeg curl
fi
msg_ok "Dependencies installed (with thumbnail support)"
setup_user_and_dirs
# Use data_path if provided
if [[ "$data_path" != "$DATA_PATH" ]]; then
DATA_PATH="$data_path"
mkdir -p "$DATA_PATH"
chown "$SVC_USER:$SVC_GROUP" "$DATA_PATH"
fi
msg_info "Downloading ${APP}"
curl -fsSL "$SRC_URL" -o "$BIN_PATH"
chmod +x "$BIN_PATH"
chown "$SVC_USER:$SVC_GROUP" "$BIN_PATH"
msg_ok "Downloaded to ${BIN_PATH}"
msg_info "Creating configuration"
cat <<EOF >"$CONF_PATH"
[global]
p: ${port}
ansi
e2dsa
e2ts
theme: 2
grid
no-robots
force-js
lo: ${LOG_PATH}/cpp-%Y-%m%d.txt.xz
EOF
if [[ -n "$admin_user" && -n "$admin_pass" ]]; then
cat <<EOF >>"$CONF_PATH"
[accounts]
${admin_user}: ${admin_pass}
EOF
fi
cat <<EOF >>"$CONF_PATH"
[/]
${DATA_PATH}
accs:
EOF
if [[ -n "$admin_user" ]]; then
cat <<EOF >>"$CONF_PATH"
rw: *
rwmda: ${admin_user}
EOF
else
cat <<EOF >>"$CONF_PATH"
rw: *
EOF
fi
chmod 640 "$CONF_PATH"
chown "$SVC_USER:$SVC_GROUP" "$CONF_PATH"
msg_ok "Created configuration"
msg_info "Creating service"
if [[ "$OS" == "Alpine" ]]; then
cat <<'SERVICEEOF' >"$SERVICE_PATH"
#!/sbin/openrc-run
name="copyparty"
description="CopyParty file server"
command="$(command -v python3)"
command_args="/usr/local/bin/copyparty-sfx.py -c /etc/copyparty.conf"
command_background=true
directory="/var/lib/copyparty"
pidfile="/run/copyparty.pid"
output_log="/var/log/copyparty/copyparty.log"
error_log="/var/log/copyparty/copyparty.err"
depend() {
need net
}
SERVICEEOF
chmod +x "$SERVICE_PATH"
$STD rc-update add copyparty default
$STD rc-service copyparty start
else
cat <<SERVICEEOF >"$SERVICE_PATH"
[Unit]
Description=CopyParty file server
After=network.target
[Service]
User=${SVC_USER}
Group=${SVC_GROUP}
WorkingDirectory=${DATA_PATH}
ExecStart=/usr/bin/python3 ${BIN_PATH} -c ${CONF_PATH}
Restart=always
StandardOutput=append:${LOG_PATH}/copyparty.log
StandardError=append:${LOG_PATH}/copyparty.err
[Install]
WantedBy=multi-user.target
SERVICEEOF
systemctl daemon-reload
systemctl enable --now copyparty.service &>/dev/null
fi
msg_ok "Created and started service"
# Create update script
msg_info "Creating update script"
ensure_usr_local_bin_persist
cat <<'UPDATEEOF' >/usr/local/bin/update_copyparty
#!/usr/bin/env bash
# CopyParty Update Script
type=update bash -c "$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/tools/addon/copyparty.sh)"
UPDATEEOF
chmod +x /usr/local/bin/update_copyparty
msg_ok "Created update script (/usr/local/bin/update_copyparty)"
echo ""
msg_ok "${APP} installed successfully"
msg_ok "Web UI: ${BL}http://${LOCAL_IP}:${port}${CL}"
msg_ok "Storage: ${BL}${DATA_PATH}${CL}"
msg_ok "Config: ${BL}${CONF_PATH}${CL}"
if [[ -n "$admin_user" ]]; then
echo ""
msg_ok "Login: ${GN}${admin_user}${CL} / ${GN}${admin_pass}${CL}"
fi
}
# ==============================================================================
# MAIN
# ==============================================================================
header_info
ensure_usr_local_bin_persist
get_lxc_ip
# Handle type=update (called from update script)
if [[ "${type:-}" == "update" ]]; then
if [[ -f "$BIN_PATH" ]]; then
update
else
msg_error "${APP} is not installed. Nothing to update."
exit 233
fi
exit 0
fi
# Check if already installed
if [[ -f "$BIN_PATH" ]]; then
msg_warn "${APP} is already installed."
echo ""
echo -n "${TAB}Uninstall ${APP}? (y/N): "
read -r uninstall_prompt
if [[ "${uninstall_prompt,,}" =~ ^(y|yes)$ ]]; then
uninstall
exit 0
fi
echo -n "${TAB}Update ${APP}? (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 "${APP} is not installed."
echo ""
echo -e "${TAB}${INFO} This will install:"
echo -e "${TAB} - CopyParty (Python file server)"
echo -e "${TAB} - Thumbnail support (Pillow, FFmpeg)"
echo -e "${TAB} - Systemd/OpenRC service"
echo ""
echo -n "${TAB}Install ${APP}? (y/N): "
read -r install_prompt
if [[ "${install_prompt,,}" =~ ^(y|yes)$ ]]; then
install
else
msg_warn "Installation cancelled. Exiting."
exit 0
fi