Magellan Linux

Diff of /trunk/mlivecdbuild/mlivecdbuild2.sh

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

revision 348 by niro, Sun Mar 5 02:18:28 2006 UTC revision 464 by niro, Sat Apr 14 15:23:27 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) continue;;
56     *) die "custom_services: unkown command ${cmd}";;
57     esac
58    
59     # add given services from profile
60     if [[ -n ${services} ]]
61     then
62     local i
63     for i in ${services}
64     do
65     MROOT="${CDCHROOTDIR}" rc-config ${cmd} ${i} || die "rc ${cmd} ${i}"
66     done
67     fi
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) continue;;
86     *) die "custom_packages: unkown command ${cmd}";;
87     esac
88    
89     if [[ -n ${packages} ]]
90     then
91    
92     :> ${CDCHROOTDIR}/.installrc
93     local i
94     for i in ${packages}
95     do
96     add_initrc "mage install ${i}"
97     done
98     add_initrc "mage clean"
99    
100     # now run the .installrc script
101     mount -t proc proc ${CDCHROOTDIR}/proc || die "mount proc"
102     mount -t sysfs sysfs ${CDCHROOTDIR}/sys || die "mount sys"
103     mount -o bind /dev ${CDCHROOTDIR}/dev || die "mount dev"
104     chroot ${CDCHROOTDIR} /bin/bash -i /.installrc || die "chr00ting"
105     umount ${CDCHROOTDIR}/dev || die "umount dev"
106     umount ${CDCHROOTDIR}/proc || die "umount proc"
107     umount ${CDCHROOTDIR}/sys || die "umount sys"
108     [ -f ${CDCHROOTDIR}/.installrc ] && rm ${CDCHROOTDIR}/.installrc
109     fi
110    }
111    
112    read_config()
113    {
114     local file="$1"
115     local pkg
116    
117     ( cat ${file}; echo ) | while read pkg
118     do
119     case "${pkg}" in
120     \#*|"") continue ;;
121     esac
122     echo "${pkg}"
123     done
124    }
125    
126  prepare_iso()  prepare_iso()
127  {  {
128   echo Preparing LiveCD ISO Image ...   echo Preparing LiveCD ISO Image ...
# Line 66  prepare_iso() Line 143  prepare_iso()
143    
144   echo Setting up services ...   echo Setting up services ...
145    
  # change mountfs with mountfslivecd  
  MROOT="${CDCHROOTDIR}" rc-config del mountfs || die "rc del mountfs"  
  MROOT="${CDCHROOTDIR}" rc-config add mountfslivecd || die "rc add mountfslivecd"  
   
146   # add hardware detection   # add hardware detection
147   MROOT="${CDCHROOTDIR}" rc-config add hwdetect || die "rc add hwdetect"   MROOT="${CDCHROOTDIR}" rc-config add hwdetect || die "rc add hwdetect"
148    
149   # del checkfs   # del checkfs
150   MROOT="${CDCHROOTDIR}" rc-config del checkfs || die "rc del checkfs"   MROOT="${CDCHROOTDIR}" rc-config del checkfs || die "rc del checkfs"
151    
152     # add custom packages
153     [[ -n ${ADD_PACKAGES} ]] && custom_packages install "${ADD_PACKAGES}"
154     [ -f $(get_profile add_packages) ] && custom_packages install "$(read_config $(get_profile add_packages))"
155    
156     # del custom packages
157     [[ -n ${DEL_PACKAGES} ]] && custom_packages uninstall "${DEL_PACKAGES}"
158     [ -f $(get_profile del_packages) ] && custom_packages uninstall "$(read_config $(get_profile del_packages))"
159    
160     # add given services from profile
161     [[ -n ${ADD_SERVICES} ]] && custom_services add "${ADD_SERVICES}"
162     [ -f $(get_profile add_services) ] && custom_services add "$(read_config $(get_profile add_services))"
163    
164     # del given services from profile
165     [[ -n ${DEL_SERVICES} ]] && custom_services del "${DEL_SERVICES}"
166     [ -f $(get_profile del_services) ] && custom_services del "$(read_config $(get_profile del_services))"
167    
168     # setup default runlevel
169     [[ -n ${DEFAULT_RUNLEVEL} ]] && custom_services default "${DEFAULT_RUNLEVEL}"
170    
171     if [ -f $(get_profile prepare_custom) ]
172     then
173     echo Running custom user script ...
174     source $(get_profile prepare_custom) || die "running custom user script"
175     fi
176    
177   echo Cleaning unwanted files ...   echo Cleaning unwanted files ...
178   :> ${CDCHROOTDIR}/etc/mtab || die "whiping /etc/mtab"   :> ${CDCHROOTDIR}/etc/mtab || die "whiping /etc/mtab"
179     [ -f ${CDCHROOTDIR}/root/.bash_history ] && rm ${CDCHROOTDIR}/root/.bash_history
180  }  }
181    
182  generate_rootfs()  generate_rootfs()
# Line 113  install_bootloader() Line 212  install_bootloader()
212  generate_initrd()  generate_initrd()
213  {  {
214   local CHROOTSH="$(mktemp -p ${CDCHROOTDIR})"   local CHROOTSH="$(mktemp -p ${CDCHROOTDIR})"
  echo "DEBUG: ${CHROOTSH}"  
215    
216   echo Generating initrd image ...   echo Generating initrd image ...
217   echo '#!/bin/bash' > ${CHROOTSH} || die   echo '#!/bin/bash' > ${CHROOTSH} || die
# Line 149  generate_iso() Line 247  generate_iso()
247   popd   popd
248  }  }
249    
250    generate_dvd()
251    {
252     echo Generating DVD Image ...
253     install -d ${CDISOROOT}
254     pushd ${CDISOROOT} &&
255     growisofs -dvd-compat \
256     -rock \
257     -full-iso9660-filenames \
258     -allow-leading-dots \
259     -disable-deep-relocation \
260     -output ${LIVECDROOT}/${CDISONAME} \
261     -eltorito-boot isolinux/isolinux.bin \
262     -eltorito-catalog isolinux/boot.cat \
263     -no-emul-boot \
264     -boot-load-size 4 \
265     -boot-info-table \
266     -volid "${CDID}" \
267     ${CDISOROOT} #&> /dev/null
268     popd
269    }
270    
271  enter_livecd()  enter_livecd()
272  {  {
273   mount -t sysfs sysfs ${CDCHROOTDIR}/proc   mount -t sysfs sysfs ${CDCHROOTDIR}/proc
# Line 163  enter_livecd() Line 282  enter_livecd()
282   /bin/bash -i   /bin/bash -i
283  }  }
284    
285    usage()
286    {
287     echo "Usage: $(basename $0) [command] [profile] ..."
288     echo
289     echo "Commands:"
290     echo "    bootstrap  - bootstraps the rootfs for the livecd"
291     echo "    prepare    - prepare the rootfs to run from a livecd"
292     echo "    rootfs     - generates the squashfs rootfs image"
293     echo "    initrd     - generates a livecd suitable initrd"
294     echo "    bootloader - installs the bootloader"
295     echo "    isogen     - generate the final livecd iso image"
296     echo "    dvdgen     - same as isogen but creates a dvd-image"
297     echo "    all        - runs all tasks to get a livecd from zero"
298     echo
299     echo "    for example '$(basename $0) all default'"
300     echo "    creates a livecd using the default profile."
301     echo
302    }
303    
304  # source profile config - overrides all other vars  # source profile config - overrides all other vars
305  [ -f ${PROFILES_DIR}/${CDPROFILE}/config ] && . ${PROFILES_DIR}/${CDPROFILE}/config  [ -f ${PROFILES_DIR}/${CDPROFILE}/config ] && . ${PROFILES_DIR}/${CDPROFILE}/config
306    
307  bootstrap_system  case $1 in
308  prepare_iso   bootstrap) bootstrap_system;;
309  generate_rootfs   prepare) prepare_iso;;
310  generate_initrd   rootfs) generate_rootfs;;
311  install_bootloader   initrd) generate_initrd;;
312  generate_iso   bootloader) install_bootloader;;
313     isogen) generate_iso;;
314     dvdgen) generate_dvd;;
315     all)
316     bootstrap_system
317     prepare_iso
318     generate_rootfs
319     generate_initrd
320     install_bootloader
321     if [[ ${DEFINE_DVD} = 1 ]]
322     then
323     generate_dvd
324     else
325     generate_iso
326     fi
327     ;;
328     *|'') usage;;
329    esac

Legend:
Removed from v.348  
changed lines
  Added in v.464