Added a new livecd-bash_profile that sources ~/.bashrc in case we're called from...
[catalyst.git] / livecd / runscript / default-runscript.sh
1 # Copyright 1999-2004 Gentoo Foundation
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.25 2005/03/29 18:53:32 wolf31o2 Exp $
4
5 #return codes to be used by archscript
6 die() {
7         echo "$1"
8         exit 1
9 }
10
11 case ${clst_livecd_cdfstype} in
12         zisofs)
13                 cmdline_opts="looptype=zisofs loop=/zisofs"
14                 ;;
15         normal)
16                 cmdline_opts="looptype=normal loop=/livecd.loop"
17                 ;;
18         noloop)
19                 cmdline_opts="looptype=noloop"
20                 ;;
21         squashfs)
22                 cmdline_opts="looptype=squashfs loop=/livecd.squashfs"
23                 ;;
24         gcloop)
25                 cmdline_opts="looptype=gcloop loop=/livecd.gcloop"
26                 ;;
27 esac
28
29 source ${clst_livecd_archscript}
30
31 create_normal_loop() {
32
33                 #We get genkernel-built kernels and initrds in place, create the loopback fs on 
34                 #$clst_cdroot_path, mount it, copy our bootable filesystem over, umount it, and 
35                 #we then have a ready-to-burn ISO tree at $clst_cdroot_path.
36
37                 echo "Calculating size of loopback filesystem..."
38                 loopsize=`du -ks ${clst_chroot_path} | cut -f1`
39                 [ "${loopsize}" = "0" ] && loopsize=1
40                 # Add 4MB for filesystem slop
41                 loopsize=`expr ${loopsize} + 4096`
42                 echo "Creating loopback file..."
43                 dd if=/dev/zero of=${clst_cdroot_path}/livecd.loop bs=1k count=${loopsize} || die "livecd.loop creation failure"
44                 mke2fs -m 0 -F -q ${clst_cdroot_path}/livecd.loop || die "Couldn't create ext2 filesystem"
45                 install -d ${clst_cdroot_path}/loopmount
46                 sync; sync; sleep 3 #try to work around 2.6.0+ loopback bug
47                 mount -t ext2 -o loop ${clst_cdroot_path}/livecd.loop ${clst_cdroot_path}/loopmount || die "Couldn't mount loopback ext2 filesystem"
48                 sync; sync; sleep 3 #try to work around 2.6.0+ loopback bug
49                 echo "cp -a ${clst_chroot_path}/* ${clst_cdroot_path}/loopmount"
50                 cp -a ${clst_chroot_path}/* ${clst_cdroot_path}/loopmount 
51
52                 [ $? -ne 0 ] && { umount ${clst_cdroot_path}/loopmount; die "Couldn't copy files to loopback ext2 filesystem"; }
53                 umount ${clst_cdroot_path}/loopmount || die "Couldn't unmount loopback ext2 filesystem"
54                 rm -rf ${clst_cdroot_path}/loopmount
55                 #now, $clst_cdroot_path should contain a proper bootable image for our iso, including
56                 #boot loader and loopback filesystem.
57 }
58
59 create_zisofs() {
60
61         rm -rf "${clst_cdroot_path}/zisofs" > /dev/null 2>&1
62         echo "Creating zisofs..."
63         mkzftree -z 9 -p2 "${clst_chroot_path}" "${clst_cdroot_path}/zisofs" || die "Could not run mkzftree, did you emerge zisofs"
64
65 }
66
67 create_noloop() {
68
69         echo "Copying files for image (no loop)..."
70         cp -a "${clst_chroot_path}"/* "${clst_cdroot_path}" || die "Could not copy files to image (no loop)"
71         
72 }
73
74 create_gcloop() {
75         create_normal_loop
76         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?"
77         rm -f "${clst_cdroot_path}/livecd.loop"
78         # only a gcloop image should exist in cdroot path
79         
80 }
81
82 create_squashfs() {
83         echo "Creating squashfs..."
84         mksquashfs "${clst_chroot_path}" "${clst_cdroot_path}/livecd.squashfs" -noappend || die "mksquashfs failed, did you emerge squashfs-tools?"
85         
86 }
87
88 ## START RUNSCRIPT
89
90 case $1 in
91         kernel)
92                 shift
93                 numkernels="$1"
94                 shift
95                 
96                 # setup genkernel and do any pre-kernel merge opts
97                 cp -a ${clst_sharedir}/livecd/runscript-support/pre-kmerge.sh ${clst_chroot_path}/tmp
98                 ${clst_CHROOT} ${clst_chroot_path} /tmp/pre-kmerge.sh || exit 1
99                 rm -f ${clst_chroot_path}/tmp/pre-kmerge.sh
100
101                 # the kernel merge process is done in a chroot
102                 cp -a ${clst_sharedir}/livecd/runscript-support/kmerge.sh ${clst_chroot_path}/tmp
103                 count=0
104                 while [ ${count} -lt ${numkernels} ]
105                 do
106                         export clst_kname="$1"
107                         shift
108                         export clst_ksource="$1"
109                         shift
110                         export clst_kextversion="$1"
111                         shift
112                 ${clst_CHROOT} ${clst_chroot_path} /tmp/kmerge.sh || exit 1
113                 count=$(( ${count} + 1 ))
114                 done
115                 rm -f ${clst_chroot_path}/tmp/kmerge.sh
116         
117                 # clean up genkernel and do any post-kernel merge opts
118                 cp -a ${clst_sharedir}/livecd/runscript-support/post-kmerge.sh ${clst_chroot_path}/tmp
119                 ${clst_CHROOT} ${clst_chroot_path} /tmp/post-kmerge.sh || exit 1
120                 rm -f ${clst_chroot_path}/tmp/post-kmerge.sh
121                 ;;
122
123         preclean)
124                 # move over the motd (if applicable)
125                 if [ -n "${clst_livecd_motd}" ]
126                 then
127                         cp -a ${clst_livecd_motd} ${clst_chroot_path}/etc/motd
128                 else
129                         cp -a ${clst_sharedir}/livecd/files/generic.motd.txt \
130                                 ${clst_sharedir}/livecd/files/universal.motd.txt \
131                                 ${clst_sharedir}/livecd/files/minimal.motd.txt \
132                                 ${clst_sharedir}/livecd/files/environmental.motd.txt \
133                                 ${clst_sharedir}/livecd/files/gamecd.motd.txt \
134                                 ${clst_chroot_path}/etc
135                 fi
136         
137                 # move over the xinitrc (if applicable)
138                 if [ -n "${clst_livecd_xinitrc}" ]
139                 then
140                         cp -a ${clst_livecd_xinitrc} ${clst_chroot_path}/etc/X11/xinit/xinitrc
141                 fi
142
143                 # move over the environment
144                 cp ${clst_sharedir}/livecd/files/livecd-bashrc \
145                         ${clst_chroot_path}/root/.bashrc
146                 cp ${clst_sharedir}/livecd/files/livecd-bash_profile \
147                         ${clst_chroot_path}/root/.bash_profile
148                 cp ${clst_sharedir}/livecd/files/livecd-local.start \
149                         ${clst_chroot_path}/etc/conf.d/local.start
150                 mkdir -p /usr/share/faces
151                 cp ${clst_sharedir}/livecd/files/gentoo.png \
152                         ${clst_chroot_path}/usr/share/faces
153
154                 # touch /etc/startx if our livecd/type requires it
155                 if [ "${clst_livecd_type}" = "gentoo-gamecd" ] #\
156                 #|| [ "${clst_livecd_type}" = "gentoo-release-environmental" ]
157                 then
158                         touch ${clst_chroot_path}/etc/startx
159                 fi
160                 
161                 # now, finalize and tweak the livecd fs (inside of the chroot)
162                 cp ${clst_sharedir}/livecd/runscript-support/livecdfs-update.sh ${clst_chroot_path}/tmp
163                 ${clst_CHROOT} ${clst_chroot_path} /tmp/livecdfs-update.sh || exit 1
164                 rm -f ${clst_chroot_path}/tmp/livecdfs-update.sh
165
166                 # execute gamecdfs-update.sh if we're a gamecd
167                 if [ "${clst_livecd_type}" = "gentoo-gamecd" ]
168                 then
169                         cp ${clst_sharedir}/livecd/runscript-support/gamecdfs-update.sh ${clst_chroot_path}/tmp
170                         ${clst_CHROOT} ${clst_chroot_path} /tmp/gamecdfs-update.sh || exit 1
171                         rm -f ${clst_chroot_path}/tmp/gamecdfs-update.sh
172                 fi
173                 
174                 # if the user has their own fs update script, execute it
175                 if [ -n "${clst_livecd_fsscript}" ]
176                 then
177                         cp ${clst_livecd_fsscript} ${clst_chroot_path}/tmp/fsscript.sh
178                         chmod 755 ${clst_chroot_path}/tmp/fsscript.sh
179                         ${clst_CHROOT} ${clst_chroot_path} /tmp/fsscript.sh || exit 1
180                         rm -f ${clst_chroot_path}/tmp/fsscript.sh
181                 fi
182                 ;;
183
184         clean)
185                 find ${clst_chroot_path}/usr/lib -iname "*.pyc" -exec rm -f {} \;
186                 ;;
187
188         bootloader)
189                 ;;
190
191         cdfs)
192                 loopret=1
193                 if [ "${clst_livecd_cdfstype}" = "normal" ]
194                 then
195                         create_normal_loop
196                         loopret=$?
197                 elif [ "${clst_livecd_cdfstype}" = "zisofs" ]
198                 then
199                         create_zisofs
200                         loopret=$?
201                 elif [ "${clst_livecd_cdfstype}" = "noloop" ]
202                 then
203                         create_noloop
204                         loopret=$?
205                 elif [ "${clst_livecd_cdfstype}" = "gcloop" ]
206                 then
207                         create_gcloop
208                         loopret=$?
209                 elif [ "${clst_livecd_cdfstype}" = "squashfs" ]
210                 then
211                         create_squashfs
212                         loopret=$?
213                 fi              
214                 exit $loopret
215                 ;;
216
217         iso)
218                 ;;
219 esac
220 exit 0