mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2026-08-02 19:13:04 +02:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ef8feb43b3 | |||
| ada63788bc |
@@ -0,0 +1,190 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Copyright (c) 2021-2026 community-scripts ORG
|
||||||
|
# Author: MickLesk (CanbiZ)
|
||||||
|
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
|
||||||
|
# Source: https://github.com/portainer/portainer
|
||||||
|
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
|
||||||
|
declare -f init_tool_telemetry &>/dev/null && init_tool_telemetry "portainer" "addon"
|
||||||
|
|
||||||
|
# Enable error handling
|
||||||
|
set -Eeuo pipefail
|
||||||
|
trap 'error_handler' ERR
|
||||||
|
|
||||||
|
# ==============================================================================
|
||||||
|
# CONFIGURATION
|
||||||
|
# ==============================================================================
|
||||||
|
APP="Portainer"
|
||||||
|
APP_TYPE="addon"
|
||||||
|
INSTALL_PATH="/opt/portainer"
|
||||||
|
COMPOSE_FILE="${INSTALL_PATH}/compose.yaml"
|
||||||
|
DEFAULT_PORT=9443
|
||||||
|
|
||||||
|
# Initialize all core functions (colors, formatting, icons, STD mode)
|
||||||
|
load_functions
|
||||||
|
|
||||||
|
# ==============================================================================
|
||||||
|
# UNINSTALL
|
||||||
|
# ==============================================================================
|
||||||
|
function uninstall() {
|
||||||
|
msg_info "Uninstalling ${APP}"
|
||||||
|
|
||||||
|
if [[ -f "$COMPOSE_FILE" ]]; then
|
||||||
|
msg_info "Stopping and removing Docker containers"
|
||||||
|
cd "$INSTALL_PATH"
|
||||||
|
$STD docker compose down --volumes --remove-orphans
|
||||||
|
msg_ok "Stopped and removed Docker containers"
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm -rf "$INSTALL_PATH"
|
||||||
|
rm -f "/usr/local/bin/update_portainer"
|
||||||
|
msg_ok "${APP} has been uninstalled"
|
||||||
|
}
|
||||||
|
|
||||||
|
# ==============================================================================
|
||||||
|
# UPDATE
|
||||||
|
# ==============================================================================
|
||||||
|
function update() {
|
||||||
|
msg_info "Pulling latest ${APP} image"
|
||||||
|
cd "$INSTALL_PATH"
|
||||||
|
$STD docker compose pull
|
||||||
|
msg_ok "Pulled latest image"
|
||||||
|
|
||||||
|
msg_info "Restarting ${APP}"
|
||||||
|
$STD docker compose up -d --remove-orphans
|
||||||
|
msg_ok "Restarted ${APP}"
|
||||||
|
|
||||||
|
msg_ok "Updated successfully"
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
|
# ==============================================================================
|
||||||
|
# CHECK DOCKER
|
||||||
|
# ==============================================================================
|
||||||
|
function check_docker() {
|
||||||
|
if ! command -v docker &>/dev/null; then
|
||||||
|
msg_error "Docker is not installed. This script requires an existing Docker LXC. Exiting."
|
||||||
|
exit 10
|
||||||
|
fi
|
||||||
|
if ! docker compose version &>/dev/null; then
|
||||||
|
msg_error "Docker Compose plugin is not available. Please install it before running this script. Exiting."
|
||||||
|
exit 10
|
||||||
|
fi
|
||||||
|
msg_ok "Docker $(docker --version | cut -d' ' -f3 | tr -d ',') and Docker Compose are available"
|
||||||
|
}
|
||||||
|
|
||||||
|
# ==============================================================================
|
||||||
|
# CHECK EXISTING CONTAINER
|
||||||
|
# ==============================================================================
|
||||||
|
function check_existing_container() {
|
||||||
|
# Guards against clobbering a Portainer container not managed by this addon
|
||||||
|
# (e.g. Business/Enterprise Edition installed manually or via the legacy docker.sh flow)
|
||||||
|
if docker ps -a --format '{{.Names}}' | grep -q '^portainer$'; then
|
||||||
|
msg_error "A container named 'portainer' already exists but is not managed by this addon."
|
||||||
|
msg_error "This may be a Portainer Business/Enterprise Edition install or a manual setup."
|
||||||
|
msg_error "Remove/rename that container first, or manage it manually. Exiting."
|
||||||
|
exit 10
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# ==============================================================================
|
||||||
|
# INSTALL
|
||||||
|
# ==============================================================================
|
||||||
|
function install() {
|
||||||
|
check_docker
|
||||||
|
check_existing_container
|
||||||
|
|
||||||
|
msg_info "Creating install directory"
|
||||||
|
mkdir -p "$INSTALL_PATH"
|
||||||
|
msg_ok "Created ${INSTALL_PATH}"
|
||||||
|
|
||||||
|
msg_info "Downloading Docker Compose file"
|
||||||
|
curl -fsSL "https://downloads.portainer.io/ce-sts/portainer-compose.yaml" -o "$COMPOSE_FILE"
|
||||||
|
msg_ok "Downloaded Docker Compose file"
|
||||||
|
|
||||||
|
msg_info "Starting ${APP}"
|
||||||
|
cd "$INSTALL_PATH"
|
||||||
|
$STD docker compose up -d
|
||||||
|
msg_ok "Started ${APP}"
|
||||||
|
|
||||||
|
# Create update script
|
||||||
|
msg_info "Creating update script"
|
||||||
|
cat <<'UPDATEEOF' >/usr/local/bin/update_portainer
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
# Portainer Update Script
|
||||||
|
type=update bash -c "$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/tools/addon/portainer.sh)"
|
||||||
|
UPDATEEOF
|
||||||
|
chmod +x /usr/local/bin/update_portainer
|
||||||
|
msg_ok "Created update script (/usr/local/bin/update_portainer)"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
msg_ok "${APP} is reachable at: ${BL}https://${LOCAL_IP}:${DEFAULT_PORT}${CL}"
|
||||||
|
echo ""
|
||||||
|
msg_warn "On first access, you'll be prompted to create an admin account."
|
||||||
|
}
|
||||||
|
|
||||||
|
# ==============================================================================
|
||||||
|
# MAIN
|
||||||
|
# ==============================================================================
|
||||||
|
|
||||||
|
# Handle type=update (called from update script)
|
||||||
|
if [[ "${type:-}" == "update" ]]; then
|
||||||
|
header_info
|
||||||
|
if [[ -f "$COMPOSE_FILE" ]]; then
|
||||||
|
update
|
||||||
|
else
|
||||||
|
msg_error "${APP} is not installed. Nothing to update."
|
||||||
|
exit 233
|
||||||
|
fi
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
header_info
|
||||||
|
get_lxc_ip
|
||||||
|
|
||||||
|
# Check if already installed
|
||||||
|
if [[ -f "$COMPOSE_FILE" ]]; 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} - Portainer (via Docker Compose)"
|
||||||
|
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
|
||||||
Reference in New Issue
Block a user