|
5 | 5 | # gl0bal01 - WpQuickDev |
6 | 6 | set -euo pipefail |
7 | 7 |
|
8 | | -# Color output functions |
9 | | -red() { echo -e "\033[31m$1\033[0m"; } |
10 | | -green() { echo -e "\033[32m$1\033[0m"; } |
11 | | -yellow() { echo -e "\033[33m$1\033[0m"; } |
12 | | -blue() { echo -e "\033[34m$1\033[0m"; } |
| 8 | +ESC=$(printf '\033') |
| 9 | +red() { printf '%s[31m%s%s[0m\n' "$ESC" "$1" "$ESC"; } |
| 10 | +green() { printf '%s[32m%s%s[0m\n' "$ESC" "$1" "$ESC"; } |
| 11 | +yellow() { printf '%s[33m%s%s[0m\n' "$ESC" "$1" "$ESC"; } |
| 12 | +blue() { printf '%s[34m%s%s[0m\n' "$ESC" "$1" "$ESC"; } |
13 | 13 |
|
14 | 14 | PROJECT_NAME="${1:-wordpress-dev}" |
15 | 15 |
|
|
22 | 22 |
|
23 | 23 | echo "$(blue "🚀 Creating WordPress Development Environment: $PROJECT_NAME")" |
24 | 24 |
|
25 | | -# Cleanup on interrupt before .env is written |
26 | | -SETUP_COMPLETE=0 |
| 25 | +# Remove partial project dir if setup aborts before .env is written |
27 | 26 | cleanup_on_exit() { |
28 | | - if [ "$SETUP_COMPLETE" -eq 0 ] && [ -n "${PROJECT_DIR:-}" ] && [ -d "$PROJECT_DIR" ] && [ ! -f "$PROJECT_DIR/.env" ]; then |
| 27 | + if [ -n "${PROJECT_DIR:-}" ] && [ -d "$PROJECT_DIR" ] && [ ! -f "$PROJECT_DIR/.env" ]; then |
29 | 28 | red "⚠️ Setup interrupted — removing partial project directory: $PROJECT_DIR" |
30 | 29 | rm -rf "$PROJECT_DIR" |
31 | 30 | fi |
@@ -395,9 +394,8 @@ fix-permissions: ## Fix file permissions for development |
395 | 394 | @echo "🔧 Fixing permissions..." |
396 | 395 | @mkdir -p wordpress plugins themes uploads backups .docker/mysql-logs |
397 | 396 | @chmod 0700 backups 2>/dev/null || true |
398 | | - @find wordpress plugins themes uploads -type d -exec chmod 0775 {} + 2>/dev/null || true |
399 | | - @find wordpress plugins themes uploads -type f -exec chmod 0664 {} + 2>/dev/null || true |
400 | | - @$(DOCKER_COMPOSE) exec -T wordpress bash -lc 'install -d -m 0775 /var/www/html/wp-content/plugins /var/www/html/wp-content/themes /var/www/html/wp-content/uploads 2>/dev/null || true; find /var/www/html -type d -exec chmod 0775 {} + 2>/dev/null || true; find /var/www/html -type f -exec chmod 0664 {} + 2>/dev/null || true' |
| 397 | + @find wordpress plugins themes uploads \( -type d -exec chmod 0775 {} + \) -o \( -type f -exec chmod 0664 {} + \) 2>/dev/null || true |
| 398 | + @$(DOCKER_COMPOSE) exec -T wordpress bash -lc 'install -d -m 0775 /var/www/html/wp-content/plugins /var/www/html/wp-content/themes /var/www/html/wp-content/uploads 2>/dev/null || true; find /var/www/html \( -type d -exec chmod 0775 {} + \) -o \( -type f -exec chmod 0664 {} + \) 2>/dev/null || true' |
401 | 399 | @echo "✅ Permissions fixed" |
402 | 400 |
|
403 | 401 | plugin: fix-permissions ## Create plugin (usage: make plugin name=my-plugin) |
@@ -1103,30 +1101,26 @@ mkdir -p plugins themes uploads backups .docker/mysql-logs wordpress |
1103 | 1101 | # Create .gitkeep files to maintain directory structure |
1104 | 1102 | touch plugins/.gitkeep themes/.gitkeep |
1105 | 1103 |
|
1106 | | -# Dev-friendly perms so both www-data and wpcli can write |
1107 | | -find wordpress plugins themes uploads -type d -exec chmod 0775 {} + 2>/dev/null || true |
1108 | | -find wordpress plugins themes uploads -type f -exec chmod 0664 {} + 2>/dev/null || true |
| 1104 | +# Dev-friendly perms on the freshly-created top-level dirs only. |
| 1105 | +# Recursive perms on WP core are handled later by `make fix-permissions`. |
| 1106 | +chmod 0775 wordpress plugins themes uploads 2>/dev/null || true |
1109 | 1107 | chmod 0700 backups 2>/dev/null || true |
1110 | 1108 |
|
1111 | 1109 | # Set proper permissions for scripts |
1112 | 1110 | chmod +x backup.sh restore.sh health-check.sh plugin-status.sh |
1113 | 1111 |
|
1114 | 1112 | # Validate generated docker-compose.yml syntax |
1115 | | -if command -v docker >/dev/null 2>&1; then |
1116 | | - if docker compose version >/dev/null 2>&1; then |
1117 | | - if ! docker compose config >/dev/null 2>&1; then |
1118 | | - red "❌ Generated docker-compose.yml is invalid" |
1119 | | - exit 1 |
1120 | | - fi |
1121 | | - elif command -v docker-compose >/dev/null 2>&1; then |
1122 | | - if ! docker-compose config >/dev/null 2>&1; then |
1123 | | - red "❌ Generated docker-compose.yml is invalid" |
1124 | | - exit 1 |
1125 | | - fi |
1126 | | - fi |
| 1113 | +if docker compose version >/dev/null 2>&1; then |
| 1114 | + COMPOSE_VALIDATE="docker compose" |
| 1115 | +elif command -v docker-compose >/dev/null 2>&1; then |
| 1116 | + COMPOSE_VALIDATE="docker-compose" |
| 1117 | +else |
| 1118 | + COMPOSE_VALIDATE="" |
| 1119 | +fi |
| 1120 | +if [ -n "$COMPOSE_VALIDATE" ] && ! $COMPOSE_VALIDATE config >/dev/null 2>&1; then |
| 1121 | + red "❌ Generated docker-compose.yml is invalid" |
| 1122 | + exit 1 |
1127 | 1123 | fi |
1128 | | - |
1129 | | -SETUP_COMPLETE=1 |
1130 | 1124 |
|
1131 | 1125 | echo "" |
1132 | 1126 | green "✅ Enhanced WordPress Development Environment created with Plugin Development Workflow!" |
|
0 commit comments