summaryrefslogtreecommitdiffstats
path: root/scripts/upd-instroot
blob: 54c0b3a2730de7ba69654dfc6d31ae1b38c2fa62 (plain)
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
#!/bin/bash

ORIGDIR=`pwd`
STRIP=strip

ARCH=`uname -m | sed -e 's/i.86/i386/'`

if [ "$ARCH" = sparc64 ]; then
	exec sparc32 $0 $*
fi

NEEDGR=yes
if [ $(uname -m) = ia64 ]; then
    NEEDGR=""
    STRIP=echo
fi

if [ -z "$1" ]; then
	echo "upd-instroot: updates instimage from a Red Hat RPMS directory"
	echo "usage:        $0 <packagedir> [<targetdir>]"
	exit 1
fi

if [ ! -d $1 ]; then
	LATEST="latest --arch $ARCH"
fi

# remove all non unused python files
pythondeps() {
        DIR=$1

	mkdir -p $DIR/proc
	mount -t proc /proc $DIR/proc
        if [ $ARCH = "sparc" ]; then
	    mkdir $DIR/dev
	    mknod $DIR/dev/openprom c 10 139
	fi
	(chroot $DIR /usr/bin/anaconda -m dir://mnt/source --test --text --traceonly; \
	cd $DIR; find usr/lib/python* usr/lib/anaconda -type f | sed 's,^,/,' ) | \
        sort | uniq -u | sed s,^,./, | while read fn; do
  	    [ ! -d $DIR/$fn ] && rm $DIR/$fn
  	done
	umount $DIR/proc
	rmdir $DIR/proc
	rm -rf $DIR/dev
}

prunePackageList() {
	PACKAGEPATH=$1
	PACKAGES="$2"

	if [ -n "$LATEST" ]; then
	    $LATEST $PACKAGEPATH $PACKAGES
	    return
	fi

	PATTERN=""
	PACKAGEFILES=""
	for PKG in $PACKAGES; do
	    PATTERN="${PATTERN:+${PATTERN}|}(^$PKG )"
	    PACKAGEFILES="$PACKAGEFILES $(ls $PACKAGEPATH/${PKG}*)"
	done

	PACKAGEFILES=$(ls $PACKAGEFILES | sort -u)

	rpm --qf "%{NAME} $PACKAGEPATH/%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}.rpm\n" \
		-qp $PACKAGEFILES  | egrep "$PATTERN"  | sed 's/.* //'
}

expandPackageSet() {
    RPMS=$1
    PKGDEST=$2
    KEEPFILE=$3

    for n in $RPMS; do 
	echo -ne "\rExpanding packages..." $(basename $n)
	if [ $(rpm -qp --qf '%{NAME}' $n) = "glibc" ] ; then
	    GLIBC=$n
	fi 
	rpm2cpio $n | (cd $PKGDEST; cpio -E $KEEPFILE --quiet -iumd)
	echo -ne "\rExpanding packages..." "$(basename $n | sed 's/./ /g')"
    done
}

PACKAGEDIR=$1

if [ -z "$2" ]; then
    DEST=/tmp/upd-instroot
else
    DEST=$2
fi

if [ -z "$3" ]; then
    DESTGR=/tmp/upd-instroot
else
    DESTGR=$3
fi


rm -rf $DEST $DESTGR
mkdir -p $DEST
mkdir -p $DESTGR

PACKAGES="glibc ldconfig setup python newt libtermcap zlib ash e2fsprogs
	  util-linux raidtools locale-ja popt mount procps rpm XFree86
	  Xconfigurator anaconda anaconda-runtime kudzu-devel kudzu db3
	  rpm-python syslinux"

if [ $ARCH = i386 ]; then
    PACKAGES="$PACKAGES kernel-pcmcia-cs"
fi

# xpm is missing

# Some packages are listed twice, but that's okay
PACKAGESGR="XFree86-libs imlib libpng libtiff libjpeg
      XFree86-S3 XFree86-S3V 
      XFree86-FBDev XFree86-I128 XFree86-3DLabs XFree86-VGA16
      XFree86-75dpi-fonts XFree86-ISO8859-2-75dpi-fonts glib gtk+
      XFree86-ISO8859-9-75dpi-fonts esound audiofile gnome-libs
      XFree86-100dpi-fonts XFree86-ISO8859-2 XFree86-ISO8859-9
      e2fsprogs fileutils glibc rsh less ftp readline gzip
      popt specspo util-linux
      rpm rpm-devel open grep net-tools traceroute 
      tar procps textutils sed ncurses bash cpio mt-st iputils sh-utils
      XFree86-cyrillic-fonts XFree86 Xconfigurator pygnome pygtk
      pygtk-libglade pygnome-libglade pygnome-applet pygnome-capplet"

