updated podman-update.sh
This commit is contained in:
@@ -1,68 +1,95 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# 1. Configuration: LIST OF EXCLUDED FOLDERS
|
# 1. CONFIGURATION
|
||||||
# NOTE: Items must be separated by SPACES, not commas.
|
# List folders to exclude (separated by spaces, NOT commas)
|
||||||
EXCLUDED_FOLDERS=("ai" "dns-adguard" "dns-pihole" "immich")
|
EXCLUDED_FOLDERS=("ai" "dns-adguard" "dns-pihole" "immich")
|
||||||
|
|
||||||
# 2. Set the base directory to the current script location
|
# 2. VALIDATION
|
||||||
BASE_DIR="."
|
# Ensure the script is running as root (Sudo) to avoid permission issues
|
||||||
|
if [ "$EUID" -ne 0 ]; then
|
||||||
|
echo "=========================================="
|
||||||
|
echo "ERROR: Please run this script as root"
|
||||||
|
echo "Usage: sudo $0"
|
||||||
|
echo "=========================================="
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
echo "========================================"
|
# 3. SETUP ABSOLUTE PATHS
|
||||||
echo "Starting Podman Update Script"
|
# Get the absolute path of the directory where this script is located
|
||||||
echo "Current Directory: $(pwd)"
|
# This ensures that even if we 'cd' into folders, we don't lose track of where we are.
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
|
||||||
|
echo "=========================================="
|
||||||
|
echo "Starting Podman Maintenance Script"
|
||||||
|
echo "Target Directory: $SCRIPT_DIR"
|
||||||
echo "Excluded Folders: ${EXCLUDED_FOLDERS[*]}"
|
echo "Excluded Folders: ${EXCLUDED_FOLDERS[*]}"
|
||||||
echo "========================================"
|
echo "=========================================="
|
||||||
|
|
||||||
# 3. Loop through all directories in the base directory
|
# 4. MAIN LOOP (Using Globbing instead of 'find' to prevent Subshell issues)
|
||||||
for dir in "$BASE_DIR"/*/; do
|
# "$SCRIPT_DIR"/*/ iterates through all immediate subdirectories
|
||||||
# Extract just the folder name
|
for dir in "$SCRIPT_DIR"/*/; do
|
||||||
|
# Extract just the folder name (e.g., /podman/essential/ -> "essential")
|
||||||
folder_name=$(basename "$dir")
|
folder_name=$(basename "$dir")
|
||||||
|
|
||||||
# --- NEW SAFER EXCLUSION LOGIC ---
|
# --- EXCLUSION CHECK ---
|
||||||
skip_folder=0
|
skip_folder=0
|
||||||
for excluded in "${EXCLUDED_FOLDERS[@]}"; do
|
for excluded in "${EXCLUDED_FOLDERS[@]}"; do
|
||||||
if [[ "$folder_name" == "$excluded" ]]; then
|
if [[ "$folder_name" == "$excluded" ]]; then
|
||||||
|
# Debug: echo "Skipping $folder_name (Excluded)"
|
||||||
skip_folder=1
|
skip_folder=1
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ "$skip_folder" -eq 1 ]; then
|
if [ "$skip_folder" -eq 1 ]; then
|
||||||
echo "[SKIPPING] Excluded folder found: $folder_name"
|
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
# ---------------------------------
|
# ---------------------
|
||||||
|
|
||||||
# Check if docker-compose.yml exists
|
# Check for compose file (handles both .yml and .yaml)
|
||||||
|
COMPOSE_FILE=""
|
||||||
if [ -f "$dir/docker-compose.yml" ]; then
|
if [ -f "$dir/docker-compose.yml" ]; then
|
||||||
echo ""
|
COMPOSE_FILE="$dir/docker-compose.yml"
|
||||||
echo "[PROCESSING] Updating stack in: $folder_name"
|
elif [ -f "$dir/docker-compose.yaml" ]; then
|
||||||
|
COMPOSE_FILE="$dir/docker-compose.yaml"
|
||||||
|
fi
|
||||||
|
|
||||||
# Change directory to the folder containing the compose file
|
# If file exists, proceed with updates
|
||||||
|
if [ -n "$COMPOSE_FILE" ]; then
|
||||||
|
echo ""
|
||||||
|
echo "=========================================="
|
||||||
|
echo "[PROCESSING] Folder: $folder_name"
|
||||||
|
|
||||||
|
# Change directory to the stack
|
||||||
|
# We trap errors in cd to prevent the script from running commands in the wrong place
|
||||||
cd "$dir" || {
|
cd "$dir" || {
|
||||||
echo "Error: Could not enter $dir"
|
echo "[ERROR] Could not enter $dir"
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
# Pull the latest images
|
echo " -> Step 1: Stopping containers..."
|
||||||
echo " -> Pulling latest images..."
|
podman-compose stop
|
||||||
|
|
||||||
|
echo " -> Step 2: Removing containers and networks (Down)..."
|
||||||
|
podman-compose down
|
||||||
|
|
||||||
|
echo " -> Step 3: Pulling latest images..."
|
||||||
podman-compose pull
|
podman-compose pull
|
||||||
|
|
||||||
# Force recreate and restart containers
|
echo " -> Step 4: Starting services (Up -d)..."
|
||||||
# -d: Detached mode
|
podman-compose up -d
|
||||||
# --force-recreate: Stops and recreates containers
|
|
||||||
echo " -> Force restarting services..."
|
|
||||||
podman-compose up -d --force-recreate
|
|
||||||
|
|
||||||
# Return to the original base directory
|
echo " -> [COMPLETED] $folder_name is updated."
|
||||||
cd "$BASE_DIR" || exit
|
|
||||||
|
|
||||||
echo "[FINISHED] $folder_name updated."
|
# Return to the base directory (Safety measure)
|
||||||
|
cd "$SCRIPT_DIR" || exit
|
||||||
else
|
else
|
||||||
echo "[IGNORE] No compose file found in $folder_name"
|
# Debug: Uncomment the line below to see which folders are being ignored
|
||||||
|
# echo "[IGNORE] No compose file in: $folder_name"
|
||||||
|
:
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "========================================"
|
echo ""
|
||||||
echo "All tasks completed."
|
echo "=========================================="
|
||||||
echo "========================================"
|
echo "All tasks successfully completed."
|
||||||
|
echo "=========================================="
|
||||||
|
|||||||
Reference in New Issue
Block a user