2005-09-03 15:42:28 +00:00
#!/bin/sh
# ugly: this variable is set during port install time
2005-09-22 18:15:14 +00:00
ezjail_prefix=EZJAIL_PREFIX
2005-11-14 20:33:11 +00:00
ezjail_etc=${ezjail_prefix}/etc
2005-11-17 12:28:39 +00:00
ezjail_share=${ezjail_prefix}/share/ezjail
2005-12-18 16:47:21 +00:00
ezjail_examples=${ezjail_prefix}/share/examples/ezjail
2005-11-14 20:33:11 +00:00
ezjail_jailcfgs=${ezjail_etc}/ezjail
2005-09-03 15:42:28 +00:00
2006-01-20 19:32:50 +00:00
# read user config
[ -f ${ezjail_etc}/ezjail.conf ] && . ${ezjail_etc}/ezjail.conf
2005-09-03 15:42:28 +00:00
2005-09-12 12:33:42 +00:00
# set defaults
ezjail_jaildir=${ezjail_jaildir:-"/usr/jails"}
2006-02-06 13:18:30 +00:00
ezjail_jailtemplate=${ezjail_jailtemplate:-"${ezjail_jaildir}/newjail"}
ezjail_jailbase=${ezjail_jailbase:-"${ezjail_jaildir}/basejail"}
ezjail_jailfull=${ezjail_jailfull:-"${ezjail_jaildir}/fulljail"}
ezjail_flavours=${ezjail_flavours:-"${ezjail_jaildir}/flavours"}
2005-09-12 12:33:42 +00:00
ezjail_sourcetree=${ezjail_sourcetree:-"/usr/src"}
2006-01-16 05:06:04 +00:00
ezjail_portscvsroot=${ezjail_portscvsroot:-":pserver:anoncvs@anoncvs.at.FreeBSD.org:/home/ncvs"}
2005-09-12 12:33:42 +00:00
ezjail_mount_enable=${ezjail_mount_enable:-"YES"}
ezjail_devfs_enable=${ezjail_devfs_enable:-"YES"}
ezjail_devfs_ruleset=${ezjail_devfs_ruleset:-"devfsrules_jail"}
ezjail_procfs_enable=${ezjail_procfs_enable:-"YES"}
ezjail_fdescfs_enable=${ezjail_fdescfs_enable:-"YES"}
2006-01-20 19:32:50 +00:00
# define our bail out shortcut
2006-02-08 10:56:35 +00:00
exerr () { echo -e "$*"; exit 1; }
2005-11-14 20:33:11 +00:00
2006-03-21 16:33:05 +00:00
# define detach strategy for image jails
detach_images () {
# unmount and detach memory disc
if [ "${newjail_img_device}" ]; then
2006-04-03 18:19:54 +00:00
umount ${newjail_root} > /dev/null
[ "${newjail_image}" = "crypto" ] && gbde detach /dev/${newjail_img_device} > /dev/null
mdconfig -d -u ${newjail_img_device} > /dev/null
2006-04-03 18:21:50 +00:00
[ "$1" = "success" ] || rm -f ${newjail_img}
2006-03-21 16:33:05 +00:00
fi
}
2005-09-12 12:33:42 +00:00
# check for command
2006-02-16 13:12:59 +00:00
[ "$1" ] || exerr "Usage: `basename -- $0` [create|delete|list|update] {params}"
2005-09-03 15:42:28 +00:00
case "$1" in
2005-11-14 20:33:11 +00:00
######################## ezjail-admin CREATE ########################
2005-09-03 15:42:28 +00:00
create)
2005-09-12 12:33:42 +00:00
shift
2006-03-21 16:33:05 +00:00
args=`getopt f:r:s:xic $*` || exerr "Usage: `basename -- $0` create [-f flavour] [-r jailroot] [-s size] [-xic] jailname jailip"
2005-09-12 12:33:42 +00:00
newjail_root=
2005-11-14 20:33:11 +00:00
newjail_flavour=
2005-09-14 15:22:57 +00:00
newjail_softlink=
2006-03-21 16:33:05 +00:00
newjail_image=
newjail_imagesize=
newjail_device=
2005-09-12 12:33:42 +00:00
newjail_fill="YES"
2006-02-06 02:29:42 +00:00
set -- ${args}
2005-09-22 11:45:47 +00:00
for arg do
2006-02-06 02:29:42 +00:00
case ${arg} in
2005-09-12 12:33:42 +00:00
-x) newjail_fill="NO"; shift;;
-r) newjail_root="$2"; shift 2;;
2005-11-14 20:33:11 +00:00
-f) newjail_flavour="$2"; shift 2;;
2006-03-21 16:33:05 +00:00
-i) newjail_image="simple"; shift;;
-s) newjail_imagesize="$2"; shift 2;;
-c) newjail_image="crypto"; shift;;
2005-09-12 12:33:42 +00:00
--) shift; break;;
esac
2006-02-06 13:18:30 +00:00
done
2006-03-21 16:33:05 +00:00
newjail_name=$1; newjail_ip=$2
2005-09-12 12:33:42 +00:00
2005-09-24 13:41:35 +00:00
# we need at least a name and an ip for new jail
2006-02-06 13:18:30 +00:00
[ "${newjail_name}" -a "${newjail_ip}" -a $# = 2 ] || exerr "Usage: `basename -- $0` create [-f flavour] [-r jailroot] [-x] jailname jailip"
2005-09-12 12:33:42 +00:00
2006-03-21 16:33:05 +00:00
# check for sanity of settings concerning the image feature
[ "${newjail_image}" -a "$newjail_fill" = "YES" -a ! "${newjail_imagesize}" ] && exerr "Image jails need an image size."
2006-03-12 23:27:45 +00:00
# check, whether ezjail-update has been called. existence of
2005-10-21 20:42:53 +00:00
# ezjail_jailbase is our indicator
2006-01-20 19:32:50 +00:00
[ -d ${ezjail_jailbase} ] || exerr "Error: base jail does not exist. Please run 'ezjail-admin update' first."
2005-10-21 20:42:53 +00:00
2005-09-14 15:22:57 +00:00
# relative paths don't make sense in rc.scripts
2006-02-16 13:12:59 +00:00
[ "${ezjail_jaildir%%[!/]*}" ] || exerr "Error: Need an absolute path in ezjail_jaildir, it currently is set to: ${ezjail_jaildir}."
2006-01-20 19:32:50 +00:00
2006-02-09 16:43:24 +00:00
# jail names must not irritate file systems, excluding dots from this list
# was done intentionally to permit foo.com style directory names, however,
# the jail name will be foo_com in most scripts
2006-02-01 19:54:26 +00:00
newjail_name=`echo -n ${newjail_name} | tr /~ __`
2006-02-02 22:55:33 +00:00
newjail_nname=`echo -n "${newjail_name}" | tr -c [:alnum:] _`
2005-11-17 12:36:49 +00:00
newjail_root=${newjail_root:-"${ezjail_jaildir}/${newjail_name}"}
2005-09-14 15:22:57 +00:00
2006-03-06 18:24:50 +00:00
# This scenario really will only lead to real troubles in the 'fulljail'
# case, but I should still explain this to the user and not claim that
# "an ezjail would already exist"
[ "${newjail_nname}" = "basejail" -o "${newjail_nname}" = "newjail" -o "${newjail_nname}" = "fulljail" -o "${newjail_nname}" = "flavours" ] && \
exerr "Error: ezjail needs the ${newjail_nname} directory for its own administrative purposes. Please rename the ezjail."
2006-02-02 22:55:33 +00:00
# jail names may lead to identical configs, eg. foo.bar.com == foo-bar.com
# so check, whether we might be running into problems
[ -e ${ezjail_jailcfgs}/${newjail_nname} ] && exerr "Error: an ezjail config already exists at ${ezjail_jailcfgs}/${newjail_nname}. Please rename the ezjail."
2006-02-09 16:43:24 +00:00
# if jail root specified on command line is not absolute, make it absolute
# inside our jail directory
2006-02-16 13:12:59 +00:00
[ "${newjail_root%%[!/]*}" ] || newjail_root=${ezjail_jaildir}/${newjail_root}
2005-09-14 15:22:57 +00:00
2006-03-12 23:27:45 +00:00
# if a directory at the specified jail root already exists, refuse to
2006-02-15 14:36:55 +00:00
# install
2006-03-03 14:04:19 +00:00
[ -e ${newjail_root} -a "${newjail_fill}" = "YES" ] && exerr "Error: the specified jail root ${newjail_root} alread exists."
2006-02-15 14:36:55 +00:00
2006-03-12 23:27:45 +00:00
# if jail root specified on command line does not lie within our jail
2006-02-09 16:43:24 +00:00
# directory, we need to create a softlink
2006-02-06 02:42:22 +00:00
if [ "${newjail_root##${ezjail_jaildir}}" = "${newjail_root}" ]; then
2006-02-06 13:18:30 +00:00
newjail_softlink=${ezjail_jaildir}/`basename -- ${newjail_root}`
[ -e ${newjail_softlink} -a "${newjail_fill}" = "YES" ] && exerr "Error: an ezjail already exists at ${newjail_softlink}."
2005-11-14 20:33:11 +00:00
fi
# do some sanity checks on the selected flavour (if any)
2006-02-09 16:43:24 +00:00
[ "${newjail_flavour}" -a ! -d ${ezjail_flavours}/${newjail_flavour} ] && exerr "Error: Flavour config directory ${ezjail_flavours}/${newjail_flavour} not found."
2005-09-14 15:22:57 +00:00
2006-02-09 16:43:24 +00:00
#
# All sanity checks that may lead to errors are hopefully passed here
#
2006-01-20 19:32:50 +00:00
2006-03-21 16:33:05 +00:00
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
[ -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_img=${newjail_img}.img
# If NOT exist, create image
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."
[ "${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}"
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}`
2006-04-03 18:19:54 +00:00
[ $? = 0 ] || detach_images || exerr "Error: Could not attach image device. (Command failed was 'mdconfig -a -t vnode -f ${newjail_img}')"
2006-03-21 16:33:05 +00:00
if [ "${newjail_image}" = "crypto" ]; then
# Initialise crypto image
echo "Initialising crypto device. Enter a new passphrase twice..."
2006-04-03 18:19:54 +00:00
gbde init /dev/${newjail_img_device} -L ${newjail_lock} || detach_images || exerr "Error: Could not initialise crypto image."
2006-03-21 16:33:05 +00:00
echo "Attaching crypto device. Enter the passphrase..."
2006-04-03 18:19:54 +00:00
gbde attach /dev/${newjail_img_device} -l ${newjail_lock} || detach_images || exerr "Error: Could not attach crypto image."
2006-03-21 16:33:05 +00:00
newjail_device=${newjail_img_device}.bde
else
newjail_device=${newjail_img_device}
fi
# Format memory image
2006-04-03 18:19:54 +00:00
newfs /dev/${newjail_device} || detach_images || exerr "Error: Could not newfs ${newjail_img_device}."
2006-03-21 16:33:05 +00:00
# Create mount point and mount
2006-04-03 18:19:54 +00:00
mkdir -p ${newjail_root} || detach_images || exerr "Error: Could not create jail root mount point ${newjail_root}."
mount /dev/${newjail_device} ${newjail_root} || detach_images || exerr "Error: Could not mount ${newjail_device} to ${newjail_root}."
2006-03-21 16:33:05 +00:00
else
[ -e ${newjail_root} -a ! -d ${newjail_root} ] && exerr "Error: Could not create mount point for your jail image. A file exists at its location. (For existing image jails, call this tool without the .img suffix when specifying jail root.)"
[ -d ${newjail_root} ] || mkdir -p ${newjail_root}
fi
fi
2005-09-14 15:22:57 +00:00
# now take a copy of our template jail
2006-02-06 02:29:42 +00:00
if [ "${newjail_fill}" = "YES" ]; then
2006-03-21 16:33:05 +00:00
mkdir -p ${newjail_root} && cd ${ezjail_jailtemplate} && find * | cpio -p -v ${newjail_root} > /dev/null
[ $? = 0 ] || detach_images || exerr "Error: Could not copy template jail."
2005-09-14 15:22:57 +00:00
fi
# if a soft link is necessary, create it now
2006-03-21 16:33:05 +00:00
[ "${newjail_softlink}" ] && ln -s ${newjail_root} ${newjail_softlink}
2005-09-12 12:33:42 +00:00
2006-02-09 16:43:24 +00:00
# if the automount feature is not disabled, this fstab entry for new jail
# will be obeyed
2006-03-21 16:33:05 +00:00
echo -n > /etc/fstab.${newjail_nname}
[ "${newjail_image}" ] && \
echo ${newjail_root}.device ${newjail_root} ufs rw 0 0 >> /etc/fstab.${newjail_nname}
echo ${ezjail_jailbase} ${newjail_root}/basejail nullfs ro 0 0 >> /etc/fstab.${newjail_nname}
2005-09-14 15:22:57 +00:00
2006-03-21 16:33:05 +00:00
# now, where everything seems to have gone right, create control file in
2006-02-09 16:43:24 +00:00
# ezjails config dir
2006-01-20 19:32:50 +00:00
mkdir -p ${ezjail_jailcfgs}
2006-04-01 17:07:33 +00:00
echo "# To specify the start up order of your ezjails, use these lines to" > ${ezjail_jailcfgs}/${newjail_nname}
echo "# create a Jail dependency tree. See rcorder(8) for more details." >> ${ezjail_jailcfgs}/${newjail_nname}
2006-04-01 18:46:43 +00:00
echo -e "#\n# PROVIDE: \n# REQUIRE: \n# BEFORE: \n#\n" >> ${ezjail_jailcfgs}/${newjail_nname}
2006-04-01 17:07:33 +00:00
echo export jail_${newjail_nname}_hostname=\"${newjail_name}\" >> ${ezjail_jailcfgs}/${newjail_nname}
2006-03-21 16:33:05 +00:00
echo export jail_${newjail_nname}_ip=\"${newjail_ip}\" >> ${ezjail_jailcfgs}/${newjail_nname}
echo export jail_${newjail_nname}_rootdir=\"${newjail_root}\" >> ${ezjail_jailcfgs}/${newjail_nname}
echo export jail_${newjail_nname}_exec=\"/bin/sh /etc/rc\" >> ${ezjail_jailcfgs}/${newjail_nname}
echo export jail_${newjail_nname}_mount_enable=\"${ezjail_mount_enable}\" >> ${ezjail_jailcfgs}/${newjail_nname}
echo export jail_${newjail_nname}_devfs_enable=\"${ezjail_devfs_enable}\" >> ${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}
2005-09-22 11:45:47 +00:00
echo export jail_${newjail_nname}_fdescfs_enable=\"${ezjail_fdescfs_enable}\" >> ${ezjail_jailcfgs}/${newjail_nname}
2006-03-21 16:33:05 +00:00
[ "${newjail_image}" ] && \
echo export jail_${newjail_nname}_image=\"${newjail_img}\" >> ${ezjail_jailcfgs}/${newjail_nname}
[ "${newjail_image}" = "crypto" ] && \
echo export jail_${newjail_nname}_cryptimage=\"YES\" >> ${ezjail_jailcfgs}/${newjail_nname}
2005-09-12 12:33:42 +00:00
2006-03-21 16:33:05 +00:00
# Final steps for flavour installation
if [ "${newjail_fill}" = "YES" -a "${newjail_flavour}" ]; then
2006-02-09 16:43:24 +00:00
# install files and config to new jail
2006-03-03 14:04:19 +00:00
cd ${ezjail_flavours}/${newjail_flavour} && find * | cpio -p -v ${newjail_root} > /dev/null
[ $? = 0 ] || echo "Warning: Could not fully install flavour."
2005-12-31 16:40:36 +00:00
2006-02-09 16:43:24 +00:00
# If a config is found, make it auto run on jails startup
if [ -f ${newjail_root}/ezjail.flavour ]; then
2006-02-09 00:44:49 +00:00
ln -s /ezjail.flavour ${newjail_root}/etc/rc.d/ezjail-config.sh
2006-02-09 18:21:49 +00:00
chmod 0700 ${newjail_root}/ezjail.flavour
2006-02-09 00:44:49 +00:00
echo "Note: Shell scripts installed, flavourizing on jails first startup."
fi
2005-12-31 16:40:36 +00:00
fi
2006-03-21 16:33:05 +00:00
# Detach (crypto and) memory discs
2006-04-03 18:19:54 +00:00
detach_images success
2006-03-21 16:33:05 +00:00
2006-02-10 16:05:58 +00:00
#
2006-02-09 16:43:24 +00:00
# For user convenience some scenarios commonly causing headaches are checked
2006-02-10 16:05:58 +00:00
#
2006-01-20 19:32:50 +00:00
2005-11-19 04:27:56 +00:00
# check, whether IP is configured on a local interface, warn if it isnt
2006-01-20 19:32:50 +00:00
ping -c 1 -m 1 -t 1 -q ${newjail_ip} > /dev/null
[ $? = 0 ] || echo "Warning: IP ${newjail_ip} not configured on a local interface."
2005-11-19 04:27:56 +00:00
# check, whether some host system services do listen on the Jails IP
2006-02-06 02:29:42 +00:00
TIFS=${IFS}; IFS=_
2006-01-20 19:32:50 +00:00
newjail_listener=`sockstat -4 -l | grep ${newjail_ip}:[[:digit:]]`
2006-02-08 10:56:35 +00:00
[ $? = 0 ] && echo -e "Warning: Some services already seem to be listening on IP ${newjail_ip}\n This may cause some confusion, here they are:\n${newjail_listener}"
2005-11-19 04:27:56 +00:00
newjail_listener=`sockstat -4 -l | grep \*:[[:digit:]]`
2006-02-08 11:05:51 +00:00
[ $? = 0 ] && echo -e "Warning: Some services already seem to be listening on all IP, (including ${newjail_ip})\n This may cause some confusion, here they are:\n${newjail_listener}"
2006-02-06 02:29:42 +00:00
IFS=${TIFS}
2006-03-21 16:33:05 +00:00
2005-09-03 15:42:28 +00:00
;;
2005-11-14 20:33:11 +00:00
######################## ezjail-admin DELETE ########################
2005-12-18 16:47:21 +00:00
delete)
2005-09-24 13:41:35 +00:00
shift
2006-02-09 16:43:24 +00:00
args=`getopt w $*` || exerr "Usage: `basename -- $0` delete [-w] jailname"
2006-01-20 19:32:50 +00:00
oldjail_wipe=
2006-02-06 02:29:42 +00:00
set -- ${args}
2005-09-24 13:41:35 +00:00
for arg do
2006-02-06 02:29:42 +00:00
case ${arg} in
2005-09-24 13:41:35 +00:00
-w) oldjail_wipe="YES"; shift;;
--) shift; break;;
esac
2006-02-06 13:18:30 +00:00
done
oldjail_name=$1
2005-09-24 13:41:35 +00:00
# we only need name of jail to vanish
2006-02-06 13:18:30 +00:00
[ "${oldjail_name}" -a $# = 1 ] || exerr "Usage: `basename -- $0` delete [-w] jailname"
2005-09-24 13:41:35 +00:00
2005-09-25 11:57:21 +00:00
# tidy up jail name the ezjail way
2006-02-06 02:42:22 +00:00
oldjail_nname=`echo -n ${oldjail_name} | tr -c [:alnum:] _`
2005-09-25 11:57:21 +00:00
2005-09-24 13:41:35 +00:00
# check for existence of jail in our records
2006-01-20 19:32:50 +00:00
[ -f ${ezjail_jailcfgs}/${oldjail_nname} ] || exerr "Error: Nothing known about jail ${oldjail_name}."
2005-09-24 13:41:35 +00:00
2006-02-09 16:43:24 +00:00
# fetch information about the jail to be gone by parsing our records
2005-09-25 11:57:21 +00:00
. ${ezjail_jailcfgs}/${oldjail_nname}
2005-09-25 12:52:04 +00:00
eval oldjail_rootdir=\"\$jail_${oldjail_nname}_rootdir\"
2006-03-21 16:33:05 +00:00
eval oldjail_image=\"\$jail_${oldjail_nname}_image\"
2005-09-25 11:57:21 +00:00
2005-11-09 01:24:59 +00:00
# if jail is still running, refuse to go any further
2006-02-08 11:05:51 +00:00
[ -f /var/run/jail_${oldjail_nname}.id ] && exerr "Error: Jail appears to be still running, stop it first.\n(/var/run/jail_${oldjail_nname}.id exists)."
2005-11-09 01:24:59 +00:00
2006-03-12 23:27:45 +00:00
# now we know everything we need to let the jail be gone remove entry
2006-02-09 16:43:24 +00:00
# from ezjail resource structure, delete fstab.JAILNAME
2005-09-25 12:52:04 +00:00
rm -f ${ezjail_jailcfgs}/${oldjail_nname}
2006-01-20 19:32:50 +00:00
rm -f /etc/fstab.${oldjail_nname}
2005-09-25 11:57:21 +00:00
# if there is a soft link pointing to the jail root, remove it
2006-01-20 19:32:50 +00:00
oldjail_softlink=${ezjail_jaildir}/`basename ${oldjail_rootdir}`
[ -L ${oldjail_softlink} ] && rm ${oldjail_softlink}
2005-09-25 11:57:21 +00:00
# if wiping the jail was requested, remove it
2006-03-21 16:33:05 +00:00
if [ "${oldjail_wipe}" ]; then
[ "${oldjail_image}" ] && rm -f ${oldjail_image} ${oldjail_image%.img}.lock ${oldjail_image%.img}.device
rm -rf ${oldjail_rootdir}
fi
2005-09-03 15:42:28 +00:00
;;
2005-11-14 20:33:11 +00:00
######################## ezjail-admin LIST ########################
2006-02-09 16:43:24 +00:00
list)
2006-04-01 18:27:52 +00:00
ezjail_list=${ezjail_list:-`rcorder ${ezjail_prefix}/etc/ezjail/*`}
ezjail_list=`basename -a ${ezjail_list}`
for jail in ${ezjail_list}; do
2006-01-20 19:32:50 +00:00
. ${ezjail_jailcfgs}/${jail}
2005-09-27 13:39:30 +00:00
eval jail_ip=\"\$jail_${jail}_ip\"
eval jail_hostname=\"\$jail_${jail}_hostname\"
eval jail_rootdir=\"\$jail_${jail}_rootdir\"
2006-01-20 19:32:50 +00:00
printf "%-15s %-28s %s\\n" ${jail_ip} ${jail_hostname} ${jail_rootdir}
2005-09-22 18:14:43 +00:00
done
2005-11-17 00:30:15 +00:00
2005-09-03 15:42:28 +00:00
;;
2005-11-14 20:33:11 +00:00
######################## ezjail-admin UPDATE ########################
2005-12-18 16:47:21 +00:00
setup|update)
2005-09-20 22:30:40 +00:00
shift
2006-02-09 16:43:24 +00:00
args=`getopt ipPs: $*` || exerr "Usage: `basename -- $0` update [-s sourcetree] [-i] [-pP]"
2005-09-20 22:30:40 +00:00
2005-09-22 11:45:47 +00:00
updatejail_installaction="world"
2006-01-16 05:06:04 +00:00
updatejail_provideports=
2005-09-20 22:30:40 +00:00
2006-02-06 02:29:42 +00:00
set -- ${args}
2005-09-22 11:45:47 +00:00
for arg do
2006-02-06 02:29:42 +00:00
case ${arg} in
2005-09-22 11:45:47 +00:00
-i) updatejail_installaction="installworld"; shift;;
2005-09-20 22:30:40 +00:00
-s) ezjail_sourcetree="$2"; shift 2;;
2006-01-16 05:06:04 +00:00
-p) updatejail_provideports="YES"; shift;;
-P) updatejail_provideports="YES"; updatejail_installaction="none"; shift;;
2005-09-20 22:30:40 +00:00
--) shift; break;;
esac
2006-02-06 13:18:30 +00:00
done
2005-09-03 15:42:28 +00:00
2006-02-06 02:42:22 +00:00
if [ "${updatejail_installaction}" = "none" ]; then
2006-03-12 23:27:45 +00:00
# check, whether ezjail-update has been called. existence of
2006-01-16 05:06:04 +00:00
# ezjail_jailbase is our indicator
2006-01-20 19:32:50 +00:00
[ -d ${ezjail_jailbase} ] || exerr "Error: base jail does not exist. You cannot fill base jails ports tree before creating it. Please run 'ezjail-admin update' first."
2006-01-16 05:06:04 +00:00
else
# Bump the user for some of the most common errors
2006-01-20 19:32:50 +00:00
[ -d ${ezjail_sourcetree} ] || exerr "Cannot find your copy of the FreeBSD source tree in ${ezjail_sourcetree}."
[ -e ${ezjail_sourcetree}/Makefile ] || exerr "Your source tree in ${ezjail_sourcetree} seems to be incomplete (Makefile missing)."
2006-01-16 05:06:04 +00:00
2006-02-09 16:43:24 +00:00
# Normally fulljail should be renamed by past ezjail-admin commands.
2006-01-16 05:06:04 +00:00
# However those may have failed
2006-03-03 14:04:19 +00:00
[ -d "${ezjail_jailfull}" ] && chflags -R noschg ${ezjail_jailfull} && rm -rf ${ezjail_jailfull}
mkdir -p ${ezjail_jailfull} || exerr "Cannot create temporary Jail directory."
2006-01-16 05:06:04 +00:00
# make our world
2006-03-03 14:04:19 +00:00
cd ${ezjail_sourcetree} && make ${updatejail_installaction} DESTDIR=${ezjail_jailfull} || exerr "make ${updatejail_installaction} failed."
2006-01-16 05:06:04 +00:00
# setup world
2006-03-03 14:04:19 +00:00
cd ${ezjail_sourcetree}/etc && make distribution DESTDIR=${ezjail_jailfull} || exerr "make distribution failed."
2006-01-16 05:06:04 +00:00
# Fill basejail from installed world
2006-03-03 14:04:19 +00:00
cd ${ezjail_jailfull} || exerr "Cant access temporary Jail directory."
2006-02-06 13:18:30 +00:00
# This mkdir is important, since cpio will create intermediate
2006-02-06 02:29:42 +00:00
# directories with permission 0700 which is bad
2006-01-20 19:32:50 +00:00
mkdir -p ${ezjail_jailbase}/usr
2006-03-15 12:47:56 +00:00
for dir in bin boot lib libexec rescue sbin usr/bin usr/games usr/include usr/lib usr/libdata usr/libexec usr/sbin usr/src usr/share; do
2006-02-09 16:43:24 +00:00
find ${dir} | cpio -d -p -v ${ezjail_jailbase} || exerr "Installation of ${dir} failed."
2006-02-06 02:29:42 +00:00
chflags -R noschg ${dir}; rm -r ${dir}; ln -s /basejail/${dir} ${dir}
2006-01-16 05:06:04 +00:00
done
mkdir basejail
2006-02-06 02:29:42 +00:00
# Try to remove the old template jail
2006-03-03 14:04:19 +00:00
[ -d ${ezjail_template} ] && chflags -R noschg ${ezjail_jailtemplate} && rm -rf ${ezjail_jailtemplate}
2006-01-16 05:06:04 +00:00
mv ${ezjail_jailfull} ${ezjail_jailtemplate}
# If the default flavour example has not yet been copied, do it now
2006-02-09 18:11:06 +00:00
[ -d ${ezjail_flavours}/default ] || mkdir -p ${ezjail_flavours} && cp -p -R ${ezjail_examples}/default ${ezjail_flavours}
2006-01-16 05:06:04 +00:00
fi # installaction="none"
# The user may want to have a ports tree in basejail
2006-02-06 02:29:42 +00:00
if [ "${updatejail_provideports}" = "YES" ]; then
2006-01-16 05:06:04 +00:00
# if /usr/ports/CVS exists, assume cvs up is safe
if [ -f ${ezjail_jailbase}/usr/ports/CVS/Root ]; then
echo -n "Updating ports from "; cat ${ezjail_jailbase}/usr/ports/CVS/Root
echo "Gathering local information may take a while."
2006-03-03 14:04:19 +00:00
cd ${ezjail_jailbase}/usr/ports/ && cvs -d ${ezjail_portscvsroot} up -Pd
2006-01-16 05:06:04 +00:00
else
echo "Checking out ports from ${ezjail_portscvsroot}"
mkdir -p ${ezjail_jailbase}/usr/ports/
2006-03-03 14:04:19 +00:00
cd ${ezjail_jailbase}/usr/ && cvs -d ${ezjail_portscvsroot} co ports
2006-01-16 05:06:04 +00:00
fi
[ $? = 0 ] || exerr "Updating ports failed."
2005-09-03 15:42:28 +00:00
fi
2006-02-09 16:43:24 +00:00
# A ports collection inside jails is hardly useful w/o an appropriate
# /etc/make.conf. If we find basejail/usr/ports/Makefile, assume that
2006-03-12 23:27:45 +00:00
# the admin wants a working make.conf in new jails also a softlink to
2006-02-09 16:43:24 +00:00
# the ports in basejail is provided
2006-01-20 19:32:50 +00:00
if [ -f ${ezjail_jailbase}/usr/ports/Makefile ]; then
# no /usr/ports? link to /basejail/usr/ports
[ -e ${ezjail_jailtemplate}/usr/ports ] || ln -s /basejail/usr/ports ${ezjail_jailtemplate}/usr/ports
if [ -f ${ezjail_examples}/default/etc/make.conf -a ! -f ${ezjail_jailtemplate}/etc/make.conf ]; then
cp -p ${ezjail_examples}/default/etc/make.conf ${ezjail_jailtemplate}/etc/
echo "Note: a non-standard /etc/make.conf was copied to the template jail in order to get the ports collection running inside jails."
fi
2006-01-16 05:06:04 +00:00
fi
2005-12-18 16:47:21 +00:00
2005-09-05 02:51:02 +00:00
;;
*)
2006-02-06 13:18:30 +00:00
exerr "Usage: `basename -- $0` [create|delete|list|update] {params}"
2005-09-03 15:42:28 +00:00
;;
esac