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 580 by niro, Fri Oct 12 21:29:13 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    
90     # respect proxies
91     [[ -n ${http_proxy} ]] && add_initrc "export http_proxy=${http_proxy}"
92     [[ -n ${ftp_proxy} ]] && add_initrc "export ftp_proxy=${ftp_proxy}"
93     [[ -n ${no_proxy} ]] && add_initrc "export no_proxy=${no_proxy}"
94    
95     # do not auto-start any services!
96     add_initrc "export MAGE_BOOTSTRAP=true"
97    
98     local i
99     for i in ${packages}
100     do
101     add_initrc "mage install ${i}"
102     done
103     add_initrc "mage clean"
104    
105     # now run the .installrc script
106     mount -t proc proc ${CDCHROOTDIR}/proc || die "mount proc"
107     mount -t sysfs sysfs ${CDCHROOTDIR}/sys || die "mount sys"
108     mount -o bind /dev ${CDCHROOTDIR}/dev || die "mount dev"
109     chroot ${CDCHROOTDIR} /bin/bash -i /.installrc || die "chr00ting"
110     umount ${CDCHROOTDIR}/dev || die "umount dev"
111     umount ${CDCHROOTDIR}/proc || die "umount proc"
112     umount ${CDCHROOTDIR}/sys || die "umount sys"
113     [ -f ${CDCHROOTDIR}/.installrc ] && rm ${CDCHROOTDIR}/.installrc
114     fi
115     ;;
116     *) die "custom_packages: unkown command ${cmd}";;
117     esac
118    }
119    
120    read_config()
121    {
122     local file="$1"
123     local pkg
124    
125     ( cat ${file}; echo ) | while read pkg
126     do
127     case "${pkg}" in
128     \#*|"") continue ;;
129     esac
130     echo "${pkg}"
131     done
132    }
133    
134  prepare_iso()  prepare_iso()
135  {  {
136   echo Preparing LiveCD ISO Image ...   echo Preparing LiveCD ISO Image ...
137    
138   # fixes some issues with xfree/xorg xkb   # fixes some issues with xfree/xorg xkb
139   if [ -L "${CDCHROOTDIR}/etc/X11/xkb" -a -d "/usr/X11R6/lib/X11/xkb" ]   if [[ -L ${CDCHROOTDIR}/etc/X11/xkb ]] && [[ -d /usr/X11R6/lib/X11/xkb ]]
140   then   then
141   rm ${CDCHROOTDIR}/etc/X11/xkb || die   rm ${CDCHROOTDIR}/etc/X11/xkb || die
142   mv ${CDCHROOTDIR}/usr/X11R6/lib/X11/xkb ${CDCHROOTDIR}/etc/X11 || die   mv ${CDCHROOTDIR}/usr/X11R6/lib/X11/xkb ${CDCHROOTDIR}/etc/X11 || die
# Line 66  prepare_iso() Line 151  prepare_iso()
151    
152   echo Setting up services ...   echo Setting up services ...
153    
  # change mountfs with mountfslivecd  
  MROOT="${CDCHROOTDIR}" rc-config del mountfs || die "rc del mountfs"  
  MROOT="${CDCHROOTDIR}" rc-config add mountfslivecd || die "rc add mountfslivecd"  
   
154   # add hardware detection   # add hardware detection
155   MROOT="${CDCHROOTDIR}" rc-config add hwdetect || die "rc add hwdetect"   MROOT="${CDCHROOTDIR}" rc-config add hwdetect || die "rc add hwdetect"
156    
157   # del checkfs   # del checkfs
158   MROOT="${CDCHROOTDIR}" rc-config del checkfs || die "rc del checkfs"   MROOT="${CDCHROOTDIR}" rc-config del checkfs || die "rc del checkfs"
159    
160     # add custom packages
161     [[ -n ${ADD_PACKAGES} ]] && custom_packages install "${ADD_PACKAGES}"
162     [ -f $(get_profile add_packages) ] && custom_packages install "$(read_config $(get_profile add_packages))"
163    
164     # del custom packages
165     [[ -n ${DEL_PACKAGES} ]] && custom_packages uninstall "${DEL_PACKAGES}"
166     [ -f $(get_profile del_packages) ] && custom_packages uninstall "$(read_config $(get_profile del_packages))"
167    
168     # add given services from profile
169     [[ -n ${ADD_SERVICES} ]] && custom_services add "${ADD_SERVICES}"
170     [ -f $(get_profile add_services) ] && custom_services add "$(read_config $(get_profile add_services))"
171    
172     # del given services from profile
173     [[ -n ${DEL_SERVICES} ]] && custom_services del "${DEL_SERVICES}"
174     [ -f $(get_profile del_services) ] && custom_services del "$(read_config $(get_profile del_services))"
175    
176     # setup default runlevel
177     [[ -n ${DEFAULT_RUNLEVEL} ]] && custom_services default "${DEFAULT_RUNLEVEL}"
178    
179     if [ -f $(get_profile prepare_custom) ]
180     then
181     echo Running custom user script ...
182     source $(get_profile prepare_custom) || die "running custom user script"
183     fi
184    
185   echo Cleaning unwanted files ...   echo Cleaning unwanted files ...
186   :> ${CDCHROOTDIR}/etc/mtab || die "whiping /etc/mtab"   :> ${CDCHROOTDIR}/etc/mtab || die "whiping /etc/mtab"
187     [ -f ${CDCHROOTDIR}/root/.bash_history ] && rm ${CDCHROOTDIR}/root/.bash_history
188  }  }
189    
190  generate_rootfs()  generate_rootfs()
# Line 113  install_bootloader() Line 220  install_bootloader()
220  generate_initrd()  generate_initrd()
221  {  {
222   local CHROOTSH="$(mktemp -p ${CDCHROOTDIR})"   local CHROOTSH="$(mktemp -p ${CDCHROOTDIR})"
  echo "DEBUG: ${CHROOTSH}"  
223    
224   echo Generating initrd image ...   echo Generating initrd image ...
225   echo '#!/bin/bash' > ${CHROOTSH} || die   echo '#!/bin/bash' > ${CHROOTSH} || die
# Line 149  generate_iso() Line 255  generate_iso()
255   popd   popd
256  }  }
257    
258    generate_dvd()
259    {
260     echo Generating DVD Image ...
261     install -d ${CDISOROOT}
262     pushd ${CDISOROOT} &&
263     growisofs -dvd-compat \
264     -rock \
265     -full-iso9660-filenames \
266     -allow-leading-dots \
267     -disable-deep-relocation \
268     -output ${LIVECDROOT}/${CDISONAME} \
269     -eltorito-boot isolinux/isolinux.bin \
270     -eltorito-catalog isolinux/boot.cat \
271     -no-emul-boot \
272     -boot-load-size 4 \
273     -boot-info-table \
274     -volid "${CDID}" \
275     ${CDISOROOT} #&> /dev/null
276     popd
277    }
278    
279  enter_livecd()  enter_livecd()
280  {  {
281   mount -t sysfs sysfs ${CDCHROOTDIR}/proc   mount -t sysfs sysfs ${CDCHROOTDIR}/proc
# Line 160  enter_livecd() Line 287  enter_livecd()
287   HOME=/root \   HOME=/root \
288   TERM=$TERM PS1='\u:\w\$ ' \   TERM=$TERM PS1='\u:\w\$ ' \
289   PATH=/bin:/usr/bin:/sbin:/usr/sbin \   PATH=/bin:/usr/bin:/sbin:/usr/sbin \
290     http_proxy=${http_proxy} \
291     ftp_proxy=${ftp_proxy} \
292     no_proxy=${no_proxy} \
293   /bin/bash -i   /bin/bash -i
294  }  }
295    
296    usage()
297    {
298     echo "Usage: $(basename $0) [command] [profile] ..."
299     echo
300     echo "Commands:"
301     echo "    bootstrap  - bootstraps the rootfs for the livecd"
302     echo "    prepare    - prepare the rootfs to run from a livecd"
303     echo "    rootfs     - generates the squashfs rootfs image"
304     echo "    initrd     - generates a livecd suitable initrd"
305     echo "    bootloader - installs the bootloader"
306     echo "    isogen     - generate the final livecd iso image"
307     echo "    dvdgen     - same as isogen but creates a dvd-image"
308     echo "    all        - runs all tasks to get a livecd from zero"
309     echo "    enter      - enters the rootfs of a livecd"
310     echo
311     echo "    for example '$(basename $0) all default'"
312     echo "    creates a livecd using the default profile."
313     echo
314    }
315    
316  # source profile config - overrides all other vars  # source profile config - overrides all other vars
317  [ -f ${PROFILES_DIR}/${CDPROFILE}/config ] && . ${PROFILES_DIR}/${CDPROFILE}/config  [ -f ${PROFILES_DIR}/${CDPROFILE}/config ] && . ${PROFILES_DIR}/${CDPROFILE}/config
318    
319  bootstrap_system  case $1 in
320  prepare_iso   bootstrap) bootstrap_system;;
321  generate_rootfs   prepare) prepare_iso;;
322  generate_initrd   rootfs) generate_rootfs;;
323  install_bootloader   initrd) generate_initrd;;
324  generate_iso   bootloader) install_bootloader;;
325     isogen) generate_iso;;
326     dvdgen) generate_dvd;;
327     all)
328     bootstrap_system
329     prepare_iso
330     generate_rootfs
331     generate_initrd
332     install_bootloader
333     if [[ ${DEFINE_DVD} = 1 ]]
334     then
335     generate_dvd
336     else
337     generate_iso
338     fi
339     ;;
340     enter) enter_livecd ;;
341     *|'') usage;;
342    esac

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