Magellan Linux

Diff of /trunk/mlivecdbuild/mlivecdbuild2.sh

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

revision 359 by niro, Sun Mar 5 02:18:28 2006 UTC revision 360 by niro, Mon Mar 27 21:23:02 2006 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    
146   # change mountfs with mountfslivecd  # not needed with initscripts 0.3.6-r2
147   MROOT="${CDCHROOTDIR}" rc-config del mountfs || die "rc del mountfs"  # # change mountfs with mountfslivecd
148   MROOT="${CDCHROOTDIR}" rc-config add mountfslivecd || die "rc add mountfslivecd"  # MROOT="${CDCHROOTDIR}" rc-config del mountfs || die "rc del mountfs"
149    # MROOT="${CDCHROOTDIR}" rc-config add mountfslivecd || die "rc add mountfslivecd"
150    
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"
# Line 76  prepare_iso() Line 154  prepare_iso()
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 163  enter_livecd() Line 266  enter_livecd()
266   /bin/bash -i   /bin/bash -i
267  }  }
268    
269    usage()
270    {
271     echo "Usage: $(basename $0) [command] [profile] ..."
272     echo
273     echo "Commands:"
274     echo "    bootstrap  - bootstraps the rootfs for the livecd"
275     echo "    prepare    - prepare the rootfs to run from a livecd"
276     echo "    rootfs     - generates the squashfs rootfs image"
277     echo "    initrd     - generates a livecd suitable initrd"
278     echo "    bootloader - installs the bootloader"
279     echo "    isogen     - generate the final livecd iso image"
280     echo "    all        - runs all tasks to get a livecd from zero"
281     echo
282     echo "    for example '$(basename $0) all default'"
283     echo "    creates a livecd using the default profile."
284     echo
285    }
286    
287  # source profile config - overrides all other vars  # source profile config - overrides all other vars
288  [ -f ${PROFILES_DIR}/${CDPROFILE}/config ] && . ${PROFILES_DIR}/${CDPROFILE}/config  [ -f ${PROFILES_DIR}/${CDPROFILE}/config ] && . ${PROFILES_DIR}/${CDPROFILE}/config
289    
290  bootstrap_system  #bootstrap_system
291  prepare_iso  #prepare_iso
292  generate_rootfs  #generate_rootfs
293  generate_initrd  #generate_initrd
294  install_bootloader  #install_bootloader
295  generate_iso  #generate_iso
296    
297    case $1 in
298     bootstrap) bootstrap_system;;
299     prepare) prepare_iso;;
300     rootfs) generate_rootfs;;
301     initrd) generate_initrd;;
302     bootloader) install_bootloader;;
303     isogen) generate_iso;;
304     all)
305     bootstrap_system
306     prepare_iso
307     generate_rootfs
308     generate_initrd
309     install_bootloader
310     generate_iso
311     ;;
312     *|'') usage;;
313    esac

Legend:
Removed from v.359  
changed lines
  Added in v.360