Apache Tomcat: update support and refactor install script (#10739)

This commit is contained in:
CanbiZ (MickLesk)
2026-01-12 18:11:42 +01:00
committed by GitHub
parent c8f6786783
commit 25594c30aa
3 changed files with 83 additions and 68 deletions

View File

@@ -11,7 +11,7 @@ var_disk="${var_disk:-5}"
var_cpu="${var_cpu:-1}" var_cpu="${var_cpu:-1}"
var_ram="${var_ram:-1024}" var_ram="${var_ram:-1024}"
var_os="${var_os:-debian}" var_os="${var_os:-debian}"
var_version="${var_version:-12}" var_version="${var_version:-13}"
var_unprivileged="${var_unprivileged:-1}" var_unprivileged="${var_unprivileged:-1}"
header_info "$APP" header_info "$APP"
@@ -20,15 +20,79 @@ color
catch_errors catch_errors
function update_script() { function update_script() {
header_info header_info
check_container_storage check_container_storage
check_container_resources check_container_resources
if ! ls -d /opt/tomcat-* >/dev/null 2>&1; then
msg_error "No ${APP} Installation Found!" TOMCAT_DIR=$(ls -d /opt/tomcat-* 2>/dev/null | head -n1)
exit if [[ -z "$TOMCAT_DIR" || ! -d "$TOMCAT_DIR" ]]; then
fi msg_error "No ${APP} Installation Found!"
msg_error "Currently we don't provide an update function for this ${APP}."
exit exit
fi
# Detect major version and current version from install path (e.g., /opt/tomcat-11 -> 11)
TOMCAT_MAJOR=$(basename "$TOMCAT_DIR" | grep -oP 'tomcat-\K[0-9]+')
if [[ -z "$TOMCAT_MAJOR" ]]; then
msg_error "Cannot determine Tomcat major version from path: $TOMCAT_DIR"
exit
fi
CURRENT_VERSION=$(grep -oP 'Apache Tomcat Version \K[0-9.]+' "$TOMCAT_DIR/RELEASE-NOTES" 2>/dev/null || echo "unknown")
LATEST_VERSION=$(curl -fsSL "https://dlcdn.apache.org/tomcat/tomcat-${TOMCAT_MAJOR}/" | grep -oP 'v[0-9]+\.[0-9]+\.[0-9]+(-M[0-9]+)?/' | sort -V | tail -n1 | sed 's/\/$//; s/v//')
if [[ -z "$LATEST_VERSION" ]]; then
msg_error "Failed to fetch latest version for Tomcat ${TOMCAT_MAJOR}"
exit
fi
if [[ "$CURRENT_VERSION" == "$LATEST_VERSION" ]]; then
msg_ok "${APP} ${CURRENT_VERSION} is already up to date"
exit
fi
msg_info "Stopping Tomcat service"
systemctl stop tomcat
msg_ok "Stopped Tomcat service"
msg_info "Backing up configuration and applications"
BACKUP_DIR="/tmp/tomcat-backup-$$"
mkdir -p "$BACKUP_DIR"
cp -a "$TOMCAT_DIR/conf" "$BACKUP_DIR/conf"
cp -a "$TOMCAT_DIR/webapps" "$BACKUP_DIR/webapps"
[[ -d "$TOMCAT_DIR/lib" ]] && cp -a "$TOMCAT_DIR/lib" "$BACKUP_DIR/lib"
msg_ok "Backed up configuration and applications"
msg_info "Downloading Tomcat ${LATEST_VERSION}"
TOMCAT_URL="https://dlcdn.apache.org/tomcat/tomcat-${TOMCAT_MAJOR}/v${LATEST_VERSION}/bin/apache-tomcat-${LATEST_VERSION}.tar.gz"
curl -fsSL "$TOMCAT_URL" -o /tmp/tomcat-update.tar.gz
msg_ok "Downloaded Tomcat ${LATEST_VERSION}"
msg_info "Installing update"
rm -rf "${TOMCAT_DIR:?}"/*
tar --strip-components=1 -xzf /tmp/tomcat-update.tar.gz -C "$TOMCAT_DIR"
rm -f /tmp/tomcat-update.tar.gz
msg_ok "Installed update"
msg_info "Restoring configuration and applications"
cp -a "$BACKUP_DIR/conf"/* "$TOMCAT_DIR/conf/"
cp -a "$BACKUP_DIR/webapps"/* "$TOMCAT_DIR/webapps/" 2>/dev/null || true
if [[ -d "$BACKUP_DIR/lib" ]]; then
for jar in "$BACKUP_DIR/lib"/*.jar; do
[[ -f "$jar" ]] || continue
jar_name=$(basename "$jar")
if [[ ! -f "$TOMCAT_DIR/lib/$jar_name" ]]; then
cp "$jar" "$TOMCAT_DIR/lib/"
fi
done
fi
rm -rf "$BACKUP_DIR"
chown -R root:root "$TOMCAT_DIR"
msg_ok "Restored configuration and applications"
msg_info "Starting Tomcat service"
systemctl start tomcat
msg_ok "Started Tomcat service"
msg_ok "Updated successfully!"
exit
} }
start start

View File

@@ -6,7 +6,7 @@
], ],
"date_created": "2025-03-04", "date_created": "2025-03-04",
"type": "ct", "type": "ct",
"updateable": false, "updateable": true,
"privileged": false, "privileged": false,
"interface_port": 8080, "interface_port": 8080,
"documentation": "https://cwiki.apache.org/confluence/display/TOMCAT", "documentation": "https://cwiki.apache.org/confluence/display/TOMCAT",
@@ -23,7 +23,7 @@
"ram": 1024, "ram": 1024,
"hdd": 5, "hdd": 5,
"os": "debian", "os": "debian",
"version": "12" "version": "13"
} }
} }
], ],

View File

@@ -13,19 +13,6 @@ setting_up_container
network_check network_check
update_os update_os
msg_info "Installing Dependencies"
$STD apt-get install -y \
lsb-release \
apt-transport-https
msg_ok "Installed Dependencies"
msg_info "Setting up Adoptium Repository"
mkdir -p /etc/apt/keyrings
curl -fsSL "https://packages.adoptium.net/artifactory/api/gpg/key/public" | gpg --dearmor >/etc/apt/trusted.gpg.d/adoptium.gpg
echo "deb https://packages.adoptium.net/artifactory/deb $(awk -F= '/^VERSION_CODENAME/{print$2}' /etc/os-release) main" >/etc/apt/sources.list.d/adoptium.list
$STD apt-get update
msg_ok "Set up Adoptium Repository"
read -r -p "${TAB3}Which Tomcat version would you like to install? (9, 10.1, 11): " version read -r -p "${TAB3}Which Tomcat version would you like to install? (9, 10.1, 11): " version
case $version in case $version in
9) 9)
@@ -33,25 +20,8 @@ case $version in
echo "Which LTS Java version would you like to use? (8, 11, 17, 21): " echo "Which LTS Java version would you like to use? (8, 11, 17, 21): "
read -r jdk_version read -r jdk_version
case $jdk_version in case $jdk_version in
8) 8 | 11 | 17 | 21)
msg_info "Installing Temurin JDK 8 (LTS) for Tomcat $TOMCAT_VERSION" JAVA_VERSION="$jdk_version" setup_java
$STD apt-get install -y temurin-8-jdk
msg_ok "Setup Temurin JDK 8 (LTS)"
;;
11)
msg_info "Installing Temurin JDK 11 (LTS) for Tomcat $TOMCAT_VERSION"
$STD apt-get install -y temurin-11-jdk
msg_ok "Setup Temurin JDK 11 (LTS)"
;;
17)
msg_info "Installing Temurin JDK 17 (LTS) for Tomcat $TOMCAT_VERSION"
$STD apt-get install -qqy temurin-17-jdk
msg_ok "Setup Temurin JDK 17 (LTS)"
;;
21)
msg_info "Installing Temurin JDK 21 (LTS) for Tomcat $TOMCAT_VERSION"
$STD apt-get install -y temurin-21-jdk
msg_ok "Setup Temurin JDK 21 (LTS)"
;; ;;
*) *)
msg_error "Invalid JDK version selected. Please enter 8, 11, 17 or 21." msg_error "Invalid JDK version selected. Please enter 8, 11, 17 or 21."
@@ -61,26 +31,14 @@ case $version in
;; ;;
10 | 10.1) 10 | 10.1)
TOMCAT_VERSION="10" TOMCAT_VERSION="10"
echo "Which LTS Java version would you like to use? (11, 17): " echo "Which LTS Java version would you like to use? (11, 17, 21): "
read -r jdk_version read -r jdk_version
case $jdk_version in case $jdk_version in
11) 11 | 17 | 21)
msg_info "Installing Temurin JDK 11 (LTS) for Tomcat $TOMCAT_VERSION" JAVA_VERSION="$jdk_version" setup_java
$STD apt-get install -y temurin-11-jdk
msg_ok "Setup Temurin JDK 11"
;;
17)
msg_info "Installing Temurin JDK 17 (LTS) for Tomcat $TOMCAT_VERSION"
$STD apt-get install -y temurin-17-jdk
msg_ok "Setup Temurin JDK 17"
;;
21)
msg_info "Installing Temurin JDK 21 (LTS) for Tomcat $TOMCAT_VERSION"
$STD apt-get install -y temurin-21-jdk
msg_ok "Setup Temurin JDK 21 (LTS)"
;; ;;
*) *)
msg_error "Invalid JDK version selected. Please enter 11 or 17." msg_error "Invalid JDK version selected. Please enter 11, 17 or 21."
exit 1 exit 1
;; ;;
esac esac
@@ -90,15 +48,8 @@ case $version in
echo "Which LTS Java version would you like to use? (17, 21): " echo "Which LTS Java version would you like to use? (17, 21): "
read -r jdk_version read -r jdk_version
case $jdk_version in case $jdk_version in
17) 17 | 21)
msg_info "Installing Temurin JDK 17 (LTS) for Tomcat $TOMCAT_VERSION" JAVA_VERSION="$jdk_version" setup_java
$STD apt-get install -qqy temurin-17-jdk
msg_ok "Setup Temurin JDK 17"
;;
21)
msg_info "Installing Temurin JDK 21 (LTS) for Tomcat $TOMCAT_VERSION"
$STD apt-get install -y temurin-21-jdk
msg_ok "Setup Temurin JDK 21 (LTS)"
;; ;;
*) *)
msg_error "Invalid JDK version selected. Please enter 17 or 21." msg_error "Invalid JDK version selected. Please enter 17 or 21."