moving files around to reduce confusion
[catalyst.git] / 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/livecd/runscript/Attic/default-runscript.sh,v 1.1 2004/03/04 23:29:45 zhen 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                                 
126                                 #set the timezone for the kernel build
127                                 rm /etc/localtime
128                                 ln -s /usr/share/zoneinfo/UTC /etc/localtime
129
130                                 [ -e /var/tmp/$clst_kname.use ] && export USE="\$( cat /var/tmp/$clst_kname.use )" || unset USE
131                                 # Don't use pkgcache here, as the kernel source may get emerge with different USE variables
132                                 # (and thus different patches enabled/disabled.) Also, there's no real benefit in using the
133                                 # pkgcache for kernel source ebuilds.
134                                 emerge $clst_ksource || exit 1
135                                 [ ! -e /usr/src/linux ] && die "Can't find required directory /usr/src/linux"
136                                 #if catalyst has set NULL_VALUE, extraversion wasn't specified so we skip this part
137                                 if [ "$clst_kextversion" != "NULL_VALUE" ]
138                                 then
139                                         # Append Extraversion
140                                         sed -i -e "s:EXTRAVERSION \(=.*\):EXTRAVERSION \1-${clst_kextversion}:" /usr/src/linux/Makefile
141                                 fi
142                                 if [ -n "${clst_CCACHE}" ]
143                                 then
144                                         #enable ccache for genkernel
145                                         export PATH="/usr/lib/ccache/bin:\${PATH}"
146                                 fi
147                                 genkernel ${genkernel_args} --kerneldir=/usr/src/linux --kernel-config=/var/tmp/$clst_kname.config --minkernpackage=/tmp/binaries/$clst_kname.tar.bz2 all || exit 1
148                                 #now we merge any kernel-dependent packages
149                                 if [ -e /var/tmp/$clst_kname.packages ]
150                                 then
151                                         for x in \$( cat /var/tmp/$clst_kname.packages )
152                                         do
153                                                 # we don't want to use the pkgcache for these since the results
154                                                 # are kernel-dependent.
155                                                 echo DEBUG emerge "\$x"
156                                                 emerge "\$x"
157                                         done
158                                 fi
159                                 cd /usr/src
160                                 rm -rf linux*
161                                 #now the unmerge... (wipe db entry)
162                                 emerge -C $clst_ksource
163                                 unset USE
164 EOF
165                         [ $? -ne 0 ] && exit 1 
166                         count=$(( $count + 1 ))
167                 done
168                 $clst_CHROOT $clst_chroot_path /bin/bash << EOF
169                         #cleanup steps
170                         source /etc/profile
171                         emerge -C genkernel 
172                         /sbin/depscan.sh
173                         find /lib/modules -name modules.dep -exec touch {} \;
174 EOF
175         [ $? -ne 0 ] && exit 1
176         ;;
177
178         preclean)
179                 cat > $clst_chroot_path/etc/init.d/local << EOF
180 #!/sbin/runscript
181 # Copyright 1999-2003 Gentoo Technologies, Inc.
182 # Distributed under the terms of the GNU General Public License v2
183 # $Header: /var/cvsroot/gentoo/src/catalyst/livecd/runscript/Attic/default-runscript.sh,v 1.1 2004/03/04 23:29:45 zhen Exp $
184
185 depend() {
186         after *
187 }
188
189 start() {
190         ebegin "Auto-scrambling root password for security"
191         echo root:`pwgen -s 16` | chpasswd  > /dev/null 2>&1
192         eend $? "Failed to start local."
193 }
194
195 stop() {
196         ebegin "Stopping local"
197         eend $? "Failed to stop local."
198 }
199 EOF
200                 
201                 $clst_CHROOT $clst_chroot_path /bin/bash << EOF
202                         # SCRIPT TO UPDATE FILESYSTEM SPECIFIC FOR LIVECD. THIS GETS EXECUTED IN CHROOT
203                         env-update
204                         source /etc/profile
205                         if [ -e /etc/sshd/sshd_config ]
206                                 then
207                                         #allow root logins to the livecd by default
208                                         sed -e "s/^#PermitRootLogin\ yes/PermitRootLogin\ yes/" /etc/ssh/sshd_config > /etc/ssh/sshd_config1
209                                         mv /etc/ssh/sshd_config1 /etc/ssh/sshd_config
210                         fi
211                                 
212                         rc-update del iptables default
213                         rc-update del netmount default
214 #                       rc-update add hotplug default
215 #                       rc-update add kudzu default
216                         rc-update add autoconfig default
217                         rc-update del keymaps
218                         rc-update del consolefont
219                         rc-update add metalog default
220                         rc-update add modules default
221                         [ -e /etc/init.d/bootsplash ] && rc-update add bootsplash default
222                         rm -rf /etc/localtime
223                         cp /usr/share/zoneinfo/GMT /etc/localtime
224                         echo "livecd" > /etc/hostname
225                         sed -i -e '/\/dev\/[RBS]*/ s/^/#/' /etc/fstab
226                         echo "tmpfs             /       tmpfs   defaults        0 0" >> /etc/fstab
227                         sed -i -e '/dev-state/ s/^/#/' /etc/devfsd.conf
228                         # END OF SCRIPT TO UPDATE FILESYSTEM
229 EOF
230                 [ $? -ne 0 ] && exit 1 
231         ;;
232
233         clean)
234                 find $clst_chroot_path/usr/lib -iname "*.pyc" -exec rm -f {} \;
235         ;;
236
237         bootloader)
238         ;;
239
240         cdfs)
241                 loopret=1
242                 if [ "${clst_livecd_cdfstype}" = "normal" ]
243                 then
244                         create_normal_loop
245                         loopret=$?
246                 elif [ "${clst_livecd_cdfstype}" = "zisofs" ]
247                 then
248                         create_zisofs
249                         loopret=$?
250                 elif [ "${clst_livecd_cdfstype}" = "noloop" ]
251                 then
252                         create_noloop
253                         loopret=$?
254                 elif [ "${clst_livecd_cdfstype}" = "gcloop" ]
255                 then
256                         create_gcloop
257                         loopret=$?
258                 elif [ "${clst_livecd_cdfstype}" = "squashfs" ]
259                 then
260                         create_squashfs
261                         loopret=$?
262                 fi              
263                 exit $loopret
264         ;;
265
266         iso)
267         ;;
268 esac
269 exit 0