-
Notifications
You must be signed in to change notification settings - Fork 0
/
radiasoft-download.sh
401 lines (388 loc) · 11.2 KB
/
radiasoft-download.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
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
#!/bin/bash
_named_json=*-named.json
rpm_perl_build() {
install -m 400 .netrc ~
case $1 in
bivio-named)
rpm_perl_build_named "$@"
;;
bivio-perl)
rpm_perl_build_perl "$@"
;;
irs-a2a-sdk)
rpm_perl_build_irs_a2a_sdk "$@"
;;
perl-*)
rpm_perl_build_app "$@"
;;
*)
install_err "bad args: $*"
;;
esac
}
rpm_perl_build_app() {
declare rpm_base=$1 root=$2 exe_prefix=$3 app_root=$4 facade_uri=$5
umask 022
declare build_d=$PWD
declare facades_d=/var/www/facades
declare javascript_d=/usr/share/Bivio-bOP-javascript
declare weak_pw_d=/usr/share/Bivio-bOP-weak-password
declare bop_d=/usr/src/bop
declare version=$(date -u +%Y%m%d.%H%M%S)
declare fpm_args=()
if [[ $root == Bivio ]]; then
rpm_perl_git_clone irs-a2a-sdk
source irs-a2a-sdk/install-jdk8.sh
rm -rf irs-a2a-sdk
export CLASSPATH="/usr/java/*"
mkdir "$javascript_d"
# No channels here, because the image gets the channel tag
rpm_perl_git_clone javascript-Bivio
cd javascript-Bivio
bash build.sh "$javascript_d"
cd ..
rm -rf javascript-Bivio
mkdir "$weak_pw_d"
rpm_perl_git_clone weak-password
cd weak-password
bash build.sh "$weak_pw_d"
cd ..
rm -rf weak-password
#TODO(robnagler) move this to master when in production
cat > /etc/bivio.bconf <<'EOF'
use Bivio::DefaultBConf;
Bivio::DefaultBConf->merge_dir({
'Bivio::UI::Facade' => {
http_host => 'www.bivio.biz',
mail_host => 'bivio.biz',
},
});
EOF
chmod 444 /etc/bivio.bconf
fpm_args+=( "$javascript_d" "$weak_pw_d" )
else
rpm_perl_install_bivio_rpm
fi
declare app_d=${app_root//::/\/}
declare files_d=$app_d/files
rpm_perl_git_clone "$rpm_base"
mv "$rpm_base" "$root"
# POSTIT: radiasoft/rsconf/rsconf/component/btest.py
mkdir -p "$bop_d"
rsync -a --exclude .git "$root" "$bop_d/"
chmod -R a+rX "$bop_d"
if [[ $root == Bivio ]]; then
# POSIT: radiasoft/rsconf/rsconf/component/bop.py
declare src_d=/usr/share/Bivio-bOP-src
mkdir -m 755 -p "$src_d"
rsync -a --exclude .git "$bop_d/$root" "$src_d/"
# perl-Bivio installs directory
fpm_args+=( "$bop_d" "$src_d" )
else
fpm_args+=( "$bop_d/$root" )
fi
perl -p -e "s{EXE_PREFIX}{$exe_prefix}g;s{ROOT}{$root}g" <<'EOF' > Makefile.PL
use strict;
require 5.005;
use ExtUtils::MakeMaker ();
use File::Find ();
my($_EXE_FILES) = [];
my($_PM) = {};
File::Find::find(sub {
if (-d $_ && $_ =~ m#((^|/)(\.git|old|t)|-|\.old)$#) {
$File::Find::prune = 1;
return;
}
my($file) = $File::Find::name;
$file =~ s#^\./##;
push(@$_EXE_FILES, $file)
if $file =~ m{(?:^|/)(?:EXE_PREFIX-[-\w]+$)$|Bivio/Util/bivio$};
# $(INST_LIBDIR) is where MakeMaker copies packages during
# the build process. The variable is interpolated by make.
$_PM->{$file} = '$(INST_LIBDIR)/' . $file
if $file =~ /\.pm$/;
return;
}, 'ROOT');
ExtUtils::MakeMaker::WriteMakefile(
NAME => 'ROOT',
ABSTRACT => 'ROOT',
VERSION => '1.0',
EXE_FILES => $_EXE_FILES,
'PM' => $_PM,
AUTHOR => 'Bivio',
PREREQ_PM => {},
);
EOF
perl Makefile.PL DESTDIR=/ INSTALLDIRS=vendor < /dev/null
make POD2MAN=true
fpm_args+=(
$( make POD2MAN=true pure_install 2>&1 | perl -n -e 'm{Installing (/usr/bin/\S+)} && print("$1\n")' )
"/usr/share/perl5/vendor_perl/$root"
)
rm -rf "$facades_d"
declare tgt=$facades_d
mkdir -p "$(dirname "$tgt")" "$tgt"
cd "$files_d"
declare dirs
if [[ -d ddl || -d plain ]]; then
tgt=$tgt/$facade_uri
# view is historical for Artisans (slideshow and extremeperl)
# so no need here.
dirs=( plain ddl )
mkdir -p "$tgt"
else
dirs=( $(find * -type d -prune -print) )
fi
find "${dirs[@]}" -type l -print -o -type f -print \
| tar Tcf - - | (cd "$tgt"; tar xpf -)
declare bconf_f=$build_d/build.bconf
cat > "$bconf_f" <<EOF
use strict;
use $app_root::BConf;
$app_root::BConf->merge_dir({
'Bivio::UI::Facade' => {
local_file_root => '$facades_d',
},
'Bivio::Ext::DBI' => {
connection => 'Bivio::SQL::Connection::None',
},
});
EOF
BCONF=$bconf_f bivio project link_facade_files
for facade in "$facades_d"/*; do
if [[ ! -L $facade ]]; then
mkdir -p "$facade/plain"
ln -s -r "$javascript_d" "$facade/plain/b"
fi
done
case $root in
Societas)
cd "$build_d"
rpm_perl_git_clone irs-a2a-sdk
cd irs-a2a-sdk
source install-jdk8.sh
export CLASSPATH="$PWD/*:/usr/java/*"
cd "$build_d"/Societas/files/java
javac *.java
jar -cf /usr/java/societas.jar *.class
cd "$build_d"
fpm_args+=( /usr/java/societas.jar )
;;
*)
;;
esac
if [[ $root == Bivio ]]; then
fpm_args+=( "$facades_d" )
else
fpm_args+=( "$facades_d"/* )
fi
find "${fpm_args[@]}" | sort > "$rpm_build_include_f"
echo perl-Bivio > "$rpm_build_depends_f"
}
rpm_perl_build_irs_a2a_sdk() {
declare build_d=$PWD
umask 022
declare -a schemas=( irs-efile-schemas ca-efile-schemas co-efile-schemas )
for r in irs-a2a-sdk "${schemas[@]}"; do
rpm_perl_git_clone "$r"
done
cd irs-a2a-sdk
declare d=/usr/java
mkdir -p "$d"
for f in *.jar; do
install -m 444 "$f" "$d/$f"
echo "$d/$f"
done | sort > "$rpm_build_include_f"
d=/usr/local/irs-a2a-sdk
declare -a dirs=( $d )
mkdir -p "$d"/config
cp config/* "$d"/config
for s in "${schemas[@]}"; do
cd "../$s"
d="/usr/local/$s"
dirs+=( $d )
mkdir -p "$d"
cp -a 2*v* "$d"
done
cd "$build_d"
chmod a+rX "${dirs[@]}"
find "${dirs[@]}" | sort >> "$rpm_build_include_f"
echo java > "$rpm_build_depends_f"
}
rpm_perl_build_perl() {
declare x=(
/usr/java/bcprov-jdk15-145.jar
/usr/java/itextpdf-5.5.8.jar
/usr/java/yui-compressor.jar
/usr/local/share/catdoc
/usr/local/lib64/perl5
/usr/local/share/perl5
/usr/local/bin/catdoc
/usr/local/bin/catppt
/usr/local/bin/docx2txt
/usr/local/bin/html2ps
/usr/local/bin/ldat
/usr/local/bin/perl2html
/usr/local/bin/trgrep
/usr/local/bin/unixtime
/usr/local/bin/xls2csv
/usr/local/awstats
/etc/postgrey
/usr/sbin/postgrey
/usr/share/postgrey
)
find "${x[@]}" | sort > "$rpm_build_include_f"
echo perl > "$rpm_build_depends_f"
}
rpm_perl_build_named() {
declare rpm_base=$1
# named config is not world readable
umask 027
declare build_d=$PWD
declare version=$(date -u +%Y%m%d.%H%M%S)
declare fpm_args=()
rpm_perl_install_bivio_rpm
declare -a c=( generate )
declare f
shopt -s nullglob
c+=( $_named_json )
shopt -u nullglob
(cat bivio-named.pl && echo '->{NamedConf};') | bivio NamedConf "${c[@]}"
declare db_d=/srv/bivio_named/db
mkdir -p "$db_d"
tail -n +11 etc/named.conf > "$db_d/zones.conf"
# We expect something like: zone .*.in-addr.arpa" in {
# if that's not there, we have a problem. Better to break now
# than later.
if [[ ! $(head -1 "$db_d/zones.conf") = 'zone "." in {' ]]; then
install_err "$db_d/zones.conf: expecting zone "." in {: got $(head -5 $db_d/zones.conf)"
fi
mv var/named/* "$db_d"
declare tmp_conf=$build_d/tmp.conf
perl -pe "s{/var/named}{$db_d}" etc/named.conf > "$tmp_conf"
declare res=$(
named-checkconf -z "$tmp_conf" \
| grep -v 'zone.*loaded.serial' \
| grep -v '_sip.*/SRV.*is a CNAME .illegal.'
)
if [[ $res ]]; then
install_err "named-checkconf failed with: $res"
fi
chgrp -R named "$db_d"
find "$db_d"/* | sort > "$rpm_build_include_f"
echo bind > "$rpm_build_depends_f"
}
rpm_perl_copy_bivio_rpm() {
# POSIT: Contains multiple directories separated by spaces
declare f=${rpm_perl_install_dir%% *}/perl-Bivio-dev.rpm
if [[ -r $f ]]; then
cp "$f" .
fi
}
rpm_perl_git_clone() {
install_git_clone https://github.com/biviosoftware/"$1"
}
rpm_perl_install_bivio_rpm() {
# rpm_perl_copy_bivio_rpm puts it here
declare f=perl-Bivio-dev.rpm
if ! [[ -r $f ]]; then
# Only used development, but will work regardless
f=$(install_foss_server)/$f
fi
install_yum_install "$f"
}
rpm_perl_install_rpm() {
declare base=$1
if [[ ! ${rpm_perl_install_dir:-} ]]; then
return
fi
# Y2100
declare f="$(ls -t "$base"-20[0-9][0-9]*rpm | head -1)"
declare c d l
# POSIT: Contains multiple directories separated by spaces
for d in $rpm_perl_install_dir; do
install -m 444 "$f" "$d/"
for c in dev alpha; do
l="$d/$base-$c.rpm"
rm -f "$l"
ln -s "$f" "$l"
done
done
}
rpm_perl_main() {
if (( $# < 1 )); then
install_err 'must supply bivio-perl, Root (for perl-Root), etc.'
fi
declare root=$1
declare root_lc=${root,,}
declare exe_prefix
declare app_root=$root
declare facade_uri=$root_lc
declare rpm_base build_args
declare extra_conf=
case $1 in
rpm_build_do)
install_repo_eval rpm-build "$@"
return
;;
bivio-named)
declare -a extra_conf=( "$PWD/bivio-named.pl" )
if [[ ! -r ${extra_conf[0]} ]]; then
install_err "${extra_conf[0]}: must exist"
fi
shopt -s nullglob
# POSIT: no spaces in paths
extra_conf+=( $PWD/$_named_json )
shopt -u nullglob
rpm_base=bivio-named
build_args=$rpm_base
;;
bivio-perl)
rpm_base=bivio-perl
build_args=$rpm_base
;;
irs-a2a-sdk)
rpm_base=irs-a2a-sdk
build_args=$rpm_base
;;
Artisans)
exe_prefix=a
;;
Bivio)
app_root=Bivio::PetShop
exe_prefix=b
facade_uri=petshop
;;
Sensorimotor)
exe_prefix=sp
;;
Societas)
exe_prefix=s
;;
Zoe)
exe_prefix=zoe
facade_uri=zoescore
;;
*)
install_err "$1: unknown Perl app"
;;
esac
umask 077
declare p=$PWD
install_tmp_dir
declare t=$PWD
if [[ $extra_conf ]]; then
cp "${extra_conf[@]}" .
fi
rpm_perl_copy_bivio_rpm
cp ~/.netrc .
: ${rpm_base:=perl-$root}
export rpm_build_user=root
: ${build_args:="$rpm_base $root $exe_prefix $app_root $facade_uri"}
install_repo_eval rpm-build "$rpm_base" "biviosoftware/perl" biviosoftware/rpm-perl rpm_perl_build $build_args
rpm_perl_install_rpm "$rpm_base"
# only necessary for testing; the files are owned by root, and run as vagrant
cd "$p"
install_sudo rm -rf "$t"
}
rpm_perl_main "${install_extra_args[@]}"