#!/bin/bash #/* #* tcos-buildchroot This script creates a chroot to build TCOS 32bits images #* #* Copyright (C) 2006-2009 mariodebian at gmail #* #* This program is free software; you can redistribute it and/or #* modify it under the terms of the GNU General Public License #* as published by the Free Software Foundation; either version 2 #* of the License, or (at your option) any later version. #* #* This program is distributed in the hope that it will be useful, #* but WITHOUT ANY WARRANTY; without even the implied warranty of #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #* GNU General Public License for more details. #* #* You should have received a copy of the GNU General Public License #* along with this program; if not, write to the Free Software #* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #*/ if [ $(id -u) != 0 ]; then echo "Error: need to exec as root user" >&2 exit 1 fi . /etc/tcos/tcos.conf . /etc/tcos/version.conf . ${TCOS_DIR}/tcos-generation-functions.sh for tpl in $(tcos_get_templates); do . $tpl done # load forced settings for derivatives if [ -d /etc/tcos/conf.d/ ]; then for file in /etc/tcos/conf.d/tcos*conf; do [ -e $file ] && . $file done fi # default settings TCOS_ARCH=i386 TCOS_FLAVOUR=standard TCOS_MIRROR="http://www.tcosproject.org" TCOS_PACKAGES="tcos-keyring initramfs-tools-tcos tcos-usplash p910nd xvnc4viewer" TCOS_PACKAGES="${TCOS_PACKAGES} binutils acpid alsa-utils twm dropbear mbr" TCOS_PACKAGES="${TCOS_PACKAGES} rdesktop pulseaudio pulseaudio-module-x11 pulseaudio-utils pulseaudio-esound-compat libasound2-plugins" DISTRO_PACKAGES="xserver-xorg xutils xfonts-base xfonts-100dpi libgl1-mesa-dri libgl1-mesa-glx libglu1-mesa mtools xterm wget dosfstools" DISTRO_PACKAGES="${DISTRO_PACKAGES} x11-utils debootstrap eject debconf grub syslinux squashfs-tools mknbi" DISTRO_PACKAGES="${DISTRO_PACKAGES} dhcp3-client python python-dbus alsa-base xauth xserver-xorg-input-all xserver-xorg-input-mouse" # apt options (force-yes) APT_OPTS="-y --force-yes" ACTION= GENTCOS_OPTS="-tftp" MIRROR_EXTRAS="" TCOS_EXPERIMENTAL="" UBUNTU_DEF_MIRROR=http://archive.ubuntu.com/ubuntu/ UBUNTU_DEF_MIRROR2=http://security.ubuntu.com/ubuntu/ DEBIAN_DEF_MIRROR=http://ftp.de.debian.org/debian/ set_conf() { if [ "${DISTRIBUTION}" = "ubuntu" ]; then if [ ! $MIRROR ]; then MIRROR=$UBUNTU_DEF_MIRROR ; fi if [ ! $MIRROR2 ]; then MIRROR2=$UBUNTU_DEF_MIRROR2 ; fi MIRROR_EXTRAS="universe restricted multiverse" DISTRO_PACKAGES="console-setup ${DISTRO_PACKAGES}" else if [ ! $MIRROR ]; then MIRROR=$DEBIAN_DEF_MIRROR ; fi #DISTRO_PACKAGES="console-data ${DISTRO_PACKAGES} libltdl3 " DISTRO_PACKAGES="console-data ${DISTRO_PACKAGES}" fi } # load forced settings for derivatives if [ -d /etc/tcos/conf.d/ ]; then for file in /etc/tcos/conf.d/tcos*conf; do [ -e $file ] && . $file done fi usage() { cat << EOF tcos-buildchroot usage: Actions: --create (Create chroot) --update (Update chroot) --install=package1,package2 (Install some packages in chroot) --update-images (Update chroot TCOS images) Options: --arch=xxx (Set Architecture of chroot, default: $TCOS_ARCH) --flavour=xxx (Set flavour of chroot, default: $TCOS_FLAVOUR) --version=xxx (Set version of chroot, default: $TCOS_DISTRO) --forcedistro=xxx (Set distro of chroot, default: $DISTRIBUTION) --dir=xxx (Set dir of chroot, default: $TCOS_CHROOT) --tcos-exp (Enable experimental TCOS branch) EOF if [ "$DISTRIBUTION" = "ubuntu" ]; then cat << EOF --mirror=xxx (Set mirror of chroot, default: $UBUNTU_DEF_MIRROR) --securitymirror=xxx (Set security mirror of chroot, default: $UBUNTU_DEF_MIRROR2) EOF else cat << EOF --mirror=xxx (Set mirror of chroot, default: $DEBIAN_DEF_MIRROR) EOF fi cat << EOF --tcosmirror=xxx (Set mirror of TCOS, default: $TCOS_MIRROR) --kversion=xxx (Set kernel version of chroot, default: $TCOS_KERNEL) --gentcos="xxx" (Set gentcos cmdline options) EOF } chrootcreate() { mkdir -p ${TCOS_CHROOT} debootstrap --arch "${TCOS_ARCH}" ${TCOS_DISTRO} ${TCOS_CHROOT} ${MIRROR} if [ $? != 0 ]; then echo "Error running debootstrap." ; exit $?; fi # Add TCOS mirror echo "deb ${TCOS_MIRROR} $TCOS_DISTRO main $TCOS_EXPERIMENTAL" >> ${TCOS_CHROOT}/etc/apt/sources.list # add extras (universe and multiverse repos) if [ "${MIRROR_EXTRAS}" != "" ]; then echo "deb ${MIRROR} ${TCOS_DISTRO} ${MIRROR_EXTRAS}" >> ${TCOS_CHROOT}/etc/apt/sources.list echo "deb ${MIRROR2} ${TCOS_DISTRO}-security main ${MIRROR_EXTRAS}" >> ${TCOS_CHROOT}/etc/apt/sources.list echo "deb ${MIRROR} ${TCOS_DISTRO}-updates main ${MIRROR_EXTRAS}" >> ${TCOS_CHROOT}/etc/apt/sources.list fi # add extra source include in forced settings if [ ! -z ${MIRROR_EXTRA} ];then echo ${MIRROR_EXTRA} >> ${TCOS_CHROOT}/etc/apt/sources.list fi # add /etc/resolv.conf (some versions of cdebootstrap don't create it) cat /etc/resolv.conf > ${TCOS_CHROOT}/etc/resolv.conf # avoid to use a shell script in chroot if [ "$(file ${TCOS_CHROOT}/sbin/start-stop-daemon | grep -c ELF)" = "1" ]; then cp ${TCOS_CHROOT}/sbin/start-stop-daemon ${TCOS_CHROOT}/sbin/start-stop-daemon.original fi if [ "$(file ${TCOS_CHROOT}/sbin/start-stop-daemon.REAL | grep -c ELF)" = "1" ]; then cp ${TCOS_CHROOT}/sbin/start-stop-daemon.REAL ${TCOS_CHROOT}/sbin/start-stop-daemon.original fi cat << EOF > ${TCOS_CHROOT}/etc/apt/apt.conf APT::Install-Recommends "false"; APT::Install-Suggests "false"; EOF mount --bind /proc ${TCOS_CHROOT}/proc mount --bind /sys ${TCOS_CHROOT}/sys # preseed linux-image message cat << EOF > ${TCOS_CHROOT}/preseed linux-image-${TCOS_KERNEL} linux-image-${TCOS_KERNEL}/preinst/lilo-initrd-${TCOS_KERNEL} boolean false linux-image-${TCOS_KERNEL} linux-image-${TCOS_KERNEL}/preinst/bootloader-initrd-${TCOS_KERNEL} boolean false linux-image-${TCOS_KERNEL} linux-image-${TCOS_KERNEL}/postinst/create-kimage-link-${TCOS_KERNEL} boolean false linux-image-${TCOS_KERNEL} shared/kernel-image/really-run-bootloader boolean false console-common console-data/keymap/policy select Don't touch keymap console-data console-data/keymap/policy select Don't touch keymap console-setup console-setup/variant select USA console-setup console-setup/charmap select UTF-8 console-setup console-setup/layoutcode string us console-setup console-setup/compose select No compose key console-setup console-setup/fontsize-text select 16 console-setup console-setup/optionscode string console-setup console-setup/layout select USA console-setup console-setup/detect detect-keyboard console-setup console-setup/detected note console-setup console-setup/variantcode string console-setup console-setup/codesetcode string Uni1 console-setup console-setup/dont_ask_layout error console-setup console-setup/modelcode string pc105 console-setup console-setup/ask_detect boolean false console-setup console-setup/altgr select No AltGr key console-setup console-setup/ttys string /dev/tty[1-6] console-setup console-setup/model select Generic 105-key (Intl) PC console-setup console-setup/fontsize-fb select 16 console-setup console-setup/switch select No temporary switch console-setup console-setup/codeset select . Combined - Latin; Slavic Cyrillic; Hebrew; basic Arabic console-setup console-setup/toggle select No toggling console-setup console-setup/fontface select Fixed console-setup console-setup/fontsize string 16 dash dash/sh boolean false EOF cat << CMD > ${TCOS_CHROOT}/sbin/start-stop-daemon #!/bin/sh exit 0 CMD cat << CMD > ${TCOS_CHROOT}/usr/sbin/invoke-rc.d #!/bin/sh exit 0 CMD chmod +x ${TCOS_CHROOT}/sbin/start-stop-daemon ${TCOS_CHROOT}/usr/sbin/invoke-rc.d cat << EOC | chroot ${TCOS_CHROOT} export LC_ALL=C LC_MESSAGES=C DEBCONF_FRONTEND="noninteractive" DEBIAN_FRONTEND="noninteractive" apt-get $APT_OPTS update apt-get $APT_OPTS dist-upgrade apt-get install $APT_OPTS tcos-keyring apt-get $APT_OPTS update apt-get install $APT_OPTS ${DISTRO_PACKAGES} apt-get clean debconf-set-selections /preseed rm -f /preseed apt-get $APT_OPTS upgrade EOC if [ "${DISTRIBUTION}" = "ubuntu" ]; then cat << EOC | chroot ${TCOS_CHROOT} export LC_ALL=C LC_MESSAGES=C DEBCONF_FRONTEND="noninteractive" DEBIAN_FRONTEND="noninteractive" apt-get install $APT_OPTS linux-image-${TCOS_KERNEL} apt-get install $APT_OPTS linux-ubuntu-modules-${TCOS_KERNEL} apt-get install $APT_OPTS linux-restricted-modules-${TCOS_KERNEL} apt-get install $APT_OPTS ${TCOS_PACKAGES} apt-get install $APT_OPTS tcos-extra-modules-${TCOS_KERNEL} apt-get clean /etc/init.d/dropbear stop || true EOC # need umount this directory to allow remove later chroot from distros grather than gutsy #if [ ${TCOS_DISTRO} = "gutsy" -o ${TCOS_DISTRO} = "hardy" ]; then if [ -d ${TCOS_CHROOT}/lib/modules/${TCOS_KERNEL}/volatile/ ]; then umount ${TCOS_CHROOT}/lib/modules/${TCOS_KERNEL}/volatile/ >/dev/null 2>&1 fi ###################################### else # DISTRO != ubuntu cat << EOC | chroot ${TCOS_CHROOT} export LC_ALL=C LC_MESSAGES=C DEBCONF_FRONTEND="noninteractive" DEBIAN_FRONTEND="noninteractive" apt-get install $APT_OPTS linux-image-${TCOS_KERNEL} apt-get install $APT_OPTS tcos-extra-modules-${TCOS_KERNEL} apt-get install $APT_OPTS ${TCOS_PACKAGES} apt-get clean /etc/init.d/dropbear stop || true rm -f /preseed EOC fi touch ${TCOS_CHROOT}/etc/tcos/chroot umount -l ${TCOS_CHROOT}/proc umount -l ${TCOS_CHROOT}/sys } # end of chrootcreate() ############################################################################### chrootupdate() { cat /etc/resolv.conf > ${TCOS_CHROOT}/etc/resolv.conf [ ! -e ${TCOS_CHROOT}/sbin/start-stop-daemon ] && cat << CMD > ${TCOS_CHROOT}/sbin/start-stop-daemon #!/bin/sh exit 0 CMD [ ! -e ${TCOS_CHROOT}/usr/sbin/invoke-rc.d ] && cat << CMD > ${TCOS_CHROOT}/usr/sbin/invoke-rc.d #!/bin/sh exit 0 CMD chmod +x ${TCOS_CHROOT}/sbin/start-stop-daemon ${TCOS_CHROOT}/usr/sbin/invoke-rc.d # copy console keymap if [ -e /etc/console/boottime.kmap.gz ]; then mkdir -p ${TCOS_CHROOT}/etc/console cp /etc/console/boottime.kmap.gz ${TCOS_CHROOT}/etc/console fi if [ -e /etc/console-setup/boottime.kmap.gz ]; then mkdir -p ${TCOS_CHROOT}/etc/console-setup cp /etc/console-setup/boottime.kmap.gz ${TCOS_CHROOT}/etc/console-setup/ fi if [ -e /etc/console-setup/cached.kmap.gz ]; then mkdir -p ${TCOS_CHROOT}/etc/console-setup cp /etc/console-setup/cached.kmap.gz ${TCOS_CHROOT}/etc/console-setup/ fi cat << EOC | chroot ${TCOS_CHROOT} export LC_ALL=C LC_MESSAGES=C DEBCONF_FRONTEND="noninteractive" DEBIAN_FRONTEND="noninteractive" apt-get update apt-get $APT_OPTS dist-upgrade apt-get install $APT_OPTS ${TCOS_PACKAGES} apt-get install $APT_OPTS ${DISTRO_PACKAGES} apt-get clean EOC # need umount this directory to allow remove later chroot from distros grather than gutsy if [ -d ${TCOS_CHROOT}/lib/modules/${TCOS_KERNEL}/volatile/ ]; then umount ${TCOS_CHROOT}/lib/modules/${TCOS_KERNEL}/volatile/ >/dev/null 2>&1 fi touch ${TCOS_CHROOT}/etc/tcos/chroot } ############################################################################### chrootinstallpkg() { cat /etc/resolv.conf > ${TCOS_CHROOT}/etc/resolv.conf [ ! -e ${TCOS_CHROOT}/sbin/start-stop-daemon ] && cat << CMD > ${TCOS_CHROOT}/sbin/start-stop-daemon #!/bin/sh exit 0 CMD [ ! -e ${TCOS_CHROOT}/usr/sbin/invoke-rc.d ] && cat << CMD > ${TCOS_CHROOT}/usr/sbin/invoke-rc.d #!/bin/sh exit 0 CMD chmod +x ${TCOS_CHROOT}/sbin/start-stop-daemon ${TCOS_CHROOT}/usr/sbin/invoke-rc.d cat << EOC | chroot ${TCOS_CHROOT} export LC_ALL=C LC_MESSAGES=C DEBCONF_FRONTEND="noninteractive" DEBIAN_FRONTEND="noninteractive" apt-get update apt-get $APT_OPTS install $@ apt-get clean EOC } ############################################################################### chrootcp() { if [ -e "$1" ]; then mkdir -p "${TCOS_CHROOT}/$(dirname $1)" cp "$1" "${TCOS_CHROOT}/$(dirname $1)/" fi } chrootupdateimages() { cat /etc/resolv.conf > ${TCOS_CHROOT}/etc/resolv.conf # copy some files chrootcp /usr/share/tcos-core/lockscreen-custom.png chrootcp /etc/default/console-setup chrootcp /etc/default/keyboard chrootcp /etc/adjtime TCOS_KERNEL=$(awk -F"=" '/^TCOS_KERNEL=/ {print $2}' ${TCOS_CHROOT}/etc/tcos/tcos.conf | sed 's/"//g') if [ -f /etc/tcos/templates/tcosconfig.conf ]; then mkdir -p ${TCOS_CHROOT}/etc/tcos/templates/ cp /etc/tcos/templates/tcosconfig.conf ${TCOS_CHROOT}/etc/tcos/templates/ if grep -q "TCOS_KERNEL" ${TCOS_CHROOT}/etc/tcos/templates/tcosconfig.conf; then TCOS_KERNEL=$(awk -F"=" '/^TCOS_KERNEL=/ {print $2}' ${TCOS_CHROOT}/etc/tcos/templates/tcosconfig.conf | sed 's/"//g') fi fi mount --bind /proc ${TCOS_CHROOT}/proc cat << EOC | chroot ${TCOS_CHROOT} LC_ALL=C LC_MESSAGES=C gentcos ${GENTCOS_OPT} EOC umount -l ${TCOS_CHROOT}/proc # this is exec outside chroot rm -rf /var/lib/tcos/tftp/vmlinuz-${TCOS_KERNEL} \ /var/lib/tcos/tftp/usr-${TCOS_KERNEL}.squashfs \ /var/lib/tcos/tftp/initramfs-${TCOS_KERNEL} \ /var/lib/tcos/tftp/linux-${TCOS_KERNEL}.nbi \ /var/lib/tcos/fs-${TCOS_KERNEL} [ ! -e /var/lib/tcos/tftp/vmlinuz-${TCOS_KERNEL} ] && \ ln -s ${TCOS_CHROOT}/boot/vmlinuz-${TCOS_KERNEL} /var/lib/tcos/tftp/ [ ! -e /var/lib/tcos/tftp/usr-${TCOS_KERNEL}.squashfs ] && \ ln -s ${TCOS_CHROOT}/var/lib/tcos/tftp/usr-${TCOS_KERNEL}.squashfs /var/lib/tcos/tftp/ [ ! -e /var/lib/tcos/tftp/initramfs-${TCOS_KERNEL} ] && \ [ -e ${TCOS_CHROOT}/var/lib/tcos/tftp/initramfs-${TCOS_KERNEL} ] && \ ln -s ${TCOS_CHROOT}/var/lib/tcos/tftp/initramfs-${TCOS_KERNEL} /var/lib/tcos/tftp/ [ ! -e /var/lib/tcos/tftp/linux-${TCOS_KERNEL}.nbi ] && \ [ -e ${TCOS_CHROOT}/var/lib/tcos/tftp/linux-${TCOS_KERNEL}.nbi ] && \ ln -s ${TCOS_CHROOT}/var/lib/tcos/tftp/linux-${TCOS_KERNEL}.nbi /var/lib/tcos/tftp/ # NFS files and dirs [ ! -e /var/lib/tcos/tftp/initramfs-${TCOS_KERNEL}-nfs ] && \ [ -e ${TCOS_CHROOT}/var/lib/tcos/tftp/initramfs-${TCOS_KERNEL}-nfs ] && \ ln -s ${TCOS_CHROOT}/var/lib/tcos/tftp/initramfs-${TCOS_KERNEL}-nfs /var/lib/tcos/tftp/ [ ! -d /var/lib/tcos/fs-${TCOS_KERNEL} ] && \ [ -d ${TCOS_CHROOT}/var/lib/tcos/fs-${TCOS_KERNEL} ] && \ ln -s ${TCOS_CHROOT}/var/lib/tcos/fs-${TCOS_KERNEL} /var/lib/tcos/ # generate pxelinux.cfg/default parse_pxelinuxcfg } ############################################################################### # # Script begins here # if [ "$#" = 0 ]; then echo "No parameters !!" usage exit 1 fi OPTIONS=`getopt -o d:ko:r:v --long create,update,install:,update-images,help,version:,forcedistro:,arch:,flavour:,dir:,mirror:,securitymirror:,tcosmirror:,kversion:,gentcos:,debug,quiet,verbose,tcos-exp -n "$0" -- "$@"` if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi eval set -- "$OPTIONS" while true; do case "$1" in --help) usage ; exit 0 ;; --version) TCOS_DISTRO=$2; shift 2 ;; --forcedistro) DISTRIBUTION=$2; shift 2;; --arch) TCOS_ARCH=$2 ; shift 2 ;; --flavour) TCOS_FLAVOUR=$2; shift 2 ;; --mirror) MIRROR=$2; shift 2 ;; --securitymirror) MIRROR2=$2; shift 2;; --tcosmirror) TCOS_MIRROR=$2; shift 2 ;; --dir) TCOS_CHROOT=$2 ; shift 2 ;; --kversion) TCOS_KERNEL=$2; shift 2 ;; --gentcos) GENTCOS_OPT=$2; shift 2 ;; --debug) echo "FIXME DEBUG"; shift ;; --quiet) echo "FIXME QUIET"; shift ;; --verbose) echo "FIXME VERBOSE";shift ;; --tcos-exp) TCOS_EXPERIMENTAL="experimental"; shift ;; --create) ACTION=create ; shift ;; --update) ACTION=update ; shift ;; --install) ACTION=installpkgs PKGS="$2"; shift 2;; --update-images) ACTION=update-images; shift;; --) shift ; break ;; *) usage; echo "Unknow option $1"; exit -1 ;; esac done # load conf with forces settings set_conf # save data in tcos-buildchroot.conf or load if chroot exists if [ ! -f ${TCOS_CHROOT}/tcos-buildchroot.conf ]; then mkdir -p ${TCOS_CHROOT} echo "DISTRIBUTION=$DISTRIBUTION" > ${TCOS_CHROOT}/tcos-buildchroot.conf echo "MIRROR=$MIRROR" >> ${TCOS_CHROOT}/tcos-buildchroot.conf echo "MIRROR2=$MIRROR2" >> ${TCOS_CHROOT}/tcos-buildchroot.conf echo "TCOS_MIRROR=$TCOS_MIRROR" >> ${TCOS_CHROOT}/tcos-buildchroot.conf echo "TCOS_KERNEL=$TCOS_KERNEL" >> ${TCOS_CHROOT}/tcos-buildchroot.conf echo "TCOS_DISTRO=$TCOS_DISTRO" >> ${TCOS_CHROOT}/tcos-buildchroot.conf echo "TCOS_EXPERIMENTAL=$TCOS_EXPERIMENTAL" >> ${TCOS_CHROOT}/tcos-buildchroot.conf else . ${TCOS_CHROOT}/tcos-buildchroot.conf fi if [ "$ACTION" != "" ]; then case $ACTION in update) chrootupdate; exit ;; create) chrootcreate; exit ;; installpkgs) tmp=$(echo $PKGS | sed 's/,/ /g') chrootinstallpkg $tmp ; exit ;; update-images) chrootupdateimages; exit ;; *) echo "Error, unknow action: $ACTION" exit 1 ;; esac fi