Refactor A-B (#15075)

This commit is contained in:
Slaviša Arežina
2026-06-13 18:43:15 +02:00
committed by GitHub
parent 07ab5dc16e
commit d4b9bc86e8
17 changed files with 93 additions and 173 deletions
+8 -12
View File
@@ -26,26 +26,26 @@ function update_script() {
check_container_resources
TOMCAT_DIR=$(ls -d /opt/tomcat-* 2>/dev/null | head -n1)
if [[ -z "$TOMCAT_DIR" || ! -d "$TOMCAT_DIR" ]]; then
if [[ -z $TOMCAT_DIR || ! -d $TOMCAT_DIR ]]; then
msg_error "No ${APP} Installation Found!"
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
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
if [[ -z $LATEST_VERSION ]]; then
msg_error "Failed to fetch latest version for Tomcat ${TOMCAT_MAJOR}"
exit
fi
if [[ "$CURRENT_VERSION" == "$LATEST_VERSION" ]]; then
if [[ $CURRENT_VERSION == "$LATEST_VERSION" ]]; then
msg_ok "${APP} ${CURRENT_VERSION} is already up to date"
exit
fi
@@ -54,13 +54,9 @@ function update_script() {
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"
create_backup $TOMCAT_DIR/conf
[[ -d $TOMCAT_DIR/webapps ]] && create_backup $TOMCAT_DIR/webapps
[[ -d $TOMCAT_DIR/lib ]] && create_backup $TOMCAT_DIR/lib
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"
@@ -78,7 +74,7 @@ function update_script() {
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
[[ -f $jar ]] || continue
jar_name=$(basename "$jar")
if [[ ! -f "$TOMCAT_DIR/lib/$jar_name" ]]; then
cp "$jar" "$TOMCAT_DIR/lib/"