aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorStanislav Ochotnicky <sochotnicky@gmail.com>2009-06-25 15:57:29 +0200
committerStanislav Ochotnicky <sochotnicky@gmail.com>2009-06-25 23:12:22 +0200
commit31f11d5ab95bc41e1b138fd29e1a199f062e0930 (patch)
tree93da7567f947f6c6011f68bec4c5cca96d1a54ea /util
parentMoved python source files into 'src' subdir (diff)
downloadcollagen-31f11d5ab95bc41e1b138fd29e1a199f062e0930.tar.gz
collagen-31f11d5ab95bc41e1b138fd29e1a199f062e0930.tar.bz2
collagen-31f11d5ab95bc41e1b138fd29e1a199f062e0930.zip
Added script to create base tinderbox chroot
Usage: For first run stage tarball has to be specified (also portage_dir if it's not /usr/portage). For subsequent executions only base_chroot (created during first run and optionally modified) and work_chroot need to be supplied
Diffstat (limited to 'util')
-rwxr-xr-xutil/mktinderboxchroot.sh155
1 files changed, 155 insertions, 0 deletions
diff --git a/util/mktinderboxchroot.sh b/util/mktinderboxchroot.sh
new file mode 100755
index 0000000..7ec4198
--- /dev/null
+++ b/util/mktinderboxchroot.sh
@@ -0,0 +1,155 @@
+#!/bin/bash
+# vim: set sw=4 sts=4 et :
+
+
+# Directory from which we will rsync portage to chroot
+PORTAGE_DIR=/usr/portage
+
+# stage tarball path
+STAGE_TARBALL=""
+
+
+# ==================================================================
+# CODE
+# ===================================================================
+
+
+help()
+{
+ echo "Usage: `basename $0` OPTIONS BASE_CHROOT_DIR WORK_CHROOT_DIR"
+ echo
+ echo " -c force clean BASE_CHROOT if it exists and start over from scratch"
+ echo " -p PORTAGE_DIR directory where portage is (default is /usr/portage)"
+ echo " -s STAGE_FILE stage file used to create base chroot directory"
+
+ exit 1
+}
+
+clean_work_chroot()
+{
+ echo -n "Cleaning work chroot..."
+ if [ -d $WORK_CHROOT ];then
+ umount "$WORK_CHROOT/dev"
+ umount "$WORK_CHROOT/proc"
+ rm -rf "$WORK_CHROOT"
+ fi
+ echo Done
+}
+
+clean_base_chroot()
+{
+ echo -n "Cleaning base chroot..."
+ if [ -d "$BASE_CHROOT" ];then
+ rm -rf "$BASE_CHROOT"
+ fi
+ if [ -f "$BASE_CHROOT.tar" ];then
+ rm -f "$BASE_CHROOT.tar"
+ fi
+ echo Done
+}
+
+
+FORCE_CLEAN_BASE=0
+
+while getopts "p:s:c" Option
+do
+ case $Option in
+ p ) PORTAGE_DIR="$OPTARG";;
+ s ) STAGE_TARBALL="$OPTARG";;
+ c ) FORCE_CLEAN_BASE=1;;
+ * ) echo "Unimplemented option chosen.";; # DEFAULT
+ esac
+done
+
+
+shift $(($OPTIND - 1))
+
+if [ $# -ne 2 ];then
+ echo "Wrong number of arguments"
+ help
+fi
+
+BASE_CHROOT="$1"
+WORK_CHROOT="$2"
+
+echo "Using settings:"
+echo "base chroot directory: $BASE_CHROOT"
+echo "work chroot directory: $WORK_CHROOT"
+echo "portage directory: $PORTAGE_DIR"
+echo "stage tarball: $STAGE_TARBALL"
+
+
+if [ $FORCE_CLEAN_BASE -eq 1 ];then
+ clean_base_chroot
+fi
+
+if [ -d "$BASE_CHROOT" ];then
+ echo "We found $BASE_CHROOT directory, assuming it's ready"
+else
+ if [ -z "$STAGE_TARBALL" ];then
+ echo "We need stage tarball to create base chroot!! (option -s)"
+ help
+ fi
+
+ # we will need to create usr/ anyway so why not do it at once
+ mkdir -p "$BASE_CHROOT/usr"
+
+ echo -n "Unpacking stage tarball..."
+ tar xf "$STAGE_TARBALL" -C "$BASE_CHROOT"
+ if [ $? -ne 0 ];then
+ echo "Errors unpacking stage tarball, bailing out!!!"
+ rm -rf "$BASE_CHROOT"
+ exit 1
+ fi
+ echo Done
+
+ echo -n "RSyncing portage dir to $BASE_CHROOT..."
+ rsync -va "$PORTAGE_DIR" "$BASE_CHROOT/usr"
+
+ if [ $? -ne 0 ];then
+ echo "Errors syncing portage directory, bailing out!!!"
+ rm -rf "$BASE_CHROOT"
+ exit 1
+ fi
+ echo Done
+
+ echo -n "Creating tar from $BASE_CHROOT..."
+ tar cf "$BASE_CHROOT.tar" -C "$BASE_CHROOT" .
+ if [ $? -ne 0 ];then
+ echo "Creating tar from $BASE_CHROOT failed, bailing out!!!"
+ rm -rf "$BASE_CHROOT"
+ exit 1
+ fi
+ echo Done
+fi
+
+
+clean_work_chroot
+
+echo -n "Untaring base chroot to work chroot now"
+mkdir -p "$WORK_CHROOT"
+tar pxf "$BASE_CHROOT.tar" -C "$WORK_CHROOT"
+if [ $? -ne 0 ];then
+ echo "There were problems unpacking base chroot to work chroot!!"
+ exit 1
+fi
+echo Done
+
+
+echo -n "Copying settings..."
+cp -L /etc/resolv.conf "$WORK_CHROOT/etc"
+cp -L /etc/make.conf "$WORK_CHROOT/etc"
+echo Done
+
+echo -n "Mounting filesystems..."
+mount -t proc none "$WORK_CHROOT/proc"
+mount -o bind /dev "$WORK_CHROOT/dev"
+echo Done
+
+
+echo -n "Chrooting and updating env..."
+# so that we can run env-update
+chroot "$WORK_CHROOT" /usr/sbin/env-update
+echo Done
+
+exit 0