-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathfuncs.sh
More file actions
195 lines (175 loc) · 5.18 KB
/
funcs.sh
File metadata and controls
195 lines (175 loc) · 5.18 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
# ech-dev-utils utility functions
function envcheck()
{
# check an env var that is needed here is set
if [[ "$1" == "" ]]
then
echo "Missing env var - exiting"
exit 1
fi
}
function whenisitagain()
{
/bin/date -u +%Y%m%d-%H%M%S
}
cli_test() {
local port=$1
local runparm=$2
local target="foo.example.com"
local lres="0"
local gorp="-g "
if [[ "$runparm" == "public" ]]
then
gorp="-g "
target="example.com"
elif [[ "$runparm" == "grease" ]]
then
gorp="-g "
elif [[ "$runparm" == "hrr" ]]
then
gorp="-P $RUNTOP/echconfig.pem -R "
elif [[ "$runparm" == "real" ]]
then
gorp="-P $RUNTOP/echconfig.pem "
else
echo "bad cli_test parameter $runparm, exiting"
exit 99
fi
envcheck $EDTOP
envcheck $CLILOGFILE
envcheck $allgood
$EDTOP/scripts/echcli.sh $clilog $gorp -p $port -H $target -s localhost -f index.html -d >>$CLILOGFILE 2>&1
lres=$?
if [[ "$lres" != "0" ]]
then
echo "test failed: $EDTOP/scripts/echcli.sh $clilog $gorp -p $port -H $target -s localhost -f index.html"
allgood="no"
fi
}
# stop a lighttpd if one is running
lighty_stop() {
local pfile="$RUNTOP/lighttpd/logs/lighttpd.pid"
if [ -s $pfile ]
then
kill `cat $pfile`
rm -f $pfile
fi
}
# Check if a lighttpd is running, start one if not
lighty_start() {
local cfgfile=$1
local pfile="$RUNTOP/lighttpd/logs/lighttpd.pid"
lighty_stop
envcheck $RUNTOP
envcheck $LIGHTY
envcheck $SRVLOGFILE
if [ ! -f $cfgfile ]
then
echo "Can't read $cfgfile - exiting"
exit 45
fi
if [[ "$PACKAGING" == "" ]]
then
$LIGHTY/src/lighttpd -f $cfgfile -m $LIGHTY/src/.libs >>$SRVLOGFILE 2>&1
else
lighttpd -f $cfgfile >>$SRVLOGFILE 2>&1
fi
# Check we now have a lighty running
if [ ! -f $pfile ]
then
echo "Can't read $pfile - exiting"
exit 45
fi
}
s_server_start() {
local srunning=`ps -ef | grep s_server | grep -v grep | grep -v tail | awk '{print $2}'`
local hrr=$1
local be_port=$2
envcheck $EDTOP
envcheck $SRVLOGFILE
if [[ "$srunning" == "" ]]
then
# ditch or keep server tracing
if [[ "$hrr" == "hrr" ]]
then
# $EDTOP/scripts/echsvr.sh -e -k echconfig.pem -p $be_port -R >>$SRVLOGFILE 2>&1 &
$EDTOP/scripts/echsvr.sh -e -n -p $be_port -R >>$SRVLOGFILE 2>&1 &
else
# $EDTOP/scripts/echsvr.sh -e -k echconfig.pem -p $be_port >>$SRVLOGFILE 2>&1 &
$EDTOP/scripts/echsvr.sh -e -n -p $be_port >>$SRVLOGFILE 2>&1 &
fi
# recheck in a sec
sleep 2
srunning=`ps -ef | grep s_server | grep -v grep | grep -v tail | awk '{print $2}'`
if [[ "$srunning" == "" ]]
then
echo "Failed to start s_server - exiting"
exit 87
fi
fi
}
s_server_stop() {
local srunning=`ps -ef | grep s_server | grep -v grep | grep -v tail | awk '{print $2}'`
if [[ "$srunning" != "" ]]
then
kill $srunning
fi
}
# hackyery hack - prepare a nginx conf to use in localhost tests
do_envsubst() {
envcheck $EDTOP
envcheck $RUNTOP
# We'll use sed for now as figuring out how to get envsubst running in the github CI
# isn't (yet;-) obvious
# cat $EDTOP/configs/nginxsplit.conf | envsubst '{$RUNTOP}' >$RUNTOP/nginx/nginxsplit.conf
# cat $EDTOP/configs/nginxmin.conf | envsubst '{$RUNTOP}' >$RUNTOP/nginx/nginxmin.conf
sed "s#\$RUNTOP#$RUNTOP#g" "$EDTOP/configs/nginxmin.conf" > "$RUNTOP/nginx/nginxmin.conf"
sed "s#\$RUNTOP#$RUNTOP#g" "$EDTOP/configs/nginxsplit.conf" > "$RUNTOP/nginx/nginxsplit.conf"
}
prep_server_dirs() {
local tech=$1
envcheck $RUNTOP
cd $RUNTOP
# make sure fake CA is setup
if [ ! -d $RUNTOP/cadir ]
then
# don't re-do this if not needed, might break other configs
$EDTOP/scripts/make-example-ca.sh
fi
# make sure we have an ECHConfig PEM file
if [ ! -f $RUNTOP/echconfig.pem ]
then
$CMDPATH ech -public_name example.com || true
fi
if [ ! -d $RUNTOP/echkeydir ]
then
mkdir -p $RUNTOP/echkeydir
cp $RUNTOP/echconfig.pem $RUNTOP/echkeydir/echconfig.pem.ech
fi
# make directories for lighttpd stuff if needed
mkdir -p $RUNTOP/$tech/logs
for docroot in example.com foo.example.com baz.example.com
do
mkdir -p $RUNTOP/$tech/dir-$docroot
# check for/make a home page for example.com and other virtual hosts
if [ ! -f $RUNTOP/$tech/dir-$docroot/index.html ]
then
cat >$RUNTOP/$tech/dir-$docroot/index.html <<EOF
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>$docroot $tech top page.</title>
</head>
<!-- Background white, links blue (unvisited), navy (visited), red
(active) -->
<body bgcolor="#FFFFFF" text="#000000" link="#0000FF"
vlink="#000080" alink="#FF0000">
<p>This is the pretty dumb top page for $tech $docroot testing. </p>
</body>
</html>
EOF
fi
done
cd -
}