Repository navigation
Expand file tree
/
Copy pathsetup_admin.sh
More file actions
executable file
·84 lines (70 loc) · 3.01 KB
/
Copy pathsetup_admin.sh
File metadata and controls
executable file
·84 lines (70 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
# WordPress Local Development Environment - Admin Setup
# Run this script to configure system-level settings that require admin privileges
echo "🔐 WordPress Local Development Environment - Admin Setup"
echo "========================================================"
echo ""
echo "This script will configure system-level settings that require admin privileges:"
echo "1. Trust SSL certificates in system keychain"
echo "2. Configure hosts file entries for local domains"
echo ""
# Function to add domain to hosts file
add_domain_to_hosts() {
local domain=$1
local hosts_file="/etc/hosts"
if ! grep -q "$domain" "$hosts_file"; then
echo "Adding $domain to hosts file..."
echo "127.0.0.1 $domain" | sudo tee -a "$hosts_file" > /dev/null
echo "✅ Added $domain to hosts file"
else
echo "ℹ️ $domain already exists in hosts file"
fi
}
# Function to trust SSL certificate
trust_ssl_cert() {
local cert_file=$1
local domain=$2
if [[ -f "$cert_file" ]]; then
echo "Trusting SSL certificate for $domain..."
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain "$cert_file"
echo "✅ SSL certificate trusted for $domain"
else
echo "⚠️ Certificate file not found: $cert_file"
fi
}
# Check for existing projects and configure them
if [[ -d "wordpress-projects" ]]; then
echo "🔍 Scanning for existing WordPress projects..."
for project_dir in wordpress-projects/*/; do
if [[ -d "$project_dir" ]]; then
project_name=$(basename "$project_dir")
config_file="$project_dir/config.json"
cert_file="$project_dir/ssl/cert.pem"
if [[ -f "$config_file" ]]; then
# Extract domain from config file
domain=$(python3 -c "import json; print(json.load(open('$config_file')).get('domain', 'local.$project_name.test'))" 2>/dev/null || echo "local.$project_name.test")
# Remove subfolder from domain for hosts file
clean_domain=$(echo "$domain" | cut -d'/' -f1)
echo ""
echo "📂 Configuring project: $project_name"
echo " Domain: $clean_domain"
# Add to hosts file
add_domain_to_hosts "$clean_domain"
# Trust SSL certificate
if [[ -f "$cert_file" ]]; then
trust_ssl_cert "$cert_file" "$clean_domain"
fi
fi
fi
done
else
echo "ℹ️ No WordPress projects found. Create a project first, then run this script."
fi
echo ""
echo "✅ Admin setup complete!"
echo ""
echo "📋 Next steps:"
echo "1. Create WordPress projects through the web interface at http://localhost:5001"
echo "2. Run this script again after creating new projects to configure them"
echo "3. Your sites will be accessible at https://local.PROJECT_NAME.test"
echo ""