From bbf39bd59f31084d499c2cdd064274093b39dad8 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 9 Apr 2010 23:56:28 +0200 Subject: added dependency based system to run defined tasks --- broot.sh | 66 +++++++++++++------------- inc/bootstrap.inc.sh | 46 ------------------ inc/chroot-functions.inc.sh | 8 ++-- inc/env.inc.sh | 8 ++-- inc/functions.inc.sh | 96 ++++++++++++++++++++++++++++++++++++++ inc/helper.inc.sh | 10 ++-- inc/update.inc.sh | 4 +- tasks/bootstrap.task.sh | 47 +++++++++++++++++++ tasks/bootstrap_precheck.task.sh | 10 ++++ tasks/build_busybox.task.sh | 7 +++ tasks/buildtools.task.sh | 17 +++++++ tasks/cleanup.task.sh | 6 +++ tasks/locales.task.sh | 11 +++++ tasks/update.task.sh | 10 ++++ tasks/update_chrootscripts.task.sh | 7 +++ 15 files changed, 260 insertions(+), 93 deletions(-) delete mode 100644 inc/bootstrap.inc.sh create mode 100644 inc/functions.inc.sh create mode 100644 tasks/bootstrap.task.sh create mode 100644 tasks/bootstrap_precheck.task.sh create mode 100644 tasks/build_busybox.task.sh create mode 100644 tasks/buildtools.task.sh create mode 100644 tasks/cleanup.task.sh create mode 100644 tasks/locales.task.sh create mode 100644 tasks/update.task.sh create mode 100644 tasks/update_chrootscripts.task.sh diff --git a/broot.sh b/broot.sh index 1daf193..e3d2c74 100755 --- a/broot.sh +++ b/broot.sh @@ -1,48 +1,46 @@ #!/bin/bash . ./inc/env.inc.sh # read slx config to find paths -. ./inc/chroot-functions.inc.sh # chroot wrapper -. ./inc/bootstrap.inc.sh # bootsrap buildroot -. ./inc/helper.inc.sh # misc functions (setup bindmounts, etc) -. ./inc/color.inc.sh # functions for color ouput -. ./inc/update.inc.sh # buildroot update functions +. ./inc/functions.inc.sh case $1 in "setup") - if [ ! -e $buildrootpath/bootstraped ]; then - bootstrap - else - echo " * Found existing buildroot - running update instead" - updatebuildroot - fi + tasks="bootstrap locales update buildtools" ;; "update") - if [ ! -e $buildrootpath/bootstraped ]; then - echo " * Can't find existing buildroot - running setup instead" - bootstrap - else - updatebuildroot - fi + tasks="update update_chrootscripts" ;; - "build-bb") - if [ ! -e $buildrootpath/bootstraped ]; then - echo " * Error: didn't find existing buildroot" - else - echo " * Building busybox" - updateScripts - chroot-exec /root/bin/build-bb.sh - fi + "build-bb") + tasks="build_busybox" + # chroot-exec /root/bin/build-bb.sh ;; - "build-initramfs-pkgs") - if [ ! -e $buildrootpath/bootstraped ]; then - echo " * Error: didn't find existing buildroot" - else - echo " * Building preboot packages" - updateScripts - chroot-exec /root/bin/build-preboot.sh - fi + "build-initramfs-pkgs") + tasks="build_busybox build_packages build_kernel" + # updateScripts + # chroot-exec /root/bin/build-preboot.sh + ;; + "purge") + destroyBindmounts >/dev/null 2>&1 + # just to be sure nothing is mounted anymore + destroyBindmounts >/dev/null 2>&1 + # now we're hopefully on the safe side + destroyBindmounts >/dev/null 2>&1 + # better safe than sorry + destroyBindmounts >/dev/null 2>&1 + + rm -rf $BROOT_BUILDROOT_PATH + echo "Buildroot was removed successfully." + ;; + "resume") + [ -f $BROOT_BUILDROOT_PATH/.resume ] && . $BROOT_BUILDROOT_PATH/.resume ;; *) - echo "Usage: broot (setup|update|build-bb)" + echo "Usage: broot (setup|update|build-bb)" + exit 23 esac + +cleanup_tmp +[ "x$tasks" != "x" ] && runtasks + +exit 0 diff --git a/inc/bootstrap.inc.sh b/inc/bootstrap.inc.sh deleted file mode 100644 index 7822b96..0000000 --- a/inc/bootstrap.inc.sh +++ /dev/null @@ -1,46 +0,0 @@ - -bootstrap () { - [ ! -d $buildrootpath ] && mkdir -p $buildrootpath - - echo "broot is going to run debootsrap now: ~-_" - echo " depending on your machine/connection this can _-~ " - echo " take up to 20min.. time enough for a coffee ;) c|_| " - echo "press Strg-c to abbort" - echo -n "Starting debootsrap in .. " - echo -en "${R}3${NONE} " && sleep 1 && \ - echo -en "${R}2${NONE} " && sleep 1 && \ - echo -en "${R}1${NONE} " && sleep 1 && \ - echo ".. go " - - export DEBOOTSTRAP_DIR="$BROOT_BASE_DIR/contrib/debootstrap" - - mkdir -p "$buildrootpath/root/bin" - - mkdir -p "/tmp/deb/partial" - mkdir -p "$buildrootpath/var/cache/apt/archives" - mount -o bind "/tmp/deb" "$buildrootpath/var/cache/apt/archives" - - $DEBOOTSTRAP_DIR/debootstrap --arch="i386" squeeze $buildrootpath http://ftp.de.debian.org/debian - - touch $buildrootpath/bootstraped - - sed -i -e "s,main,main non-free," $buildrootpath/etc/apt/sources.list - setupBindmounts $buildrootpath - updatebuildroot $buildrootpath - chroot-exec aptitude update - - chroot-aptinstall locales - sed -i -e "s,^#.*\(en_US.*\)$,\1," $buildrootpath/etc/locale.gen - chroot-exec locale-gen - chroot-aptinstall build-essential - chroot-aptinstall git-core subversion - chroot-aptinstall firmware-iwlwifi firmware-linux firmware-linux-free firmware-linux-nonfree linux-image-2.6.32-trunk-686-bigmem - - cp ./chroot-scripts/* $buildrootpath/root/bin/ - chmod 700 $buildrootpath/root/bin/* - - # chroot-exec /root/bin/build-bb.sh - - destroyBindmounts - -} diff --git a/inc/chroot-functions.inc.sh b/inc/chroot-functions.inc.sh index b07f3ea..5693a54 100644 --- a/inc/chroot-functions.inc.sh +++ b/inc/chroot-functions.inc.sh @@ -1,13 +1,13 @@ chroot-exec () { - if [ $(mount |grep -c $buildrootpath/dev) -eq 0 ]; then + if [ $(mount |grep -c $BROOT_BUILDROOT_PATH/dev) -eq 0 ]; then setupBindmounts fi - chroot $buildrootpath linux32 $@ + chroot $BROOT_BUILDROOT_PATH linux32 $@ } chroot-aptinstall () { - if [ $(mount |grep -c $buildrootpath/dev) -eq 0 ]; then + if [ $(mount |grep -c $BROOT_BUILDROOT_PATH/dev) -eq 0 ]; then setupBindmounts fi - chroot $buildrootpath linux32 aptitude install -y $@ + chroot $BROOT_BUILDROOT_PATH linux32 aptitude install -y $@ } diff --git a/inc/env.inc.sh b/inc/env.inc.sh index bab613c..34e9c5b 100644 --- a/inc/env.inc.sh +++ b/inc/env.inc.sh @@ -1,12 +1,14 @@ slxsettings=$(slxsettings 2>/dev/null ) if [ $? -eq 0 ]; then - buildrootpath=$(slxsettings |grep public-path | sed -e "s,^.*='\(.*\)'$,\1,") - buildrootpath="$buildrootpath/buildroot" + BROOT_BUILDROOT_PATH=$(slxsettings |grep public-path | sed -e "s,^.*='\(.*\)'$,\1,") + BROOT_BUILDROOT_PATH="$BROOT_BUILDROOT_PATH/buildroot" else - buildrootpath="/tmp/buildroot" + BROOT_BUILDROOT_PATH="/tmp/buildroot" fi SCRIPT=$(readlink -f $0) SCRIPTPATH=`dirname $SCRIPT` BROOT_BASE_DIR=$SCRIPTPATH +BROOT_LOG=/tmp/broot.log +[ -e /tmp/.broot.tasks ] && rm -rf /tmp/.broot.tasks diff --git a/inc/functions.inc.sh b/inc/functions.inc.sh new file mode 100644 index 0000000..9535750 --- /dev/null +++ b/inc/functions.inc.sh @@ -0,0 +1,96 @@ + +. ./inc/chroot-functions.inc.sh +. ./inc/color.inc.sh +. ./inc/helper.inc.sh + +cleanup_tmp(){ + rm -f /tmp/.broot* >/dev/null 2>&1 +} + +runtasks() { + echo "tasks=(${tasks[@]:0} cleanup)" > /tmp/.broot.tasks + touch /tmp/.broot.runtime_events + while [ -f /tmp/.broot.tasks -a ! -f /tmp/.broot.exit ] + do + # reread tasks list + . /tmp/.broot.tasks + . /tmp/.broot.runtime_events + + [ -f $BROOT_BUILDROOT_PATH/.broot.packages.installed ] || mkdir -p $BROOT_BUILDROOT_PATH && touch $BROOT_BUILDROOT_PATH/.broot.packages.installed + . $BROOT_BUILDROOT_PATH/.broot.packages.installed + + if [ -f /tmp/.broot.tasks.replace ]; then + mv /tmp/.broot.tasks.replace /tmp/.broot.tasks + . /tmp/.broot.tasks + fi + + #TODO: check dependencies + fulltasks=${tasks[@]:0} + t=${tasks[@]:0:1} + tmp_tasks=${tasks[@]:1} + if [ -e "./tasks/$t.task.sh" ]; then + #echo "DEBUG: parsing task: $t" + #echo "DEBUG: rest of list: $tmp_tasks" + #echo "DEBUG: fulltasklist $fulltasks" + . ./tasks/$t.task.sh + eval append=\$${t}_append + + still_need="" + + eval runtime_dependencies=\$${t}_runtime_dependencies + have_all_runtime_dependencies=1 + for d in $runtime_dependencies + do + eval dep=\$${d}_finished + ##echo "check for $dep" + if [ "x$dep" != "x1" ]; then + have_all_runtime_dependencies=0 + if [ "x$still_need" == "x" ]; then + still_need="$d" + else + still_need="$d $still_need" + fi + fi + done + + eval package_dependencies=\$${t}_package_dependencies + have_all_package_dependencies=1 + for d in $package_dependencies + do + eval dep=\$${d}_installed + # echo "check for $dep" + if [ "x$dep" != "x1" ]; then + have_all_package_dependencies=0 + if [ "x$still_need" == "x" ]; then + still_need="$d" + else + still_need="$d $still_need" + fi + fi + done + + if [ "x$have_all_runtime_dependencies" == "x0" -o "x$have_all_package_dependencies" == "x0" ]; then + echo "tasks=($still_need $fulltasks)" > /tmp/.broot.tasks + #echo "DEBUG: unmatched dependencies: prepending: $still_need; tasks: $fulltasks" + else + echo "-- [$t] --" + eval $t + echo "--" + echo "${t}_finished=1" >> /tmp/.broot.runtime_events + # TODO: + echo "${t}_installed=1" >> $BROOT_BUILDROOT_PATH/.broot.packages.installed + echo "tasks=($append $tmp_tasks)" > /tmp/.broot.tasks + #echo "DEBUG: appended tasks: $append; old tasklist $tmp_tasks" + fi + else + echo "Error: task \"$t\" not found.." + echo "Unfinished tasks: $fulltasks" + echo "Try to fix the problem and run: \"$0 resume\"" + echo "tasks=($fulltasks)" > $BROOT_BUILDROOT_PATH/.resume + exit 42 + fi + done + rm -f /tmp/.broot.tasks + rm -f /tmp/.broot.exit + rm -f /tmp/.broot.runtime_events +} diff --git a/inc/helper.inc.sh b/inc/helper.inc.sh index eed974d..00c1915 100644 --- a/inc/helper.inc.sh +++ b/inc/helper.inc.sh @@ -1,11 +1,13 @@ setupBindmounts() { - mount -o bind /proc $buildrootpath/proc - mount -o bind /dev $buildrootpath/dev + mount -o bind /proc $BROOT_BUILDROOT_PATH/proc + mount -t devtmpfs dev $BROOT_BUILDROOT_PATH/dev + chroot $BROOT_BUILDROOT_PATH mount -t devpts devpts /dev/pts } destroyBindmounts() { - umount $buildrootpath/proc - umount $buildrootpath/dev + umount $BROOT_BUILDROOT_PATH/proc + umount $BROOT_BUILDROOT_PATH/dev/pts + umount $BROOT_BUILDROOT_PATH/dev umount /tmp/deb } diff --git a/inc/update.inc.sh b/inc/update.inc.sh index af3ff9d..fa7cd25 100644 --- a/inc/update.inc.sh +++ b/inc/update.inc.sh @@ -5,6 +5,6 @@ updatebuildroot () { } updateScripts () { - cp ./chroot-scripts/* $buildrootpath/root/bin/ - chmod 700 $buildrootpath/root/bin/* + cp ./chroot-scripts/* $BROOT_BUILDROOT_PATH/root/bin/ + chmod 700 $BROOT_BUILDROOT_PATH/root/bin/* } diff --git a/tasks/bootstrap.task.sh b/tasks/bootstrap.task.sh new file mode 100644 index 0000000..2f0624b --- /dev/null +++ b/tasks/bootstrap.task.sh @@ -0,0 +1,47 @@ +bootstrap_append="update update_chrootscripts locales" +bootstrap_runtime_dependencies="bootstrap_precheck" + +bootstrap () { + + local ME=bootstrap + + [ ! -d $BROOT_BUILDROOT_PATH ] && mkdir -p $BROOT_BUILDROOT_PATH + + echo " broot is going to run debootsrap now: ~-_" + echo " depending on your machine/connection this can _-~ " + echo " take up to 20min.. time enough for a coffee ;) c|_| " + echo " press Strg-c to abbort" + echo -n " Starting debootsrap in .. " + echo -en "${R}3${NONE} " && sleep 1 && \ + echo -en "${R}2${NONE} " && sleep 1 && \ + echo -en "${R}1${NONE} " && sleep 1 && \ + echo ".. go " + + export DEBOOTSTRAP_DIR="$BROOT_BASE_DIR/contrib/debootstrap" + + # create directory for scripts to be run inside the buildroot + mkdir -p "$BROOT_BUILDROOT_PATH/root/bin" + + # create bindmount outside to apt cache outside chroot + mkdir -p "/tmp/deb/partial" + mkdir -p "$BROOT_BUILDROOT_PATH/var/cache/apt/archives" + mount -o bind "/tmp/deb" "$BROOT_BUILDROOT_PATH/var/cache/apt/archives" + + # run bootstrap itself + echo -n " debootstrap running: " + $DEBOOTSTRAP_DIR/debootstrap --arch="i386" squeeze $BROOT_BUILDROOT_PATH http://ftp.de.debian.org/debian | tee $BROOT_LOG.$ME - | awk '{printf "."}' + lastline=$(tail -n 1 $BROOT_LOG.$ME) + echo "done" + echo " debootstrap finished with: $lastline" + + # write bootstrap lock + touch $BROOT_BUILDROOT_PATH/bootstraped + + # add non-free to apt sources + sed -i -e "s,main,main non-free," $BROOT_BUILDROOT_PATH/etc/apt/sources.list + + echo " update package list" + # update package list + chroot-exec aptitude update >> $BROOT_LOG.$ME + echo " finished all for bootstrap" +} diff --git a/tasks/bootstrap_precheck.task.sh b/tasks/bootstrap_precheck.task.sh new file mode 100644 index 0000000..f2ab6dd --- /dev/null +++ b/tasks/bootstrap_precheck.task.sh @@ -0,0 +1,10 @@ +bootstrap_precheck () { + + local ME=bootstrap_precheck + + if [ -f $BROOT_BUILDROOT_PATH/bootstraped ]; then + tasks=${tmp_tasks#bootstrap} + echo "tasks=(update $tasks)" > /tmp/.broot.tasks.replace + echo " System already bootstraped, run update instead" + fi +} diff --git a/tasks/build_busybox.task.sh b/tasks/build_busybox.task.sh new file mode 100644 index 0000000..eaf373e --- /dev/null +++ b/tasks/build_busybox.task.sh @@ -0,0 +1,7 @@ +build_busybox_package_dependencies="buildtools" + +build_busybox() { + local ME=build_busybox + echo " Building busybox" + chroot-exec /root/bin/build-bb.sh >> $BROOT_LOG.$ME +} diff --git a/tasks/buildtools.task.sh b/tasks/buildtools.task.sh new file mode 100644 index 0000000..da8544a --- /dev/null +++ b/tasks/buildtools.task.sh @@ -0,0 +1,17 @@ +buildtools_package_dependencies="update" + +buildtools() { + local ME=buildtools + + echo -n " Install build-essentials " + chroot-aptinstall build-essential | tee - $DEBUG.$ME | awk '{printf "."}' 2>&1 + echo "done" + + echo -n " Install git, svn " + chroot-aptinstall git-core subversion | tee -a - $DEBUG.$ME | awk '{printf "."}' 2>&1 + echo "done" + + echo -n " Install kernelsources and firmware packages " + chroot-aptinstall firmware-iwlwifi firmware-linux firmware-linux-free firmware-linux-nonfree linux-image-2.6.32-trunk-686-bigmem | tee -a - $DEBUG.$ME | awk '{printf "."}' 2>&1 + echo "done" +} diff --git a/tasks/cleanup.task.sh b/tasks/cleanup.task.sh new file mode 100644 index 0000000..1f25878 --- /dev/null +++ b/tasks/cleanup.task.sh @@ -0,0 +1,6 @@ +cleanup() { + # make sure all bindmounts have been umounted + echo " Umount temporary (bind)mounts" + destroyBindmounts + touch /tmp/.broot.exit +} diff --git a/tasks/locales.task.sh b/tasks/locales.task.sh new file mode 100644 index 0000000..3afc19f --- /dev/null +++ b/tasks/locales.task.sh @@ -0,0 +1,11 @@ +locales_require_bindmounts=1 + +locales() { + local ME=locales + # fix locales + chroot-aptinstall locales > $BROOT_LOG.$ME 2>&1 + sed -i -e "s,^#.*\(en_US.*\)$,\1," $BROOT_BUILDROOT_PATH/etc/locale.gen + chroot-exec locale-gen >> $BROOT_LOG.$ME 2>&1 + lastline=$(tail -n 1 $BROOT_LOG.$ME) + echo " $lastline" +} diff --git a/tasks/update.task.sh b/tasks/update.task.sh new file mode 100644 index 0000000..f6ec089 --- /dev/null +++ b/tasks/update.task.sh @@ -0,0 +1,10 @@ +update_package_dependencies="bootstrap" + +update() { + ME=update + echo " Refresh apt sources" + chroot-exec aptitude update > $DEBUG.$ME 2>&1 + echo -n " Running system update " + chroot-exec aptitude -y safe-upgrade | tee -a - $DEBUG.$ME | awk '{printf "."}' 2>&1 + echo "done" +} diff --git a/tasks/update_chrootscripts.task.sh b/tasks/update_chrootscripts.task.sh new file mode 100644 index 0000000..9302fae --- /dev/null +++ b/tasks/update_chrootscripts.task.sh @@ -0,0 +1,7 @@ +update_chrootscripts () { + rm -f $BROOT_BUILDROOT_PATH/root/bin/*.sh 2>&1 > /dev/null + cp ./chroot-scripts/* $BROOT_BUILDROOT_PATH/root/bin/ + chmod 700 $BROOT_BUILDROOT_PATH/root/bin/* + count=$(ls -1 $BROOT_BUILDROOT_PATH/root/bin/*.sh|wc -l) + echo " Reinstalled $count scripts" +} -- cgit v1.2.3-55-g7522