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 978 by niro, Thu Apr 29 20:37:04 2010 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     add_initrc 'die() { if [ $? -eq 1 ]; then echo "ERROR: $@"; exit 1; fi; }'
98    
99     local i
100     for i in ${packages}
101     do
102     add_initrc "mage ${cmd} ${i} || die ${i}"
103     done
104     add_initrc "mage clean"
105    
106     # now run the .installrc script
107     mount -t proc proc ${CDCHROOTDIR}/proc || die "mount proc"
108     mount -t sysfs sysfs ${CDCHROOTDIR}/sys || die "mount sys"
109     mount -o bind /dev ${CDCHROOTDIR}/dev || die "mount dev"
110     chroot ${CDCHROOTDIR} /bin/bash -i /.installrc || die "chr00ting"
111     umount ${CDCHROOTDIR}/dev || die "umount dev"
112     umount ${CDCHROOTDIR}/proc || die "umount proc"
113     umount ${CDCHROOTDIR}/sys || die "umount sys"
114     [ -f ${CDCHROOTDIR}/.installrc ] && rm ${CDCHROOTDIR}/.installrc
115     fi
116     ;;
117     *) die "custom_packages: unkown command ${cmd}";;
118     esac
119    }
120    
121    read_config()
122    {
123     local file="$1"
124     local pkg
125    
126     ( cat ${file}; echo ) | while read pkg
127     do
128     case "${pkg}" in
129     \#*|"") continue ;;
130     esac
131     echo "${pkg}"
132     done
133    }
134    
135  prepare_iso()  prepare_iso()
136  {  {
137   echo Preparing LiveCD ISO Image ...   echo Preparing LiveCD ISO Image ...
138    
139   # fixes some issues with xfree/xorg xkb   # fixes some issues with xfree/xorg xkb
140   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 ]]
141   then   then
142   rm ${CDCHROOTDIR}/etc/X11/xkb || die   rm ${CDCHROOTDIR}/etc/X11/xkb || die
143   mv ${CDCHROOTDIR}/usr/X11R6/lib/X11/xkb ${CDCHROOTDIR}/etc/X11 || die   mv ${CDCHROOTDIR}/usr/X11R6/lib/X11/xkb ${CDCHROOTDIR}/etc/X11 || die
# Line 62  prepare_iso() Line 148  prepare_iso()
148   install -m 0644 $(get_profile fstab) ${CDCHROOTDIR}/etc/fstab || die   install -m 0644 $(get_profile fstab) ${CDCHROOTDIR}/etc/fstab || die
149   install -m 0644 $(get_profile motd) ${CDCHROOTDIR}/etc/motd || die   install -m 0644 $(get_profile motd) ${CDCHROOTDIR}/etc/motd || die
150   install -m 0644 $(get_profile issue) ${CDCHROOTDIR}/etc/issue || die   install -m 0644 $(get_profile issue) ${CDCHROOTDIR}/etc/issue || die
151     install -m 0644 $(get_profile net.eth0) ${CDCHROOTDIR}/etc/conf.d/net.eth0 || die
152   echo "${CDHOSTNAME}" > ${CDCHROOTDIR}/etc/hostname || die   echo "${CDHOSTNAME}" > ${CDCHROOTDIR}/etc/hostname || die
153    
154   echo Setting up services ...   echo Setting up services ...
155    
156   # change mountfs with mountfslivecd  # # add hardware detection
157   MROOT="${CDCHROOTDIR}" rc-config del mountfs || die "rc del mountfs"  # MROOT="${CDCHROOTDIR}" rc-config add hwdetect || die "rc add hwdetect"
  MROOT="${CDCHROOTDIR}" rc-config add mountfslivecd || die "rc add mountfslivecd"  
   
  # add hardware detection  
  MROOT="${CDCHROOTDIR}" rc-config add hwdetect || die "rc add hwdetect"  
