forked from cms-sw/cmsdist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.file
executable file
·688 lines (598 loc) · 22.7 KB
/
bootstrap.file
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
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
#!/bin/bash
# Revision: $Revision: 1.81 $
set -e
if [ X"$(id -u)" = X0 ]; then
echo "*** CMS SOFTWARE INSTALLATION ABORTED ***" 1>&2
echo "CMS software cannot be installed as the super-user." 1>&2
echo "(We recommend reading any standard unix security guide.)" 1>&2
exit 1
fi
if [ "X`printf hasprintf 2>/dev/null`" = Xhasprintf ]; then
echo_n() { printf "%s" ${1+"$@"}; }
elif [ "X`echo -n`" = "X-n" ]; then
echo_n() { echo ${1+"$@"}"\c"; }
else
echo_n() { echo -n ${1+"$@"}; }
fi
cleanup_and_exit () {
exitcode=$1
exitmessage=$2
[ "X$exitmessage" = X ] || { echo && echo $exitmessage 1>&2; }
[ "X$debug" = Xtrue ] && exit $exitcode
[ "X$tempdir" = X ] || [ -d $tempdir ] && rm -rf $tempdir
[ "X$DOWNLOAD_DIR" = X ] || [ -d $DOWNLOAD_DIR ] && rm -rf $DOWNLOAD_DIR
[ "X$importTmp" = X ] || [ -d $importTmp ] && rm -rf $importTmp
exit $exitcode
}
download_method=
download_curl () { curl -f -H "Cache-Control: max-age=0" -q -s "$1" -o "$2.tmp" && mv "$2.tmp" "$2"; }
download_wget () { (wget --no-check-certificate --header="Cache-Control: max-age=0" -q -O "$2.tmp" "$1" 2>/dev/null || wget -q -O "$2.tmp" "$1") && mv "$2.tmp" "$2"; }
download_none () { cleanup_and_exit 1 "No curl or wget, cannot fetch $1"
}
# Figure out how to download stuff
if [ -z "$download_method" ]; then
if [ `wget --version 2>/dev/null | wc -l` != 0 ]; then
download_method=wget
elif [ `curl --version 2>/dev/null | wc -l` != 0 ]; then
download_method=curl
else
download_method=none
fi
fi
# Safely create a user-specific temp directory.
# We look for TMPDIR since /tmp might not be user
# writeable.
# Notice that -p option does not work on MacOSX and
# ${${TMPDIR:-/tmp}} is zsh only.
if [ "X$TMPDIR" = X ]
then
tempdir=`mktemp -d /tmp/tmpXXXXX`
else
tempdir=`mktemp -d $TMPDIR/tmpXXXXX`
fi
# We have our own version of find-provides for bootstrap, so that we don't
# depend on a "system" rpm installation. This is particularly handy in the case
# of macosx and other unsupported distributions which don't use rpm as a
# package manager (e.g. ubuntu).
rpmFindProvides=$tempdir/my-find-provides
cat > $rpmFindProvides <<\EOF_FIND_PROVIDES
#!/bin/bash
# This script reads filenames from STDIN and outputs any relevant provides
# information that needs to be included in the package.
filelist=`sed "s/['\"]/\\\&/g"`
solist=$(echo $filelist | grep "\\.so" | grep -v "^/lib/ld.so" | \
xargs file -L 2>/dev/null | grep "ELF.*shared object" | cut -d: -f1)
pythonlist=
tcllist=
#
# --- Alpha does not mark 64bit dependencies
case `uname -m` in
alpha*) mark64="" ;;
*) mark64="()(64bit)" ;;
esac
#
# --- Library sonames and weak symbol versions (from glibc).
for f in $solist; do
soname=$(objdump -p $f | awk '/SONAME/ {print $2}')
lib64=`if file -L $f 2>/dev/null | \
grep "ELF 64-bit" >/dev/null; then echo "$mark64"; fi`
if [ "$soname" != "" ]; then
if [ ! -L $f ]; then
echo $soname$lib64
objdump -p $f | awk '
BEGIN { START=0 ; }
/Version definitions:/ { START=1; }
/^[0-9]/ && (START==1) { print $4; }
/^$/ { START=0; }
' | \
grep -v $soname | \
while read symbol ; do
echo "$soname($symbol)`echo $lib64 | sed 's/()//'`"
done
fi
else
echo ${f##*/}$lib64
fi
done | sort -u
#
# --- Perl modules.
[ -x /usr/lib/rpm/perl.prov ] &&
echo $filelist | tr '[:blank:]' \\n | grep '\.pm$' | /usr/lib/rpm/perl.prov | sort -u
#
# --- Python modules.
[ -x /usr/lib/rpm/python.prov -a -n "$pythonlist" ] &&
echo $pythonlist | tr '[:blank:]' \\n | /usr/lib/rpm/python.prov | sort -u
#
# --- Tcl modules.
[ -x /usr/lib/rpm/tcl.prov -a -n "$tcllist" ] &&
echo $tcllist | tr '[:blank:]' \\n | /usr/lib/rpm/tcl.prov | sort -u
exit 0
EOF_FIND_PROVIDES
mkdir -p $tempdir/lib/perl5/site_perl/RPM/Header/PurePerl
mkdir -p $tempdir/bin
cat << \EOF_RPM_HEADER_PUREPERL_PM > $tempdir/lib/perl5/site_perl/RPM/Header/PurePerl.pm
@RPM_HEADER_PUREPERL_PM@
EOF_RPM_HEADER_PUREPERL_PM
cat << \EOF_RPM_HEADER_PUREPERL_TAGSTABLE_PM > $tempdir/lib/perl5/site_perl/RPM/Header/PurePerl/Tagtable.pm
@RPM_HEADER_PUREPERL_TAGSTABLE_PM@
EOF_RPM_HEADER_PUREPERL_TAGSTABLE_PM
export PERL5LIB=$tempdir/lib/perl5/site_perl
cat << \EOF_RPM_HEADER_PL > $tempdir/bin/rpmHeader.pl
#!/usr/bin/env perl
die "Missing package name." if ($#ARGV == -1);
my $fp = $ARGV[0];
use RPM::Header::PurePerl;
tie %HDR, "RPM::Header::PurePerl", $fp or die "An error occurred: $RPM::err";
if ($#ARGV == 1)
{
$l = $HDR{$ARGV[1]};
print join("\n", @$l);
print "\n";
exit;
}
while ( ($k,$v) = each %HDR) {
$l = $HDR{$k};
if ($ARGV == 0)
{
print "$k:";
print join(",", @$l);
print "\n";
}
}
EOF_RPM_HEADER_PL
source() { . ${1+"$@"}; }
chmod u+x $rpmFindProvides $tempdir/bin/rpmHeader.pl
server=cmsrep.cern.ch
server_main_dir=cmssw
repository=cms
groups="lcg cms external"
unsupportedDistribution=false
rootdir=$(pwd)
testInstance=false
while [ $# -gt 0 ]; do
case $1 in
setup )
command=setup
shift ;;
reseed )
command=reseed
shift;;
-path|-p )
[ $# -gt 0 ] || cleanup_and_exit 1 "Option \`$1' requires an argument"
if [ "$(echo $2 | cut -b 1)" = "/" ]; then
rootdir="$2"
else
rootdir="$PWD/$2"
fi
shift; shift ;;
-server )
[ $# -gt 1 ] || cleanup_and_exit 1 "Option \`$1' requires an argument"
server=$2
testInstance=true
shift; shift ;;
-server-path )
[ $# -gt 1 ] || cleanup_and_exit 1 "Option \`$1' requires an argument"
$hasRepository || cleanup_and_exit 1 "Cannot specify -repository and -server-path at the same time"
server_main_dir=`echo $2 | sed -e 's|/$||' | sed -e "s|\(.*\)/[^/]*$|\1|"`
repository=`echo $2 | sed -e 's|/$||' | sed -e "s|.*/\([^/]*\)$|\1|"`
echo "server_main_dir $server_main_dir"
echo "repository $repository"
testInstance=true
hasServerPath=true
shift; shift ;;
-repository|-r )
[ $# -gt 1 ] || cleanup_and_exit 1 "Option \`$1' requires an argument"
$hasServerPath || cleanup_and_exit 1 "Cannot specify -repository and -server-path at the same time"
repository=$2
hasRepository=true
testInstance=true
shift; shift ;;
-groups|-g )
[ $# -gt 1 ] || cleanup_and_exit 1 "Option \`$1' requires at lease one argument"
shift
groups=""
while [ $# -gt 0 ]
do
[ "X$(echo $1 | cut -b1)" = X- ] && break
[ "X$1" = Xsetup ] && break
[ "X$1" = Xreseed ] && break
groups="$groups $1"
shift
done
testInstance=true
;;
-architecture|-arch|-a )
[ $# -gt 1 ] || cleanup_and_exit 1 "Option \`$1' requires at lease one argument"
cmsplatf="$2"
shift; shift ;;
-unsupported_distribution_hack )
unsupportedDistribution=true; shift
;;
-verbose|-v )
verbose=true; shift
doReturn="\n"
;;
-debug )
debug=true; shift
doReturn="\n"
;;
-assume-yes|-y )
assumeYes=true; shift
;;
-only-once )
onlyOnce=true; shift
;;
-additional-pkgs )
while [ $# -gt 0 ]
do
[ "X$(echo $1 | cut -b1)" = X- ] && break
[ "X$1" = Xsetup ] && break
[ "X$1" = Xreseed ] && break
additionalPkgs="$additionalPkgs $1"
shift
done
;;
-help|-h )
cat << \EOF_HELP
bootstrap.sh
A script to bootstrap a CMS software area.
Syntax:
bootstrap.sh setup [-path <cms-path>] [-server <server>] [-server-path <download-path>]
-path <cms-path> : location of where the installation must be done (default $PWD).
-server <server> : repositories are to be found on server <server> (default cmsrep.cern.ch).
-server-path <download-path> : package structure is found on <download-path> on server (default cms/cpt/Software/download/apt).
-repository <repository> : use private apt repository cms.<username> (default: public repository)
-groups <groups-list> : list of the channels we want to subscribe to (default: "cms external lcg virtual").
EOF_HELP
cleanup_and_exit 1
;;
* )
cleanup_and_exit 1 "bootstrap.sh: argument $1 not supported"
;;
esac
done
# Get cmsos from the web.
cmsos=$server/$server_main_dir/$repository/cmsos
[ "X$verbose" = Xtrue ] && echo_n "Downloading cmsos file..."
download_${download_method} $cmsos $tempdir/cmsos
[ -f $tempdir/cmsos ] || cleanup_and_exit 1 "FATAL: Unable to download cmsos: $cmsos"
source $tempdir/cmsos
# Use cmsos to guess the platform if it is not set on command line.
if [ "X$cmsplatf" = X ]
then
cmsplatf=`cmsos`_`defaultCompiler`
fi
case $cmsplatf in
osx*)
cpio_opts="--insecure";;
esac
rpmdb=$cmsplatf/var/lib/rpm
rpmlock=$rootdir/$cmsplatf/var/lib/rpm/__db.0
importTmp=$rootdir/$cmsplatf/tmp/system-import
[ "X$verbose" = Xtrue ] && echo "Using $download_method to download files."
[ "X$verbose" = Xtrue ] && echo "RPM db in $cmsplatf/var/lib/rpm."
# Get the architecture driver from the web
driver=$server/$server_main_dir/$repository/$cmsplatf-driver.txt
[ "X$verbose" = Xtrue ] && echo_n "Downloading driver file..."
download_${download_method} $driver $tempdir/$cmsplatf-driver.txt
[ -f $tempdir/$cmsplatf-driver.txt ] || cleanup_and_exit 1 "FATAL: Unable to download platform driver: $driver"
eval `cat $tempdir/$cmsplatf-driver.txt`
[ "X$verbose" = Xtrue ] && echo "Done."
perlHarvester () {
[ "X$verbose" = Xtrue ] && echo && echo "...Harvesting for perl modules" 1>&2
for x in $(perl -e 'print "@INC\n"'); do
find -L $x 2>/dev/null |
grep -v -e '\(^[.]/\|[/]$\)' |
grep -e '\([.]p[lm]$\|[.]pod$\)' |
sed -e "s|$x/||;s|^[0-9.]*/||;s|^[-a-z0-9]*-thread-multi/||;s|[.]p[ml]||;s|[.]pod||;s|/|::|g;s|^\(.*\)|Provides: perl(\1)|"
done | sort | uniq
}
generateSeedSpec () {
# Seed system info
# GL asound odbc java libtcl libtk
[ "X$verbose" = Xtrue ] && echo && echo "...Seeding RPM database from selected system RPMs." 1>&2
# Decide which seeds to use. Notice that in case
# rhXYZ_WWW_ does not exists we try to use
# rhX_WWW_ platformSeeds before dropping to
# the (optional) platformSeeds.
requiredSeeds=$(eval echo $`cmsos`_platformSeeds)
if [ "X$requiredSeeds" = X ]
then
requiredSeeds=$(eval echo $`cmsos | sed -e 's|\([0-9]\)[0-9]*|\1|'`_platformSeeds)
fi
if [ "X$requiredSeeds" = X ]
then
seed="$platformSeeds"
else
seed="$requiredSeeds"
unsupportedDistribution=false
fi
if $unsupportedDistribution
then
echo "WARNING: you are running on an unsupported distribution."
echo "This might lead to unknown problems."
seed="$seed $unsupportedSeeds"
fi
rm -rf $importTmp
mkdir -p $importTmp
cd $importTmp
mkdir -p SOURCES BUILD SPEC RPMS SRPMS tmp
: > SOURCES/none
# FIXME: It might be better to use rootdir rather than PWD
(echo "%define _sourcedir $PWD/SOURCES"
echo "%define _builddir $PWD/BUILD"
echo "%define _specdir $PWD/SPEC"
echo "%define _rpmdir $PWD/RPMS"
echo "%define _srcrpmdir $PWD/SRPMS"
echo "%define _tmppath $PWD/tmp"
echo "%define _topdir $PWD"
echo "%define _rpmfilename system-base-import.rpm"
echo;
echo "Name: system-base-import"
echo "Version: 1.0"
echo "Release: `date +%s`"
echo "Summary: Base system seed"
echo "License: Unknown"
echo "Group: Hacks"
echo "Packager: install.sh"
echo "Source: none"
for provide in $additionalProvides
do
echo "Provides: $provide"
done
if $unsupportedDistribution
then
# Guess perl
echo "Provides: perl = `perl -MConfig -e 'print $Config{api_revision}.\".\".($Config{api_version}*1000).$Config{api_subversion};'`"
for provide in $unsupportedProvides
do
echo "Provides: $provide"
done
fi
case $cmsplatf in
osx* )
ls /System/Library/Frameworks | grep -v -e '[ ()]' | sed 's!.framework!!;s!^!Provides: !'
find /usr/bin | grep -v -e '[ ()]' | sed 's!^!Provides: !'
find /bin | grep -v -e '[ ()]' | sed 's!^!Provides: !'
/bin/ls -1 /usr/lib/*.dylib | grep -v -e '[ ()]' | awk -F"/" '{print $4}' | sed 's!^!Provides: !' || true
/bin/ls -1 /usr/lib/*/*.dylib | grep -v -e '[ ()]' | awk -F"/" '{print $5}' | sed 's!^!Provides: !' || true
/bin/ls -1 /usr/X11R6/lib/*.dylib | grep -v -e '[ ()]' | awk -F"/" '{print $5}' | sed 's!^!Provides: !' || true
;;
esac
if [ "$(which dpkg 2>&1 | grep 'no dpkg' )" = "" ]
then
[ "X$verbose" = Xtrue ] && echo && echo "...dpkg found in $(which dpkg), using it to seed the database." >&2
for p in $seed; do
if [ "$(dpkg -L $p 2>&1 | grep 'is not installed')" = "" ]; then
dpkg -L $p 2>/dev/null | sed -e "s|^|Provides:|"
dpkg -L $p 2>/dev/null | $rpmFindProvides | sed -e "s|^|Provides:|" || true
fi
done
perlHarvester
fi
if which rpm 2>&1 >/dev/null && [ "$(rpm -qa 2>&1 | grep 'use alien')" = "" ]
then
[ "X$verbose" = Xtrue ] && echo && echo "...rpm found in $(which rpm), using it to seed the database." >&2
for p in $requiredSeeds; do
rpm -q $p >/dev/null || { echo "Required package $p is missing." ; exit 1; }
done
for p in $seed; do
rpm -q $p --provides | sed 's!<*=.*!!; s!^!Provides: !' || true
rpm -q $p --list | fgrep .so | fgrep -v -e /lib/. -e /lib64/. | sed 's!^.*/!Provides: !' || true
rpm -q $p --list | fgrep /bin/ | sed 's!^!Provides: !' || true
done
fi
echo; echo "%description"; echo "Seeds RPM repository from the base system."
echo; echo "%prep"; echo "%build"; echo "%install"; echo "%files";
) > system-base-import.spec
if [ "X$?" = X0 ]; then : ; else
echo "There was an error generating the platform seed"
exit 1
fi
perl -p -i -e 's|^Provides:[\s]*$||' system-base-import.spec
cd $was
}
seed ()
{
rcfile=$1
cd $importTmp
(source $rootdir/bootstraptmp/BOOTSTRAP/inst/$cmsplatf/external/rpm/$rpm_version/etc/profile.d/init.sh
rpmbuild -ba --define "_topdir $PWD" --rcfile $rcfile system-base-import.spec >/dev/null 2>&1
[ "X$verbose" = Xtrue ] && echo && echo "...Seeding database in in $rootdir/$rpmdb"
rpm --define "_rpmlock_path $rpmlock" -U -r $rootdir --rcfile $rcfile --dbpath $rootdir/$rpmdb RPMS/system-base-import.rpm
) || cleanup_and_exit $? "Error while seeding rpm database with system packages."
cd $was
}
setup() {
# FIXME: this is the ugliest trick ever found in a shell script.
# The problem is that rpm sometimes applies the value of --root
# to dbpath, some other times it does not.
# At some point this should be really fixed in the rpm sources,
# but for the time being we keep it as it is.
[ "$rootdir" = "" ] && cleanup_and_exit 1 "Installation path not specified."
rootdir=`echo $rootdir | perl -p -e 's|/$||'`
mkdir -p $rootdir
eval `echo $rootdir | awk -F \/ '{print "fakelink=$rootdir/"$2}'`
if [ ! -e $fakelink ]
then
#echo $rootdir | awk -F \/ '{print "ln -s /"$2" $rootdir/"$2}'
command=`echo $rootdir | awk -F \/ '{print "ln -s /"$2" $rootdir/"$2}'`
eval $command
fi
# Fetch the required RPMS for RPM and APT from the server and install them using rpmcpio
export DOWNLOAD_DIR=$rootdir/bootstraptmp/BOOTSTRAP
mkdir -p $DOWNLOAD_DIR
cd $DOWNLOAD_DIR
downloadPath=$server/$server_main_dir/$repository/RPMS/$cmsplatf
# Get the architecture driver from the web
driver=$server/$server_main_dir/$repository/$cmsplatf-driver.txt
echo_n "Downloading driver file..."
download_${download_method} $driver $tempdir/$cmsplatf-driver.txt
[ -f $tempdir/$cmsplatf-driver.txt ] || cleanup_and_exit 1 "Unable to download platform driver: $driver"
eval `cat $tempdir/$cmsplatf-driver.txt`
echo "Done."
echo_n "Downloading bootstrap core packages..."
for pkg in $packageList
do
download_${download_method} $downloadPath/$pkg $pkg
[ -f $pkg ] || cleanup_and_exit 1 "Error downloading $pkg. Exiting."
done
echo "Done."
was=`pwd`
cd $rootdir
forceOption=""
if [ -d $rootdir/$rpmdb ]
then
[ "X$onlyOnce" = Xtrue ] && cleanup_and_exit 0 "Area already initialised. Skipping bootstrap and exiting."
if [ "X$assumeYes" = Xtrue ]
then
forceOption=--force
else
read -e -p "Warning, $rootdir already set up. Do you want to reconfigure it? [ y / N ] " override
case $(echo $override | tr [A-Z] [a-z]) in
y|ye|yes)
forceOption=--force
;;
*)
cleanup_and_exit 0 "No changes made. Exiting... "
;;
esac
fi
else
mkdir -p $rootdir/$rpmdb
fi
# Extract the packages via rpm, source the init.sh
# Some packages might actually not be there (gcc on darwin, for example, .
# where we use the system one).
cd $DOWNLOAD_DIR
# http://linuxmafia.com/pub/linux/utilities-general/rpm2cpio
cat > myrpm2cpio <<\EOF_RPM2CPIO
#!/usr/bin/env perl
# Why does the world need another rpm2cpio? Because the existing one
# won't build unless you have half a ton of things that aren't really
# required for it, since it uses the same library used to extract RPMs.
# In particular, it won't build on the HPsUX box I'm on.
#
# Expanded quick-reference help by Rick Moen (not the original author
# of this script).
#
# add a path if desired
$gzip = "gzip";
sub printhelp {
print "\n";
print "rpm2cpio, perl version by orabidoo <odar\@pobox.com>\n";
print "\n";
print "use: rpm2cpio [file.rpm]\n";
print "\n";
exit 0;
}
if ($#ARGV == -1) {
printhelp if -t STDIN;
$f = "STDIN";
} elsif ($#ARGV == 0) {
open(F, "< $ARGV[0]") or die "Can't read file $ARGV[0]\n";
$f = 'F';
} else {
printhelp;
}
printhelp if -t STDOUT;
# gobble the file up
undef $/;
$|=1;
$rpm = <$f>;
close ($f);
($magic, $major, $minor, $crap) = unpack("NCC C90", $rpm);
die "Not an RPM\n" if $magic != 0xedabeedb;
die "Not a version 3 or 4 RPM\n" if $major != 3 and $major != 4;
$rpm = substr($rpm, 96);
while ($rpm ne '') {
$rpm =~ s/^\c@*//s;
($magic, $crap, $sections, $bytes) = unpack("N4", $rpm);
$smagic = unpack("n", $rpm);
last if $smagic eq 0x1f8b;
die "Error: header not recognized\n" if $magic != 0x8eade801;
$rpm = substr($rpm, 16*(1+$sections) + $bytes);
}
die "bogus RPM\n" if $rpm eq '';
open(ZCAT, "|gzip -cd") || die "can't pipe to gzip\n";
print ZCAT $rpm;
close ZCAT;
EOF_RPM2CPIO
echo_n "Unpacking core packages..."
# Unfortunately cpio unpacks its files including the original build path.
# We therefore need some symlink tricks to make sure that everything
# ends up in the same installation directory.
# We also use the rpmHeader.pl script to get the pre and post install
# script and we execute them by hand.
# This should really mimic what rpm does and removes the needs for
# `instroot` to be defined in the bootstrap driver.
mkdir $tempdir/scriptlets
mkdir -p $PWD/inst
for pkg in $packageList
do
pkgInstRoot=`$tempdir/bin/rpmHeader.pl $DOWNLOAD_DIR/$pkg PREFIXES | tail -1`
mkdir -p `dirname .$pkgInstRoot`
ln -sf $PWD/inst .$pkgInstRoot
$tempdir/bin/rpmHeader.pl $DOWNLOAD_DIR/$pkg PREIN | grep -v "^Unknown" | sed -e "s|[$]RPM_INSTALL_PREFIX|$PWD/inst|g" > $tempdir/scriptlets/$pkg.pre.sh
sh -ex $tempdir/scriptlets/$pkg.pre.sh
perl ./myrpm2cpio $DOWNLOAD_DIR/$pkg | cpio $cpio_opts -id || cleanup_and_exit 1 "Unable to unpack $DOWNLOAD_DIR/$pkg"
$tempdir/bin/rpmHeader.pl $DOWNLOAD_DIR/$pkg POSTIN | grep -v "^Unknown" | sed -e "s|[$]RPM_INSTALL_PREFIX|$PWD/inst|g" > $tempdir/scriptlets/$pkg.post.sh
sh -ex $tempdir/scriptlets/$pkg.post.sh
done
echo "Done."
# Generate the seed spec using the old rpm:
echo_n "Harvesting system for locally available software..."
generateSeedSpec
# Now move to use the new RPM by sourcing its init.sh
source $DOWNLOAD_DIR/inst/$cmsplatf/external/rpm/$rpm_version/etc/profile.d/init.sh
cd $rootdir
echo "Done."
# Initialise the rpmdb using the new rpm.
echo_n "Initializing local rpm database..."
rpm --define "_rpmlock_path $rpmlock" -r $rootdir --dbpath $rootdir/$rpmdb --initdb || cleanup_and_exit 1 "Unable to initialize $rootdir/$rpmdb. Exiting."
# Build the seed spec and install it, in order to seed the newly generated db.
rpmOptions="-r $rootdir --dbpath $rootdir/$rpmdb --rcfile $DOWNLOAD_DIR/inst/$cmsplatf/external/rpm/$rpm_version/lib/rpm/rpmrc --nodeps --prefix $rootdir --ignoreos --ignorearch"
seed $DOWNLOAD_DIR/inst/$cmsplatf/external/rpm/$rpm_version/lib/rpm/rpmrc
echo "Done."
# Install the packages, this time using rpm.
echo_n "Installing packages in the local rpm database..."
for pkg in $packageList
do
rpm -U $forceOption --define "_rpmlock_path $rpmlock" $rpmOptions $DOWNLOAD_DIR/$pkg || cleanup_and_exit 1 "Error while installing $pkg. Exiting."
done
echo "Done"
# If we want to use a test instance, we need to adjust the sources.list accordingly.
if $testInstance
then
perl -p -i -e "s|^([^#][^;].*) http://cmsrep.cern.ch cms/cpt/Software/download/cms/|#\$1 http://cmsrep.cern.ch cmssw/cms/|;
s|#;||;
s|\@GROUPS\@|$groups|;
s|\@SERVER\@|$server|;
s|\@SERVER_PATH\@|$server_main_dir/|;
s|\@REPOSITORY\@|$repository|" $rootdir/$cmsplatf/external/apt/$apt_version/etc/sources.list
fi
# Source the apt environment and upgrade what is already there.
echo_n "Initializing apt-get environment."
source $rootdir/$cmsplatf/external/apt/$apt_version/etc/profile.d/init.sh
apt-get update >$tempdir/apt-get-update.log 2>&1 || cleanup_and_exit 1 "There was a problem while running apt-get update. "
echo "Done"
echo_n "Installing default packages."
defaultPackages="$additionalPkgs $defaultPkgs"
[ "X$defaultPackages" = X ] || apt-get -y install $defaultPackages >$tempdir/apt-get-install.log 2>&1 || cleanup_and_exit 1 "There was \
a problem while installing the default packages "
echo "Done"
echo "Bootstrap environment to be found in: "
echo "### $rootdir/$cmsplatf/external/apt/$apt_version/etc/profile.d/init.sh"
cd $was
}
##########################################################
case $command in
setup )
setup
;;
reseed )
generateSeedSpec
seed $rootdir/$cmsplatf/external/rpm/$rpm_version/lib/rpm/rpmrc
;;
esac
cleanup_and_exit 0 "Everything completed correctly."