Commit 9ec1e72e authored by Aaron Griffin's avatar Aaron Griffin
Browse files

makechrootpkg: Allow setting rw layer dir name



Make the name of the rw layer (default <chrootdir>/rw) configurable
with a command line switch.

Useful for maintaining multipl chroots on top of a clean base.

i.e.
<chrootdir>/root  #clean chroot
<chrootdir>/rw    #default RW layer
<chrootdir>/gnome #a RW layer with all of gnome installed
<chrootdir>/kde   #a RW layer with all of KDE installed

Signed-off-by: default avatarAaron Griffin <aaronmgriffin@gmail.com>
parent 97f7e2f2
Loading
Loading
Loading
Loading
+23 −19
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ FORCE="n"
RUN=""
MAKEPKG_ARGS="-sr"
REPACK=""
LAYER="rw"
WORKDIR=$PWD

update_first="0"
@@ -25,8 +26,7 @@ APPNAME=$(basename "${0}")

usage ()
{
    echo "usage ${APPNAME} [-hcud] -r <chrootdir> [--] [makepkg args]"
    echo "      ${APPNAME} -r <chrootdir> -I <package-file>"
    echo "usage ${APPNAME} [options] -r <chrootdir> [--] [makepkg args]"
    echo " Run this script in a PKGBUILD dir to build a package inside a"
    echo " clean chroot. All unrecognized arguments passed to this script"
    echo " will be passed to makepkg."
@@ -50,10 +50,12 @@ usage ()
    echo "-d         Add the package to a local db at /repo after building"
    echo "-r <dir>   The chroot shell to use"
    echo "-I <pkg>   Install a package into the rw layer of the chroot"
    echo "-l <layer> The directory to use as the rw layer of the unionfs"
    echo "           Useful for maintain multiple layers. Default: rw"
    exit 1
}

while getopts 'hcudr:I:' arg; do
while getopts 'hcudr:I:l:' arg; do
    case "${arg}" in
        h) usage ;;
        c) clean_first=1 ;;
@@ -61,6 +63,7 @@ while getopts 'hcudr:I:' arg; do
        d) add_to_db=1 ;;
        r) chrootdir="$OPTARG" ;;
        I) install_pkg="$OPTARG" ;;
        l) LAYER="$OPTARG" ;;
        *) MAKEPKG_ARGS="$MAKEPKG_ARGS -$arg $OPTARG" ;;
    esac
done
@@ -101,8 +104,8 @@ if [ ! -d "$chrootdir/root" ]; then
    usage
fi

[ -d "$chrootdir/rw" -a "$clean_first" -eq "1" ] && rm -rf "$chrootdir/rw/" 
[ -d "$chrootdir/rw" ] || mkdir "$chrootdir/rw"
[ -d "$chrootdir/$LAYER" -a "$clean_first" -eq "1" ] && rm -rf "$chrootdir/$LAYER/" 
[ -d "$chrootdir/$LAYER" ] || mkdir "$chrootdir/$LAYER"
[ -d "$chrootdir/union" ] || mkdir "$chrootdir/union"

cleanup ()
@@ -122,7 +125,7 @@ if [ $? -ne 0 ]; then
        echo "ERROR: No unionfs available. Abandon ship!" && exit 1
    fi
fi
mount -t unionfs none -o "dirs=$chrootdir/rw=rw:$chrootdir/root=ro" "$uniondir"
mount -t unionfs none -o "dirs=$chrootdir/$LAYER=rw:$chrootdir/root=ro" "$uniondir"
trap 'cleanup' 0 1 2 15

if [ -n "$install_pkg" ]; then
@@ -214,6 +217,7 @@ export LANG=$LOCALE
cd /build
export HOME=/build
sudo -u nobody makepkg $MAKEPKG_ARGS || touch BUILD_FAILED
namcap *.pkg.tar.gz > /pkgdest/namcap.log
EOF
) > "$uniondir/chrootbuild"
chmod +x "$uniondir/chrootbuild"
@@ -239,14 +243,14 @@ if mkarchroot -r "/chrootbuild" "$uniondir"; then
    fi
else
    #just in case. We returned 1, make sure we fail
    touch ${chrootdir}/rw/build/BUILD_FAILED
    touch ${chrootdir}/union/build/BUILD_FAILED
fi

if [ -e ${chrootdir}/rw/build/BUILD_FAILED ]; then
    echo "Build failed, check $chrootdir/rw/build"
    rm ${chrootdir}/rw/build/BUILD_FAILED
if [ -e ${chrootdir}/union/build/BUILD_FAILED ]; then
    echo "Build failed, check $chrootdir/$LAYER/build"
    rm ${chrootdir}/union/build/BUILD_FAILED
else
    rm -rf ${chrootdir}/rw/build/*
    rm -rf ${chrootdir}/union/build/*
    echo "Build complete"
fi