#!/bin/sh # $Header: /home/cvsd/magellan-cvs/magellan-src/bootstrap/scripts/bootstrap-magellan.sh,v 1.1 2005-07-04 00:44:57 niro Exp $ # # bootstrap-magellan-chrooted-livecd.sh # v0.3.6-r7 (21.10.2004) # Niels Rogalla (niro@magellan-linux.de) # # creates a FHS compilant directory hirachy with devfs support # then the magellan-baselayout will be installed # All this will be handled from the host system via chroot source /etc/sysconfig/rc source $rc_functions ### setup ### CDPATH=/mnt/cdrom DEST=/mnt/magellan TOOLCHAIN=${CDPATH}/bootstrap/tools/magellan-toolchain-0.3-i486.tar.bz2 CDMAGEDIR=${CDPATH}/bootstrap/mage-src CDMAGETREE=${CDPATH}/mage-tree CDPKGDIR=${CDPATH}/packages CDMAGERC=/etc/mage.rc VERSION=0.3.6-r7 METHOD=NET # which profile ? if [ -z "${1}" ] then CDMAGEPROFILE=kernel24 else CDMAGEPROFILE="${1}" fi # which layout ? if [ -z "${2}" ] then LAYOUT=basesystem.defaults else LAYOUT="${2}" fi ### functions ### die() { echo "Error: $@" return 1 } secho() { local i i="$@" echo -e "\n${COLOREDSTAR}${i}" } mecho() { local i i="$@" echo -e "${COLMAGENTA}\t${i}${COLDEFAULT}" } necho() { local i i="$@" echo -e "${COLGREEN}${i}${COLDEFAULT}" } showversion() { echo -en "Magellan Bootstrap v${VERSION} " echo -e "-- Niels Rogalla (niro@magellan-linux.de)" } if [ -z "${DEST}" ] then echo -e "\n\$DEST not found. Your Magellan Chroot Variable must be declared." echo -e "example: export DEST=/mnt/magellan\n" exit 1 fi enter_chroot() { secho Entering Chroot ... mount -t proc proc ${DEST}/proc mount -o bind /dev ${DEST}/dev chroot ${DEST} /tools/bin/env -i \ HOME=/root TERM=$TERM PS1='\u:\w\$ ' \ PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \ /tools/bin/bash -i secho Cleanup Chroot ... mecho Unmounting Chroot filesystems ... ( umount ${DEST}/proc umount ${DEST}/dev ) evaluate_retval if [[ ${METHOD} = CDROM ]] then mecho Unmounting Mage directories ... ( umount ${DEST}/usr/packages umount ${DEST}/usr/mage ) evaluate_retval fi if [ -e ${DEST}/root/.bashrc ] then mecho Deleting instruction file ... rm ${DEST}/root/.bashrc evaluate_retval fi } create_chrootdirs() { local i # creating directories install -d ${DEST}/{bin,boot,dev/shm,etc,home,lib/dev-state,mnt,proc} || die install -d ${DEST}/etc/{opt,env.d} || die install -d ${DEST}/mnt/{floppy,cdrom} || die install -d ${DEST}/{root,sbin,tmp,usr/local,var,opt} || die for i in ${DEST}/usr ${DEST}/usr/local do install -d ${i}/{bin,etc,include,lib,sbin,share,src} || die ln -snf share/{man,doc,info} ${i} || die install -d ${i}/share/{dict,doc,info,locale,man} || die install -d ${i}/share/{nls,misc,terminfo,zoneinfo} || die install -d ${i}/share/man/man{1,2,3,4,5,6,7,8} || die done install -d ${DEST}/var/{lock,log,mail,run,spool} || die install -d ${DEST}/var/{tmp,opt,cache,lib/misc,local} || die install -d ${DEST}/opt/{bin,doc,include,info} || die install -d ${DEST}/opt/{lib,man/man{1,2,3,4,5,6,7,8}} || die ## correcting some rights chmod 0750 ${DEST}/root || die chmod 1777 ${DEST}/tmp || die chmod 1777 ${DEST}/var/tmp || die ## creating .keep files touch ${DEST}/{bin,boot,dev/shm,etc,home,lib/dev-state,mnt,proc}/.keep || die touch ${DEST}/etc/{opt,env.d}/.keep || die touch ${DEST}/mnt/{floppy,cdrom}/.keep || die touch ${DEST}/dev/.keep || die touch ${DEST}/etc/.keep || die touch ${DEST}/{root,sbin,tmp,usr/local,var,opt}/.keep || die touch ${DEST}/usr/.keep || die for i in ${DEST}/usr ${DEST}/usr/local do touch ${i}/{bin,etc,include,lib,sbin,share,src}/.keep || die touch ${i}/share/{dict,doc,info,locale,man}/.keep || die touch ${i}/share/{nls,misc,terminfo,zoneinfo}/.keep || die touch ${i}/share/man/man{1,2,3,4,5,6,7,8}/.keep || die done touch ${DEST}/var/.keep || die touch ${DEST}/var/{lock,log,mail,run,spool}/.keep || die touch ${DEST}/var/{tmp,opt,cache,lib/misc,local}/.keep || die touch ${DEST}/opt/.keep || die touch ${DEST}/opt/{bin,doc,include,info}/.keep || die touch ${DEST}/opt/{lib,man/man{1,2,3,4,5,6,7,8}}/.keep || die touch ${DEST}/opt/man/.keep || die } create_symlinks(){ mecho Creating symlinks ... ## Creating some essential symlinks for bootstrap ( ## Creating the bash and sh symlinks ln -snf /tools/bin/{basename,bash,cat,cut,date} ${DEST}/bin || die ln -snf /tools/bin/{dirname,egrep,fgrep,grep} ${DEST}/bin || die ln -snf /tools/bin/{ls,pwd,sed,stty,wc,whoami} ${DEST}/bin || die ln -snf /tools/lib/libgcc_s.so.1 ${DEST}/usr/lib || die ln -snf /tools/sbin/ldconfig ${DEST}/sbin/ldconfig || die ln -snf bash ${DEST}/bin/sh || die ## needed empty files (to prevent warnings only) touch ${DEST}/etc/env.d/dummy || die touch ${DEST}/etc/profile || die install -d ${DEST}/etc/rc.d/init.d || die touch ${DEST}/etc/rc.d/init.d/functions || die ln -snf /etc/rc.d/init.d ${DEST}/etc/init.d || die ) evaluate_retval } create_devices(){ mecho Creating needed devices for devfs ( mknod -m 611 ${DEST}/dev/console c 5 1 chgrp 4 ${DEST}/dev/console mknod -m 666 ${DEST}/dev/null c 1 3 ) evaluate_retval } unpack_toolchain(){ mecho Unpacking toolchain ... tar --no-same-owner -xvjf ${TOOLCHAIN} -C ${DEST} evaluate_retval } install_mage(){ if [[ ${METHOD} = CDROM ]] then mecho Installing Mage ... ( install -d ${DEST}/usr/lib/mage install -d ${DEST}/etc/rc.d/init.d ${CDMAGEDIR}/setup_mage.sh \ ${DEST} ${CDMAGEDIR} ${CDMAGERC} ${CDMAGEPROFILE} mount -o bind ${CDMAGETREE} ${DEST}/usr/mage mount -o bind ${CDPKGDIR} ${DEST}/usr/packages ) evaluate_retval fi if [[ ${METHOD} = NET ]] then mecho Installing Mage ... ( install -d ${DEST}/usr/lib/mage install -d ${DEST}/etc/rc.d/init.d ${CDMAGEDIR}/setup_mage.sh \ ${DEST} ${CDMAGEDIR} ${CDMAGERC} ${CDMAGEPROFILE} ) evaluate_retval fi } create_users() { mecho Creating basic passwd file ... echo 'root:x:0:0:root:/root:/bin/bash' > ${DEST}/etc/passwd evaluate_retval mecho Creating basic groups file ... cat > ${DEST}/etc/group << "EOF" root:x:0: bin:x:1: sys:x:2: kmem:x:3: tty:x:4: tape:x:5: daemon:x:6: floppy:x:7: disk:x:8: lp:x:9: dialout:x:10: audio:x:11: EOF evaluate_retval } create_bashrc() { cat ${rc_functions} > ${DEST}/root/.bashrc cat >> ${DEST}/root/.bashrc << "EOF" die() { DIE="yes" } secho() { local i i="$@" echo -e "\n${COLOREDSTAR}${i}" } mecho() { local i i="$@" echo -e "${COLMAGENTA}\t${i}${COLDEFAULT}" } EOF echo "export PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin" >> ${DEST}/root/.bashrc echo "export METHOD=${METHOD}" >> ${DEST}/root/.bashrc echo "export LAYOUT=${LAYOUT}" >> ${DEST}/root/.bashrc echo "export CDMAGEPROFILE=${CDMAGEPROFILE}" >> ${DEST}/root/.bashrc ( source ${CDMAGERC}; echo "export MY_MAGEDIR=${MAGEDIR}" >> ${DEST}/root/.bashrc ) cat >> ${DEST}/root/.bashrc << "EOF" if [[ ${METHOD} = NET ]] then mecho Updating Mage ... mage update fi # using default profile (if nothing given == kernel24) mecho Using ${MY_MAGEDIR}/profiles/${CDMAGEPROFILE}/${LAYOUT} source /etc/mage.rc ln -snf ${MY_MAGEDIR}/profiles/${CDMAGEPROFILE} /etc/mage-profile MY_LAYOUT=$(< /etc/mage-profile/${LAYOUT}) mecho Installing Baselayout ... CONFIG_PROTECT="-*" mage install ${MY_LAYOUT} #evaluate_retval mecho Please enter a root password passwd root exit EOF } # bootstrap process starts here showversion secho Starting bootstrap... unpack_toolchain mecho Creating directories ... create_chrootdirs evaluate_retval create_symlinks create_devices install_mage create_users create_bashrc enter_chroot secho Bootstraping finished... echo necho "Your System isn't configured yet ..." necho "Please edit /etc/fstab," necho " /etc/hostname," necho " /etc/hosts," necho " /etc/resolv.conf," necho " /etc/modules.autoload/kernel-VERSION," necho " /boot/grub/grub.conf" necho "that they fit to your needs ..." necho "Don't forget to write your bootsector ..." necho "After that you can delete ${DEST}/tools and reboot your system ..." echo