From 7733a6e1ec89ec346b9bf7bbb4fbcf6660aed313 Mon Sep 17 00:00:00 2001 From: Stanislav Ochotnicky Date: Wed, 12 Aug 2009 20:00:08 +0200 Subject: Added -m switch to mktinderbox chroot This makes modifications and updates of base_chroot easier. --- util/mktinderboxchroot.sh | 76 +++++++++++++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 29 deletions(-) diff --git a/util/mktinderboxchroot.sh b/util/mktinderboxchroot.sh index 8b36554..fd909f0 100755 --- a/util/mktinderboxchroot.sh +++ b/util/mktinderboxchroot.sh @@ -21,7 +21,7 @@ help() 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" - + echo " -m prepare mounts and chroot to BASE_CHROOT for its modification (update)" exit 1 } @@ -29,13 +29,7 @@ clean_work_chroot() { echo -n "Cleaning work chroot..." if [ -d $WORK_CHROOT ];then - for dir in {"PKGDIR","DISTDIR"};do - umount_dir $dir - done - for dir in $WORK_CHROOT/{"/dev","/proc","/sys","$PORTAGE_DIR"};do - umount "$dir" || umount -l "$dir" - done - + umount_all_dirs $WORK_CHROOT rm -rf --one-file-system "$WORK_CHROOT" fi echo Done @@ -53,6 +47,36 @@ clean_base_chroot() echo Done } +mount_all_dirs() +{ + ROOTDIR=$1 + echo -n "Mounting filesystems..." + mount -t proc none "$ROOTDIR/proc" + mount -o bind /dev "$ROOTDIR/dev" + mount -o bind /sys "$ROOTDIR/sys" + + mkdir -p "$ROOTDIR/$PORTAGE_DIR" + mount -o bind "$PORTAGE_DIR" "$ROOTDIR/$PORTAGE_DIR" + # this is bug/issue with current kernels, ro binds don't work so we have to remount + mount -o remount,ro "$ROOTDIR/usr/portage" + + + mount_dir "DISTDIR" $ROOTDIR + mount_dir "PKGDIR" $ROOTDIR + echo Done +} + +umount_all_dirs() +{ + ROOTDIR=$1 + for dir in {"PKGDIR","DISTDIR"};do + umount_dir $dir $ROOTDIR + done + for dir in $ROOTDIR/{"/dev","/proc","/sys","$PORTAGE_DIR"};do + umount "$dir" || umount -l "$dir" + done +} + GPSRET="" get_portage_setting() { @@ -78,13 +102,14 @@ get_portage_setting() mount_dir() { + ROOTDIR=$2 get_portage_setting $1 if [ $? -eq 0 ];then if [ ! -e "$GPSRET" ];then mkdir -p "$GPSRET" fi - mkdir -p "$WORK_CHROOT/$GPSRET" - mount -o bind "$GPSRET" "$WORK_CHROOT/$GPSRET" + mkdir -p "$ROOTDIR/$GPSRET" + mount -o bind "$GPSRET" "$ROOTDIR/$GPSRET" else echo "Unable to get setting for $1 variable" exit 1 @@ -93,18 +118,20 @@ mount_dir() umount_dir() { + ROOTDIR=$2 get_portage_setting $1 - umount "$WORK_CHROOT/$GPSRET" || umount -l "$WORK_CHROOT/$GPSRET" + umount "$ROOTDIR/$GPSRET" || umount -l "$ROOTDIR/$GPSRET" } FORCE_CLEAN_BASE=0 -while getopts "p:s:c" Option +while getopts "p:s:cm" Option do case $Option in p ) PORTAGE_DIR="$OPTARG";; s ) STAGE_TARBALL="$OPTARG";; c ) FORCE_CLEAN_BASE=1;; + m ) MODIFY_BASE_CHROOT=1;; * ) echo "Unimplemented option chosen.";; # DEFAULT esac done @@ -162,6 +189,13 @@ else fi +if [ $MODIFY_BASE_CHROOT -eq 1 ];then + mount_all_dirs $BASE_CHROOT + chroot $BASE_CHROOT /bin/bash + umount_all_dirs $BASE_CHROOT + exit 0; +fi + if [ ! -f "$BASE_CHROOT.tar" ];then echo -n "Creating tar from $BASE_CHROOT..." tar cf "$BASE_CHROOT.tar" -C "$BASE_CHROOT" . @@ -185,24 +219,8 @@ fi echo Done +mount_all_dirs $WORK_CHROOT -echo -n "Mounting filesystems..." -mount -t proc none "$WORK_CHROOT/proc" -mount -o bind /dev "$WORK_CHROOT/dev" -mount -o bind /sys "$WORK_CHROOT/sys" - -mkdir -p "$WORK_CHROOT/usr/portage" -mount -o bind "$PORTAGE_DIR" "$WORK_CHROOT/usr/portage" -# this is bug/issue with current kernels, ro binds don't work so we have to remount -mount -o remount,ro "$WORK_CHROOT/usr/portage" - - -mount_dir "DISTDIR" -mount_dir "PKGDIR" - - - -echo Done echo -n "Chrooting and updating env..." -- cgit v1.2.3-65-gdbad