Остання активність 1746485425

Версія e56a8133e1de13d9d927cdd0bf5345b68591751e

update_docker_stacks.sh Неформатований
1#!/bin/bash
2
3set -euo pipefail
4
5# Regex for valid docker compose file names
6COMPOSE_REGEX='^(docker-compose|compose)\.ya?ml$'
7
8# Colors for output
9RED='\033[0;31m'
10GREEN='\033[0;32m'
11YELLOW='\033[1;33m'
12NC='\033[0m' # No Color
13
14# Dry-run mode
15DRY_RUN=0
16
17# Parse arguments
18while [[ $# -gt 0 ]]; do
19 case "$1" in
20 --dry-run)
21 DRY_RUN=1
22 shift
23 ;;
24 *)
25 ROOT_DIR="$1"
26 shift
27 ;;
28 esac
29done
30
31# Prompt for directory if not provided
32if [[ -z "${ROOT_DIR:-}" ]]; then
33 echo -e "${YELLOW}No root directory provided.${NC}"
34 read -e -p "Enter the root directory to search: " ROOT_DIR
35fi
36
37# Validate directory
38if [[ ! -d "$ROOT_DIR" ]]; then
39 echo -e "${RED}Error: '$ROOT_DIR' is not a valid directory.${NC}"
40 exit 1
41fi
42
43echo -e "${GREEN}Searching for docker-compose files in: $ROOT_DIR${NC}"
44
45processed=()
46skipped=()
47
48find "$ROOT_DIR" -maxdepth 1 -type d -print0 | while IFS= read -r -d $'\0' dir; do
49 # Skip the root directory itself if you want only subdirs
50 # [[ "$dir" == "$ROOT_DIR" ]] && continue
51
52 compose_file=""
53 for file in "$dir"/*; do
54 filename=$(basename "$file")
55 if [[ $filename =~ $COMPOSE_REGEX ]]; then
56 compose_file="$file"
57 break
58 fi
59 done
60
61 if [[ -n "$compose_file" ]]; then
62 echo -e "${GREEN}Processing: $dir ($compose_file)${NC}"
63 processed+=("$dir")
64 if [[ $DRY_RUN -eq 0 ]]; then
65 (
66 cd "$dir" || exit 1
67 docker compose -f "$compose_file" pull && docker compose -f "$compose_file" up -d
68 )
69 else
70 echo -e "${YELLOW}[Dry-run] Would run: docker compose -f \"$compose_file\" pull && docker compose -f \"$compose_file\" up -d${NC}"
71 fi
72 else
73 echo -e "${YELLOW}No compose file found in: $dir${NC}"
74 skipped+=("$dir")
75 fi
76done
77
78echo -e "\n${GREEN}Completed processing all subdirectories.${NC}"
79echo -e "${GREEN}Processed directories:${NC}"
80for d in "${processed[@]}"; do
81 echo " $d"
82done
83
84if [[ ${#skipped[@]} -gt 0 ]]; then
85 echo -e "${YELLOW}Skipped directories (no compose file found):${NC}"
86 for d in "${skipped[@]}"; do
87 echo " $d"
88 done
89fi