diff --git a/ct/npmplus.sh b/ct/npmplus.sh new file mode 100644 index 00000000..9e3b0917 --- /dev/null +++ b/ct/npmplus.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash +source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/build.func) +# Copyright (c) 2021-2025 community-scripts ORG +# Author: MickLesk (CanbiZ) +# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE +# Source: https://github.com/ZoeyVid/NPMplus + +APP="NPMplus" +var_tags="${var_tags:-proxy;nginx}" +var_cpu="${var_cpu:-1}" +var_ram="${var_ram:-512}" +var_disk="${var_disk:-3}" +var_os="${var_os:-alpine}" +var_version="${var_version:-3.21}" +var_unprivileged="${var_unprivileged:-1}" + +header_info "$APP" +variables +color +catch_errors + +function update_script() { + UPD=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "UPDATE MODE" --radiolist --cancel-button Exit-Script "Spacebar = Select" 14 60 2 \ + "1" "Check for Alpine Updates" OFF \ + "2" "Update NPMplus Docker Container" ON \ + 3>&1 1>&2 2>&3) + + header_info "$APP" + + case "$UPD" in + "1") + msg_info "Updating Alpine OS" + $STD apk -U upgrade + msg_ok "System updated" + exit + ;; + "2") + msg_info "Updating NPMplus Container" + cd /opt + msg_info "Pulling latest container image" + $STD docker compose pull + msg_info "Recreating container" + $STD docker compose up -d + msg_ok "NPMplus container updated" + exit + ;; + esac + exit 0 +} + +start +build_container +description + +msg_ok "Completed Successfully!\n" +echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}" +echo -e "${INFO}${YW} Access it using the following URL:${CL}" +echo -e "${TAB}${GATEWAY}${BGN}https://${IP}:81${CL}" diff --git a/install/npmplus-install.sh b/install/npmplus-install.sh new file mode 100644 index 00000000..ef355bc0 --- /dev/null +++ b/install/npmplus-install.sh @@ -0,0 +1,114 @@ +#!/usr/bin/env bash + +# Copyright (c) 2021-2025 community-scripts ORG +# Author: MickLesk (CanbiZ) +# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE +# Source: https://github.com/ZoeyVid/NPMplus + +source /dev/stdin <<<"$FUNCTIONS_FILE_PATH" +color +verb_ip6 +catch_errors +setting_up_container +network_check +update_os + +msg_info "Installing Dependencies" +$STD apk add \ + tzdata \ + gawk \ + yq +msg_ok "Installed Dependencies" + +msg_info "Installing Docker & Compose" +$STD apk add docker +$STD rc-service docker start +$STD rc-update add docker default + +get_latest_release() { + curl -fsSL https://api.github.com/repos/$1/releases/latest | grep '"tag_name":' | cut -d'"' -f4 +} +DOCKER_COMPOSE_LATEST_VERSION=$(get_latest_release "docker/compose") +DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker} +mkdir -p $DOCKER_CONFIG/cli-plugins +curl -fsSL https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_LATEST_VERSION/docker-compose-linux-x86_64 -o ~/.docker/cli-plugins/docker-compose +chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose +msg_ok "Installed Docker & Compose" + +msg_info "Fetching NPMplus" +cd /opt +curl -fsSL "https://raw.githubusercontent.com/ZoeyVid/NPMplus/refs/heads/develop/compose.yaml" -o compose.yaml +msg_ok "Fetched NPMplus" + +attempts=0 +while true; do + read -r -p "${TAB3}Enter your TZ Identifier (e.g., Europe/Berlin): " TZ_INPUT + if validate_tz "$TZ_INPUT"; then + break + fi + msg_error "Invalid timezone! Please enter a valid TZ identifier." + + attempts=$((attempts + 1)) + if [[ "$attempts" -ge 3 ]]; then + msg_error "Maximum attempts reached. Exiting." + exit 1 + fi +done + +read -r -p "${TAB3}Enter your ACME Email: " ACME_EMAIL_INPUT + +yq -i " + .services.npmplus.environment |= + (map(select(. != \"TZ=*\" and . != \"ACME_EMAIL=*\")) + + [\"TZ=$TZ_INPUT\", \"ACME_EMAIL=$ACME_EMAIL_INPUT\"]) +" /opt/compose.yaml + +msg_info "Building and Starting NPMplus (Patience)" +$STD docker compose up -d +CONTAINER_ID="" +for i in {1..60}; do + CONTAINER_ID=$(docker ps --filter "name=npmplus" --format "{{.ID}}") + if [[ -n "$CONTAINER_ID" ]]; then + STATUS=$(docker inspect --format '{{.State.Health.Status}}' "$CONTAINER_ID" 2>/dev/null || echo "starting") + if [[ "$STATUS" == "healthy" ]]; then + msg_ok "NPMplus is running and healthy" + break + elif [[ "$STATUS" == "unhealthy" ]]; then + msg_error "NPMplus container is unhealthy! Check logs." + docker logs "$CONTAINER_ID" + exit 1 + fi + fi + sleep 2 + [[ $i -eq 60 ]] && msg_error "NPMplus container did not become healthy within 120s." && docker logs "$CONTAINER_ID" && exit 1 +done +msg_ok "Builded and started NPMplus" + +motd_ssh +customize + +msg_info "Retrieving Default Login (Patience)" +LOGFILE="/tmp/npmplus.log" +docker logs "$CONTAINER_ID" &>"$LOGFILE" & + +PASSWORD_FOUND=0 +for i in {1..60}; do + if grep -q "Creating a new user:" "$LOGFILE"; then + PASSWORD_LINE=$(grep "Creating a new user:" "$LOGFILE" | head -n1) + PASSWORD=$(echo "$PASSWORD_LINE" | awk -F 'password: ' '{print $2}') + if [[ -n "$PASSWORD" ]]; then + echo -e "username: admin@example.org\npassword: $PASSWORD" >/opt/.npm_pwd + msg_ok "Saved default login to /opt/.npm_pwd" + PASSWORD_FOUND=1 + break + fi + fi + sleep 2 +done + +if [[ $PASSWORD_FOUND -eq 0 ]]; then + msg_error "Could not retrieve default login after 60 seconds." + echo -e "\nYou can manually try:\n docker logs $CONTAINER_ID | grep 'Creating a new user:'\n" +fi + +rm -f "$LOGFILE"