Magellan Linux

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

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