Last clean ups before merge to ezjail-admin
This commit is contained in:
parent
6628078be7
commit
761bf8e2e9
@ -46,7 +46,7 @@ case "$1" in
|
|||||||
######################## ezjail-admin CREATE ########################
|
######################## ezjail-admin CREATE ########################
|
||||||
create)
|
create)
|
||||||
shift
|
shift
|
||||||
args=`getopt xf:r:is:c $*` || exerr "Usage: `basename -- $0` create [-f flavour] [-r jailroot] [-i size] [-xc] jailname jailip"
|
args=`getopt f:r:s:xic $*` || exerr "Usage: `basename -- $0` create [-f flavour] [-r jailroot] [-s size] [-xic] jailname jailip"
|
||||||
|
|
||||||
newjail_root=
|
newjail_root=
|
||||||
newjail_flavour=
|
newjail_flavour=
|
||||||
@ -124,23 +124,43 @@ create)
|
|||||||
#
|
#
|
||||||
|
|
||||||
if [ "${newjail_image}" ]; then
|
if [ "${newjail_image}" ]; then
|
||||||
|
# Strip trailing slashes from jail root, those would confuse image path
|
||||||
newjail_img=${newjail_root%/}; while [ "${newjail_img}" -a -z "${newjail_img%%*/}" ]; do newjail_img=${newjail_img%/}; done
|
newjail_img=${newjail_root%/}; while [ "${newjail_img}" -a -z "${newjail_img%%*/}" ]; do newjail_img=${newjail_img%/}; done
|
||||||
[ -z "${newjail_img}" ] && exerr "Error: Could not determine image file name, something is wrong with the jail root: ${newjail_root}."
|
[ -z "${newjail_img}" ] && exerr "Error: Could not determine image file name, something is wrong with the jail root: ${newjail_root}."
|
||||||
|
|
||||||
|
# Location of our image and crypto image lock file
|
||||||
newjail_lock=${newjail_img}.lock
|
newjail_lock=${newjail_img}.lock
|
||||||
newjail_img=${newjail_img}.img
|
newjail_img=${newjail_img}.img
|
||||||
|
|
||||||
|
# If NOT exist, create image
|
||||||
if [ "$newjail_fill" = "YES" ]; then
|
if [ "$newjail_fill" = "YES" ]; then
|
||||||
[ -e "${newjail_img}" ] && exerr "Error: a file exists at the location ${newjail_img}, preventing our own image file to be created."
|
[ -e "${newjail_img}" ] && exerr "Error: a file exists at the location ${newjail_img}, preventing our own image file to be created."
|
||||||
|
[ "${newjail_image}" = "crypto" -a -e "${newjail_lock}" ] && exerr "Error: a file exists at the location ${newjail_lock}, preventing our own crypto image lock file to be created."
|
||||||
|
|
||||||
|
# Now create jail disc image
|
||||||
touch "${newjail_img}"
|
touch "${newjail_img}"
|
||||||
dd if=/dev/random of="${newjail_img}" bs="${newjail_imagesize}" count=1 || exerr "Error: Could not (or not fully) create the image file. You might want to check (and possibly remove) the file ${newjail_img}. The image size provided was ${newjail_imagesize}."
|
dd if=/dev/random of="${newjail_img}" bs="${newjail_imagesize}" count=1 || exerr "Error: Could not (or not fully) create the image file. You might want to check (and possibly remove) the file ${newjail_img}. The image size provided was ${newjail_imagesize}."
|
||||||
|
|
||||||
|
# And attach device
|
||||||
newjail_img_device=`mdconfig -a -t vnode -f ${newjail_img}`
|
newjail_img_device=`mdconfig -a -t vnode -f ${newjail_img}`
|
||||||
|
|
||||||
if [ "${newjail_image}" = "crypto" ]; then
|
if [ "${newjail_image}" = "crypto" ]; then
|
||||||
|
# Initialise crypto image
|
||||||
|
# XXX TODO: catch error and detach memory disc
|
||||||
|
echo "Initialising crypto device. Enter a new passphrase twice..."
|
||||||
gbde init /dev/${newjail_img_device} -L ${newjail_lock}
|
gbde init /dev/${newjail_img_device} -L ${newjail_lock}
|
||||||
|
|
||||||
|
# XXX TODO: catch error and detach memory disc
|
||||||
|
echo "Attaching crypto device. Enter the passphrase..."
|
||||||
gbde attach /dev/${newjail_img_device} -l ${newjail_lock}
|
gbde attach /dev/${newjail_img_device} -l ${newjail_lock}
|
||||||
newjail_device=${newjail_img_device}.bde
|
newjail_device=${newjail_img_device}.bde
|
||||||
else
|
else
|
||||||
newjail_device=${newjail_img_device}
|
newjail_device=${newjail_img_device}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Format memory image
|
||||||
newfs /dev/${newjail_device}
|
newfs /dev/${newjail_device}
|
||||||
|
# Create mount point and mount
|
||||||
mkdir -p ${newjail_root}
|
mkdir -p ${newjail_root}
|
||||||
mount /dev/${newjail_device} ${newjail_root}
|
mount /dev/${newjail_device} ${newjail_root}
|
||||||
else
|
else
|
||||||
@ -151,8 +171,7 @@ create)
|
|||||||
|
|
||||||
# now take a copy of our template jail
|
# now take a copy of our template jail
|
||||||
if [ "${newjail_fill}" = "YES" ]; then
|
if [ "${newjail_fill}" = "YES" ]; then
|
||||||
mkdir -p ${newjail_root} && cd ${ezjail_jailtemplate} && \
|
mkdir -p ${newjail_root} && cd ${ezjail_jailtemplate} && find * | cpio -p -v ${newjail_root} > /dev/null
|
||||||
find * | cpio -p -v ${newjail_root} > /dev/null
|
|
||||||
[ $? = 0 ] || detach_images || exerr "Error: Could not copy template jail."
|
[ $? = 0 ] || detach_images || exerr "Error: Could not copy template jail."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -178,7 +197,7 @@ create)
|
|||||||
echo export jail_${newjail_nname}_devfs_ruleset=\"devfsrules_jail\" >> ${ezjail_jailcfgs}/${newjail_nname}
|
echo export jail_${newjail_nname}_devfs_ruleset=\"devfsrules_jail\" >> ${ezjail_jailcfgs}/${newjail_nname}
|
||||||
echo export jail_${newjail_nname}_procfs_enable=\"${ezjail_procfs_enable}\" >> ${ezjail_jailcfgs}/${newjail_nname}
|
echo export jail_${newjail_nname}_procfs_enable=\"${ezjail_procfs_enable}\" >> ${ezjail_jailcfgs}/${newjail_nname}
|
||||||
echo export jail_${newjail_nname}_fdescfs_enable=\"${ezjail_fdescfs_enable}\" >> ${ezjail_jailcfgs}/${newjail_nname}
|
echo export jail_${newjail_nname}_fdescfs_enable=\"${ezjail_fdescfs_enable}\" >> ${ezjail_jailcfgs}/${newjail_nname}
|
||||||
[ "${newjail_imagesize}" ] && \
|
[ "${newjail_image}" ] && \
|
||||||
echo export jail_${newjail_nname}_image=\"${newjail_img}\" >> ${ezjail_jailcfgs}/${newjail_nname}
|
echo export jail_${newjail_nname}_image=\"${newjail_img}\" >> ${ezjail_jailcfgs}/${newjail_nname}
|
||||||
[ "${newjail_image}" = "crypto" ] && \
|
[ "${newjail_image}" = "crypto" ] && \
|
||||||
echo export jail_${newjail_nname}_cryptimage=\"YES\" >> ${ezjail_jailcfgs}/${newjail_nname}
|
echo export jail_${newjail_nname}_cryptimage=\"YES\" >> ${ezjail_jailcfgs}/${newjail_nname}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user