summaryrefslogtreecommitdiffstats
path: root/scripts/upd-instroot
blob: ae1e91e9187cfbb524f0db0554e45659167ab917 (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
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
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
#!/bin/bash

ORIGDIR=`pwd`
DEBUG=""
NEEDGR=yes

if [ "$1" == "--debug" ]; then
    DEBUG="--debug"
    shift
fi

if [ "$1" == "--nogr" ]; then
    NEEDGR=""
    shift
fi

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

if [ ! -d $1 ]; then
	if [ -z "$ARCH" ]; then
		echo "ARCH must be set" >&2
		exit 1
	fi
fi

PACKAGEDIR=$1

if [ -z "$ARCH" ]; then
	ARCH=`rpm --nodigest --nosignature -qp --qf "%{ARCH}" $PACKAGEDIR/anaconda-runtime*.rpm`
fi

if [ $ARCH = x86_64 -o $ARCH = s390x -o $ARCH = ppc64 ]; then
    LIBDIR=lib64
else
    LIBDIR=lib
fi


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

	PATTERN=""
	PACKAGEFILES=""
	for PKG in $PACKAGES; do
	    PATTERN="${PATTERN:+${PATTERN}|}(^$PKG )"
	    PACKAGEFILES="$PACKAGEFILES $(ls $PACKAGEPATH/$PKG*{$ARCH,noarch}.rpm 2>/dev/null)"
	done

	# gtk+, enough said
	PATTERN=$(echo $PATTERN | sed 's,[\+\*],\\&,g')

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

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

# pulled right out of mkinitrd....
DSO_DEPS=""
LDSO=""
get_dso_deps() {
    root="$1" ; shift
    bin="$1" ; shift
    DSO_DEPS=""

    declare -a FILES
    declare -a NAMES

    # this is a hack, but the only better way requires binutils or elfutils
    # be installed.  i.e., we need readelf to find the interpretter.
    if [ -z "$LDSO" ]; then
        for ldso in /lib*/ld*.so* ; do
            [ -x $ldso ] || continue
            $ldso --verify $bin >/dev/null 2>&1 || continue
            LDSO=$(echo $ldso |sed -e "s/$root//")
            break
        done
    fi

    # I still hate shell.
    declare -i n=0
    while read NAME I0 FILE ADDR I1 ; do
        [ "$FILE" == "not" ] && FILE="$FILE $ADDR"
        NAMES[$n]="$NAME"
        FILES[$n]="$FILE"
        let n++
    done << EOF
        $(LD_TRACE_PRELINKING=1 LD_WARN= LD_TRACE_LOADED_OBJECTS=1 \
            chroot $root $LDSO $bin 2>/dev/null)
EOF

    [ ${#FILES[*]} -eq 0 ] && return 1

    # we don't want the name of the binary in the list
    if [ "${FILES[0]}" == "$bin" ]; then
        FILES[0]=""
        NAMES[0]=""
        [ ${#FILES[*]} -eq 1 ] && return 1
    fi

    declare -i n=0
    while [ $n -lt ${#FILES[*]} ]; do
        FILE="${FILES[$n]}"
        if [ "$FILE" == "not found" ]; then
            cat 1>&2 <<EOF
There are missing files on your system.  The dynamic object $bin
requires ${NAMES[$n]} n order to properly function.  mkinitrd cannot continue.
EOF
            exit 1
        fi
       case "$FILE" in
         /lib*)
           TLIBDIR=`echo "$FILE" | sed 's,\(/lib[^/]*\)/.*$,\1,'`
           BASE=`basename "$FILE"`
           # Prefer nosegneg libs over direct segment accesses on i686.
           if [ -f "$TLIBDIR/i686/nosegneg/$BASE" ]; then
             FILE="$TLIBDIR/i686/nosegneg/$BASE"
           # Otherwise, prefer base libraries rather than their optimized
           # variants.
           elif [ -f "$TLIBDIR/$BASE" ]; then
             FILE="$TLIBDIR/$BASE"
           fi
           ;;
       esac
        dynamic="yes"
        let n++
    done

    DSO_DEPS="${FILES[@]}"
}

instFile() {
    FILE=$1
    DESTROOT=$2

    if [ -e $DESTROOT/$FILE -o -h $DESTROOT/$FILE ]; then
      return
    elif [ ! -d $DESTROOT/`dirname $FILE` ]; then
      mkdir -p $DESTROOT/`dirname $FILE`
    fi
    if [ -L $FILE ]; then
	cp -al $FILE $DESTROOT/`dirname $FILE`
	instFile `readlink $FILE`
	return
    else
	cp -aL $FILE $DESTROOT/`dirname $FILE`
    fi

    get_dso_deps $(pwd) "$FILE"
    local DEPS="$DSO_DEPS"
    for x in $DEPS ; do 
      instFile $x $DESTROOT
    done
}

expandPackageSet() {
    YUMCONF=$1
    RPMS=$2
    PKGDEST=$3
    KEEPFILES=$4

    [ -d $PKGDEST ] || die "ERROR: directory missing: $PKGDEST"
    mkdir $PKGDEST/yumdir
    yum -c $YUMCONF -y --installroot=$PKGDEST/yumdir install $RPMS

    # figure out the theme to keep
    if [ -f $PKGDEST/yumdir/etc/gtk-2.0/gtkrc ]; then
	gtktheme=$(grep "gtk-theme-name" $PKGDEST/yumdir/etc/gtk-2.0/gtkrc | awk {'print $3;'} | sed -e 's/"//g')
	echo "usr/share/themes/$gtktheme" >> $KEEPFILES
	# find gtk engine needed
	for engine in `grep engine $PKGDEST/yumdir/usr/share/themes/$gtktheme/gtk-2.0/gtkrc | awk {'print $2;'} | sed -e 's/"//g' | sort -u` ; do
	    echo "usr/$LIBDIR/gtk-2.0/*/engines/*$engine*" >> $KEEPFILES
	done
	
	theme=$(grep "gtk-icon-theme-name" $PKGDEST/yumdir/etc/gtk-2.0/gtkrc | awk {'print $3;'} | sed -e 's/"//g')
	while [ -n "$theme" ]; do 
	    echo "usr/share/icons/$theme" >> $KEEPFILES
	    theme=$(grep Inherits $PKGDEST/yumdir/usr/share/icons/$theme/index.theme | cut -d = -f 2)
	done
    fi

    pushd $PKGDEST/yumdir >/dev/null
    cat $KEEPFILES | while read spec ; do
      for filespec in `find . -path "./$spec"` ; do
	if [ ! -e $filespec ]; then
	    continue
	elif [ ! -d $filespec ]; then
	    instFile $filespec $PKGDEST
	else
	    for i in `find $filespec -type f` ; do instFile $i $PKGDEST ; done
	fi
      done
    done
    popd >/dev/null

    rm -fr $PKGDEST/yumdir
}

die () {
    echo "$@"
    echo "Aborting instroot creation..."
    exit 1
}

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

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

if [ -n "$4" ]; then
    TOPDIR=$4
elif [ -d $PACKAGEDIR/repodata ]; then
    TOPDIR=$PACKAGEDIR
elif [ -d $PACKAGEDIR/../repodata ]; then
    TOPDIR=$PACKAGEDIR/..
elif [ -d $PACKAGEDIR/../../repodata ]; then
    TOPDIR=$PACKAGEDIR/../..
else
    echo "Unable to find repodata!"
    exit 1
fi


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

PACKAGES="glibc glibc-common setup openssl python newt slang libselinux
	 libsepol libtermcap zlib ash e2fsprogs util-linux raidtools popt
	 procps rpm rpm-libs Xconfigurator anaconda tzdata python-libs
	 anaconda-runtime kudzu hwdata bzip2 beecrypt mdadm libsemanage
	 bzip2-libs dosfstools pciutils reiserfs-utils parted sed
	 busybox-anaconda rpm-python booty hdparm lvm2 beecrypt
	 rhpl pyxf86config libxml2 glib2 sqlite neon libselinux-python
	 elfutils-libelf krb5-libs convertdb1 jfsutils audit-libs pam
	 xfsprogs xfsdump dmapi libacl libattr attr acl python-urlgrabber
	 policy policycoreutils pyparted xorg-x11 selinux-policy-targeted
	 libstdc++ expat libgcc readline ncurses yum python-sqlite
	 python-elementtree pykickstart e2fsprogs-libs iscsi-initiator-utils
	 db4 rhpxl xorg-x11-server-Xorg libuser-python libuser system-config-date
	 yum-metadata-parser gfs2-utils libvolume_id nash yum-fedorakmod
	 libdhcp libnl libdhcp6client libdhcp4client newt-python
	 device-mapper device-mapper-libs dmraid keyutils-libs libsemanage-python
	 python-pyblock mkinitrd libbdevid libbdevid-python nss nspr
	 *-firmware"

if [ $ARCH = i386 -o $ARCH = x86_64 ]; then
    PACKAGES="$PACKAGES pcmciautils"
fi

if [ $ARCH = i386 -o $ARCH = x86_64 -o $ARCH = ia64 ]; then
    PACKAGES="$PACKAGES dmidecode"
fi

if [ $ARCH = ia64 ]; then
    PACKAGES="$PACKAGES elilo"
fi

if [ $ARCH = s390 -o $ARCH = s390x ]; then
    PACKAGES="$PACKAGES s390utils binutils libgcc tcp_wrappers
              sed net-tools openssl openssh openssh-server coreutils
              login initscripts bash portmap pam 
              login mount grep modutils gawk
              strace xorg-x11-xauth xorg-x11-libs"
fi

if [ $ARCH = ppc -o $ARCH = ppc64 ]; then
    PACKAGES="$PACKAGES pcmciautils pdisk yaboot hfsutils"
fi

# xpm is missing

# Some packages are listed twice, but that's okay
#
# The packages in this list are needed for the graphical installer to run
# 
# Extra stuff we want for rescue mode should go in PACKAGESRESCUE
#
PACKAGESGR="anaconda libpng gtk2 libglade2 fonts-ISO8859-2 fonts-ISO8859-9
           e2fsprogs coreutils glibc glibc-common
           popt specspo util-linux rpm rpm-libs tzdata
           procps bash cpio gpm pygtk2-libglade pygobject2
           Xconfigurator pygtk2 gdk-pixbuf libpixman
           reiserfs-utils atk pango freetype gnome-python2-canvas cairo
           libgnomecanvas libart_lgpl libgcc libacl libattr libstdc++ expat
           anaconda-images anaconda-help ttfonts-ko taipeifonts rhpl
           system-config-keyboard Xft fontconfig gtk2-engines gnome-themes
           gtkhtml2 gnome-python2-gtkhtml2 gail libthai
           ttfonts-ja ttfonts-zh_TW bitmap-fonts-cjk urw-fonts fonts-arabic
           comps-extras convertdb1 fonts-bengali
           vnc-server vnc-libs libjpeg tcp_wrappers system-config-date
           xfsprogs xfsdump dmapi attr acl policy policycoreutils
           selinux-policy-targeted ttfonts-zh_CN redhat-artwork
           xorg-x11-libs xorg-x11-ISO8859-2-75dpi-fonts echo-icon-theme
           xorg-x11-ISO8859-9-75dpi-fonts xorg-x11-100dpi-fonts
           xorg-x11-xfs xorg-x11 xorg-x11-KOI8-R xorg-x11-KOI8-R-75dpi-fonts
           xorg-x11-base-fonts xorg-x11-ISO8859-15-75dpi-fonts
           fonts-xorg-ISO8859-2-75dpi fonts-xorg-ISO8859-15-75dpi
           fonts-xorg-ISO8859-9-75dpi fonts-xorg-100dpi
           fonts-xorg-KOI8-R fonts-xorg-KOI8-R-75dpi fonts-xorg-base
           xorg-x11-base xorg-x11-ISO8859-15-75dpi system-logos
           xorg-x11-libs-data xorg-x11-xfs prelink redhat-logos fedora-logos
           ttfonts-ta ttfonts-bn ttfonts-gu ttfonts-hi ttfonts-pa
           fonts-japanese fonts-chinese fonts-korean fonts-indic fonts-sinhala
           fonts-malayalam fonts-oriya fonts-kannada fonts-telugu
           fonts-gujarati fonts-hindi fonts-punjabi fonts-tamil synaptics
           firstboot pycairo pirut dejavu-lgc-fonts
           dmraid python-pyblock libbdevid libbdevid-python zenity"

#
# stuff ONLY included for rescue mode
#
# these packages are combined with the PACKAGES and PACKAGESGR for big stage 2
#
PACKAGESRESCUE="bzip2 bzip2-libs dump libidn groff
                findutils ftp gzip iputils joe krb5-libs less man
                modutils mtools mt-st mtr net-tools open smartmontools
                openssh openssh-clients pciutils rsh traceroute tar rsync
                device-mapper device-mapper-libs dmraid"

if [ $ARCH = i386 -o $ARCH = x86_64 ]; then
    PACKAGESRESCUE="$PACKAGESRESCUE gpart grub"
fi

# turn off options we dont want, ie. set package list to something harmless
if [ -z "$NEEDGR" ]; then
    PACKAGESGR="bash"
    PACKAGESRESCUE="bash"
fi

#
# add bootloader for particular arch
#
if [ $ARCH = sparc ]; then
    PACKAGESGR="$PACKAGESGR tilo silo"
fi

if [ $ARCH = i386 -o $ARCH = x86_64 ]; then
    PACKAGESGR="$PACKAGESGR syslinux memtest86+" 
fi

if [ $ARCH = alpha ]; then
    PACKAGESGR="$PACKAGESGR aboot"
fi

if [ $ARCH = ia64 ]; then
    PACKAGESGR="$PACKAGESGR elilo"
fi

if [ $ARCH = ppc ]; then
    PACKAGESGR="$PACKAGESGR fbset yaboot ppc64-utils"
fi

# dogtail stuff...
PACKAGESGR="$PACKAGESGR gail at-spi libbonobo ORBit2"

# modular xorg...
XORGLIBS="libICE libSM libX11 libXcursor libXext libXfixes libXft libXi libxkbfile libXmu libXpm libXrandr libXrender libXt libXxf86misc libXaw liblbxutil libXfont libfontenc libXau libXdmcp libXfont libXinerama"
XORGFONTS="xorg-x11-fonts-75dpi xorg-x11-fonts-base xorg-x11-fonts-cyrillic xorg-x11-fonts-ISO8859-15-75dpi xorg-x11-fonts-ISO8859-1-75dpi xorg-x11-fonts-ISO8859-2-75dpi xorg-x11-fonts-ISO8859-9-75dpi xorg-x11-fonts-misc xorg-x11-fonts-ethiopic"
XORG="$XORGLIBS xorg-x11-drivers $XORGFONTS xorg-x11-server-Xorg xorg-x11-xauth xorg-x11-font-utils xorg-x11-xkb-utils xorg-x11-xkbdata xorg-x11-server-utils xkeyboard-config"

PACKAGES="$PACKAGES $XORGDRIVERS"
PACKAGESGR="$PACKAGESGR $XORG"


#
# KEEPFILE is all files to keep from the packages in PACKAGES
#
# This is what is present in http, ftp, and hard drive installs, and is
# supposed to be a small image because these methods keep it in RAM.
#
# It also is the base on which the other install images build on top of,
# so if something is needed by all images it should go here
#
KEEPFILE=${TMPDIR:-/tmp}/keepfile.$$

cat > $KEEPFILE <<EOF
boot/efi/EFI/redhat/elilo.efi
bin/ash
bin/fdisk*
bin/mkfs*
bin/sed
etc/group
etc/passwd
etc/iscsid.conf
etc/mke2fs.conf
etc/pcmcia/*
etc/protocols
etc/services
etc/selinux/targeted/booleans
etc/selinux/targeted/policy/policy.*
etc/selinux/targeted/contexts/files/*
etc/selinux/targeted/contexts/*
etc/selinux/targeted/*
usr/share/selinux/targeted/*
etc/security/selinux/policy.*
etc/security/selinux/file_contexts
etc/yum/pluginconf.d/fedorakmod.conf
$LIBDIR/bdevid/*
$LIBDIR/libaudit*.so*
$LIBDIR/libc[-.]*
$LIBDIR/libm[-.]*
$LIBDIR/libpthread*
$LIBDIR/librt[-.]*
$LIBDIR/ld*.so*
$LIBDIR/libblkid*
$LIBDIR/libbz2*
$LIBDIR/libcom_err*
$LIBDIR/libcrypt*
$LIBDIR/libdb-*
$LIBDIR/libdevmapper*
$LIBDIR/libdl*
$LIBDIR/libe2p*
$LIBDIR/libexpat*
$LIBDIR/libext2fs*
$LIBDIR/libkeyutils*
$LIBDIR/liblvm-10.so*
$LIBDIR/libgcc_s*
$LIBDIR/libnsl*
$LIBDIR/libnss_dns*
$LIBDIR/libnss_files*
$LIBDIR/libpam*
$LIBDIR/libresolv*
$LIBDIR/libselinux*
$LIBDIR/libsemanage*
$LIBDIR/libsepol*
$LIBDIR/libss*
$LIBDIR/libtermcap*
$LIBDIR/libhandle*
$LIBDIR/libattr*
$LIBDIR/libdm*
$LIBDIR/libutil*
$LIBDIR/libuuid*
$LIBDIR/libglib*
$LIBDIR/libgmodule*
$LIBDIR/libgobject*
$LIBDIR/libgthread*
$LIBDIR/libncurses*
$LIBDIR/libvolume_id*
$LIBDIR/libtinfo*
$LIBDIR/libz.*
lib/terminfo/*
sbin/badblocks
sbin/busybox.anaconda
sbin/clock
sbin/debugfs
sbin/dosfslabel
sbin/e2fsck
sbin/e2fsadm
sbin/e2label
sbin/fsck.ext2
sbin/fsck.ext3
sbin/fsck.jfs
sbin/fsck.xfs
sbin/fdisk
sbin/hdparm
sbin/hwclock
sbin/jfs_tune
sbin/ldconfig
sbin/lvm*
sbin/mdadm
sbin/mkdosfs
sbin/mke2fs
sbin/mkfs.ext2
sbin/mkfs.ext3
sbin/mkfs.jfs
sbin/mkfs.xfs
sbin/mkfs.msdos
sbin/mkfs.vfat
sbin/mkreiserfs
sbin/mkraid
sbin/mkswap
sbin/parted
sbin/pcmcia-socket-startup
sbin/pdisk
sbin/probe
sbin/reiserfstune
sbin/resize2fs
sbin/tune2fs
sbin/xfsdump
sbin/xfsrestore
sbin/xfs_repair
usr/sbin/xfs_db
usr/sbin/xfs_check
usr/sbin/xfs_copy
sbin/*gfs*
sbin/iscsid
sbin/iscsiadm
sbin/iscsistart
usr/bin/python
usr/bin/python?.?
usr/bin/hmount
usr/bin/humount
usr/bin/hcopy
usr/bin/hattrib
usr/bin/hformat
usr/lib/anaconda-runtime/*
usr/lib/anaconda/*
usr/lib/anaconda/installclasses/*
usr/lib/anaconda/textw/*
usr/lib/booty/*
usr/kerberos/$LIBDIR/libkrb5.so*
usr/kerberos/$LIBDIR/libkrb5support.so*
usr/kerberos/$LIBDIR/libk5crypto.so*
usr/kerberos/$LIBDIR/libcom_err.so*
usr/kerberos/$LIBDIR/libgssapi_krb5.so*
usr/$LIBDIR/libbdevid.so*
usr/$LIBDIR/libdmraid.so*
usr/$LIBDIR/libkrb5.so*
usr/$LIBDIR/libkrb5support.so*
usr/$LIBDIR/libk5crypto.so*
usr/$LIBDIR/libcom_err.so*
usr/$LIBDIR/libgssapi_krb5.so*
usr/$LIBDIR/gconv/ISO8859-1.so
usr/$LIBDIR/gconv/gconv-modules
usr/$LIBDIR/libbeecrypt*
usr/$LIBDIR/libssl*
usr/$LIBDIR/libcrypto*
usr/$LIBDIR/libdhcp*
usr/$LIBDIR/libelf*
usr/$LIBDIR/libnash*
usr/$LIBDIR/libncurses*
usr/$LIBDIR/libnewt*
usr/$LIBDIR/libnl*
usr/$LIBDIR/libnss3.so
usr/$LIBDIR/libparted*
usr/$LIBDIR/libpopt*
$LIBDIR/libpopt*
usr/$LIBDIR/libpython*
usr/$LIBDIR/libneon*
usr/$LIBDIR/libnspr*
usr/$LIBDIR/libplc4*
usr/$LIBDIR/libplds4*
usr/$LIBDIR/libsqlite3*
usr/$LIBDIR/libsoftokn3*
usr/$LIBDIR/librpm-*4.?.so*
usr/$LIBDIR/librpmbuild-*4.?.so*
usr/$LIBDIR/librpmdb*4.?.so*
usr/$LIBDIR/librpmio*4.?.so*
usr/$LIBDIR/libslang*
usr/$LIBDIR/libstdc++.so.6*
usr/$LIBDIR/libuser.so*
usr/$LIBDIR/libuser/*
usr/$LIBDIR/libxml2.so*
usr/$LIBDIR/libz.*
usr/$LIBDIR/libreadline*
usr/$LIBDIR/python?.?/*
usr/$LIBDIR/python?.?/email/*
usr/$LIBDIR/python?.?/xml/etree/
usr/$LIBDIR/python?.?/site-packages/*kudzu*
usr/$LIBDIR/python?.?/site-packages/bdevid.so
usr/$LIBDIR/python?.?/site-packages/rpmmodule.so
usr/$LIBDIR/python?.?/site-packages/partedmodule.so
usr/$LIBDIR/python?.?/site-packages/ixf86configmodule.so
usr/$LIBDIR/python?.?/site-packages/xf86config.py
usr/$LIBDIR/python?.?/site-packages/libusermodule.so
usr/$LIBDIR/python?.?/site-packages/*sqlite*
usr/$LIBDIR/python?.?/site-packages/rhpl
usr/$LIBDIR/python?.?/site-packages/cElementTree.so
usr/$LIBDIR/python?.?/site-packages/block
usr/$LIBDIR/python?.?/site-packages/*.pth
usr/$LIBDIR/python?.?/site-packages/*selinux*
usr/lib/locale/*
usr/lib/python?.?/site-packages/elementtree/*
usr/lib/python?.?/site-packages/rpmUtils/*
usr/lib/python?.?/site-packages/urlgrabber/*
usr/lib/python?.?/site-packages/yum/*
usr/lib/python?.?/site-packages/repomd/*
usr/lib/python?.?/site-packages/pirut/*
usr/lib/python?.?/site-packages/pykickstart/*
usr/lib/python?.?/site-packages/rhpxl/*
usr/lib/rpm/macros
usr/lib/rpm/rpmpopt
usr/lib/rpm/rpmrc
usr/lib/yaboot/addnote
usr/lib/yaboot/ofboot
usr/lib/yaboot/yaboot
usr/lib/yum-plugins/fedorakmod.py*
usr/libexec/convertdb1
usr/share/locale/*/LC_MESSAGES/anaconda.mo
usr/share/locale/*/LC_MESSAGES/system-config-date.mo
usr/share/locale/locale.alias
usr/sbin/anaconda
usr/sbin/ddcprobe
usr/sbin/dmidecode
usr/sbin/mkofboot
usr/sbin/ofpath
usr/sbin/ybin
usr/sbin/load_policy
usr/sbin/semodule
usr/sbin/genhomedircon
sbin/setfiles
usr/sbin/lvm
usr/sbin/gptsync
usr/share/anaconda/anaconda.conf
usr/share/selinux/targeted/base.pp
usr/share/system-config-date/zonetab.py*
usr/share/terminfo/l/linux
usr/share/terminfo/v/vt100
usr/share/terminfo/v/vt100-nav
usr/share/hwdata/pci.ids
usr/share/hwdata/videoaliases
usr/share/hwdata/videoaliases/*
usr/share/hwdata/videodrivers
usr/share/hwdata/MonitorsDB
usr/share/xorg/extramodes
usr/share/xorg/vesamodes
usr/share/zoneinfo/zone.tab
EOF

if [ $ARCH = s390 -o $ARCH = s390x ]; then
    cat >> $KEEPFILE <<EOF
usr/share/terminfo/a/ansi
usr/share/terminfo/d/dumb
usr/share/terminfo/k/kterm
usr/share/terminfo/s/screen
usr/share/terminfo/v/vt102
usr/share/terminfo/x/xterm
usr/share/terminfo/x/xterm-color
usr/bin/strace
usr/bin/ldd
usr/sbin/chroot
usr/sbin/sshd
usr/sbin/glibc_post_upgrade
sbin/cmsfslst
sbin/cmsfscat
sbin/busybox.anaconda
sbin/ifconfig
sbin/route
sbin/portmap
sbin/fdasd
sbin/dasdfmt
sbin/swapon
sbin/swapoff
sbin/mkswap
bin/bash
bin/dd
bin/gawk
bin/mount
bin/umount
bin/mknod
bin/sleep
bin/login
bin/cat
bin/chmod
bin/sort
$LIBDIR/libpam.so*
$LIBDIR/libdl.so*
$LIBDIR/libdl-*.so*
usr/$LIBDIR/libz.so*
$LIBDIR/libnsl.so*
$LIBDIR/libnsl-*.so*
$LIBDIR/libnss*
$LIBDIR/libutil.so*
$LIBDIR/libutil-*.so*
$LIBDIR/libcrypt*
$LIBDIR/libc.so*
$LIBDIR/libc-*so*
lib/ld*.so*
$LIBDIR/ld*.so*
$LIBDIR/libresolv.so*
$LIBDIR/libresolv-*.so*
$LIBDIR/libvtoc*.so*
$LIBDIR/libz.so*
lib/modules/ibm/*
etc/pam.d/sshd
etc/pam.d/other
etc/security/limits.conf
etc/security/pam_env.conf
lib/security
$LIBDIR/security/pam_*
usr/$LIBDIR/libwrap.so*
usr/$LIBDIR/libXmuu.so*
usr/$LIBDIR/libX11.so*
usr/$LIBDIR/libXext.so*
usr/$LIBDIR/libXxf86misc.so*
usr/bin/xauth
EOF
fi

#
# KEEPFILEGR is all files to keep from the packages in PACKAGESGR
#
# This defines the files in addition to KEEPFILE that make up the install
# images for NFS and CD/DVD based installs.  This image is not loaded into
# memory so it can be considerably larger.
#
# The rescue mode of anaconda uses these files as well as those defined
# by KEEPFILERESCUE below.  The total size of this image should be
# under the size of the miniature CD used for the rescue CD (around 68MB).
#
KEEPFILEGR=${TMPDIR:-/tmp}/keepfilegr.$$
cp $KEEPFILE $KEEPFILEGR
cat >> $KEEPFILEGR <<EOF
boot/efi/EFI/redhat/elilo.efi
boot/memtest86*
bin/bash
bin/cat
bin/chmod
bin/cp
bin/cpio
bin/dd
bin/df
bin/du
bin/ln
bin/ls
bin/mkdir
bin/mv
bin/ps
bin/rm
bin/rpm
bin/touch
boot/*.b
boot/bootlx
etc/fb.modes
etc/gtk-2.0/gtkrc*
etc/im_palette.pal
etc/imrc
etc/man.config
etc/pango/*
etc/fonts/*
etc/prelink.conf
etc/rpm/macros.prelink
$LIBDIR/bdevid/*
$LIBDIR/libacl*
$LIBDIR/libattr*
$LIBDIR/libgcc*
$LIBDIR/libnss_dns*
$LIBDIR/libproc*
sbin/addRamDisk
sbin/addSystemMap
sbin/debugfs
sbin/e2fsck
sbin/e2label
sbin/reiserfsck
sbin/reiserfstune
sbin/fsck
sbin/fsck.ext2
sbin/fsck.ext3
sbin/fsck.jfs
sbin/fsck.reiserfs
sbin/parted
sbin/silo
sbin/tune2fs
usr/bin/Xorg
usr/bin/setxkbmap
usr/bin/xkbcomp
usr/share/X11/XKeysymDB
usr/share/X11/fonts/misc/6x13*
usr/share/X11/fonts/misc/fonts*
usr/share/X11/fonts/misc/cursor*
usr/share/X11/fonts/misc/olcursor*
usr/share/X11/fonts/Type1/l047013t*
usr/share/X11/fonts/Type1/*
usr/share/X11/fonts/TTF/GohaTibebZemen.ttf
usr/share/X11/locale/*
usr/share/X11/rgb*
usr/share/X11/xkb/*
usr/$LIBDIR/xserver/SecurityPolicy
usr/$LIBDIR/libbdevid.so*
usr/$LIBDIR/libICE*
usr/$LIBDIR/libSM*
usr/$LIBDIR/libXaw.so*
usr/$LIBDIR/libX11*
usr/$LIBDIR/libXcursor*
usr/$LIBDIR/libXext*
usr/$LIBDIR/libXfixes*
usr/$LIBDIR/libXft*
usr/$LIBDIR/libXi*
usr/$LIBDIR/libxkbfile*
usr/$LIBDIR/libXmu*
usr/$LIBDIR/libXpm*
usr/$LIBDIR/libXrandr*
usr/$LIBDIR/libXrender*
usr/$LIBDIR/libXt*
usr/$LIBDIR/libXxf86misc*
usr/$LIBDIR/liblbxutil*
usr/$LIBDIR/libXfont*
usr/$LIBDIR/libfontenc*
usr/$LIBDIR/libXau*
usr/$LIBDIR/libXdmcp*
usr/$LIBDIR/xorg/modules/*
usr/$LIBDIR/xorg/modules/input/*
usr/bin/chattr*
usr/bin/fc-cache
usr/bin/gdialog
usr/bin/gtk-query*
usr/bin/gdk-pixbuf-query-loaders*
usr/bin/gtk-update-icon-cache*
usr/bin/head
usr/bin/lsattr*
usr/bin/maketilo
usr/bin/mini-wm
usr/bin/pango*
usr/bin/syslinux
usr/bin/mkzimage
usr/bin/tac
usr/bin/tail
usr/bin/tilo
usr/bin/uniq
usr/bin/zenity
usr/bin/Xvnc
usr/bin/vncconfig
usr/bin/vncpasswd
usr/bin/reduce-font
usr/lib/anaconda/iw
usr/$LIBDIR/gconv/*
usr/$LIBDIR/gdk-pixbuf/loaders/*xpm*
usr/$LIBDIR/gdk-pixbuf/loaders/*png*
usr/$LIBDIR/gdk-pixbuf/loaders/*la*
usr/$LIBDIR/gtk-2.0/*/engines/libclearlooks.so
usr/$LIBDIR/gtk-2.0/*/loaders/*xpm*
usr/$LIBDIR/gtk-2.0/*/loaders/*png*
usr/$LIBDIR/gtk-2.0/*/loaders/*la*
usr/$LIBDIR/gtk-2.0/immodules/
usr/$LIBDIR/libImlib*
usr/$LIBDIR/libXft*
usr/$LIBDIR/libart*
usr/$LIBDIR/libatk*
usr/$LIBDIR/libaudio*
usr/$LIBDIR/libpixman*
usr/$LIBDIR/libcairo*
usr/$LIBDIR/libesd*
usr/$LIBDIR/libfontconfig*
usr/$LIBDIR/libfreetype*
usr/$LIBDIR/libgailutil*
usr/$LIBDIR/libgdk*
usr/$LIBDIR/libglade*
usr/$LIBDIR/libgnomecanvas*
usr/$LIBDIR/libgnomeui*
usr/$LIBDIR/libgpm*
usr/$LIBDIR/libgtk*
usr/$LIBDIR/libjpeg*
usr/$LIBDIR/libpango*
usr/$LIBDIR/libpng.so.3*
usr/$LIBDIR/libpng12.so*
usr/$LIBDIR/librfb.so*
usr/$LIBDIR/libstdc++.so.*
usr/$LIBDIR/libthai*
usr/$LIBDIR/libwrap*
usr/$LIBDIR/pango/*
usr/$LIBDIR/python?.?/site-packages/cairo/*
usr/$LIBDIR/python?.?/site-packages/gtk*/gtk/*
usr/$LIBDIR/python?.?/site-packages/gtk*/*
usr/$LIBDIR/rpm/rpmpopt
usr/lib/syslinux/*
usr/lib/yaboot/*
usr/sbin/chroot
usr/sbin/ddcprobe
usr/sbin/fbset
usr/sbin/prelink
usr/sbin/smartctl
usr/share/anaconda/*
usr/share/firstboot/firstboot_module_window*
usr/share/fonts/dejavu-lgc/DejaVuLGCSans.ttf
usr/share/fonts/dejavu-lgc/DejaVuLGCSans-Bold.ttf
usr/share/fonts/dejavu-lgc/DejaVuLGCSansMono.ttf
usr/share/fonts/korean/TrueType/dotum.ttf
usr/share/fonts/japanese/TrueType/sazanami-gothic.ttf
usr/share/fonts/chinese/TrueType/uming*.ttf
usr/share/fonts/bengali/MuktiNarrow.ttf
usr/share/fonts/arabic/KacstFarsi.ttf
usr/share/fonts/arabic/KacstQura.ttf
usr/share/fonts/tamil/lohit_ta.ttf
usr/share/fonts/gujarati/lohit_gu.ttf
usr/share/fonts/bengali/lohit_bn.ttf
usr/share/fonts/hindi/lohit_hi.ttf
usr/share/fonts/punjabi/lohit_pa.ttf
usr/share/fonts/oriya/lohit_or.ttf
usr/share/fonts/malayalam/lohit_ml.ttf
usr/share/fonts/kannada/lohit_kn.ttf
usr/share/fonts/telugu/lohit_te.ttf
usr/share/fonts/sinhala/lklug.ttf
usr/share/locale/*/LC_MESSAGES/anaconda.mo
usr/share/locale/*/LC_MESSAGES/system-config-date.mo
usr/share/locale/*/LC_MESSAGES/redhat-dist.mo
usr/share/locale/*/LC_MESSAGES/system-config-keyboard.mo
usr/share/locale/*/LC_MESSAGES/gtk20.mo
usr/share/locale/*/LC_MESSAGES/libc.mo
usr/share/locale/*/LC_MESSAGES/rhpl.mo
usr/share/locale/*/LC_MESSAGES/rhpxl.mo
usr/share/locale/*/LC_MESSAGES/parted.mo
usr/share/locale/*/LC_MESSAGES/pirut.mo
usr/share/locale/*/LC_MESSAGES/zenity.mo
usr/share/pirut/*
usr/share/pixmaps/comps/*.png
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/ppc64-utils/*
usr/share/system-config-keyboard/*
usr/share/system-config-date/*
usr/share/terminfo/x/xterm
usr/share/vte/termcap/xterm
usr/share/zenity
usr/share/zoneinfo/zone.tab
EOF

TIMEZONES="
usr/share/zoneinfo/Africa
usr/share/zoneinfo/America
usr/share/zoneinfo/Antarctica
usr/share/zoneinfo/Arctic
usr/share/zoneinfo/Asia
usr/share/zoneinfo/Atlantic
usr/share/zoneinfo/Australia
usr/share/zoneinfo/Canada
usr/share/zoneinfo/Europe
usr/share/zoneinfo/Indian
usr/share/zoneinfo/Japan
usr/share/zoneinfo/Mideast
usr/share/zoneinfo/Pacific
usr/share/zoneinfo/US
"

# more dogtail stuff...
cat >> $KEEPFILEGR <<EOF
usr/$LIBDIR/gtk-2.0/modules/libatk-bridge.so
usr/$LIBDIR/gtk-2.0/modules/libgail.so
usr/libexec/bonobo-activation-server
usr/libexec/at-spi-registryd
usr/$LIBDIR/libORBit*
usr/$LIBDIR/libbonobo*
usr/$LIBDIR/libspi*
usr/$LIBDIR/libcspi*
usr/$LIBDIR/bonobo/servers/*
usr/$LIBDIR/libXevie*
EOF



#
# KEEPFILERESCUE is all files to keep from the packages in PACKAGESRESCUE
#
# This defines the files in addition to KEEPFILE and KEEPFILEGR that make up 
# the install images for NFS and CD/DVD based rescue mode installs.  This 
# image is not loaded into memory so it can be considerably larger.
#
# NOTE: hd, ftp, and http rescue mode use and image based on KEEPFILE since
#       it has to be much smaller due to memory usage.
#
KEEPFILERESCUE=${TMPDIR:-/tmp}/keepfilerescue.$$
cat > $KEEPFILERESCUE <<EOF
bin/gunzip
bin/gzip
bin/mt
bin/ping
bin/sync
bin/tar
bin/zcat
etc/joe/*
sbin/arp
sbin/depmod
sbin/dmraid.static
sbin/dmsetup.static
sbin/dump
sbin/ifconfig
sbin/insmod
sbin/lsmod
sbin/lspci
sbin/modinfo
sbin/modprobe
sbin/netstat
sbin/restore
sbin/rrestore
sbin/rmmod
sbin/route
usr/bin/bunzip2
usr/bin/bzcat
usr/bin/bzip2
usr/bin/emacs
usr/bin/find
usr/bin/ftp
usr/bin/jmacs
usr/bin/joe
usr/bin/jpico
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/mmove
usr/bin/mpartition
usr/bin/mrd
usr/bin/mread
usr/bin/mren
usr/bin/mshowfat
usr/bin/mtools
usr/bin/mtype
usr/bin/mzip
usr/bin/open
usr/bin/rcp
usr/bin/rlogin
usr/bin/rsh
usr/bin/rsync
usr/bin/scp
usr/bin/sftp
usr/bin/shred
usr/bin/ssh
usr/bin/termidx
usr/bin/xargs
usr/bin/groff
usr/bin/iconv
usr/$LIBDIR/libidn*
usr/kerberos/$LIBDIR/libgssapi*
usr/kerberos/$LIBDIR/libkrb5*
usr/kerberos/$LIBDIR/libk5crypto*
usr/kerberos/$LIBDIR/libcom_err*
usr/sbin/mtr
usr/sbin/smartctl
usr/sbin/traceroute
EOF

if [ $ARCH = i386 -o $ARCH = x86_64 ]; then
    cat >> $KEEPFILERESCUE <<-EOF
boot/grub
sbin/grub
sbin/grub-install
sbin/grub-md5-crypt
sbin/grub-set-default
usr/bin/gpart
usr/bin/mbchk
usr/share/grub/*
EOF
fi

echo "Assembling package list..."
RPMS="$PACKAGES"
[ -n "$DEBUG" ] && echo "RPMS are $RPMS"
RPMSGR="$PACKAGES $PACKAGESGR $PACKAGESRESCUE"
[ -n "$DEBUG" ] && echo "RPMSGR are $RPMSGR"

rm -rf $DEST; mkdir -p $DEST/usr/sbin
rm -rf $DESTGR; mkdir -p $DESTGR/usr/sbin $DESTGR/var/lib $DESTGR/boot
ln -s /tmp $DESTGR/var/lib/xkb 

#
# concat KEEPFILEGR and KEEPFILERESCUE lists
#
cat $KEEPFILERESCUE >> $KEEPFILEGR
cat $KEEPFILE >> $KEEPFILEGR

#
# filter paths in keepfile lists for use by cpio
#
for file in $KEEPFILE $KEEPFILEGR; do
   cat $file | awk '{print $1 "\n./" $1}' > $file-
   mv -f $file- $file
done

yumconf=$(mktemp /tmp/yum.conf.XXXXXX)
cat > $yumconf <<EOF 
[main]
keepcache=0
gpgcheck=0
plugins=0
reposdir=

[anacondarepo]
name=anaconda repo
baseurl=file://$TOPDIR
enabled=1
EOF

echo "Expanding text packages..."
expandPackageSet $yumconf "$RPMS" $DEST $KEEPFILE

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

echo "Expanding graphical packages..."
expandPackageSet $yumconf "$RPMSGR" $DESTGR $KEEPFILEGR

rm -f $yumconf

# echo "retrieving timezones"
# TZDIR=${TMPDIR:-/tmp}/glibc-timezone-$$
# mkdir -p $TZDIR/usr/share/zoneinfo
# rpm2cpio $TZDATA | (cd $TZDIR; cpio --quiet -iumd usr/share/zoneinfo ./usr/share/zoneinfo ./usr/share/zoneinfo/* usr/share/zoneinfo/*)
# [ $? = 0 ] || die "ERROR: Unable to expand timezone data ($TZDATA)"
# (cd $TZDIR; tar cSpf - $TIMEZONES) | (cd $DEST; tar xSpf -)
# (cd $TZDIR; tar cSpf - $TIMEZONES) | (cd $DESTGR; tar xSpf -)

chown -R root:root $DEST $DESTGR
chmod -R a+rX-w $DEST $DESTGR
if [ $ARCH = s390 -o $ARCH = s390x ]; then
    for i in $DEST $DESTGR; do
	mv $i/bin/sed $i/bin/sed_save
	mv $i/bin/sort $i/bin/sort_save
    done
fi

for i in $DEST $DESTGR; do
    # there's never a case with only one of these...
    if [ -f $i/sbin/dmraid.static ]; then
        mv $i/sbin/dmraid.static $i/sbin/dmraid
        mv $i/sbin/dmsetup.static $i/sbin/dmsetup
    fi
done

# change mtimes to 0 (to match what happens on the cramfs)
for p in $DEST $DESTGR; do
    $p/usr/lib/anaconda-runtime/fixmtime.py $DEBUG $p
done

# for p in $DEST $DESTGR; do
#    if [ -f $p/usr/lib/locale/locale-archive.tmpl ]; then
#       mv $p/usr/lib/locale/locale-archive.tmpl $p/usr/lib/locale/locale-archive
#    fi
# done

# Remove locales unused during the install
cat $DESTGR/usr/lib/anaconda/lang-table* | awk '
{ gsub("-", "", $4);
  print $4;
  print gensub(/\..*$/,"","",$4);
  print gensub(/_.*$/,"","",$4);
  if (split ($4, a, ".") > 1) {
    print gensub(/\..*$/,tolower("." a[2]),"",$4);
  };
  print $2;
}
' | sed -e 's/latn/Latn/g' | LC_ALL=C sort -u > $DESTGR/locales
for p in lib share; do (
cd $DESTGR/usr/$p/locale && {
ls | grep -v locale.alias | grep -v locale-archive | LC_ALL=C sort > $DESTGR/locales.list
LC_ALL=C comm -13 $DESTGR/locales $DESTGR/locales.list | xargs rm -rf
}
); done
rm -f $DESTGR/locales $DESTGR/locales.list

# fixup joe links
if [ -n "$NEEDGR" -a -d "$DESTDIR"/etc/joe ]; then
    ln -fs jpicorc $DESTGR/etc/joe/picorc
    ln -fs jpicorc $DESTGR/etc/joe/jnanorc
    ln -fs jpicorc $DESTGR/etc/joe/nanorc
    ln -fs jmacsrc $DESTGR/etc/joe/emacsrc
    ln -fs jmacs $DESTGR/usr/bin/emacs
    ln -fs jpico $DESTGR/usr/bin/pico
    ln -fs jpico $DESTGR/usr/bin/nano
fi

# create selinux config
if [ -e $DEST/etc/selinux/targeted ]; then
  cat > $DEST/etc/selinux/config <<EOF
SELINUX=permissive
SELINUXTYPE=targeted
EOF
  cp $DEST/etc/selinux/config $DESTGR/etc/selinux/config
fi

cat > $DEST/etc/shells <<EOF
/bin/sh
EOF

echo "Creating nsswitch.conf"
cat > $DEST/etc/nsswitch.conf <<EOF
# munged nsswitch.conf with just what anaconda needs
# created by upd-instroot
#
passwd:     files
shadow:     files
group:      files
hosts:      files dns
ethers:     files
netmasks:   files
networks:   files
protocols:  files
rpc:        files
services:   files
netgroup:   files
automount:  files
aliases:    files
EOF

echo "Creating libuser.conf"
cat > $DEST/etc/libuser.conf <<EOF
[defaults]
skeleton = /mnt/sysimage/etc/skel
mailspooldir = /mnt/sysimage/var/mail
crypt_style = md5
modules = files shadow
create_modules = files shadow
[files]
directory = /mnt/sysimage/etc
[shadow]
directory = /mnt/sysimage/etc
EOF

cp $DEST/etc/shells $DESTGR/etc/shells
cp $DEST/etc/nsswitch.conf $DESTGR/etc/nsswitch.conf
cp $DEST/etc/libuser.conf $DESTGR/etc/libuser.conf

sed -i 's|\(installforallkernels\) = 0|\1 = 1|' $DEST/etc/yum/pluginconf.d/fedorakmod.conf
cp $DEST/etc/yum/pluginconf.d/fedorakmod.conf $DESTGR/etc/yum/pluginconf.d/

# fixup man.config to point into /mnt/sysimage for rescue
if [ -n "$NEEDGR" ]; then
    echo "Fixing up /etc/man.config to point into /mnt/sysimage"
    mv $DESTGR/etc/man.config $DESTGR/etc/man.config-old
    cat $DESTGR/etc/man.config-old | sed 's^/usr/bin^/mnt/sysimage/usr/bin^' | sed 's^/bin/cat^/mnt/sysimage/usr/bin/cat^'  > $DESTGR/etc/man.config
    rm -f $DESTGR/etc/man.config-old
fi

if [ -n "$NEEDGR" ]; then
    echo "Running mkfontdir..."
    mkfontdir $DESTGR/usr/share/X11/fonts/*
fi

echo "Creating SELinux policy..."
if [ -x $DESTGR/usr/sbin/semodule ]; then
    ( cd $DESTGR
      x=$(ls usr/share/selinux/targeted/*.pp | grep -v -e base.pp -e enableaudit.pp | awk '{ print "-i /" $1 }')
    /usr/sbin/chroot $DESTGR /usr/sbin/semodule -b /usr/share/selinux/targeted/base.pp $x -n -s targeted )
fi
rm -rf $DEST/etc/selinux
rm -rf $DEST/usr/share/selinux $DESTGR/usr/share/selinux
mkdir $DEST/etc/selinux
cp -r $DESTGR/etc/selinux/* $DEST/etc/selinux/

rm -f $KEEPFILE $KEEPFILEGR $KEEPFILERESCUE

for p in $DEST $DESTGR; do
	echo "Scrubbing trees..." "$p"
	cp $p/usr/lib/anaconda/raidstart-stub $p/usr/bin/raidstart
	cp $p/usr/lib/anaconda/raidstop-stub $p/usr/bin/raidstop
	cp $p/usr/lib/anaconda/losetup-stub $p/usr/bin/losetup
	cp $p/usr/lib/anaconda/dhcpclient-stub $p/usr/bin/dhcpclient
	( cd $p/usr/bin && rm -f pump && ln -sf dhcpclient pump )
	cp $p/usr/lib/anaconda/list-harddrives-stub $p/usr/bin/list-harddrives
	cp $p/usr/lib/anaconda/kudzu-probe-stub $p/usr/bin/kudzu-probe
	cp $p/usr/lib/anaconda/loadkeys-stub $p/usr/bin/loadkeys
	cp $p/usr/lib/anaconda/mknod-stub $p/usr/bin/mknod
	cp $p/usr/lib/anaconda/syslogd-stub $p/usr/bin/syslogd
	mv $p/usr/sbin/anaconda $p/usr/bin/anaconda
	mv $p/usr/lib/anaconda-runtime/lib* $p/usr/$LIBDIR

	# we only want the libunicode-lite stuff on the minimal image
	if [ $p = $DESTGR ]; then
	    rm -f $p/usr/$LIBDIR/libunicode-lite*
	fi

	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 -sf busybox $p/bin/sh
	fi

	[ -d $p/bin ] || die "ERROR: directory missing: $p/bin"
	[ -d $p/sbin ] || die "ERROR: directory missing: $p/sbin"
	(cd $p/bin; find) | (cd $p/bin; /bin/cpio --quiet -pdmu $p/usr/bin)
	(cd $p/sbin; find) | (cd $p/sbin; /bin/cpio --quiet -pdmu $p/usr/sbin)
	rm -rf $p/bin
	rm -rf $p/sbin

	# copy bootloader files for sparc
	if [ $ARCH = sparc -a $p = $DESTGR ]; then
	    mkdir -p $p/usr/lib/anaconda-runtime/boot
	    [ -d $p/boot ] || die "ERROR: directory missing: $p/boot"
	    (cd $p/boot; find -name "*.b") | (cd $p/boot; /bin/cpio --quiet -pdmu $p/usr/lib/anaconda-runtime/boot)
        fi

	# copy bootloader file for alpha
	if [ $ARCH = alpha -a $p = $DESTGR ]; then
	    mkdir -p $p/usr/lib/anaconda-runtime/boot
	    cp -af $p/boot/bootlx $p/usr/lib/anaconda-runtime/boot
        fi
	
	# copy bootloader files for ia64
	if [ $ARCH = ia64 -a $p = $DESTGR ]; then
	    mkdir -p $p/usr/lib/anaconda-runtime/boot
	    cp -af $p/boot/efi/EFI/redhat//* $p/usr/lib/anaconda-runtime/boot
	fi    

	# copy bootloader files for i386/x86_64
	if [ $ARCH = i386 -o $ARCH = x86_64 ]; then
	    if [ $p = $DESTGR ]; then
		mkdir -p $p/usr/lib/anaconda-runtime/boot
		cp -af $p/boot/memtest* $p/usr/lib/anaconda-runtime/boot
	    fi
	fi

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

	find $p -name "*.a" | xargs rm -rf
	find $p -name "lib*.la" |grep -v "usr/$LIBDIR/gtk-2.0" | xargs rm -rf
	for f in newt popt rpm rpmio; do
	    rm -f $p/usr/$LIBDIR/lib$f.so
	done

	# nuke some python stuff we don't need
        for d in idle distutils bsddb lib-old hotshot doctest.py pydoc.py site-packages/japanese site-packages/japanese.pth ; do
	    rm -rf $p/$d
	done

	if [ "$ARCH" != "s390" -a "$ARCH" != "s390x" ]; then
	   (cd $p/lib* && rm -f libnss_files.so.1 libnss_dns.so.1)
	fi

	if [ -d $DEST/usr/share/zoneinfo ]; then
	    (cd $DEST/usr/share/zoneinfo; find . -type f -or -type l | 
		grep '^./[A-Z]' | sort | sed 's/^..//' | 
		gzip -9) > $p/usr/lib/timezones.gz
	else
	    echo "ERROR: unable to explode tzdata for small images"
	fi

	$p/usr/lib/anaconda-runtime/scrubtree $p
done

echo "Compressing .mo files in stage2 images..."
if [ -d $DEST/usr/share/locale ]; then
    for i in `find $DEST/usr/share/locale -name anaconda.mo`; do
	gzip -9 $i
	mv -f $i.gz $i
    done
fi

if [ -n "$NEEDGR" ]; then
    echo "Creating fontconfig cache"
    /usr/sbin/chroot $DESTGR /usr/bin/fc-cache
    rm -f $DESTGR/usr/bin/fc-cache
fi

echo "Creating debug dir"
for p in $DEST $DESTGR ; do
    mkdir -p $p/usr/lib/debug
    mkdir -p $p/usr/src/debug
done

if [ $ARCH = "alpha" ]; then
    rm -rf $DEST/usr/share/locale
    rm -rf $DEST/usr/$LIBDIR/locale
fi

echo "Patching python library..."

# always use passive mode for ftp installs
cd $DEST/usr/$LIBDIR/python*
patch -p0 > /dev/null <<EOF
--- urllib.py.orig	Thu Oct 25 17:05:06 2001
+++ urllib.py	Thu Oct 25 17:05:34 2001
@@ -453,6 +453,7 @@
         path, attrs = splitattr(path)
         path = unquote(path)
         dirs = path.split('/')
+        dirs[0] = '/' + dirs[0]
         dirs, file = dirs[:-1], dirs[-1]
         if dirs and not dirs[0]: dirs = dirs[1:]
         if dirs and not dirs[0]: dirs[0] = '/'
@@ -707,6 +708,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)
EOF
cd -

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

# some python stuff we don't need for stage2
rm -rf $DESTGR/usr/$LIBDIR/python?.?/site-packages/distutils/
rm -rf $DESTGR/usr/$LIBDIR/python?.?/site-packages/lib-dynload/japanese
rm -rf $DESTGR/usr/$LIBDIR/python?.?/site-packages/encodings/
rm -rf $DESTGR/usr/$LIBDIR/python?.?/site-packages/compiler/
rm -rf $DESTGR/usr/$LIBDIR/python?.?/site-packages/email/test/
rm -rf $DESTGR/usr/$LIBDIR/python?.?/site-packages/curses/
rm -rf $DESTGR/usr/$LIBDIR/python?.?/site-packages/pydoc.py

# clean up tzdata
rm -rf $TZDIR

# this is only for the minimal second stage
echo "Cleaning ramdisk install images..."
rm -rf $DEST/usr/lib/anaconda-runtime