take out use=-x
[catalyst.git] / examples / livecd / runscript / default-runscript.sh
1 # Copyright 1999-2004 Gentoo Technologies, Inc.
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo/src/catalyst/examples/livecd/runscript/Attic/default-runscript.sh,v 1.18 2004/02/26 04:35:07 brad_mssw Exp $
4
5 #return codes to be used by archscript
6
7 die() {
8         echo "$1"
9         exit 1
10 }
11
12 case $clst_livecd_cdfstype in
13 zisofs)
14         cmdline_opts="looptype=zisofs loop=/zisofs"
15         ;;
16 normal)
17         cmdline_opts="looptype=normal loop=/livecd.loop"
18         ;;
19 noloop)
20         cmdline_opts="looptype=noloop"
21         ;;
22 squashfs)
23         cmdline_opts="looptype=squashfs loop=/livecd.squashfs"
24         ;;
25 gcloop)
26         cmdline_opts="looptype=gcloop loop=/livecd.gcloop"
27         ;;
28 esac
29
30 source ${clst_livecd_archscript}
31
32 create_normal_loop()
33 {
34                 #We get genkernel-built kernels and initrds in place, create the loopback fs on 
35                 #$clst_cdroot_path, mount it, copy our bootable filesystem over, umount it, and 
36                 #we then have a ready-to-burn ISO tree at $clst_cdroot_path.
37
38                 echo "Calculating size of loopback filesystem..."
39                 loopsize=`du -ks $clst_chroot_path | cut -f1`
40                 [ "$loopsize" = "0" ] && loopsize=1
41                 #increase the size by 1/3, then divide by 4 to get 4k blocks
42 #               loopsize=$(( ( $loopsize + ( $loopsize / 2 ) ) / 4  ))
43                 # Add 4MB for filesystem slop
44                 loopsize=`expr $loopsize + 4096`
45                 echo "Creating loopback file..."
46                 dd if=/dev/zero of=$clst_cdroot_path/livecd.loop bs=1k count=$loopsize || die "livecd.loop creation failure"
47                 #echo "Calculating number of inodes required for ext2 filesystem..."
48                 #numnodes=`find $clst_chroot_path | wc -l`
49                 #numnodes=$(( $numnodes + 200 ))
50                 mke2fs -m 0 -F -q $clst_cdroot_path/livecd.loop || die "Couldn't create ext2 filesystem"
51 #               mke2fs -m 0 -F -b 4096 -q $clst_cdroot_path/livecd.loop || die "Couldn't create ext2 filesystem"
52                 install -d $clst_cdroot_path/loopmount
53                 sync; sync; sleep 3 #try to work around 2.6.0+ loopback bug
54                 mount -t ext2 -o loop $clst_cdroot_path/livecd.loop $clst_cdroot_path/loopmount || die "Couldn't mount loopback ext2 filesystem"
55                 sync; sync; sleep 3 #try to work around 2.6.0+ loopback bug
56                 echo "cp -a $clst_chroot_path/* $clst_cdroot_path/loopmount"
57                 cp -a $clst_chroot_path/* $clst_cdroot_path/loopmount 
58
59                 [ $? -ne 0 ] && { umount $clst_cdroot_path/loopmount; die "Couldn't copy files to loopback ext2 filesystem"; }
60                 umount $clst_cdroot_path/loopmount || die "Couldn't unmount loopback ext2 filesystem"
61                 rm -rf $clst_cdroot_path/loopmount
62                 #now, $clst_cdroot_path should contain a proper bootable image for our iso, including
63                 #boot loader and loopback filesystem.
64 }
65
66 create_zisofs()
67 {
68         rm -rf "${clst_cdroot_path}/zisofs" > /dev/null 2>&1
69         echo "Creating zisofs..."
70         mkzftree -z 9 -p2 "${clst_chroot_path}" "${clst_cdroot_path}/zisofs" || die "Could not run mkzftree, did you emerge zisofs"
71 }
72
73 create_noloop()
74 {
75         echo "Copying files for image (no loop)..."
76         cp -a "${clst_chroot_path}/*" "${clst_cdroot_path}" || die "Could not copy files to image (no loop)"
77 }
78
79 create_gcloop()
80 {
81         create_normal_loop
82         compress_gcloop_ucl -b 131072 -c 10 "${clst_cdroot_path}/livecd.loop" "${clst_cdroot_path}/livecd.gcloop" || die "compress_gcloop_ucl failed, did you emerge gcloop?"
83         rm -f "${clst_cdroot_path}/livecd.loop"
84         # only a gcloop image should exist in cdroot path
85 }
86
87 create_squashfs()
88 {
89         echo "Creating squashfs..."
90         mksquashfs -noappend "${clst_chroot_path}" "${clst_cdroot_path}/livecd.squashfs" || die "mksquashfs failed, did you emerge squashfs?"
91 }
92
93 case $1 in
94         kernel)
95                 shift
96                 numkernels="$1"
97                 shift
98                 $clst_CHROOT $clst_chroot_path /bin/bash << EOF
99                 env-update
100                 source /etc/profile
101                 export CONFIG_PROTECT="-*"
102                 [ -n "${clst_ENVSCRIPT}" ] && source /tmp/envscript
103                 emerge genkernel
104                 install -d /tmp/binaries
105 EOF
106         [ $? -ne 0 ] && exit 1
107                 count=0
108                 while [ $count -lt $numkernels ]
109                 do
110                         clst_kname="$1"
111                         shift
112                         clst_ksource="$1"
113                         shift
114                         clst_kextversion="$1"
115                         shift
116                         $clst_CHROOT $clst_chroot_path /bin/bash << EOF
117                                 die() {
118                                         echo "$1"
119                                         exit 1
120                                 }
121                                 # Script to build each kernel, kernel-related packages 
122                                 source /etc/profile
123                                 [ -n "${clst_ENVSCRIPT}" ] && source /tmp/envscript
124                                 rm -f /usr/src/linux
125                                 [ -e /var/tmp/$clst_kname.use ] && export USE="\$( cat /var/tmp/$clst_kname.use )" || unset USE
126                                 # Don't use pkgcache here, as the kernel source may get emerge with different USE variables
127                                 # (and thus different patches enabled/disabled.) Also, there's no real benefit in using the
128                                 # pkgcache for kernel source ebuilds.
129                                 emerge $clst_ksource || exit 1
130                                 [ ! -e /usr/src/linux ] && die "Can't find required directory /usr/src/linux"
131                                 #if catalyst has set NULL_VALUE, extraversion wasn't specified so we skip this part
132                                 if [ "$clst_kextversion" != "NULL_VALUE" ]
133                                 then
134                                         # Append Extraversion
135                                         sed -i -e "s:EXTRAVERSION \(=.*\):EXTRAVERSION \1-${clst_kextversion}:" /usr/src/linux/Makefile
136                                 fi
137                                 if [ -n "${clst_CCACHE}" ]
138                                 then
139                                         #enable ccache for genkernel
140                                         export PATH="/usr/lib/ccache/bin:\${PATH}"
141                                 fi
142                                 genkernel ${genkernel_args} --kerneldir=/usr/src/linux --kernel-config=/var/tmp/$clst_kname.config --minkernpackage=/tmp/binaries/$clst_kname.tar.bz2 all || exit 1
143                                 #now we merge any kernel-dependent packages
144                                 if [ -e /var/tmp/$clst_kname.packages ]
145                                 then
146                                         for x in \$( cat /var/tmp/$clst_kname.packages )
147                                         do
148                                                 # we don't want to use the pkgcache for these since the results
149                                                 # are kernel-dependent.
150                                                 echo DEBUG emerge "\$x"
151                                                 emerge "\$x"
152                                         done
153                                 fi
154                                 cd /usr/src
155                                 rm -rf linux*
156                                 #now the unmerge... (wipe db entry)
157                                 emerge -C $clst_ksource
158                                 unset USE
159 EOF
160                         [ $? -ne 0 ] && exit 1 
161                         count=$(( $count + 1 ))
162                 done
163                 $clst_CHROOT $clst_chroot_path /bin/bash << EOF
164                         #cleanup steps
165                         source /etc/profile
166                         emerge -C genkernel 
167                         /sbin/depscan.sh
168                         find /lib/modules -name modules.dep -exec touch {} \;
169 EOF
170         [ $? -ne 0 ] && exit 1
171         ;;
172
173         preclean)
174                 $clst_CHROOT $clst_chroot_path /bin/bash << EOF
175                         # SCRIPT TO UPDATE FILESYSTEM SPECIFIC FOR LIVECD. THIS GETS EXECUTED IN CHROOT
176                         env-update
177                         source /etc/profile
178                         rc-update del iptables default
179                         rc-update del netmount default
180 #                       rc-update add hotplug default
181 #                       rc-update add kudzu default
182                         rc-update add autoconfig default
183                         rc-update del keymaps
184                         rc-update del consolefont
185                         rc-update add metalog default
186                         rc-update add modules default
187                         [ -e /etc/init.d/bootsplash ] && rc-update add bootsplash default
188                         rm -rf /etc/localtime
189                         cp /usr/share/zoneinfo/GMT /etc/localtime
190                         echo "livecd" > /etc/hostname
191                         sed -i -e '/\/dev\/[RBS]*/ s/^/#/' /etc/fstab
192                         echo "tmpfs             /       tmpfs   defaults        0 0" >> /etc/fstab
193                         sed -i -e '/dev-state/ s/^/#/' /etc/devfsd.conf
194                         # END OF SCRIPT TO UPDATE FILESYSTEM
195 EOF
196                 [ $? -ne 0 ] && exit 1 
197         ;;
198
199         clean)
200                 find $clst_chroot_path/usr/lib -iname "*.pyc" -exec rm -f {} \;
201         ;;
202
203         bootloader)
204         ;;
205
206         cdfs)
207                 loopret=1
208                 if [ "${clst_livecd_cdfstype}" = "normal" ]
209                 then
210                         create_normal_loop
211                         loopret=$?
212                 elif [ "${clst_livecd_cdfstype}" = "zisofs" ]
213                 then
214                         create_zisofs
215                         loopret=$?
216                 elif [ "${clst_livecd_cdfstype}" = "noloop" ]
217                 then
218                         create_noloop
219                         loopret=$?
220                 elif [ "${clst_livecd_cdfstype}" = "gcloop" ]
221                 then
222                         create_gcloop
223                         loopret=$?
224                 elif [ "${clst_livecd_cdfstype}" = "squashfs" ]
225                 then
226                         create_squashfs
227                         loopret=$?
228                 fi              
229                 exit $loopret
230         ;;
231
232         iso)
233         ;;
234 esac
235 exit 0