if [ $ARCH != ia64 ]; then
    PACKAGESGR="$PACKAGESGR mtools pine modutils"
fi

if [ $ARCH = sparc ]; then
    PACKAGESGR="$PACKAGESGR XFree86-Sun"
elif [ $ARCH = alpha ]; then
    PACKAGESGR="$PACKAGESGR XFree86-TGA"
fi

KEEPFILE=/tmp/keepfile.$$
cat > $KEEPFILE <<EOF
sbin/ldconfig
sbin/clock
sbin/hwclock
sbin/mkfs.ext2
sbin/mke2fs
sbin/mkswap
sbin/probe
sbin/fdisk
sbin/mkraid
etc/nsswitch.conf
lib/ld-*
lib/libc*
lib/libm*
lib/libcrypt*
lib/libdl*
lib/libdb.so.2
lib/libdb.so.3
lib/libdb1*
lib/libdb-*
lib/libnsl*
lib/libnss_files*
lib/libnss_dns*
lib/libpthread*
lib/libresolv*
usr/lib/libpopt*
etc/group
etc/passwd
etc/protocols
etc/services
usr/bin/python*
usr/lib/python*
usr/bin/syslinux
usr/lib/libnewt*
lib/libtermcap*
usr/lib/libz.*
usr/lib/rpm/rpmpopt
usr/lib/rpm/macros
usr/lib/rpm/rpmrc
usr/lib/librpm.so*
bin/ash
bin/mkfs*
bin/fdisk*
sbin/badblocks
lib/libcom_err*
lib/libe2p*
lib/libext2fs*
lib/libss*
lib/libuuid*
usr/X11R6/lib/X11/Cards
usr/X11R6/share/Xconfigurator/MonitorsDB
usr/lib/anaconda/*
usr/lib/anaconda/textw/*
usr/lib/anaconda-runtime/*
usr/sbin/anaconda
usr/lib/python1.5/site-packages/kudzumodule.so
usr/share/kudzu/pcitable
usr/lib/python1.5/site-packages/rpmmodule.so
EOF

KEEPFILEGR=/tmp/keepfilegr.$$
cp $KEEPFILE $KEEPFILEGR
cat >> $KEEPFILEGR <<EOF
bin/bash
bin/cat
bin/chmod
bin/cp
bin/cpio
bin/dd
bin/df
bin/du
bin/grep
bin/gunzip
bin/gzip
bin/ln
bin/ls
bin/mkdir
bin/mt
bin/mv
bin/ping
bin/ps
bin/rm
bin/sed
bin/sync
bin/tar
bin/touch
bin/umount
bin/zcat
sbin/e2fsck
sbin/fsck
sbin/fsck.ext2
sbin/ifconfig
sbin/modprobe
sbin/depmod
sbin/lsmod
sbin/insmod
sbin/rmmod
sbin/route
lib/libproc*
lib/libutil*
lib/libnss_dns*
bin/rpm
usr/lib/rpm/rpmpopt
etc/im_palette.pal
etc/imrc
usr/lib/libesd*
usr/lib/libaudio*
usr/lib/libImlib*
usr/lib/gdkimlib*
usr/lib/libimlib-pnm*
usr/lib/libimlib-xpm*
usr/lib/libimlib-png*
usr/lib/libncurses*
usr/lib/libpng*
usr/lib/libtiff*
usr/lib/libjpeg*
usr/lib/libzvt*
usr/sbin/gnome-pty-helper
usr/X11R6/lib/libICE*
usr/X11R6/lib/libSM*
usr/X11R6/lib/libX11*
usr/X11R6/lib/libXi*
usr/X11R6/lib/libXext*
usr/X11R6/bin/setxkbmap
usr/X11R6/bin/XFree86
usr/X11R6/lib/modules/*
usr/X11R6/lib/modules/lib*
usr/X11R6/bin/XF86_3DLabs
usr/X11R6/bin/XF86_I128
usr/X11R6/bin/XF86_FBDev
usr/X11R6/bin/XF86_Mach32
usr/X11R6/bin/XF86_Mach64
usr/X11R6/bin/XF86_SVGA
usr/X11R6/bin/XF86_S3
usr/X11R6/bin/XF86_S3V
usr/X11R6/bin/XF86_VGA16
usr/X11R6/bin/XF86_TGA
usr/X11R6/bin/XsunMono
usr/X11R6/bin/Xsun
usr/X11R6/bin/Xsun24
usr/X11R6/bin/Xtest
usr/X11R6/lib/X11/fonts/75dpi/cour*
usr/X11R6/lib/X11/fonts/75dpi/helv*
usr/X11R6/lib/X11/fonts/75dpi/tim*
usr/X11R6/lib/X11/fonts/75dpi/fonts*
usr/X11R6/lib/X11/fonts/misc/6x*
usr/X11R6/lib/X11/fonts/misc/7x*
usr/X11R6/lib/X11/fonts/misc/8x*
usr/X11R6/lib/X11/fonts/misc/9x*
usr/X11R6/lib/X11/fonts/misc/12x*
usr/X11R6/lib/X11/fonts/misc/jis*
usr/X11R6/lib/X11/fonts/misc/k14*
usr/X11R6/lib/X11/fonts/misc/fonts*
usr/X11R6/lib/X11/fonts/misc/cursor*
usr/X11R6/lib/X11/fonts/misc/olcursor*
usr/X11R6/lib/X11/fonts/cyrillic/*
usr/X11R6/lib/X11/xserver/SecurityPolicy
usr/share/fonts/ISO8859-2/75dpi/cour*
usr/share/fonts/ISO8859-2/75dpi/helv*
usr/share/fonts/ISO8859-2/75dpi/tim*
usr/share/fonts/ISO8859-2/75dpi/fonts*
usr/share/fonts/ISO8859-2/misc/6x*
usr/share/fonts/ISO8859-2/misc/9x*
usr/share/fonts/ISO8859-2/misc/fonts*
usr/share/fonts/ISO8859-9/75dpi/tr*cour*
usr/share/fonts/ISO8859-9/75dpi/tr*helv*
usr/share/fonts/ISO8859-9/75dpi/tr*tim*
usr/share/fonts/ISO8859-9/75dpi/fonts*
usr/share/fonts/ISO8859-9/misc/tr*6x*
usr/share/fonts/ISO8859-9/misc/tr*9x*
usr/share/fonts/ISO8859-9/misc/fonts*
usr/X11R6/lib/X11/locale/*
usr/X11R6/lib/X11/xkb/*
usr/X11R6/lib/X11/rgb*
usr/X11R6/lib/X11/XKeysymDB
usr/X11R6/lib/libXpm*
usr/lib/libglib*
usr/lib/libthread*
etc/gtk/gtkrc*
usr/lib/gconv/*
usr/lib/libgtk*
usr/lib/libgdk*
usr/lib/libart*
usr/lib/libgnome*
usr/lib/libgmodule*
usr/lib/libgthread*
usr/lib/libgnomesupport*
usr/lib/libgnomeui*
usr/lib/libgnorba*
usr/lib/libgnorbagtk*
usr/lib/libgtkxmhtml*
usr/lib/libreadline*
usr/share/pixmaps/gnome-default-dlg.png
usr/share/pixmaps/gnome-error.png
usr/share/pixmaps/gnome-info.png
usr/share/pixmaps/gnome-question.png
usr/share/pixmaps/gnome-warning.png
usr/share/pixmaps/no.xpm
usr/share/pixmaps/yes.xpm
usr/share/terminfo/l/linux
usr/share/zoneinfo/zone.tab
usr/share/locale/*
usr/bin/chattr*
usr/bin/lsattr*
usr/bin/ftp
usr/bin/head
usr/bin/less
usr/bin/mattrib
usr/bin/mbadblocks
usr/bin/mcd
usr/bin/mcopy
usr/bin/mdel
usr/bin/mdeltree
usr/bin/mdir
usr/bin/mdu
usr/bin/mformat
usr/bin/minfo
usr/bin/mlabel
usr/bin/mmd
usr/bin/mmount
usr/bin/mpartition
usr/bin/mrd
usr/bin/mread
usr/bin/mmove
usr/bin/mren
usr/bin/mshowfat
usr/bin/mtools
usr/bin/mtype
usr/bin/mwrite
usr/bin/mzip
usr/bin/open
usr/bin/pico
usr/bin/rcp
usr/bin/rlogin
usr/bin/rsh
usr/bin/tail
usr/bin/tac
usr/bin/uniq
usr/sbin/chroot
usr/sbin/traceroute
usr/lib/anaconda/iw
usr/share/locale/*/LC_MESSAGES/anaconda.mo
usr/share/anaconda/*
usr/share/anaconda/help/*/*
usr/share/anaconda/pixmaps/*
EOF

TIMEZONES="
usr/share/zoneinfo/US
usr/share/zoneinfo/Europe
usr/share/zoneinfo/Japan
"

# sparc needs 100dpi fonts as well, otherwise
# things look ugly

if [ $ARCH = sparc ]; then
    cat >> $KEEPFILEGR <<-EOF
usr/X11R6/lib/X11/fonts/100dpi/cour*
usr/X11R6/lib/X11/fonts/100dpi/helv*
usr/X11R6/lib/X11/fonts/100dpi/tim*
usr/X11R6/lib/X11/fonts/100dpi/fonts*
usr/share/fonts/ISO8859-2/100dpi/cour*
usr/share/fonts/ISO8859-2/100dpi/helv*
usr/share/fonts/ISO8859-2/100dpi/tim*
usr/share/fonts/ISO8859-2/100dpi/fonts*
EOF
fi

echo "Assembling package list..."
RPMS=$(prunePackageList $PACKAGEDIR "$PACKAGES")
RPMSGR=$(prunePackageList $PACKAGEDIR "$PACKAGESGR")

rm -rf $DEST; mkdir -p $DEST/usr/sbin
rm -rf $DESTGR; mkdir -p $DESTGR/usr/sbin

echo -n "Expanding packages..."
expandPackageSet "$RPMS" $DEST $KEEPFILE

(cd $DEST; tar cSpf - .) | (cd $DESTGR; tar xSpf -)

expandPackageSet "$RPMSGR" $DESTGR $KEEPFILEGR
echo -e "\rExpanding packages..."

echo "retrieving timezones"
TZDIR=/tmp/glibc-timezone-$$
mkdir -p $TZDIR/usr/share/zoneinfo
rpm2cpio $GLIBC | (cd $TZDIR; cpio --quiet -iumd usr/share/zoneinfo usr/share/zoneinfo/*)
(cd $TZDIR; tar cSpf - $TIMEZONES) | (cd $DEST; tar xSpf -)
(cd $TZDIR; tar cSpf - $TIMEZONES) | (cd $DESTGR; tar xSpf -)
rm -rf $TZDIR

# XXX kludge, fix me
#rm -f $DEST/usr/lib/python1.5/site-packages/rpmmodule.so
#rm -f $DESTGR/usr/lib/python1.5/site-packages/rpmmodule.so
rm -f $DEST/usr/lib/anaconda/rpmmodule.so
rm -f $DESTGR/usr/lib/anaconda/rpmmodule.so

if [ $ARCH = sparc ]; then
    rm -f $DESTGR/usr/X11R6/bin/XF86_VGA16
fi

echo "Running mkfontdir..."
if [ -n "$NEEDGR" ]; then
    for I in $DESTGR/usr/X11R6/lib/X11/fonts/* $DESTGR/usr/share/fonts/ISO8859-2/* $DESTGR/usr/share/fonts/ISO8859-9/*; do
	mkfontdir $I
    done
fi

rm -f $KEEPFILE $KEEPFILEGR

echo -n "Scrubbing trees..."
for p in $DEST $DESTGR; do
	echo -n -e "\rScrubbing trees..." "$p"
	ln -s ../lib/anaconda/raidstart-stub $p/usr/bin/raidstart
	ln -s ../lib/anaconda/raidstop-stub $p/usr/bin/raidstop

	mv $p/usr/sbin/anaconda $p/usr/bin/anaconda
	mv $p/usr/lib/anaconda-runtime/lib* $p/usr/lib

	mv $p/usr/lib/anaconda-runtime/collage $p/usr/bin
	(cd $p/usr/bin; ./collage | $p/usr/lib/anaconda-runtime/mkcollagelinks ./collage)

	find $p -type d | xargs chmod 755

	if [ -f $p/bin/bash ]; then
	    rm -f $p/bin/ash
	    ln -s bash $p/bin/sh
	else
	    ln -s ash $p/bin/sh
	fi

	(cd $p/bin; find) | (cd $p/bin; cpio --quiet -pdmu $p/usr/bin)
	(cd $p/sbin; find) | (cd $p/sbin; cpio --quiet -pdmu $p/usr/sbin)
	rm -rf $p/bin
	rm -rf $p/sbin

	rm -rf $p/boot $p/home $p/root $p/tmp

	# Must create ld.so.conf, because ldconfig does not cache
	# dirs specified on the command line.
	touch $p/etc/ld.so.conf
	[ -d $p/usr/X11R6/lib ] && echo /usr/X11R6/lib > $p/etc/ld.so.conf
	(cd $p; chroot $p usr/sbin/ldconfig )
	rm -f $p/usr/sbin/ldconfig $p/etc/ld.so.conf

	for l in `find $p -type f -perm +100 | xargs file | sed -n 's/^\([^:]*\):.*ELF.*$/\1/p'`; do
	    $STRIP $l -R .comment -R .note `objdump -h $l | \
		sed -n 's/^.*\(\.gnu\.warning\.[^ ]*\) .*$/-R \1/p'`
	done
	find $p -name "*.a" | xargs rm -rf

	(cd /usr/share/zoneinfo; find . -type f -or -type l | 
		grep '^./[A-Z]' | sort | sed 's/^..//' | 
		gzip -9) > $p/usr/lib/timezones.gz

	if [ -d $p/usr/share/locale ]; then
	    for i in `find $p/usr/share/locale -name anaconda.mo`; do
		gzip -9 $i
		mv -f $i.gz $i
	    done
	fi
	echo -n -e "\rScrubbing trees..." "$(echo $p | sed 's/./ /g')"
done
echo -e "\rScrubbing trees..."

echo "Patching python library..."

# always use passive mode for ftp installs
cd $DEST/usr/lib/python1.5
patch -p0 > /dev/null <<EOF
--- ./urllib.py.pasv	Sun Sep 26 16:45:24 1999
+++ ./urllib.py	Sun Sep 26 16:47:56 1999
@@ -563,6 +563,7 @@
         self.ftp = ftplib.FTP()
         self.ftp.connect(self.host, self.port)
         self.ftp.login(self.user, self.passwd)
+	self.ftp.set_pasv (1)
         for dir in self.dirs:
             self.ftp.cwd(dir)
     def retrfile(self, file, type):

EOF
cd -

pythondeps $DEST

for p in $DEST $DESTGR; do
	find $p -name "*.py" | while read fn; do
	    if [ -f ${fn}c ]; then
		rm -f ${fn}c
	    fi
	    if [ -f ${fn}o ]; then
		rm -f ${fn}o
	    fi
	    if [ $p = $DEST ]; then
		ln -sf /dev/null ${fn}c
	    fi
	done
done

if [ $NEED_GR ]; then
    # Xserver needs a place to put the compiled xkb maps.
    rm -rf $DESTGR/usr/X11R6/lib/X11/xkb/compiled
    ln -s /tmp $DESTGR/usr/X11R6/lib/X11/xkb/compiled
fi

# this is only for the minimal second stage
echo "Compressing ramdisk install images..."

	cd $DEST/usr/lib
	find python1.5 | cpio --quiet -H crc -o | gzip -9 > python1.5.cgz
	rm -rf python1.5

	find anaconda | cpio --quiet -H crc -o | gzip -9 > anaconda.cgz
	rm -rf anaconda

	ls libnewt* libslang* | cpio --quiet -H crc -o | 
		gzip -9 > slang-newt.cgz
	rm -f libnewt* libslang*

	cd $DEST/usr/bin
	echo python1.5 | cpio --quiet -H crc -o | gzip -9 > python1.5.cgz
	rm -f python python1.5
	ln -s python1.5 python

	mv anaconda anaconda.real
	mv $DEST/usr/lib/anaconda-runtime/anaconda-stub anaconda

	cd $DEST/lib
	ls    libcom* libcrypt* libdl* libe2p* libext2* libm* libnss* libnsl* \
	      libpthread* libss* libtermcap* libuuid* \
			| cpio --quiet -H crc -o | gzip -9 > libs.cgz
	rm -f libcom* libcrypt* libdl* libe2p* libext2* libm* libnss* libnsl* \
	      libpthread* libss* libtermcap* libuuid*

	cd $DEST/usr
	find X11R6 | cpio --quiet -H crc -o | gzip -9 > X11R6.cgz
	rm -rf X11R6

	cd $DEST/usr/sbin
	ls [a-r]* | cpio --quiet -H crc -o | gzip -9 > sbin.cgz
	rm -f [a-r]*

	rm -rf $DEST/usr/lib/anaconda-runtime

if [ -n "$NEEDGR" ]; then
    cd $ORIGDIR
    $DESTGR/usr/lib/anaconda-runtime/checkcards.py $DESTGR/usr/share/kudzu/pcitable $DESTGR/usr/X11R6/lib/X11/Cards
fi