# HG changeset patch # User Franz Glasner # Date 1565881262 -7200 # Node ID fea2ef3ff89a371bc06fb281cca433fa105a08c1 # Parent 2e3ac70bdfc882b6b958564abfde48ddb81f3215 Populate an existing directory tree with the contents of base.txz diff -r 2e3ac70bdfc8 -r fea2ef3ff89a bin/fjail --- a/bin/fjail Thu Aug 15 16:07:53 2019 +0200 +++ b/bin/fjail Thu Aug 15 17:01:02 2019 +0200 @@ -2,7 +2,7 @@ # -*- indent-tabs-mode: nil; -*- # @(#)$HGid$ -set -eu +set -e VERSION="@@VERSION@@" @@ -26,6 +26,10 @@ privs MOUNTPOINT Adjust some Unix privileges to mounted jail datasets + + populate MOUNTPOINT BASETXZ + + Populate the jail directory in MOUNTPOINT with the base system in BASETXZ " @@ -117,6 +121,39 @@ # +# "populate" -- populate the datasets with content from a FreeBSD base.txz +# +# command_populate mountpoint basetxz +# +command_populate() { + # MOUNTPOINT -- base.txz + local _mp _basetxz + + _mp="$1" + _basetxz="$2" + + if [ -z "${_mp}" ]; then + echo "ERROR: no mountpoint given" >&2 + return 2 + fi + if [ -z "${_basetxz}" ]; then + echo "ERROR: no base.txz given" >&2 + return 2 + fi + if [ ! -d "${_mp}" ]; then + echo "ERROR: mountpoint \`${_mp}' does not exist" >&2 + return 1 + fi + if [ ! -r "${_basetxz}" ]; then + echo "ERROR: file \`${_basetxz}' is not readable" >&2 + return 1 + fi + + tar -C "${_mp}" --exclude=./var/empty -xJp -f "${_basetxz}" || { echo "ERROR: tar encountered errors" >&2; return 1; } +} + + +# # "privs" -- adjust privileges # # To be used when all ZFS datasets are mounted. @@ -174,8 +211,11 @@ privs) command_privs "$@" ;; + populate) + command_populate "$@" + ;; *) - echo "ERROR" >&2 + echo "ERROR: unknown command \`${command}'" >&2 exit 2 ;; esac