Magellan Linux

Annotation of /trunk/mlivecdbuild/mlivecdbuild2.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 471 - (hide annotations) (download) (as text)
Thu Apr 19 17:03:14 2007 UTC (17 years ago) by niro
File MIME type: application/x-sh
File size: 8830 byte(s)
-fixed complains about 'continue'

1 niro 346 #!/bin/bash
2    
3     # some default settings - gets overidden with the profile config
4 niro 360 CDPROFILE="$2"
5 niro 346 [[ -z ${CDPROFILE} ]] && CDPROFILE="default"
6     LIVECDROOT="/mnt/MLIVECDBUILD/${CDPROFILE}"
7     CDCHROOTDIR="${LIVECDROOT}/chroot"
8     CDISONAME="livecd-${CDPROFILE}.iso"
9     CDISOROOT="${LIVECDROOT}/isoroot"
10     CDKERNELNAME="magelive"
11     CDHOSTNAME="livecd-${CDPROFILE}"
12     MAGERC="/etc/mage.rc"
13     MAGE_PROFILE="$(basename $(readlink /etc/mage-profile))"
14     #TOOLCHAIN=toolchain
15     BASESYSTEM=livecdsystem26
16     CDID="mlcd-$(date +%F-%k%M)"
17    
18     # global profile pathes
19     PROFILES_DIR="/usr/lib/mlivecdbuild/profiles"
20     GLOBAL_PROFILE="${PROFILES_DIR}/global"
21    
22     die() { echo "ERROR: $@"; exit 1; }
23    
24     # get_profile $filename
25     get_profile()
26     {
27     local file="$1"
28    
29     if [[ -z ${file} ]] || [[ ! -e ${PROFILES_DIR}/${CDPROFILE}/${file} ]]
30     then
31     echo "${GLOBAL_PROFILE}/${file}"
32     return 0
33     fi
34    
35     echo "${PROFILES_DIR}/${CDPROFILE}/${file}"
36     }
37    
38     bootstrap_system()
39     {
40     mage-bootstrap \
41     --root "${CDCHROOTDIR}" \
42     --magerc "${MAGERC}" \
43     --profile "${MAGE_PROFILE}" \
44     --toolchain "${TOOLCHAIN}" \
45     --basesystem "${BASESYSTEM}" \
46     || die "bootstrapping toolchain"
47     }
48    
49 niro 360 custom_services()
50     {
51     local cmd="$1"
52     local services="$2"
53    
54     case ${cmd} in
55 niro 471 add|del|default)
56     # add given services from profile
57     if [[ -n ${services} ]]
58     then
59     local i
60     for i in ${services}
61     do
62     MROOT="${CDCHROOTDIR}" rc-config ${cmd} ${i} || die "rc ${cmd} ${i}"
63     done
64     fi
65     ;;
66 niro 360 *) die "custom_services: unkown command ${cmd}";;
67     esac
68     }
69    
70     add_initrc()
71     {
72     local var="$1"
73    
74     # sanity checks
75     [ -z "${CDCHROOTDIR}" ] && die "\$CDCHROOTDIR not given."
76     echo "${var}" >> ${CDCHROOTDIR}/.installrc || die "add_initrc() adding \$var"
77     }
78    
79     custom_packages()
80     {
81     local cmd="$1"
82     local packages="$2"
83    
84     case ${cmd} in
85 niro 471 install|uninstall)
86     if [[ -n ${packages} ]]
87     then
88     :> ${CDCHROOTDIR}/.installrc
89     local i
90     for i in ${packages}
91     do
92     add_initrc "mage install ${i}"
93     done
94     add_initrc "mage clean"
95    
96     # now run the .installrc script
97     mount -t proc proc ${CDCHROOTDIR}/proc || die "mount proc"
98     mount -t sysfs sysfs ${CDCHROOTDIR}/sys || die "mount sys"
99     mount -o bind /dev ${CDCHROOTDIR}/dev || die "mount dev"
100     chroot ${CDCHROOTDIR} /bin/bash -i /.installrc || die "chr00ting"
101     umount ${CDCHROOTDIR}/dev || die "umount dev"
102     umount ${CDCHROOTDIR}/proc || die "umount proc"
103     umount ${CDCHROOTDIR}/sys || die "umount sys"
104     [ -f ${CDCHROOTDIR}/.installrc ] && rm ${CDCHROOTDIR}/.installrc
105     fi
106     ;;
107 niro 360 *) die "custom_packages: unkown command ${cmd}";;
108     esac
109     }
110    
111     read_config()
112     {
113     local file="$1"
114     local pkg
115    
116     ( cat ${file}; echo ) | while read pkg
117     do
118     case "${pkg}" in
119     \#*|"") continue ;;
120     esac
121     echo "${pkg}"
122     done
123     }
124    
125 niro 346 prepare_iso()
126     {
127     echo Preparing LiveCD ISO Image ...
128    
129     # fixes some issues with xfree/xorg xkb
130     if [ -L "${CDCHROOTDIR}/etc/X11/xkb" -a -d "/usr/X11R6/lib/X11/xkb" ]
131     then
132     rm ${CDCHROOTDIR}/etc/X11/xkb || die
133     mv ${CDCHROOTDIR}/usr/X11R6/lib/X11/xkb ${CDCHROOTDIR}/etc/X11 || die
134     ln -s ../../../../etc/X11/xkb ${CDCHROOTDIR}/usr/X11R6/lib/X11/xkb || die
135     fi
136    
137     install -m 0644 $(get_profile inittab) ${CDCHROOTDIR}/etc/inittab || die
138     install -m 0644 $(get_profile fstab) ${CDCHROOTDIR}/etc/fstab || die
139     install -m 0644 $(get_profile motd) ${CDCHROOTDIR}/etc/motd || die
140     install -m 0644 $(get_profile issue) ${CDCHROOTDIR}/etc/issue || die
141     echo "${CDHOSTNAME}" > ${CDCHROOTDIR}/etc/hostname || die
142    
143     echo Setting up services ...
144    
145     # add hardware detection
146     MROOT="${CDCHROOTDIR}" rc-config add hwdetect || die "rc add hwdetect"
147    
148     # del checkfs
149     MROOT="${CDCHROOTDIR}" rc-config del checkfs || die "rc del checkfs"
150    
151 niro 360 # add custom packages
152     [[ -n ${ADD_PACKAGES} ]] && custom_packages install "${ADD_PACKAGES}"
153     [ -f $(get_profile add_packages) ] && custom_packages install "$(read_config $(get_profile add_packages))"
154    
155     # del custom packages
156     [[ -n ${DEL_PACKAGES} ]] && custom_packages uninstall "${DEL_PACKAGES}"
157     [ -f $(get_profile del_packages) ] && custom_packages uninstall "$(read_config $(get_profile del_packages))"
158    
159     # add given services from profile
160     [[ -n ${ADD_SERVICES} ]] && custom_services add "${ADD_SERVICES}"
161     [ -f $(get_profile add_services) ] && custom_services add "$(read_config $(get_profile add_services))"
162    
163     # del given services from profile
164     [[ -n ${DEL_SERVICES} ]] && custom_services del "${DEL_SERVICES}"
165     [ -f $(get_profile del_services) ] && custom_services del "$(read_config $(get_profile del_services))"
166    
167     # setup default runlevel
168     [[ -n ${DEFAULT_RUNLEVEL} ]] && custom_services default "${DEFAULT_RUNLEVEL}"
169    
170     if [ -f $(get_profile prepare_custom) ]
171     then
172     echo Running custom user script ...
173     source $(get_profile prepare_custom) || die "running custom user script"
174     fi
175    
176 niro 346 echo Cleaning unwanted files ...
177     :> ${CDCHROOTDIR}/etc/mtab || die "whiping /etc/mtab"
178 niro 360 [ -f ${CDCHROOTDIR}/root/.bash_history ] && rm ${CDCHROOTDIR}/root/.bash_history
179 niro 346 }
180    
181     generate_rootfs()
182     {
183     echo Generating squashfs compressed rootfs loopfile ...
184     mksquashfs ${CDCHROOTDIR} ${LIVECDROOT}/livecdrootfs.sqsh #>/dev/null 2>&1
185    
186     echo Moving rootfs loopfile to isoroot ...
187     install -d ${CDISOROOT}
188     mv ${LIVECDROOT}/livecdrootfs.sqsh ${CDISOROOT}
189     }
190    
191     install_bootloader()
192     {
193     echo Installing Bootloader ...
194    
195     # iso linux binary
196     install -d ${CDISOROOT}/isolinux
197 niro 348 install /usr/lib/mkinitrd/isolinux.bin ${CDISOROOT}/isolinux || die
198 niro 346
199     # kernel
200     local kimg="$(basename $(readlink ${CDCHROOTDIR}/boot/vmlinuz))"
201     install ${CDCHROOTDIR}/boot/${kimg} ${CDISOROOT}/isolinux/${CDKERNELNAME} || die
202    
203     install -m 0644 $(get_profile isolinux.cfg) ${CDISOROOT}/isolinux || die
204     install -m 0644 $(get_profile boot.lss) ${CDISOROOT}/isolinux || die
205     install -m 0644 $(get_profile boot.msg) ${CDISOROOT}/isolinux || die
206     install -m 0644 $(get_profile help.msg) ${CDISOROOT}/isolinux || die
207    
208     return 0
209     }
210    
211     generate_initrd()
212     {
213     local CHROOTSH="$(mktemp -p ${CDCHROOTDIR})"
214    
215     echo Generating initrd image ...
216     echo '#!/bin/bash' > ${CHROOTSH} || die
217     echo 'kv="$(readlink /boot/vmlinuz)"' >> ${CHROOTSH} || die
218     echo 'kv="${kv/kernel-}/"' >> ${CHROOTSH} || die
219     echo 'mkinitrd-livecd -f --initramfs /initrd.gz ${kv}' >> ${CHROOTSH} || die
220     chmod +x ${CHROOTSH} || die
221     chroot ${CDCHROOTDIR} /$(basename ${CHROOTSH}) || die
222     [[ -f ${CHROOTSH} ]] && rm ${CHROOTSH} || die
223    
224     # move initrd to isoroot
225     install -d ${CDISOROOT}/isolinux || die
226     mv ${CDCHROOTDIR}/initrd.gz ${CDISOROOT}/isolinux || die
227     }
228    
229     generate_iso()
230     {
231     echo Generating ISO Image ...
232     install -d ${CDISOROOT}
233     pushd ${CDISOROOT} &&
234     mkisofs -rock \
235     -full-iso9660-filenames \
236     -allow-leading-dots \
237     -disable-deep-relocation \
238     -output ${LIVECDROOT}/${CDISONAME} \
239     -eltorito-boot isolinux/isolinux.bin \
240     -eltorito-catalog isolinux/boot.cat \
241     -no-emul-boot \
242     -boot-load-size 4 \
243     -boot-info-table \
244     -volid "${CDID}" \
245     ${CDISOROOT} #&> /dev/null
246     popd
247     }
248    
249 niro 464 generate_dvd()
250     {
251     echo Generating DVD Image ...
252     install -d ${CDISOROOT}
253     pushd ${CDISOROOT} &&
254     growisofs -dvd-compat \
255     -rock \
256     -full-iso9660-filenames \
257     -allow-leading-dots \
258     -disable-deep-relocation \
259     -output ${LIVECDROOT}/${CDISONAME} \
260     -eltorito-boot isolinux/isolinux.bin \
261     -eltorito-catalog isolinux/boot.cat \
262     -no-emul-boot \
263     -boot-load-size 4 \
264     -boot-info-table \
265     -volid "${CDID}" \
266     ${CDISOROOT} #&> /dev/null
267     popd
268     }
269    
270 niro 346 enter_livecd()
271     {
272     mount -t sysfs sysfs ${CDCHROOTDIR}/proc
273     mount -t proc proc ${CDCHROOTDIR}/proc
274     mount -o bind /dev ${CDCHROOTDIR}/dev
275    
276     chroot ${CDCHROOTDIR} \
277     /usr/bin/env -i \
278     HOME=/root \
279     TERM=$TERM PS1='\u:\w\$ ' \
280     PATH=/bin:/usr/bin:/sbin:/usr/sbin \
281     /bin/bash -i
282     }
283    
284 niro 360 usage()
285     {
286     echo "Usage: $(basename $0) [command] [profile] ..."
287     echo
288     echo "Commands:"
289     echo " bootstrap - bootstraps the rootfs for the livecd"
290     echo " prepare - prepare the rootfs to run from a livecd"
291     echo " rootfs - generates the squashfs rootfs image"
292     echo " initrd - generates a livecd suitable initrd"
293     echo " bootloader - installs the bootloader"
294     echo " isogen - generate the final livecd iso image"
295 niro 464 echo " dvdgen - same as isogen but creates a dvd-image"
296 niro 360 echo " all - runs all tasks to get a livecd from zero"
297     echo
298     echo " for example '$(basename $0) all default'"
299     echo " creates a livecd using the default profile."
300     echo
301     }
302    
303 niro 346 # source profile config - overrides all other vars
304     [ -f ${PROFILES_DIR}/${CDPROFILE}/config ] && . ${PROFILES_DIR}/${CDPROFILE}/config
305    
306 niro 360 case $1 in
307     bootstrap) bootstrap_system;;
308     prepare) prepare_iso;;
309     rootfs) generate_rootfs;;
310     initrd) generate_initrd;;
311     bootloader) install_bootloader;;
312     isogen) generate_iso;;
313 niro 464 dvdgen) generate_dvd;;
314 niro 360 all)
315     bootstrap_system
316     prepare_iso
317     generate_rootfs
318     generate_initrd
319     install_bootloader
320 niro 464 if [[ ${DEFINE_DVD} = 1 ]]
321     then
322     generate_dvd
323     else
324     generate_iso
325     fi
326 niro 360 ;;
327     *|'') usage;;
328     esac