-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwordpress.sh
More file actions
179 lines (146 loc) · 5.09 KB
/
wordpress.sh
File metadata and controls
179 lines (146 loc) · 5.09 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/bin/bash
RED='\e[31m'
BLU='\e[34m'
GRN='\e[32m'
YEL='\033[0;33m'
DEF='\e[0m'
echo -e ${GRN} "Installing system utils" ${DEF}
apt-get update -qq
apt-get -qqq -y install curl net-tools bind9-host > /dev/null 2>&1
MYIP=$(curl -4s --max-time 10 ifconfig.me 2>/dev/null || curl -4s --max-time 10 icanhazip.com 2>/dev/null)
validate_domain() {
local domain=$1
host "$domain" 2>/dev/null | grep -q "has address"
}
echo
echo
echo -e ${GRN} "# ------------------------------------------------------------- #"
echo -e ${GRN} "# ${BLU}WELCOME TO WORDPRESS INSTALL SCRIPT ${GRN}#"
echo -e ${GRN} "# ------------------------------------------------------------- #"
echo
echo -e ${YEL}
while true; do
echo
printf "${YEL}Please enter Domain Name, or hit enter for insecure installation: ${DEF}"
read DOMAIN
if [ -z "$DOMAIN" ]; then
echo -e "${GRN}Proceeding without TLS (HTTP only)${DEF}"
break
fi
echo -e "${BLU}Checking DNS for ${DOMAIN}...${DEF}"
if validate_domain "$DOMAIN"; then
RESOLVED_IP=$(host "$DOMAIN" 2>/dev/null | grep "has address" | head -1 | awk '{print $NF}')
if [ "$RESOLVED_IP" = "$MYIP" ]; then
echo -e "${GRN}DNS verified: ${DOMAIN} -> ${MYIP} (direct)${DEF}"
else
echo -e "${GRN}DNS verified: ${DOMAIN} -> ${RESOLVED_IP} (CDN/proxy)${DEF}"
fi
break
else
echo -e "${RED}ERROR: Domain '${DOMAIN}' does not resolve to any IP address.${DEF}"
echo -e "${YEL}Please ensure DNS is configured correctly, then try again.${DEF}"
echo -e "${YEL}Or press Enter to skip TLS and use HTTP only.${DEF}"
fi
done
echo -e ${BLU} "Installing Docker..." ${DEF}
curl -s https://raw.githubusercontent.com/PetroSky-Cloud/One-click-app/main/docker.sh | bash
echo -e ${BLU} "Creating WordPress directories..." ${DEF}
mkdir -p /opt/wordpress
cd /opt/wordpress
echo -e ${BLU} "Generating secrets..." ${DEF}
MYSQL_ROOT_PASSWORD=$(openssl rand -hex 16)
MYSQL_PASSWORD=$(openssl rand -hex 16)
echo -e ${BLU} "Creating docker-compose.yml..." ${DEF}
cat > /opt/wordpress/docker-compose.yml << 'EOFCOMPOSE'
services:
wordpress:
image: wordpress:latest
container_name: wordpress
restart: unless-stopped
ports:
- "8080:80"
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: ${MYSQL_PASSWORD}
WORDPRESS_DB_NAME: wordpress
volumes:
- wordpress_data:/var/www/html
depends_on:
- db
db:
image: mariadb:11
container_name: wordpress_db
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
volumes:
- db_data:/var/lib/mysql
volumes:
wordpress_data:
db_data:
EOFCOMPOSE
echo -e ${BLU} "Creating environment file..." ${DEF}
cat > /opt/wordpress/.env << EOFENV
MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
MYSQL_PASSWORD=${MYSQL_PASSWORD}
EOFENV
if [ -n "$DOMAIN" ]; then
echo -e ${BLU} "Setting up Caddy reverse proxy with TLS..." ${DEF}
curl -s https://raw.githubusercontent.com/PetroSky-Cloud/One-click-app/main/caddy.sh | bash -s -- $DOMAIN 8080 false
fi
echo -e ${BLU} "Starting WordPress..." ${DEF}
docker compose pull
docker compose up -d
sleep 20
MYIP=$(curl -4s --max-time 10 ifconfig.me 2>/dev/null || curl -4s --max-time 10 icanhazip.com 2>/dev/null || echo "YOUR_SERVER_IP")
if [ -n "$DOMAIN" ]; then
ACCESS_URL="https://${DOMAIN}"
else
ACCESS_URL="http://${MYIP}:8080"
fi
echo
echo -e "${GRN}========================================================================${DEF}"
echo -e "${GRN} WORDPRESS INSTALLATION COMPLETE ${DEF}"
echo -e "${GRN}========================================================================${DEF}"
echo
echo -e "${YEL} ACCESS URL: ${GRN}${ACCESS_URL}${DEF}"
echo
echo -e "${BLU} Complete the WordPress setup wizard in your browser.${DEF}"
echo
echo -e "${GRN}========================================================================${DEF}"
echo
cat > /root/README.txt << EOF
WordPress - Website & Blog Platform
====================================
Access: ${ACCESS_URL}
First-time setup:
1. Open the URL above
2. Select your language
3. Create admin account
4. Configure site title and settings
Database Credentials (stored in /opt/wordpress/.env):
Host: db
Database: wordpress
User: wordpress
Password: ${MYSQL_PASSWORD}
Manage WordPress:
cd /opt/wordpress
docker compose ps # Check status
docker compose logs -f # View logs
docker compose restart # Restart
docker compose pull && docker compose up -d # Update
Backup:
Database: docker exec wordpress_db mysqldump -u root -p${MYSQL_ROOT_PASSWORD} wordpress > backup.sql
Files: docker cp wordpress:/var/www/html ./wordpress-files
Plugins/Themes:
Install via WordPress admin dashboard (Plugins/Themes menu)
Documentation: https://wordpress.org/documentation/
Installed: $(date)
EOF
echo -e "${BLU}README: /root/README.txt${DEF}"
echo
rm -f /etc/profile.d/install.sh