-
Notifications
You must be signed in to change notification settings - Fork 2
/
delsite.sh
executable file
·91 lines (62 loc) · 1.87 KB
/
delsite.sh
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
#!/bin/bash
#!/bin/sed -f
dir_name=$(dirname $0)
source "$dir_name/helpers/utils.sh"
source "$dir_name/functions.sh"
# Importing variable of configurations.
importing_variables $dir_name
# Setings default variables
set_defaults_variables $1 $2
TEMPORARY_FILE_VHOSTS="$dir_name/vhosts.conf"
TEMPORARY_FILE_HOSTS="$dir_name/hosts"
HOSTS_FILE="/etc/hosts"
# Verifying necessary params
verifying_params $site $db_name
# Check directory exists
dir_not_exists "Is directory this project not found."
# Database not exists exit
database_not_exists $db_name
add_separator
echo -n "Are you sure you want to remove the project? [y/n]: "
read is_remove_project
if [ "$is_remove_project" != 'y' ]; then
exit_proccess "Aborted"
fi
echo "=== Creating temporary files vhosts and hosts"
touch $TEMPORARY_FILE_VHOSTS
touch $TEMPORARY_FILE_HOSTS
echo "[Done]"
add_separator
echo "=== Removing virtual host"
sudo su -c\
"php -r \"echo preg_replace( '/\n# BEGIN $site(\n.*)+# END $site/', '', file_get_contents( '$VHOSTS_FILE' ) );\"\ > $TEMPORARY_FILE_VHOSTS"
echo "[Done]"
add_separator
echo "=== Removing website in hosts"
sudo su -c\
"sed -e \"s/$IP $site www.$site//g;/^$/d\" $HOSTS_FILE > $TEMPORARY_FILE_HOSTS"
echo "[Done]"
add_separator
echo "=== Copying new virtual host file"
sudo cp -rf $TEMPORARY_FILE_VHOSTS $VHOSTS_FILE
echo "[Done]"
add_separator
echo "=== Copying new hosts file"
sudo cp -rf $TEMPORARY_FILE_HOSTS $HOSTS_FILE
echo "[Done]"
add_separator
echo "=== Removing temporary files vhosts and hosts"
rm $TEMPORARY_FILE_VHOSTS
rm $TEMPORARY_FILE_HOSTS
echo "[Done]"
add_separator
echo "=== Removing directory $root"
rm -rf $root
echo "[Done]"
add_separator
echo "=== Deleting database $db_name"
echo "DROP DATABASE IF EXISTS $db_name;" | mysql -u"$DB_USER" -p"$DB_PASS" -h"$DB_HOST" &>> /dev/null
echo "[Done]"
add_separator
restart_server
echo "=== Project successfully removed"