Cosmetics.
This commit is contained in:
parent
7e4d3e1901
commit
c1618f230d
94
ezjail-admin
94
ezjail-admin
@ -35,8 +35,7 @@ case "$1" in
|
|||||||
######################## ezjail-admin CREATE ########################
|
######################## ezjail-admin CREATE ########################
|
||||||
create)
|
create)
|
||||||
shift
|
shift
|
||||||
args=`getopt xf:r: $*`
|
args=`getopt xf:r: $*` || exerr "Usage: `basename -- $0` create [-f flavour] [-r jailroot] [-x] jailname jailip"
|
||||||
[ $? = 0 ] || exerr "Usage: `basename -- $0` create [-f flavour] [-r jailroot] [-x] jailname jailip"
|
|
||||||
|
|
||||||
newjail_root=
|
newjail_root=
|
||||||
newjail_flavour=
|
newjail_flavour=
|
||||||
@ -57,17 +56,16 @@ create)
|
|||||||
# we need at least a name and an ip for new jail
|
# we need at least a name and an ip for new jail
|
||||||
[ "${newjail_name}" -a "${newjail_ip}" -a $# = 2 ] || exerr "Usage: `basename -- $0` create [-f flavour] [-r jailroot] [-x] jailname jailip"
|
[ "${newjail_name}" -a "${newjail_ip}" -a $# = 2 ] || exerr "Usage: `basename -- $0` create [-f flavour] [-r jailroot] [-x] jailname jailip"
|
||||||
|
|
||||||
# check, whether ezjail-update has been called. existence of
|
# check, whether ezjail-update has been called. existence of
|
||||||
# ezjail_jailbase is our indicator
|
# ezjail_jailbase is our indicator
|
||||||
[ -d ${ezjail_jailbase} ] || exerr "Error: base jail does not exist. Please run 'ezjail-admin update' first."
|
[ -d ${ezjail_jailbase} ] || exerr "Error: base jail does not exist. Please run 'ezjail-admin update' first."
|
||||||
|
|
||||||
# relative paths don't make sense in rc.scripts
|
# relative paths don't make sense in rc.scripts
|
||||||
[ "${ezjail_jaildir#/}" = "${ezjail_jaildir}" ] && exerr "Error: Need an absolute path in ezjail_jaildir, it currently is set to: ${ezjail_jaildir}."
|
[ ${ezjail_jaildir%%[!/]*} ] && exerr "Error: Need an absolute path in ezjail_jaildir, it currently is set to: ${ezjail_jaildir}."
|
||||||
|
|
||||||
# jail names must not irritate file systems, excluding dots
|
# jail names must not irritate file systems, excluding dots from this list
|
||||||
# from this list was done intentionally to permit foo.com
|
# was done intentionally to permit foo.com style directory names, however,
|
||||||
# style directory names, however, the jail name will be
|
# the jail name will be foo_com in most scripts
|
||||||
# foo_com in most scripts
|
|
||||||
|
|
||||||
newjail_name=`echo -n ${newjail_name} | tr /~ __`
|
newjail_name=`echo -n ${newjail_name} | tr /~ __`
|
||||||
newjail_nname=`echo -n "${newjail_name}" | tr -c [:alnum:] _`
|
newjail_nname=`echo -n "${newjail_name}" | tr -c [:alnum:] _`
|
||||||
@ -77,24 +75,23 @@ create)
|
|||||||
# so check, whether we might be running into problems
|
# 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."
|
[ -e ${ezjail_jailcfgs}/${newjail_nname} ] && exerr "Error: an ezjail config already exists at ${ezjail_jailcfgs}/${newjail_nname}. Please rename the ezjail."
|
||||||
|
|
||||||
# if jail root specified on command line is not absolute,
|
# if jail root specified on command line is not absolute, make it absolute
|
||||||
# make it absolute inside our jail directory
|
# inside our jail directory
|
||||||
[ "${newjail_root#/}" = "${newjail_root}" ] && newjail_root=${ezjail_jaildir}/${newjail_root}
|
[ ${newjail_root%%[!/]*} ] && newjail_root=${ezjail_jaildir}/${newjail_root}
|
||||||
|
|
||||||
# if jail root specified on command line does not lie
|
# if jail root specified on command line does not lie within our jail
|
||||||
# within our jail directory, we need to create a softlink
|
# directory, we need to create a softlink
|
||||||
if [ "${newjail_root##${ezjail_jaildir}}" = "${newjail_root}" ]; then
|
if [ "${newjail_root##${ezjail_jaildir}}" = "${newjail_root}" ]; then
|
||||||
newjail_softlink=${ezjail_jaildir}/`basename -- ${newjail_root}`
|
newjail_softlink=${ezjail_jaildir}/`basename -- ${newjail_root}`
|
||||||
[ -e ${newjail_softlink} -a "${newjail_fill}" = "YES" ] && exerr "Error: an ezjail already exists at ${newjail_softlink}."
|
[ -e ${newjail_softlink} -a "${newjail_fill}" = "YES" ] && exerr "Error: an ezjail already exists at ${newjail_softlink}."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# do some sanity checks on the selected flavour (if any)
|
# do some sanity checks on the selected flavour (if any)
|
||||||
if [ ${newjail_flavour} ]; then
|
[ "${newjail_flavour}" -a ! -d ${ezjail_flavours}/${newjail_flavour} ] && exerr "Error: Flavour config directory ${ezjail_flavours}/${newjail_flavour} not found."
|
||||||
[ -d ${ezjail_flavours}/${newjail_flavour}/ ] || exerr "Error: Flavour config directory ${ezjail_flavours}/${newjail_flavour} not found."
|
|
||||||
fi
|
|
||||||
|
|
||||||
# All sanity checks that may lead to errors are hopefully
|
#
|
||||||
# passed here
|
# All sanity checks that may lead to errors are hopefully passed here
|
||||||
|
#
|
||||||
|
|
||||||
# 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
|
||||||
@ -106,12 +103,12 @@ create)
|
|||||||
# if a soft link is necessary, create it now
|
# if a soft link is necessary, create it now
|
||||||
[ ${newjail_softlink} ] && ln -s ${newjail_root} ${newjail_softlink}
|
[ ${newjail_softlink} ] && ln -s ${newjail_root} ${newjail_softlink}
|
||||||
|
|
||||||
# if the automount feature is not disabled, this
|
# if the automount feature is not disabled, this fstab entry for new jail
|
||||||
# fstab entry for new jail will be obeyed
|
# will be obeyed
|
||||||
echo ${ezjail_jailbase} ${newjail_root}/basejail nullfs ro 0 0 > /etc/fstab.${newjail_nname}
|
echo ${ezjail_jailbase} ${newjail_root}/basejail nullfs ro 0 0 > /etc/fstab.${newjail_nname}
|
||||||
|
|
||||||
# now, where everything seems to have gone right,
|
# now, where everything seems to have gone right, create control file in
|
||||||
# create control file in ezjails config dir
|
# ezjails config dir
|
||||||
mkdir -p ${ezjail_jailcfgs}
|
mkdir -p ${ezjail_jailcfgs}
|
||||||
echo export jail_${newjail_nname}_hostname=\"${newjail_name}\" > ${ezjail_jailcfgs}/${newjail_nname}
|
echo export jail_${newjail_nname}_hostname=\"${newjail_name}\" > ${ezjail_jailcfgs}/${newjail_nname}
|
||||||
echo export jail_${newjail_nname}_ip=\"${newjail_ip}\" >> ${ezjail_jailcfgs}/${newjail_nname}
|
echo export jail_${newjail_nname}_ip=\"${newjail_ip}\" >> ${ezjail_jailcfgs}/${newjail_nname}
|
||||||
@ -125,20 +122,19 @@ create)
|
|||||||
|
|
||||||
# Final steps for flavour installation
|
# Final steps for flavour installation
|
||||||
if [ ${newjail_flavour} ]; then
|
if [ ${newjail_flavour} ]; then
|
||||||
# install files, packages and config to new jail
|
# install files and config to new jail
|
||||||
# user creating, chown and package installation on jails startup
|
|
||||||
cd ${ezjail_flavours}/${newjail_flavour}
|
cd ${ezjail_flavours}/${newjail_flavour}
|
||||||
find * | cpio -p -v ${newjail_root} > /dev/null
|
find * | cpio -p -v ${newjail_root} > /dev/null
|
||||||
|
|
||||||
if [ -f ${ezjail_share}/ezjail.flavour ]; then
|
# If a config is found, make it auto run on jails startup
|
||||||
|
if [ -f ${newjail_root}/ezjail.flavour ]; then
|
||||||
ln -s /ezjail.flavour ${newjail_root}/etc/rc.d/ezjail-config.sh
|
ln -s /ezjail.flavour ${newjail_root}/etc/rc.d/ezjail-config.sh
|
||||||
chmod 0700 ${newjail_root}/etc/rc.d/ezjail-config.sh
|
chmod 0700 ${newjail_root}/etc/rc.d/ezjail-config.sh
|
||||||
echo "Note: Shell scripts installed, flavourizing on jails first startup."
|
echo "Note: Shell scripts installed, flavourizing on jails first startup."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# For user convenience, some scenarios commonly causing
|
# For user convenience some scenarios commonly causing headaches are checked
|
||||||
# headaches are checked
|
|
||||||
|
|
||||||
# check, whether IP is configured on a local interface, warn if it isnt
|
# check, whether IP is configured on a local interface, warn if it isnt
|
||||||
ping -c 1 -m 1 -t 1 -q ${newjail_ip} > /dev/null
|
ping -c 1 -m 1 -t 1 -q ${newjail_ip} > /dev/null
|
||||||
@ -157,9 +153,8 @@ create)
|
|||||||
######################## ezjail-admin DELETE ########################
|
######################## ezjail-admin DELETE ########################
|
||||||
delete)
|
delete)
|
||||||
shift
|
shift
|
||||||
args=`getopt w $*`
|
args=`getopt w $*` || exerr "Usage: `basename -- $0` delete [-w] jailname"
|
||||||
[ $? = 0 ] || exerr "Usage: `basename -- $0` delete [-w] jailname"
|
|
||||||
|
|
||||||
oldjail_wipe=
|
oldjail_wipe=
|
||||||
|
|
||||||
set -- ${args}
|
set -- ${args}
|
||||||
@ -180,19 +175,16 @@ delete)
|
|||||||
# check for existence of jail in our records
|
# check for existence of jail in our records
|
||||||
[ -f ${ezjail_jailcfgs}/${oldjail_nname} ] || exerr "Error: Nothing known about jail ${oldjail_name}."
|
[ -f ${ezjail_jailcfgs}/${oldjail_nname} ] || exerr "Error: Nothing known about jail ${oldjail_name}."
|
||||||
|
|
||||||
# fetch information about the jail to be gone
|
# fetch information about the jail to be gone by parsing our records
|
||||||
# by parsing our records
|
|
||||||
. ${ezjail_jailcfgs}/${oldjail_nname}
|
. ${ezjail_jailcfgs}/${oldjail_nname}
|
||||||
eval oldjail_rootdir=\"\$jail_${oldjail_nname}_rootdir\"
|
eval oldjail_rootdir=\"\$jail_${oldjail_nname}_rootdir\"
|
||||||
|
|
||||||
# if jail is still running, refuse to go any further
|
# if jail is still running, refuse to go any further
|
||||||
[ -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)."
|
[ -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)."
|
||||||
|
|
||||||
# now we know everything we need to let the jail be gone
|
# now we know everything we need to let the jail be gone remove entry
|
||||||
# remove entry from ezjail resource structure
|
# from ezjail resource structure, delete fstab.JAILNAME
|
||||||
rm -f ${ezjail_jailcfgs}/${oldjail_nname}
|
rm -f ${ezjail_jailcfgs}/${oldjail_nname}
|
||||||
|
|
||||||
# delete fstab.JAILNAME
|
|
||||||
rm -f /etc/fstab.${oldjail_nname}
|
rm -f /etc/fstab.${oldjail_nname}
|
||||||
|
|
||||||
# if there is a soft link pointing to the jail root, remove it
|
# if there is a soft link pointing to the jail root, remove it
|
||||||
@ -200,11 +192,11 @@ delete)
|
|||||||
[ -L ${oldjail_softlink} ] && rm ${oldjail_softlink}
|
[ -L ${oldjail_softlink} ] && rm ${oldjail_softlink}
|
||||||
|
|
||||||
# if wiping the jail was requested, remove it
|
# if wiping the jail was requested, remove it
|
||||||
[ "${oldjail_wipe}" = "YES" ] && rm -rf ${oldjail_rootdir}
|
[ ${oldjail_wipe} ] && rm -rf ${oldjail_rootdir}
|
||||||
|
|
||||||
;;
|
;;
|
||||||
######################## ezjail-admin LIST ########################
|
######################## ezjail-admin LIST ########################
|
||||||
list)
|
list)
|
||||||
jail_list=`ls ${ezjail_jailcfgs}`
|
jail_list=`ls ${ezjail_jailcfgs}`
|
||||||
for jail in ${jail_list}; do
|
for jail in ${jail_list}; do
|
||||||
. ${ezjail_jailcfgs}/${jail}
|
. ${ezjail_jailcfgs}/${jail}
|
||||||
@ -218,8 +210,7 @@ delete)
|
|||||||
######################## ezjail-admin UPDATE ########################
|
######################## ezjail-admin UPDATE ########################
|
||||||
setup|update)
|
setup|update)
|
||||||
shift
|
shift
|
||||||
args=`getopt ipPs: $*`
|
args=`getopt ipPs: $*` || exerr "Usage: `basename -- $0` update [-s sourcetree] [-i] [-pP]"
|
||||||
[ $? = 0 ] || exerr "Usage: `basename -- $0` update [-s sourcetree] [-i] [-pP]"
|
|
||||||
|
|
||||||
updatejail_installaction="world"
|
updatejail_installaction="world"
|
||||||
updatejail_provideports=
|
updatejail_provideports=
|
||||||
@ -236,7 +227,7 @@ setup|update)
|
|||||||
done
|
done
|
||||||
|
|
||||||
if [ "${updatejail_installaction}" = "none" ]; then
|
if [ "${updatejail_installaction}" = "none" ]; then
|
||||||
# check, whether ezjail-update has been called. existence of
|
# check, whether ezjail-update has been called. existence of
|
||||||
# ezjail_jailbase is our indicator
|
# ezjail_jailbase is our indicator
|
||||||
[ -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."
|
[ -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."
|
||||||
else
|
else
|
||||||
@ -244,18 +235,17 @@ setup|update)
|
|||||||
[ -d ${ezjail_sourcetree} ] || exerr "Cannot find your copy of the FreeBSD source tree in ${ezjail_sourcetree}."
|
[ -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)."
|
[ -e ${ezjail_sourcetree}/Makefile ] || exerr "Your source tree in ${ezjail_sourcetree} seems to be incomplete (Makefile missing)."
|
||||||
|
|
||||||
# Normally fulljail should be renamed by past ezjail-admin commands
|
# Normally fulljail should be renamed by past ezjail-admin commands.
|
||||||
# However those may have failed
|
# However those may have failed
|
||||||
rm -rf ${ezjail_jailfull}; mkdir -p ${ezjail_jailfull}
|
chflags -R noschg ${ezjail_jailfull}; rm -rf ${ezjail_jailfull};
|
||||||
|
mkdir -p ${ezjail_jailfull}
|
||||||
|
|
||||||
# make our world
|
# make our world
|
||||||
cd ${ezjail_sourcetree}
|
cd ${ezjail_sourcetree}
|
||||||
make ${updatejail_installaction} DESTDIR=${ezjail_jailfull}
|
make ${updatejail_installaction} DESTDIR=${ezjail_jailfull} || exerr "make ${updatejail_installaction} failed."
|
||||||
[ $? = 0 ] || exerr "make ${updatejail_installaction} failed."
|
|
||||||
|
|
||||||
# setup world
|
# setup world
|
||||||
make distribution DESTDIR=${ezjail_jailfull}
|
make distribution DESTDIR=${ezjail_jailfull} || exerr "make distribution failed."
|
||||||
[ $? = 0 ] || exerr "make distribution failed."
|
|
||||||
|
|
||||||
# Fill basejail from installed world
|
# Fill basejail from installed world
|
||||||
cd ${ezjail_jailfull}
|
cd ${ezjail_jailfull}
|
||||||
@ -263,8 +253,7 @@ setup|update)
|
|||||||
# directories with permission 0700 which is bad
|
# directories with permission 0700 which is bad
|
||||||
mkdir -p ${ezjail_jailbase}/usr
|
mkdir -p ${ezjail_jailbase}/usr
|
||||||
for dir in bin lib libexec sbin usr/bin usr/include usr/lib usr/libexec usr/sbin usr/src usr/share; do
|
for dir in bin lib libexec sbin usr/bin usr/include usr/lib usr/libexec usr/sbin usr/src usr/share; do
|
||||||
find ${dir} | cpio -d -p -v ${ezjail_jailbase}
|
find ${dir} | cpio -d -p -v ${ezjail_jailbase} || exerr "Installation of ${dir} failed."
|
||||||
[ $? = 0 ] || exerr "Installation of ${dir} failed."
|
|
||||||
chflags -R noschg ${dir}; rm -r ${dir}; ln -s /basejail/${dir} ${dir}
|
chflags -R noschg ${dir}; rm -r ${dir}; ln -s /basejail/${dir} ${dir}
|
||||||
done
|
done
|
||||||
mkdir basejail
|
mkdir basejail
|
||||||
@ -299,9 +288,10 @@ setup|update)
|
|||||||
[ $? = 0 ] || exerr "Updating ports failed."
|
[ $? = 0 ] || exerr "Updating ports failed."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# A ports collection inside jails is hardly useful w/o an appropriate /etc/make.conf
|
# A ports collection inside jails is hardly useful w/o an appropriate
|
||||||
# if we find basejail/usr/ports/Makefile, assume that the admin wants a working make.conf in new jails
|
# /etc/make.conf. If we find basejail/usr/ports/Makefile, assume that
|
||||||
# also a softlink to the ports in basejail is provided
|
# the admin wants a working make.conf in new jails also a softlink to
|
||||||
|
# the ports in basejail is provided
|
||||||
if [ -f ${ezjail_jailbase}/usr/ports/Makefile ]; then
|
if [ -f ${ezjail_jailbase}/usr/ports/Makefile ]; then
|
||||||
# no /usr/ports? link to /basejail/usr/ports
|
# no /usr/ports? link to /basejail/usr/ports
|
||||||
[ -e ${ezjail_jailtemplate}/usr/ports ] || ln -s /basejail/usr/ports ${ezjail_jailtemplate}/usr/ports
|
[ -e ${ezjail_jailtemplate}/usr/ports ] || ln -s /basejail/usr/ports ${ezjail_jailtemplate}/usr/ports
|
||||||
|
Loading…
x
Reference in New Issue
Block a user