Commit d1068153 authored by Michele Tartara's avatar Michele Tartara
Browse files

Make build_chroot self-contained



The configuration file are included in build_chroot, and are
automatically created by the script if it is not able to find them
already in the directory pointed by $DATA_DIR.

Note that the configuration file directory is cleaned if it's temporary,
but it is left untouched if it was esplicitly specified by the user.
Signed-off-by: default avatarMichele Tartara <mtartara@google.com>
Reviewed-by: default avatarKlaus Aehlig <aehlig@google.com>
parent 91cdc18f
#!/bin/bash
#Configuration
: ${DATA_DIR=`dirname $0`/data}
: ${ARCH=amd64}
: ${DIST_RELEASE=squeeze}
: ${ARCH:=amd64}
: ${DIST_RELEASE:=squeeze}
: ${CONF_DIR:=/etc/schroot/chroot.d}
: ${CHROOT_DIR:=/srv/chroot}
: ${ALTERNATIVE_EDITOR:=/usr/bin/vim.basic}
# The value of DATA_DIR is read as well from the environment.
#Automatically generated variables
CHROOTNAME=$DIST_RELEASE-$ARCH
......@@ -17,6 +17,9 @@ CHDIR=$ROOT/$CHNAME
USER=`whoami`
COMP_FILENAME=$CHROOTNAME.tar.gz
COMP_FILEPATH=$ROOT/$COMP_FILENAME
TEMP_DATA_DIR=`mktemp -d`
ACTUAL_DATA_DIR=$DATA_DIR
ACTUAL_DATA_DIR=${ACTUAL_DATA_DIR:-$TEMP_DATA_DIR}
#Runnability checks
if [ $USER != 'root' ]
......@@ -34,16 +37,46 @@ then
exit
fi
if [ ! -d $DATA_DIR ]
#Create configuration dir and files if they do not exist
if [ ! -d $ACTUAL_DATA_DIR ]
then
mkdir $ACTUAL_DATA_DIR
echo "The data directory"
echo " $DATA_DIR"
echo "does not exist."
echo "Please, set the DATA_DIR environment variable so that it points to the"
echo "data directory."
exit
echo " $ACTUAL_DATA_DIR"
echo "has been created."
fi
if [ ! -f $ACTUAL_DATA_DIR/final.schroot.conf.in ]
then
cat <<END >$ACTUAL_DATA_DIR/final.schroot.conf.in
[${CHROOTNAME}]
description=Debian ${DIST_RELEASE} ${ARCH}
groups=src
source-root-groups=root
type=file
file=${CHROOT_DIR}/${COMP_FILENAME}
END
echo "The file"
echo " $ACTUAL_DATA_DIR/final.schroot.conf.in"
echo "has been created with default configurations."
fi
if [ ! -f $ACTUAL_DATA_DIR/temp.schroot.conf.in ]
then
cat <<END >$ACTUAL_DATA_DIR/temp.schroot.conf.in
[${CHNAME}]
description=Debian ${DIST_RELEASE} ${ARCH}
directory=${CHDIR}
groups=src
users=root
type=directory
END
echo "The file"
echo " $ACTUAL_DATA_DIR/temp.schroot.conf.in"
echo "has been created with default configurations."
fi
#Stop on errors
set -e
#Cleanup
......@@ -65,8 +98,8 @@ alias subst_variables='sed \
-e "s/\${DIST_RELEASE}/$DIST_RELEASE/"'
#Generate chroot configurations
cat $DATA_DIR/temp.schroot.conf.in | subst_variables > $TEMP_CHROOT_CONF
cat $DATA_DIR/final.schroot.conf.in | subst_variables > $FINAL_CHROOT_CONF
cat $ACTUAL_DATA_DIR/temp.schroot.conf.in | subst_variables > $TEMP_CHROOT_CONF
cat $ACTUAL_DATA_DIR/final.schroot.conf.in | subst_variables > $FINAL_CHROOT_CONF
#Install the base system
debootstrap --arch $ARCH $DIST_RELEASE $CHDIR
......@@ -183,3 +216,4 @@ echo "Done"
rm -rf $CHDIR
rm -f $TEMP_CHROOT_CONF
rm -rf $TEMP_DATA_DIR
[${CHROOTNAME}]
description=Debian ${DIST_RELEASE} ${ARCH}
groups=src
source-root-groups=root
type=file
file=${CHROOT_DIR}/${COMP_FILENAME}
[${CHNAME}]
description=Debian ${DIST_RELEASE} ${ARCH}
directory=${CHDIR}
groups=src
users=root
type=directory
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment