-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathvhost-remove.sh
More file actions
196 lines (169 loc) · 7.86 KB
/
Copy pathvhost-remove.sh
File metadata and controls
196 lines (169 loc) · 7.86 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/usr/bin/env bash
#----------------------------------------------------------------------------------
# EngineScript - A High-Performance WordPress Server Built on Ubuntu and Cloudflare
#----------------------------------------------------------------------------------
# Website: https://EngineScript.com
# GitHub: https://github.com/Enginescript/EngineScript
# License: GPL v3.0
#----------------------------------------------------------------------------------
# EngineScript Variables
source /usr/local/bin/enginescript/enginescript-variables.txt || { echo "Error: Failed to source /usr/local/bin/enginescript/enginescript-variables.txt" >&2; exit 1; }
source /home/EngineScript/enginescript-install-options.txt || { echo "Error: Failed to source /home/EngineScript/enginescript-install-options.txt" >&2; exit 1; }
# Source shared functions library
source /usr/local/bin/enginescript/scripts/functions/shared/enginescript-common.sh || { echo "Error: Failed to source /usr/local/bin/enginescript/scripts/functions/shared/enginescript-common.sh" >&2; exit 1; }
#----------------------------------------------------------------------------------
# Start Main Script
# Intro Warning
echo ""
echo "-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-"
echo "| Domain Removal |"
echo "-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-"
echo ""
echo -e "WARNING: This script will remove a site from your installation.\n\n${BOLD}This removal is irreversible and everything will be destroyed, including backups.${NORMAL}\nPlease be 100% sure of your choice before continuing with this process.\n\n"
sleep 1
# Enhanced confirmation with timeout and exit option
if ! prompt_yes_no "Are you sure you want to remove a domain from your server?" "n" 300; then
echo "Exiting domain removal script."
exit 0
fi
echo "Continuing with domain removal..."
# Domain Input
echo "For the domain name, enter only the domain portion (e.g., 'wordpresstesting')."
echo "Note: lowercase text only, no spaces or special characters. Do not include https:// or www."
echo ""
echo "Then, select a valid TLD from the provided list."
echo ""
# Prompt for domain name
while true; do
read -p "Enter the domain name (e.g., 'wordpresstesting'): " DOMAIN_NAME
if [[ "$DOMAIN_NAME" =~ ^[a-z0-9-]+$ ]]; then
echo "You entered: ${DOMAIN_NAME}"
break
else
echo "Invalid domain name. Only lowercase letters, numbers, and hyphens are allowed."
fi
done
# Prompt for TLD
echo ""
echo "Select a valid TLD from the list below:"
VALID_TLDS=(
# Common gTLDs
"com" "net" "org" "info" "biz" "name" "pro" "int"
# Popular gTLDs
"io" "dev" "app" "tech" "ai" "cloud" "store" "online" "site" "xyz" "club"
"design" "media" "agency" "solutions" "services" "digital" "studio" "live"
"blog" "news" "shop" "art" "finance" "health" "law" "marketing" "software"
# Country-code TLDs (ccTLDs)
"us" "uk" "ca" "au" "de" "fr" "es" "it" "nl" "se" "no" "fi" "dk" "jp" "cn"
"in" "br" "ru" "za" "mx" "ar" "ch" "at" "be" "pl" "gr" "pt" "tr" "kr" "hk"
"sg" "id" "my" "th" "ph" "vn" "nz" "ie" "il" "sa" "ae" "eg" "ng" "ke" "gh"
"co.uk"
)
select TLD in "${VALID_TLDS[@]}"; do
if [[ -n "$TLD" ]]; then
echo "You selected: ${TLD}"
break
else
echo "Invalid selection. Please choose a valid TLD from the list."
fi
done
# Combine domain name and TLD
DOMAIN="${DOMAIN_NAME}.${TLD}"
echo ""
echo "Full domain: ${DOMAIN}"
# Logging
LOG_FILE="/var/log/EngineScript/vhost-remove.log"
exec > >(tee -a "${LOG_FILE}") 2>&1
echo "Starting domain removal for ${DOMAIN} at $(date)"
# Remove domain from site list
# Check for the domain enclosed in quotes, matching the format in sites.sh
if grep -Fxq "\"${DOMAIN}\"" /home/EngineScript/sites-list/sites.sh
then
echo -e "${BOLD}Site List Removal Check: Passed\n\n${NORMAL}Removing ${DOMAIN} from site list...\n\n"
# Use grep -v to remove the line containing the quoted domain
grep -v "\"${DOMAIN}\"" /home/EngineScript/sites-list/sites.sh > /home/EngineScript/sites-list/sites.sh.old && mv /home/EngineScript/sites-list/sites.sh.old /home/EngineScript/sites-list/sites.sh
else
echo -e "${BOLD}Site List Removal Check: Failed\n\n${NORMAL}${DOMAIN} was not found on the site list.\n\n"
fi
# Remove MySQL credentials
if test -f "/home/EngineScript/mysql-credentials/${DOMAIN}.txt"
then
echo -e "${BOLD}MySQL Credentials Removal Check: Passed\n\n${NORMAL}Removing MySQL credentials for ${DOMAIN}...\n\n"
source "/home/EngineScript/mysql-credentials/${DOMAIN}.txt"
sudo mariadb -e "DROP DATABASE ${DB};"
sudo mariadb -e "DROP USER '${USR}'@'localhost';"
rm -f "/home/EngineScript/mysql-credentials/${DOMAIN}.txt"
else
echo -e "${BOLD}MySQL Credentials Check: Failed\n\n${NORMAL}${DOMAIN} did not have MySQL credentials.\n\n"
fi
# Remove Nginx vhosts
for VHOST in "/etc/nginx/sites-enabled/${DOMAIN}.conf" "/etc/nginx/admin/admin.${DOMAIN}.conf"; do
if test -f "${VHOST}"; then
echo -e "${BOLD}Nginx Vhost Removal Check: Passed\n\n${NORMAL}Removing ${VHOST}...\n\n"
rm -rf "${VHOST}"
else
echo -e "${BOLD}Nginx Vhost Removal Check: Failed\n\n${NORMAL}${VHOST} did not exist.\n\n"
fi
done
# Remove SSL certificates
if [[ -d "/etc/nginx/ssl/${DOMAIN}" ]];
then
echo -e "${BOLD}SSL Certificates Removal Check: Passed\n\n${NORMAL}Removing SSL certificates for ${DOMAIN}...\n\n"
rm -rf "/etc/nginx/ssl/${DOMAIN}"
else
echo -e "${BOLD}SSL Certificates Removal Check: Failed\n\n${NORMAL}${DOMAIN} did not have SSL Certificates.\n\n"
fi
# Remove main directory
if [[ -d "/var/www/sites/${DOMAIN}" ]];
then
echo -e "${BOLD}Main Directory Removal Check: Passed\n\n${NORMAL}Removing main directory for ${DOMAIN}...\n\n"
rm -rf "/var/www/sites/${DOMAIN}"
else
echo -e "${BOLD}Main Directory Removal Check: Failed\n\n${NORMAL}${DOMAIN} did not have a main directory.\n\n"
fi
# Remove backup directory
if [[ -d "/home/EngineScript/site-backups/${DOMAIN}" ]];
then
echo -e "${BOLD}Backup Directory Removal Check: Passed\n\n${NORMAL}Removing backup directory for ${DOMAIN}...\n\n"
rm -rf "/home/EngineScript/site-backups/${DOMAIN}"
else
echo -e "${BOLD}Backup Directory Removal Check: Failed\n\n${NORMAL}${DOMAIN} did not have a backup directory.\n\n"
fi
# Remove log directory
if [[ -d "/var/log/domains/${DOMAIN}" ]];
then
echo -e "${BOLD}Log Directory Removal Check: Passed\n\n${NORMAL}Removing log directory for ${DOMAIN}...\n\n"
rm -rf "/var/log/domains/${DOMAIN}"
else
echo -e "${BOLD}Log Directory Removal Check: Failed\n\n${NORMAL}${DOMAIN} did not have a log directory.\n\n"
fi
# --- Update Redis Database Count ---
echo "Updating Redis database count..."
# Source the updated site list
source /home/EngineScript/sites-list/sites.sh
# Get the number of remaining sites
REMAINING_SITES_COUNT=${#SITES[@]}
# Ensure the database count is at least 1
if [[ $REMAINING_SITES_COUNT -lt 1 ]]; then
EFFECTIVE_DB_COUNT=1
else
EFFECTIVE_DB_COUNT=$REMAINING_SITES_COUNT
fi
# Update redis.conf if the number needs changing
CURRENT_DB_COUNT=$(grep -E "^databases\s+[0-9]+" /etc/redis/redis.conf | awk '{print $2}')
if [[ "$CURRENT_DB_COUNT" != "$EFFECTIVE_DB_COUNT" ]]; then
echo "Adjusting Redis databases from ${CURRENT_DB_COUNT} to ${EFFECTIVE_DB_COUNT}..."
sed -i "s/^databases\s+[0-9]\+/databases ${EFFECTIVE_DB_COUNT}/" /etc/redis/redis.conf
else
echo "Redis database count (${EFFECTIVE_DB_COUNT}) is already correct."
fi
# Restart Services (including Redis if needed by alias-restart.sh)
echo "Restarting Nginx, PHP, and Redis..."
/usr/local/bin/enginescript/scripts/functions/alias/alias-restart.sh # This should restart nginx, php-fpm, and redis
echo ""
# Summary
echo "----------------------------------------------------------"
echo "Domain removal completed for ${DOMAIN}."
echo "Please verify that all associated files, directories, and configurations have been removed."
echo "----------------------------------------------------------"
sleep 5