Magellan Linux

Diff of /trunk/mlivecdbuild/mlivecdbuild2.sh

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 346 by niro, Sat Mar 4 23:20:39 2006 UTC revision 471 by niro, Thu Apr 19 17:03:14 2007 UTC
# Line 1  Line 1 
1  #!/bin/bash  #!/bin/bash
2    
3  # some default settings - gets overidden with the profile config  # some default settings - gets overidden with the profile config
4  CDPROFILE="$1"  CDPROFILE="$2"
5  [[ -z ${CDPROFILE} ]] && CDPROFILE="default"  [[ -z ${CDPROFILE} ]] && CDPROFILE="default"
6  LIVECDROOT="/mnt/MLIVECDBUILD/${CDPROFILE}"  LIVECDROOT="/mnt/MLIVECDBUILD/${CDPROFILE}"
7  CDCHROOTDIR="${LIVECDROOT}/chroot"  CDCHROOTDIR="${LIVECDROOT}/chroot"
# Line 46  bootstrap_system() Line 46  bootstrap_system()
46   || die "bootstrapping toolchain"   || die "bootstrapping toolchain"
47  }  }
48    
49    custom_services()
50    {
51     local cmd="$1"
52     local services="$2"
53    
54     case ${cmd} in
55     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     *) 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     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     *) 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  prepare_iso()  prepare_iso()
126  {  {
127   echo Preparing LiveCD ISO Image ...   echo Preparing LiveCD ISO Image ...
# Line 66  prepare_iso() Line 142  prepare_iso()
142    
143   echo Setting up services ...   echo Setting up services ...
144    
  # change mountfs with mountfslivecd  
  MROOT="${CDCHROOTDIR}" rc-config del mountfs || die "rc del mountfs"  
  MROOT="${CDCHROOTDIR}" rc-config add mountfslivecd || die "rc add mountfslivecd"  
   
145   # add hardware detection   # add hardware detection
146   MROOT="${CDCHROOTDIR}" rc-config add hwdetect || die "rc add hwdetect"   MROOT="${CDCHROOTDIR}" rc-config add hwdetect || die "rc add hwdetect"
147    
148   # del checkfs   # del checkfs
149   MROOT="${CDCHROOTDIR}" rc-config del checkfs || die "rc del checkfs"   MROOT="${CDCHROOTDIR}" rc-config del checkfs || die "rc del checkfs"
150    
151     # 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   echo Cleaning unwanted files ...   echo Cleaning unwanted files ...
177   :> ${CDCHROOTDIR}/etc/mtab || die "whiping /etc/mtab"   :> ${CDCHROOTDIR}/etc/mtab || die "whiping /etc/mtab"
178     [ -f ${CDCHROOTDIR}/root/.bash_history ] && rm ${CDCHROOTDIR}/root/.bash_history
179  }  }
180    
181  generate_rootfs()  generate_rootfs()
# Line 96  install_bootloader() Line 194  install_bootloader()
194    
195   # iso linux binary   # iso linux binary
196   install -d ${CDISOROOT}/isolinux   install -d ${CDISOROOT}/isolinux
197   install /usr/lib/mlivecdbuild/isolinux.bin ${CDISOROOT}/isolinux || die   install /usr/lib/mkinitrd/isolinux.bin ${CDISOROOT}/isolinux || die
198    
199   # kernel   # kernel
200   local kimg="$(basename $(readlink ${CDCHROOTDIR}/boot/vmlinuz))"   local kimg="$(basename $(readlink ${CDCHROOTDIR}/boot/vmlinuz))"
# Line 113  install_bootloader() Line 211  install_bootloader()
211  generate_initrd()  generate_initrd()
212  {  {
213   local CHROOTSH="$(mktemp -p ${CDCHROOTDIR})"   local CHROOTSH="$(mktemp -p ${CDCHROOTDIR})"
  echo "DEBUG: ${CHROOTSH}"  
214    
215   echo Generating initrd image ...   echo Generating initrd image ...
216   echo '#!/bin/bash' > ${CHROOTSH} || die   echo '#!/bin/bash' > ${CHROOTSH} || die
# Line 149  generate_iso() Line 246  generate_iso()
246   popd   popd
247  }  }
248    
249    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  enter_livecd()  enter_livecd()
271  {  {
272   mount -t sysfs sysfs ${CDCHROOTDIR}/proc   mount -t sysfs sysfs ${CDCHROOTDIR}/proc
# Line 163  enter_livecd() Line 281  enter_livecd()
281   /bin/bash -i   /bin/bash -i
282  }  }
283    
284    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     echo "    dvdgen     - same as isogen but creates a dvd-image"
296     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  # source profile config - overrides all other vars  # source profile config - overrides all other vars
304  [ -f ${PROFILES_DIR}/${CDPROFILE}/config ] && . ${PROFILES_DIR}/${CDPROFILE}/config  [ -f ${PROFILES_DIR}/${CDPROFILE}/config ] && . ${PROFILES_DIR}/${CDPROFILE}/config
305    
306  bootstrap_system  case $1 in
307  prepare_iso   bootstrap) bootstrap_system;;
308  generate_rootfs   prepare) prepare_iso;;
309  generate_initrd   rootfs) generate_rootfs;;
310  install_bootloader   initrd) generate_initrd;;
311  generate_iso   bootloader) install_bootloader;;
312     isogen) generate_iso;;
313     dvdgen) generate_dvd;;
314     all)
315     bootstrap_system
316     prepare_iso
317     generate_rootfs
318     generate_initrd
319     install_bootloader
320     if [[ ${DEFINE_DVD} = 1 ]]
321     then
322     generate_dvd
323     else
324     generate_iso
325     fi
326     ;;
327     *|'') usage;;
328    esac

Legend:
Removed from v.346  
changed lines
  Added in v.471