-
Notifications
You must be signed in to change notification settings - Fork 28
/
install-civs
executable file
·277 lines (240 loc) · 8.6 KB
/
install-civs
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#!/bin/bash
id=`id -u`
CHOWN=/usr/sbin/chown # default
CHGRP=/usr/bin/chgrp
TestAndCreateDir() {
if [ ! -d "$1" ]; then
#echo "Directory $1 does not exist. Creating it."
mkdir "$1"
if [ "$id" = 0 ]; then
$CHOWN "$WEB_USER" "$1"
$CHGRP "$WEB_GROUP" "$1"
fi
fi
}
if [ $# -ne 1 ]
then
echo "ERROR: No settings file specified."
echo "Usage: install-civs <settings-file>"
exit 1
fi
settings_file="$1"
. "$settings_file" || exit 1
echo "Read settings file."
if [ -z "$ADMIN_KEY" ]
then
echo "ERROR: Must define $ADMIN_KEY in $settings_file to be something secret."
exit 1
fi
version=`head -1 README | perl -e '@a = split / /, <STDIN>; print $a[1]'`
echo "Installing version $version"
echo "Building executables"
(cd src; make -s gettimeofday timeout lockserv) || exit 1
echo "Creating target directories"
TestAndCreateDir "$HTMLDIR"
TestAndCreateDir "$CGIBINDIR"
TestAndCreateDir "$CGIBINDIR/languages"
TestAndCreateDir "$CIVSDATADIR"
TestAndCreateDir "$CIVSDATADIR/elections"
TestAndCreateDir "$CIVSDATADIR/invites"
rm -f "$CIVSDATADIR/elections/admission_control" "$CIVSDATADIR/lockserv"
SubstituteFile() {
echo " $1 -> $2"
if [[ ! -r "$1" ]]
then
echo " File $1 not found"
exit 1
fi
sed \
-e 's|@ADDTOPATH@|'$ADDTOPATH'|' \
-e 's|@ADMIN_KEY@|'$ADMIN_KEY'|' \
-e 's|@AUTH_SENDER@|'$AUTH_SENDER'|' \
-e 's|@CGIBINDIR@|'"$CGIBINDIR"'|' \
-e 's|@CIVSBINURL@|'"$CIVSBINURL"'|' \
-e 's|@CIVSDATADIR@|'"$CIVSDATADIR"'|' \
-e 's|@CIVSHOME@|'"$CIVSHOME"'|' \
-e 's|@CIVSURL@|'"$CIVSURL"'|' \
-e 's|@DONATE_URL@|'$DONATE_URL'|' \
-e 's|@EMAIL_SALT@|'$EMAIL_SALT'|' \
-e 's|@FILTER_TAGS@|'$FILTER_TAGS'|' \
-e 's|@FIXUTF8@|'$FIXUTF8'|' \
-e 's|@LOCALDEBUG@|'$LOCALDEBUG'|' \
-e 's|@LOG_HOME_VISITS@|'$LOG_HOME_VISITS'|' \
-e 's|@MAX_CHOICES@|'$MAX_CHOICES'|' \
-e 's|@MAX_EMAIL_LOAD@|'$MAX_EMAIL_LOAD'|' \
-e 's|@MAX_IMAGE_SIZE@|'$MAX_IMAGE_SIZE'|' \
-e 's|@MAX_UPLOAD_SIZE@|'$MAX_UPLOAD_SIZE'|' \
-e 's|@MAX_VOTER_ADD@|'$MAX_VOTER_ADD'|' \
-e 's|@MAX_TEST_BALLOTS@|'$MAX_TEST_BALLOTS'|' \
-e 's|@PERL@|'$PERL'|' \
-e 's|@PERLEXT@|'$PERLEXT'|' \
-e 's|@PROTO@|'$PROTO'|' \
-e 's|@SMTP_AUTH_PASSWD@|'$SMTP_AUTH_PASSWD'|' \
-e 's|@SMTP_AUTH_USER@|'$SMTP_AUTH_USER'|' \
-e 's|@SMTP_HOST@|'$SMTP_HOST'|' \
-e 's|@SMTP_PORT@|'$SMTP_PORT'|' \
-e 's|@SMTP_STARTTLS@|'$SMTP_STARTTLS'|' \
-e 's|@SMTP_USE_SSL@|'$SMTP_USE_SSL'|' \
-e 's|@SUGGESTION_BOX@|'$SUGGESTION_BOX'|' \
-e 's|@SUPERVISOR@|'$SUPERVISOR'|' \
-e 's|@THISHOST@|'$THISHOST'|' \
-e 's|@USING_ISA@|'$USING_ISA'|' \
-e 's|@UTF8_SUFFIX@|'$UTF8_SUFFIX'|' \
-e 's|@VERSION@|'$version'|' \
< "$1" > "$2"
}
CopyFile() {
echo " $1 -> $2"
cp "$1" "$2"
}
echo "Creating language-specific web pages"
webpage_langs=( en de fr es uk ta hi ko it nl ja zh )
for file in html/index.html html/civs_create.html js/civs_hdr.js.2
do
echo " $file ->"
for lang in ${webpage_langs[@]}
do
echo " $file.$lang"
perl subst_text.pl html/static-translations.txt $lang ${file}.base ${file}.$lang || exit 1
done
done
( cd js
cat civs_hdr.js.1.base > civs_hdr.js
for lang in ${webpage_langs[@]}
do
cat civs_hdr.js.2.$lang >> civs_hdr.js
done
cat civs_hdr.js.3.base >> civs_hdr.js
) || exit 1
echo "Installing HTML content"
(
cd html
for f in civs_create.html* index.html* public_elections.html* \
proportional.html* sec_priv.html* acks.html changelog.html* \
news.html* *.var rp.html* publicized_polls.html* faq.html* \
style.css hebrew.css
do
b=`basename "$f"`
case "$f" in
*.base) dest=/dev/null;;
*.var) dest="${HTMLDIR}/${b}";;
*.html.*) dest="${HTMLDIR}/${b}${UTF8_SUFFIX}";;
*.html) dest="${HTMLDIR}/${b}${EN_SUFFIX}";;
*.css) dest="${HTMLDIR}/${b}";;
*) echo "Unrecognized file type: $f"; exit 1;;
esac
SubstituteFile "$f" "$dest"
done
) || exit 1
echo "Installing JS scripts"
(
cd js
for f in results.js vote.js ajax.js ezdom.js \
civs_hdr.js mail_mgmt.js opt_in.js add_voters.js \
jquery-ui-touch-punch/jquery.ui.touch-punch.js \
qrcodejs/qrcode.min.js
do
b=`basename "$f"`
dest="${HTMLDIR}/${b}"
SubstituteFile "$f" "$dest"
done
) || exit 1
echo "Installing CGI scripts"
for f in add_voters beatpath.pm beatpath2.pm civs_common.pm voting.pm \
close control create_election download_ballots remove_writein \
upload_ballots results top_polls.pm get_top_polls languages.pm \
election.pm mail.pm start_election algorithms.pm vote \
refresh_top_polls mail_mgmt opt_in publicize_election status \
clear_caches delete_election.pl edit_poll remove_defunct_elections \
request_deactivation request_activation resend_link \
send_result_key.pm rp.pm runoff.pm b2r.pm minimax.pm admctrl.pm rules.pm
do
target="${CGIBINDIR}/${f}"
if [ -n "$PERLEXT" ]
then
case $target in
*.pm) ;;
*.pl) ;;
*) target="${target}${PERLEXT}";;
esac
fi
SubstituteFile "cgi-bin/$f" "$target"
chmod a+x "$target"
done
echo "Installing language scripts"
for f in base_language.pm english.pm hungarian.pm italian.pm french.pm \
german.pm hebrew.pm portuguese.pm chinese.pm spanish.pm thai.pm \
russian.pm hindi.pm ukrainian.pm tamil.pm korean.pm dutch.pm \
japanese.pm
do
target="${CGIBINDIR}/${f}"
if [ -n "$PERLEXT" ]
then
case $target in
*.pm) ;;
*.pl) ;;
*) target="${target}${PERLEXT}";;
esac
fi
SubstituteFile "cgi-bin/languages/$f" "$target"
chmod a+x "$target"
done
echo "Installing images"
mkdir -p "${HTMLDIR}/images"
for f in images/{check123b,sample-ballot,vertstrip,check-civs,copy-icon}.png images/check123b.ico
do
dest="${HTMLDIR}/${f}"
CopyFile "$f" "$dest"
done
if [ ! -s $CIVSDATADIR/private_host_id ]; then
echo "*********************************************"
echo " WARNING "
echo "*********************************************"
echo ""
echo "No private key exists for the server!"
echo ""
echo "Creating a private key using the openssl pseudo-random number"
echo "generator. If you want more randomness than this, you will"
echo "need to create your own key. See the INSTALL file for more"
echo "information."
echo ""
openssl rand -base64 -out $CIVSDATADIR/private_host_id 32
echo "*********************************************"
fi
if [ ! -s $CIVSDATADIR/nonce_seed ]; then
echo "Seeding the CIVS nonce generator."
openssl rand -hex -out $CIVSDATADIR/nonce_seed 32
fi
echo "Setting permissions"
touch $CIVSDATADIR/nonce_seed $CIVSDATADIR/log $CIVSDATADIR/cgi-log \
$CIVSDATADIR/global_lock $CIVSDATADIR/email-control.txt
if [ "$id" = 0 ]; then
$CHOWN "$WEB_USER" $CIVSDATADIR/nonce_seed $CIVSDATADIR/log \
$CIVSDATADIR/cgi-log $CIVSDATADIR/global_lock \
$CIVSDATADIR/email-control.txt $CIVSDATADIR/elections
$CHGRP "$WEB_GROUP" $CIVSDATADIR/nonce_seed $CIVSDATADIR/log \
$CIVSDATADIR/cgi-log $CIVSDATADIR/global_lock \
$CIVSDATADIR/email-control.txt $CIVSDATADIR/elections
fi
chmod 600 $CIVSDATADIR/nonce_seed
chmod 644 $CIVSDATADIR/log $CIVSDATADIR/cgi-log $CIVSDATADIR/global_lock \
$CIVSDATADIR/email-control.txt
echo "Installing executables"
(cd src
if [ -e gettimeofday.exe ]; then
CopyFile gettimeofday.exe $CIVSDATADIR/gettimeofday.exe
else
CopyFile gettimeofday $CIVSDATADIR/gettimeofday
fi
if [ -e timeout.exe ]; then
CopyFile timeout.exe $CIVSDATADIR/timeout.exe
else
CopyFile timeout $CIVSDATADIR/timeout
fi
if [ -e lockserv.exe ]; then
CopyFile lockserv.exe $CIVSDATADIR/lockserv.exe
else
CopyFile lockserv $CIVSDATADIR/lockserv
fi
) || exit 1
echo "Install completed. Check for any errors reported above."