158    
159   # del checkfs   # del checkfs
160   MROOT="${CDCHROOTDIR}" rc-config del checkfs || die "rc del checkfs"   MROOT="${CDCHROOTDIR}" rc-config del checkfs || die "rc del checkfs"
161    
162     # add custom packages
163     [[ -n ${ADD_PACKAGES} ]] && custom_packages install "${ADD_PACKAGES}"
164     [ -f $(get_profile add_packages) ] && custom_packages install "$(read_config $(get_profile add_packages))"
165    
166     # del custom packages
167     [[ -n ${DEL_PACKAGES} ]] && custom_packages uninstall "${DEL_PACKAGES}"
168     [ -f $(get_profile del_packages) ] && custom_packages uninstall "$(read_config $(get_profile del_packages))"
169    
170     # add given services from profile
171     [[ -n ${ADD_SERVICES} ]] && custom_services add "${ADD_SERVICES}"
172     [ -f $(get_profile add_services) ] && custom_services add "$(read_config $(get_profile add_services))"
173    
174     # del given services from profile
175     [[ -n ${DEL_SERVICES} ]] && custom_services del "${DEL_SERVICES}"
176     [ -f $(get_profile del_services) ] && custom_services del "$(read_config $(get_profile del_services))"
177    
178     # setup default runlevel
179     [[ -n ${DEFAULT_RUNLEVEL} ]] && custom_services default "${DEFAULT_RUNLEVEL}"
180    
181     if [ -f $(get_profile prepare_custom) ]
182     then
183     echo Running custom user script ...
184     source $(get_profile prepare_custom) || die "running custom user script"
185     fi
186    
187   echo Cleaning unwanted files ...   echo Cleaning unwanted files ...
188   :> ${CDCHROOTDIR}/etc/mtab || die "whiping /etc/mtab"   :> ${CDCHROOTDIR}/etc/mtab || die "whiping /etc/mtab"
189     [ -f ${CDCHROOTDIR}/root/.bash_history ] && rm ${CDCHROOTDIR}/root/.bash_history
190  }  }
191    
192  generate_rootfs()  generate_rootfs()
# Line 113  install_bootloader() Line 222  install_bootloader()
222  generate_initrd()  generate_initrd()
223  {  {
224   local CHROOTSH="$(mktemp -p ${CDCHROOTDIR})"   local CHROOTSH="$(mktemp -p ${CDCHROOTDIR})"
  echo "DEBUG: ${CHROOTSH}"  
225    
226   echo Generating initrd image ...   echo Generating initrd image ...
227   echo '#!/bin/bash' > ${CHROOTSH} || die   echo '#!/bin/bash' > ${CHROOTSH} || die
# Line 151  generate_iso() Line 259  generate_iso()
259    
260  enter_livecd()  enter_livecd()
261  {  {
262   mount -t sysfs sysfs ${CDCHROOTDIR}/proc   mount -t sysfs sysfs ${CDCHROOTDIR}/sys
263   mount -t proc proc ${CDCHROOTDIR}/proc   mount -t proc proc ${CDCHROOTDIR}/proc
264   mount -o bind /dev ${CDCHROOTDIR}/dev   mount -o bind /dev ${CDCHROOTDIR}/dev
265    
# Line 160  enter_livecd() Line 268  enter_livecd()
268   HOME=/root \   HOME=/root \
269   TERM=$TERM PS1='\u:\w\$ ' \   TERM=$TERM PS1='\u:\w\$ ' \
270   PATH=/bin:/usr/bin:/sbin:/usr/sbin \   PATH=/bin:/usr/bin:/sbin:/usr/sbin \
271     http_proxy=${http_proxy} \
272     ftp_proxy=${ftp_proxy} \
273     no_proxy=${no_proxy} \
274   /bin/bash -i   /bin/bash -i
275    
276     umount ${CDCHROOTDIR}/dev
277     umount ${CDCHROOTDIR}/proc
278     umount ${CDCHROOTDIR}/sys
279    }
280    
281    usage()
282    {
283     echo "Usage: $(basename $0) [command] [profile] ..."
284     echo
285     echo "Commands:"
286     echo "    bootstrap  - bootstraps the rootfs for the livecd"
287     echo "    prepare    - prepare the rootfs to run from a livecd"
288     echo "    rootfs     - generates the squashfs rootfs image"
289     echo "    initrd     - generates a livecd suitable initrd"
290     echo "    bootloader - installs the bootloader"
291     echo "    isogen     - generate the final livecd iso image"
292     echo "    all        - runs all tasks to get a livecd from zero"
293     echo "    enter      - enters the rootfs of a livecd"
294     echo
295     echo "    for example '$(basename $0) all default'"
296     echo "    creates a livecd using the default profile."
297     echo
298  }  }
299    
300  # source profile config - overrides all other vars  # source profile config - overrides all other vars
301  [ -f ${PROFILES_DIR}/${CDPROFILE}/config ] && . ${PROFILES_DIR}/${CDPROFILE}/config  [ -f ${PROFILES_DIR}/${CDPROFILE}/config ] && . ${PROFILES_DIR}/${CDPROFILE}/config
302    
303  bootstrap_system  case $1 in
304  prepare_iso   bootstrap) bootstrap_system;;
305  generate_rootfs   prepare) prepare_iso;;
306  generate_initrd   rootfs) generate_rootfs;;
307  install_bootloader   initrd) generate_initrd;;
308  generate_iso   bootloader) install_bootloader;;
309     isogen) generate_iso;;
310     all)
311     bootstrap_system
312     prepare_iso
313     generate_rootfs
314     generate_initrd
315     install_bootloader
316     generate_iso
317     ;;
318     enter) enter_livecd ;;
319     *|'') usage;;
320    esac

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