aboutsummaryrefslogtreecommitdiff
path: root/src/mkjail
diff options
context:
space:
mode:
Diffstat (limited to 'src/mkjail')
-rwxr-xr-xsrc/mkjail103
1 files changed, 82 insertions, 21 deletions
diff --git a/src/mkjail b/src/mkjail
index 0f9834d..0b6adb3 100755
--- a/src/mkjail
+++ b/src/mkjail
@@ -20,11 +20,6 @@
COMMON="/usr/libexec/simplepkg/common.sh"
BASENAME="`basename $0`"
-function usage {
- echo "usage: [ARCH=arch] [VERSION=version] [ROOT=/otherroot] $BASENAME <jail-name> [template]"
- exit 1
-}
-
if [ -f "$COMMON" ]; then
source $COMMON
else
@@ -32,11 +27,87 @@ else
exit 1
fi
+function usage {
+
+ echo "usage: [ARCH=arch] [VERSION=version] [ROOT=/otherroot] $BASENAME <jail-name> [template]"
+ exit 1
+
+}
+
+function copy_template_files {
+
+ # copy template files into jail
+ # usage: copy_template_files <jail-path>
+
+ if [ -d "$1" ]; then
+ echo "$BASENAME: copying template files..."
+ if [ -d "$TEMPLATE_BASE.d" ]; then
+ if [ "$TEMPLATES_UNDER_SVN" == "1" ]; then
+ rsync -av --exclude=.svn $TEMPLATE_BASE.d/ $JAIL_ROOT/$server/
+ else
+ rsync -av $TEMPLATE_BASE.d/ $JAIL_ROOT/$server/
+ fi
+ fi
+ fi
+
+}
+
+function set_jail_perms {
+
+ # set template file permissions under a jail
+ # usage: set_jail_perms <jail-path>
+
+ if [ -s "$TEMPLATE_BASE.perms" ]; then
+ cat $TEMPLATE_BASE.perms | while read entry; do
+ file="`echo $entry | cut -d ";" -f 1`"
+ if [ -a "$TEMPLATE_BASE.d/$file" ] && [ -a "$1/$file" ]; then
+ owner="`echo entry | cut -d ";" -f 2`"
+ group="`echo entry | cut -d ";" -f 3`"
+ perms="`echo entry | cut -d ";" -f 4`"
+ chmod $perms $1/$file
+ chown $owner:$group $1/$file
+ fi
+ done
+ fi
+
+}
+
+function exec_post_install_scripts {
+
+ # exec post installation scripts
+ # usage: exec_post_install_script <jail-root> <jail-name>
+
+ if [ -z "$2" ]; then
+ return 1
+ fi
+
+ echo "$BASENAME: executing template scripts..."
+ if [ -d "$TEMPLATE_BASE.s" ]; then
+ for script in `ls $TEMPLATE_BASE.s/`; do
+ if [ -x "$TEMPLATE_BASE.s/$script" ]; then
+ exec $TEMPLATE_BASE.s/$script $1 $2
+ fi
+ done
+ fi
+
+}
+
+function jailist_update {
+
+ # update the jail list file
+ # usage: jailist_update <jail-path>
+
+ if ! grep -q "^$1" $JAIL_LIST; then
+ echo $1 >> $JAIL_LIST
+ fi
+
+}
+
if [ -z "$1" ]; then
usage
else
server="$1"
- eval_config `basename $0` -u
+ eval_config $BASENAME -u
fi
if [ ! -z "$2" ]; then
@@ -64,22 +135,12 @@ else
fi
echo "$BASENAME: instaling packages into $JAIL_ROOT/$server using $TEMPLATE..."
-install_packages
-echo "$BASENAME: copying template files..."
-if [ -d "$TEMPLATE_BASE.d" ]; then
- rsync -av $TEMPLATE_BASE.d/ $JAIL_ROOT/$server/
-fi
-
-echo "$BASENAME: executing template scripts..."
-if [ -d "$TEMPLATE.s" ]; then
- for script in `ls $TEMPLATE.s/`; do
- if [ -x "$TEMPLATE_BASE.s/$script" ]; then
- exec $TEMPLATE_BASE.s/$script $JAIL_ROOT $server
- fi
- done
-fi
+install_packages
+copy_template_files $JAIL_ROOT/$server
+set_jail_perms $JAIL_ROOT/$server
+exec_post_install_scripts $JAIL_ROOT $server
+jailist_update $JAIL_ROOT/$server
-echo $JAIL_ROOT/$server >> $JAIL_LIST
echo $BASENAME: done creating $server jail