This is a simple script I put together to automate the monotonous - and potentially dangerous - process of updating your jails to stay in sync with their host system. This is the
only purpose the script serves; it is not intended to be a comprehensive jail management utility (like ezjail, for example). Please use it only if you understand what it is doing. It performs a few basic sanity checks, but if you were to provide weird directory data to MYJAILS1 you could get into serious trouble.
As written, this script applies to FreeBSD 6.x and 7.0. It assumes:
- You've rebuilt world on the host system, as described in Chapter 23 The Cutting Edge.
- You haven't deleted files (i.e. cleanworld) from /usr/src on the host system after the successful build.
- You have installed the sysutils/cpdup port.
- You're running the script as root.
Code:
#!/bin/sh
# Author: anomie
# Date : 2008-09-06
# Please see copyright at bottom of script
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
# Initialize MYJAILS1 with your Jails!
# Do not use trailing slashes (/).
########################################
MYJAILS1="/usr/home/jail/10.5.5.101 \
/usr/home/jail/10.5.5.102 \
/usr/home/jail/10.5.5.103"
########################################
# Functions
chatter() {
echo ${MSG1}
echo '<Press Enter>'
read DUMMY1
echo ' ----------- '
echo 'Working...'
}
# Quick audit to make sure Jails are stopped.
JCHK1=$(jls)
if [ -n "${JCHK1}" ] ; then
echo 'Shut down all Jails and try again. Exiting...'
exit 1
fi
# Iterate through all Jails: first back each Jail up, then
# install world, then merge.
for I in ${MYJAILS1} ; do
if [ ! -e ${I} ] ; then
MSG1="Bad Jail directory ${I} - skipping..."
chatter
continue
fi
if [ -e ${I}.dup ] ; then
chflags -R 0 ${I}.dup
rm -rf ${I}.dup
fi
cpdup ${I} ${I}.dup
if [ $? -ne 0 ] ; then
MSG1="Problem backing up ${I} - skipping to next Jail..."
chatter
continue
fi
MSG1="Done backing up ${I}"
chatter
cd /usr/src && make installworld DESTDIR=${I}
if [ $? -ne 0 ] ; then
MSG1="installworld problem for ${I} - skipping to next Jail..."
chatter
continue
fi
MSG1="Done installing world for ${I}"
chatter
mergemaster -iU -D ${I}
if [ $? -ne 0 ] ; then
MSG1="merge problem for ${I} - skipping to next Jail..."
chatter
continue
fi
MSG1="Done merging files for ${I}"
chatter
done
echo 'Finished!'
exit 0
# ---------------------------------
# Copyright (c) 2008 anomie
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.