-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdomain.sh
executable file
·48 lines (41 loc) · 1.16 KB
/
domain.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
#!/bin/bash
confirm()
{
read -r -p "${1} [y/N] " response
case "$response" in
[yY][eE][sS]|[yY])
true
;;
*)
false
;;
esac
}
# Need to be root to access /etc/hosts file
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
if ! confirm "The /etc/hosts file will be modified do you want to continue ?"; then
exit 0
fi
# IP PHP container
IP_CONTAINER="172.40.0.10"
if grep "#[[:space:]]\{0,\}$IP_CONTAINER" /etc/hosts > /dev/null; then
echo "$IP_CONTAINER is commented in your /etc/hosts"
elif ! grep "$IP_CONTAINER" /etc/hosts > /dev/null; then
echo "Add entry $IP_CONTAINER in /etc/hosts"
echo -e "\n#Stack PHP Docker\n$IP_CONTAINER\n" >> /etc/hosts
fi
# Add domain name to your /etc/hosts
for DOMAIN_NAME in $(sed -n 's/server_name\(.*\);/\1/p' sites/*)
do
printf "Domain name "
if ! grep "$IP_CONTAINER.*[[:space:]]\{1,\}$DOMAIN_NAME" /etc/hosts > /dev/null; then
printf "[ ADD ] : "
sed -i "/$IP_CONTAINER/s/$/ $DOMAIN_NAME/" /etc/hosts > /dev/null # Add new domain name to /etc/hosts
else
printf "[ FOUND ]: "
fi
printf "$DOMAIN_NAME\n"
done