summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Leigh <rleigh@debian.org>2012-05-09 23:10:07 +0100
committerRoger Leigh <rleigh@debian.org>2012-05-09 23:10:07 +0100
commit9f1f6d4390d9f90351a3ef5b9671c3f2fd18434f (patch)
tree5a908be02d3076ca73e86a14c8fc14e501149d25
parent0297c911b136e70b70fe3007b030151c22f6a191 (diff)
downloadschroot-9f1f6d4390d9f90351a3ef5b9671c3f2fd18434f.tar.gz
contrib: Add 05customdir example
This is an example of how to use the custom chroot type.
-rwxr-xr-xcontrib/setup.d/05customdir93
-rw-r--r--contrib/setup.d/Makefile.am1
2 files changed, 94 insertions, 0 deletions
diff --git a/contrib/setup.d/05customdir b/contrib/setup.d/05customdir
new file mode 100755
index 00000000..4eff3401
--- /dev/null
+++ b/contrib/setup.d/05customdir
@@ -0,0 +1,93 @@
+#!/bin/sh
+# Copyright © 2005-2012 Roger Leigh <rleigh@debian.org>
+#
+# schroot is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# schroot is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see
+# <http://www.gnu.org/licenses/>.
+#
+#####################################################################
+
+# This script is an example of how to use the "custom" chroot type.
+# This simple example replicates some of the functionality of the
+# "directory" chroot type, using the "custom.dir" setting in place
+# of the "directory" setting, which sets CUSTOM_DIR in the script
+# environment. Here, we bind mount it as would normally happen for
+# the directory type.
+#
+# Note that this replicates some of the 10mount logic, and does not
+# handle recovery, so is not completely robust. This will require
+# reworking or splitting of 10mount into separate pieces in order
+# to handle custom types without working the logic for the custom
+# types into 10mount directly (currently the recommended course of
+# action).
+
+set -e
+
+. "$SETUP_DATA_DIR/common-data"
+. "$SETUP_DATA_DIR/common-functions"
+. "$SETUP_DATA_DIR/common-config"
+
+# Mount a filesystem
+# $1: mount options
+# $2: mount device
+# $3: mount location
+do_mount()
+{
+ info "Mounting $2 on $3"
+
+ if [ ! -d "$3" ]; then
+ mkdir -p "$3"
+ fi
+ if [ ! -d "$3" ]; then
+ fatal "$3 does not exist, and could not be created"
+ fi
+
+ info "$MOUNT_VERBOSE $1 $2 $3"
+ mount $MOUNT_VERBOSE $1 "$2" "$3"
+}
+
+if [ "$CHROOT_TYPE" = "custom" ] && [ -n "$CUSTOM_DIR" ]; then
+
+ if [ $STAGE = "setup-start" ]; then
+
+ info "CUSTOM SETUP using $CUSTOM_DIR"
+
+ case "$HOST_OS" in
+ freebsd* | k*bsd*-gnu) :
+ BINDOPT="-t nullfs"
+ ;;
+ *):
+ BINDOPT="--bind"
+ ;;
+ esac
+
+ CHROOT_MOUNT_OPTIONS="$BINDOPT $CHROOT_MOUNT_OPTIONS"
+ CHROOT_MOUNT_DEVICE="$CUSTOM_DIR"
+
+ if [ ! -d "$CUSTOM_DIR" ]; then
+ fatal "Directory '$CUSTOM_DIR' does not exist"
+ fi
+
+ if [ ! -d "$CHROOT_MOUNT_LOCATION" ]; then
+ mkdir -p "$CHROOT_MOUNT_LOCATION"
+ fi
+ if [ ! -d "$CHROOT_MOUNT_LOCATION" ]; then
+ fatal "$CHROOT_MOUNT_LOCATION does not exist, and could not be created"
+ fi
+
+ do_mount "$CHROOT_MOUNT_OPTIONS" "$CHROOT_MOUNT_DEVICE" "$CHROOT_MOUNT_LOCATION"
+
+ fi
+
+fi
+
diff --git a/contrib/setup.d/Makefile.am b/contrib/setup.d/Makefile.am
index c37ebc8d..9e058c55 100644
--- a/contrib/setup.d/Makefile.am
+++ b/contrib/setup.d/Makefile.am
@@ -22,6 +22,7 @@
include $(top_srcdir)/scripts/global.mk
noinst_SCRIPTS = \
+ 05customdir \
09fsck \
10mount-ssh \
99binfmt