-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·99 lines (76 loc) · 2.32 KB
/
test.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
92
93
94
95
96
97
98
99
#!/usr/bin/env bash
httpd_config=$(httpd -V | grep -i SERVER_CONFIG_FILE | awk -F '"' '{print $2}')
vhosts_dir=${httpd_config%/*}/vhosts
vhost_config=${vhosts_dir}/test-dot-dev-and-local.conf
listen_port=$(grep '^Listen' "$httpd_config" | awk '{print $2}')
# make sure httpd is including vhost-configs
# a. try and reuse default commented out vhost-decleration
sed -i .orig "s|#Include\(.*vhosts.*\)$|Include ${vhosts_dir}/*conf|" "$httpd_config"
# b. simply append our own
if ! grep "Include ${vhosts_dir}/\*conf" "$httpd_config" 2> /dev/null; then
echo "Include ${vhosts_dir}/*conf" >> "$httpd_config"
fi
mkdir -p "$vhosts_dir"
# replace {{…}} placeholders and write our vhost-config
sed "s|{{PATH}}|$(PWD)|g" vhosts-template.conf \
| sed "s|{{PORT}}|${listen_port}|g" \
> "$vhost_config"
# bail if something looks wrong
if ! apachectl configtest; then
exit 1
fi
# Optionally: [Clear the local DNS cache in macOS Sierra](https://coolestguidesontheplanet.com/clear-the-local-dns-cache-in-osx/)
# sudo killall -HUP mDNSResponder
apachectl -k restart &> /dev/null
# configure test run
result_id=$(date +%s)
result_file=results/${result_id}.md
mkdir -p results
hostnames=$(grep ServerName vhosts-template.conf | awk '{print $2}')
# helper functions
logresult() {
if [[ -f $1 ]]; then
echo "**${1}**" >> "$result_file"
echo >> "$result_file"
echo '```' >> "$result_file"
cat "$1" >> "$result_file"
echo '```' >> "$result_file"
echo >> "$result_file"
else
echo "$1" >> "$result_file"
fi
}
test_hostname() {
logresult "### ${1} response"
logresult
logresult '```'
curl -w '@curl-template.txt' --connect-timeout 10 -s http://${1}:$listen_port >> "$result_file"
logresult '```'
logresult
}
# take note of system
logresult "# run $result_id"
logresult
logresult '**System**'
logresult
logresult '```'
logresult "$(sw_vers)"
logresult "$(httpd -v)"
logresult '```'
logresult
# setup /etc/hosts
for name in $hostnames; do
if ! grep "$name" /etc/hosts &> /dev/null; then
echo "127.0.0.1 $name" | sudo tee -a /etc/hosts > /dev/null
fi
done
logresult /etc/hosts
# do test
for name in $hostnames; do
test_hostname $name
done
logresult '## Configs'
logresult
logresult "$vhost_config"
logresult "$httpd_config"
open "$result_file"