From 14e851341a7230eb50ac74565ea97a2d9b514d3c Mon Sep 17 00:00:00 2001 From: Jake Guffey Date: Fri, 27 Apr 2012 11:45:34 -0400 Subject: [PATCH] Implemented Nico's suggestions Parameterized {jailbase,jaildir} Replaced all usages of /usr/jail with $jaildir Explicitly fail if $os isn't FreeBSD Removed $__type/files/ as it is pointless to have now Updated man page --- conf/type/__jail/explorer/basepresent | 10 ++++++++-- conf/type/__jail/explorer/present | 8 +++++++- conf/type/__jail/explorer/status | 10 +++++++++- conf/type/__jail/files/jailbase | 1 - conf/type/__jail/gencode-local | 13 +++++++++---- conf/type/__jail/gencode-remote | 23 ++++++++++++++--------- conf/type/__jail/man.text | 19 ++++++++++++++----- conf/type/__jail/manifest | 13 ++++++++++++- conf/type/__jail/parameter/optional | 1 + conf/type/__jail/parameter/required | 1 + 10 files changed, 75 insertions(+), 24 deletions(-) delete mode 100644 conf/type/__jail/files/jailbase diff --git a/conf/type/__jail/explorer/basepresent b/conf/type/__jail/explorer/basepresent index aa155b03..f167a19c 100755 --- a/conf/type/__jail/explorer/basepresent +++ b/conf/type/__jail/explorer/basepresent @@ -18,20 +18,26 @@ # along with cdist. If not, see . # # -# See if the jailbase.tgz or /usr/jail/base dir exists +# See if the jailbase.tgz or $jaildir/base dir exists # # Debug #exec >&2 #set -x +if [ -f "$__object/parameter/jaildir" ]; then + jaildir="$(cat "$__object/parameter/name")" +else + jaildir="/usr/jail" +fi + name="base:jailbase.tgz" out="" save_IFS="$IFS" IFS=":" for cur in $name; do - if [ -e "/usr/jail/$cur" ]; then + if [ -e "${jaildir}/$cur" ]; then out="${out}:${cur}" fi done diff --git a/conf/type/__jail/explorer/present b/conf/type/__jail/explorer/present index a1f44302..2ba3b2af 100755 --- a/conf/type/__jail/explorer/present +++ b/conf/type/__jail/explorer/present @@ -31,7 +31,13 @@ else name=$__object_id fi -[ -d "/usr/jail/$name" ] && echo "EXISTS" || echo "NOTEXIST" +if [ -f "$__object/parameter/jaildir" ]; then + jaildir="$(cat "$__object/parameter/name")" +else + jaildir="/usr/jail" +fi + +[ -d "${jaildir}/$name" ] && echo "EXISTS" || echo "NOTEXIST" #set +x diff --git a/conf/type/__jail/explorer/status b/conf/type/__jail/explorer/status index 5f95f406..fe81eaf7 100755 --- a/conf/type/__jail/explorer/status +++ b/conf/type/__jail/explorer/status @@ -31,7 +31,15 @@ else name="$__object_id" fi -jls_output="$(jls | grep "[ ^I]\/usr\/jail\/${name}\$")" || true +if [ -f "$__object/parameter/jaildir" ]; then + jaildir="$(cat "$__object/parameter/name")" +else + jaildir="/usr/jail" +fi +# backslash-escaped $jaildir +sjaildir="$(echo ${jaildir} | sed 's#/#\\/#g')" + +jls_output="$(jls | grep "[ ^I]${sjaildir}\/${name}\$")" || true if [ -n "${jls_output}" ]; then echo "STARTED" diff --git a/conf/type/__jail/files/jailbase b/conf/type/__jail/files/jailbase deleted file mode 100644 index defb739a..00000000 --- a/conf/type/__jail/files/jailbase +++ /dev/null @@ -1 +0,0 @@ -Create a tarball jailbase.tgz in this directory containing the base filesystem for a jail. diff --git a/conf/type/__jail/gencode-local b/conf/type/__jail/gencode-local index 6a66c658..6292d943 100755 --- a/conf/type/__jail/gencode-local +++ b/conf/type/__jail/gencode-local @@ -22,13 +22,18 @@ # virtual machines. # -#FIXME: /usr/jail should never be hardcoded in this type -#FIXME: jailbase.tgz should not be hardcoded in this file +if [ -f "$__object/parameter/jaildir" ]; then + jaildir="$(cat "$__object/parameter/name")" +else + jaildir="/usr/jail" +fi -jailbase="/usr/jail/jailbase.tgz" +jailbase="$(cat "$__object/parameter/jailbase")" + +remotebase="${jaildir}/jailbase.tgz" basepresent="$(cat "$__object/explorer/basepresent")" if [ "$basepresent" = "NONE" ]; then - echo "$__remote_copy" "$__type/files/jailbase.tgz" "$__target_host:${jailbase}" + echo "$__remote_copy" "${jailbase}" "$__target_host:${remotebase}" fi diff --git a/conf/type/__jail/gencode-remote b/conf/type/__jail/gencode-remote index 9b91bd50..b52eb572 100755 --- a/conf/type/__jail/gencode-remote +++ b/conf/type/__jail/gencode-remote @@ -90,7 +90,12 @@ if [ -f "$__object/parameter/onboot" ]; then onboot="$(cat "$__object/parameter/onboot")" fi -jaildir="/usr/jail" +if [ -f "$__object/parameter/jaildir" ]; then + jaildir="$(cat "$__object/parameter/name")" +else + jaildir="/usr/jail" +fi + present="$(cat "$__object/explorer/present")" status="$(cat "$__object/explorer/status")" @@ -135,9 +140,9 @@ deleteJail() { fi EOF # Remove the jail's rw mountpoints - echo "rm -rf \"/usr/jail/rw/${name}\"" + echo "rm -rf \"${jailbase}/rw/${name}\"" # Remove the jail directory - echo "rm -rf \"/usr/jail/${name}\"" + echo "rm -rf \"${jailbase}/${name}\"" # Remove the jail's fstab echo "rm -f \"/etc/fstab.${name}\"" # Remove jail_$name_* lines from rc.conf @@ -207,12 +212,12 @@ EOF # Create the ro+rw mountpoint entries in fstab cat </etc/fstab.${name} <&2 #set -x -jaildir="/usr/jail" +# Can only be used on FreeBSD +os="$(cat "$__global/explorer/os")" +if [ ! "$os" = "freebsd" ]; then + echo "__jail can only be used on FreeBSD targets!" >&2 + exit 1 +fi + +if [ -f "$__object/parameter/jaildir" ]; then + jaildir="$(cat "$__object/parameter/name")" +else + jaildir="/usr/jail" +fi __directory ${jaildir} --parents yes diff --git a/conf/type/__jail/parameter/optional b/conf/type/__jail/parameter/optional index 85b94270..53b8895f 100644 --- a/conf/type/__jail/parameter/optional +++ b/conf/type/__jail/parameter/optional @@ -6,3 +6,4 @@ interface devfs-enable devfs-ruleset onboot +jaildir diff --git a/conf/type/__jail/parameter/required b/conf/type/__jail/parameter/required index ff72b5c7..29797ee6 100644 --- a/conf/type/__jail/parameter/required +++ b/conf/type/__jail/parameter/required @@ -1 +1,2 @@ state +jailbase