HEADS UP: Common elements in update and install have been moved to a function. portsnap now is default way to maintain your copy of ports tree.
This commit is contained in:
parent
0377eb1c57
commit
93be17a3c0
165
ezjail-admin
165
ezjail-admin
@ -15,9 +15,10 @@ ezjail_jaildir=${ezjail_jaildir:-"/usr/jails"}
|
||||
ezjail_jailtemplate=${ezjail_jailtemplate:-"${ezjail_jaildir}/newjail"}
|
||||
ezjail_jailbase=${ezjail_jailbase:-"${ezjail_jaildir}/basejail"}
|
||||
ezjail_jailfull=${ezjail_jailfull:-"${ezjail_jaildir}/fulljail"}
|
||||
ezjail_jailtemp=${ezjail_jaildir:-"${ezjail_jaildir}/ezjailtemp"}
|
||||
ezjail_flavours=${ezjail_flavours:-"${ezjail_jaildir}/flavours"}
|
||||
ezjail_sourcetree=${ezjail_sourcetree:-"/usr/src"}
|
||||
ezjail_portscvsroot=${ezjail_portscvsroot:-":pserver:anoncvs@anoncvs.at.FreeBSD.org:/home/ncvs"}
|
||||
ezjail_sourcetree=${ezjail_sourcetree:-"/usr/src"}
|
||||
ezjail_uglyperlhack=${ezjail_uglyperlhack:-"YES"}
|
||||
|
||||
ezjail_mount_enable=${ezjail_mount_enable:-"YES"}
|
||||
@ -28,6 +29,10 @@ ezjail_fdescfs_enable=${ezjail_fdescfs_enable:-"YES"}
|
||||
|
||||
ezjail_dirlist="bin boot lib libexec rescue sbin usr/bin usr/games usr/include usr/lib usr/libdata usr/libexec usr/sbin usr/src usr/share"
|
||||
|
||||
################################
|
||||
# End of variable initialization
|
||||
#
|
||||
|
||||
# define our bail out shortcut
|
||||
exerr () { echo -e "$*"; exit 1; }
|
||||
|
||||
@ -66,6 +71,67 @@ fetchjailinfo () {
|
||||
ezjail_id=`jls | grep " ${ezjail_hostname} " | head -n 1 | awk {'print $1'}`
|
||||
}
|
||||
|
||||
# fill the base jail - this function is used by install and update
|
||||
ezjail_splitworld() {
|
||||
# Fill basejail from installed world
|
||||
cd ${ezjail_jailfull} || exerr "Cant access temporary Jail directory."
|
||||
|
||||
# This mkdir is important, since cpio will create intermediate
|
||||
# directories with permission 0700 which is bad
|
||||
mkdir -p ${ezjail_jailbase}/usr
|
||||
for dir in ${ezjail_dirlist}; do
|
||||
find ${dir} | cpio -d -p -v ${ezjail_jailbase} || exerr "Installation of ${dir} failed."
|
||||
chflags -R noschg ${dir}; rm -r ${dir}; ln -s /basejail/${dir} ${dir}
|
||||
done
|
||||
mkdir basejail
|
||||
|
||||
# Try to remove the old template jail
|
||||
[ -d ${ezjail_jailtemplate} ] && chflags -R noschg ${ezjail_jailtemplate} && rm -rf ${ezjail_jailtemplate}
|
||||
mv ${ezjail_jailfull} ${ezjail_jailtemplate}
|
||||
|
||||
# If the default flavour example has not yet been copied, do it now
|
||||
[ -d ${ezjail_flavours}/default ] || mkdir -p ${ezjail_flavours} && cp -p -R ${ezjail_examples}/default ${ezjail_flavours}
|
||||
|
||||
# A ports collection inside jails is hardly useful w/o an appropriate
|
||||
# /etc/make.conf. If we find basejail/usr/ports/Makefile, assume that
|
||||
# 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
|
||||
# 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
|
||||
fi
|
||||
|
||||
# The ugly perl hack[tm]. Note: we wont do such things for any given
|
||||
# port :(
|
||||
[ "${ezjail_uglyperlhack}" = "YES" -a ! -L ${ezjail_jailbase}/usr/bin/perl ] && ln -s /usr/local/bin/perl ${ezjail_jailbase}/usr/bin/perl
|
||||
}
|
||||
|
||||
# The user may want to have a ports tree in basejail
|
||||
ezjail_updateports () {
|
||||
# if /usr/ports/CVS exists, assume cvs up is safe
|
||||
# this is legacy
|
||||
if [ -f ${ezjail_jailbase}/usr/ports/CVS/Root ]; then
|
||||
echo -n "Updating ports from "; cat ${ezjail_jailbase}/usr/ports/CVS/Root
|
||||
echo "Warning: Upgrading legacy ports copy. Consider removing ${ezjail_jailbase}/usr/ports and use the new portsnap strategy instead."
|
||||
echo "Gathering local information may take a while."
|
||||
cd ${ezjail_jailbase}/usr/ports/ && cvs -d ${ezjail_portscvsroot} up -Pd
|
||||
else
|
||||
portsnap fetch
|
||||
[ -d ${ezjail_jailbase}/usr/ports ] && ezjail_portsnapaction=update
|
||||
portsnap ${ezjail_portsnapaction:-"extract"}
|
||||
fi
|
||||
[ $? = 0 ] || exerr "Updating ports failed."
|
||||
}
|
||||
|
||||
#############################
|
||||
# End of function definitions
|
||||
#
|
||||
|
||||
# check for command
|
||||
[ "$1" ] || exerr "Usage: `basename -- $0` [config|create|delete|install|list|update] {params}"
|
||||
|
||||
@ -326,7 +392,6 @@ setup|update)
|
||||
|
||||
# Clean variables, prevent polution
|
||||
unset ezjail_provideports
|
||||
|
||||
ezjail_installaction="world"
|
||||
|
||||
set -- ${args}
|
||||
@ -354,64 +419,15 @@ setup|update)
|
||||
[ -d "${ezjail_jailfull}" ] && chflags -R noschg ${ezjail_jailfull} && rm -rf ${ezjail_jailfull}
|
||||
mkdir -p ${ezjail_jailfull} || exerr "Cannot create temporary Jail directory."
|
||||
|
||||
# make our world
|
||||
# make and setup our world, then split basejail and newjail
|
||||
cd ${ezjail_sourcetree} && make ${ezjail_installaction} DESTDIR=${ezjail_jailfull} || exerr "make ${ezjail_installaction} failed."
|
||||
|
||||
# setup world
|
||||
cd ${ezjail_sourcetree}/etc && make distribution DESTDIR=${ezjail_jailfull} || exerr "make distribution failed."
|
||||
|
||||
# Fill basejail from installed world
|
||||
cd ${ezjail_jailfull} || exerr "Cant access temporary Jail directory."
|
||||
# This mkdir is important, since cpio will create intermediate
|
||||
# directories with permission 0700 which is bad
|
||||
mkdir -p ${ezjail_jailbase}/usr
|
||||
for dir in ${ezjail_dirlist}; do
|
||||
find ${dir} | cpio -d -p -v ${ezjail_jailbase} || exerr "Installation of ${dir} failed."
|
||||
chflags -R noschg ${dir}; rm -r ${dir}; ln -s /basejail/${dir} ${dir}
|
||||
done
|
||||
mkdir basejail
|
||||
|
||||
# Try to remove the old template jail
|
||||
[ -d ${ezjail_jailtemplate} ] && chflags -R noschg ${ezjail_jailtemplate} && rm -rf ${ezjail_jailtemplate}
|
||||
mv ${ezjail_jailfull} ${ezjail_jailtemplate}
|
||||
|
||||
# If the default flavour example has not yet been copied, do it now
|
||||
[ -d ${ezjail_flavours}/default ] || mkdir -p ${ezjail_flavours} && cp -p -R ${ezjail_examples}/default ${ezjail_flavours}
|
||||
ezjail_splitworld
|
||||
|
||||
fi # installaction="none"
|
||||
|
||||
# The user may want to have a ports tree in basejail
|
||||
if [ "${ezjail_provideports}" = "YES" ]; then
|
||||
# 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."
|
||||
cd ${ezjail_jailbase}/usr/ports/ && cvs -d ${ezjail_portscvsroot} up -Pd
|
||||
else
|
||||
echo "Checking out ports from ${ezjail_portscvsroot}"
|
||||
mkdir -p ${ezjail_jailbase}/usr/ports/
|
||||
cd ${ezjail_jailbase}/usr/ && cvs -d ${ezjail_portscvsroot} co ports
|
||||
fi
|
||||
[ $? = 0 ] || exerr "Updating ports failed."
|
||||
fi
|
||||
|
||||
# A ports collection inside jails is hardly useful w/o an appropriate
|
||||
# /etc/make.conf. If we find basejail/usr/ports/Makefile, assume that
|
||||
# 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
|
||||
# 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
|
||||
fi
|
||||
|
||||
# The ugly perl hack[tm]. Note: we wont do such things for any given
|
||||
# port :(
|
||||
[ "${ezjail_uglyperlhack}" = "YES" -a ! -L ${ezjail_jailbase}/usr/bin/perl ] && ln -s /usr/local/bin/perl ${ezjail_jailbase}/usr/bin/perl
|
||||
# Provide a copy of ports tree in basejail
|
||||
[ "${ezjail_provideports}" = "YES" ] && ezjail_updateports
|
||||
|
||||
;;
|
||||
######################## ezjail-admin INSTALL ########################
|
||||
@ -420,14 +436,14 @@ install)
|
||||
args=`getopt mpsh:r: $*` || exerr "Usage: `basename -- $0` install [-mps] [-h host] [-r release]"
|
||||
|
||||
# Clean variables, prevent polution
|
||||
unset ezjail_release ezjail_ftphost ezjail_installmanpages ezjail_installports ezjail_installsources ezjail_dir ezjail_reldir ezjail_temp
|
||||
unset ezjail_release ezjail_ftphost ezjail_installmanpages ezjail_installports ezjail_installsources ezjail_dir ezjail_reldir
|
||||
|
||||
set -- ${args}
|
||||
for arg do
|
||||
case ${arg} in
|
||||
-m) ezjail_installmanpages=" manpages"; shift;;
|
||||
-p) ezjail_installports=" ports"; shift;;
|
||||
-s) ezjail_installsources=" src"; shift;;
|
||||
-p) ezjail_installports="YES"; shift;;
|
||||
-h) ezjail_ftphost="$2"; shift 2;;
|
||||
-r) ezjail_release="$2"; shift 2;;
|
||||
--) shift; break;;
|
||||
@ -439,8 +455,6 @@ install)
|
||||
ezjail_ftphost=${ezjail_ftphost#ftp://}
|
||||
ezjail_dir=${ezjail_ftphost#file://}
|
||||
[ "${ezjail_dir%%[!/]*}" ] || ezjail_reldir=${PWD}
|
||||
# XXX
|
||||
ezjail_temp=${ezjail_jaildir}/ezjailtemp
|
||||
|
||||
# ftp servers normally wont provide CURRENT-builds
|
||||
if [ -z "${ezjail_release}" ]; then
|
||||
@ -459,15 +473,14 @@ install)
|
||||
mkdir -p ${ezjail_jailfull} || exerr "Cannot create temporary Jail directory."
|
||||
DESTDIR=${ezjail_jailfull}
|
||||
|
||||
# XXX
|
||||
rm -rf ${ezjail_temp}
|
||||
for pkg in base ${ezjail_installmanpages} ${ezjail_installports} ${ezjail_installsources}; do
|
||||
rm -rf ${ezjail_jailtemp}
|
||||
for pkg in base ${ezjail_installmanpages} ${ezjail_installsources}; do
|
||||
|
||||
# The first case means, that a remote host has been specified.
|
||||
if [ "${ezjail_dir}" = "${ezjail_ftphost}" ]; then
|
||||
# Create and try to access temp dir
|
||||
mkdir -p ${ezjail_temp} || exerr "Could not create temporary base jail directory ${ezjail_temp}."
|
||||
cd ${ezjail_temp} || exerr "Could not cd to ${ezjail_temp}."
|
||||
mkdir -p ${ezjail_jailtemp} || exerr "Could not create temporary base jail directory ${ezjail_jailtemp}."
|
||||
cd ${ezjail_jailtemp} || exerr "Could not cd to ${ezjail_jailtemp}."
|
||||
|
||||
# Try all paths as stolen from sysinstall, break on success.
|
||||
for ezjail_path in pub/FreeBSD/releases pub/FreeBSD/snapshot pub/FreeBSD releases snapshots NO; do
|
||||
@ -482,7 +495,7 @@ install)
|
||||
[ -f install.sh ] && yes | . install.sh
|
||||
# XXX error checking.
|
||||
|
||||
rm -rf ${ezjail_temp}
|
||||
rm -rf ${ezjail_jailtemp}
|
||||
else
|
||||
cd ${basejail_reldir}/${basejail_dir}/${pkg} || exerr "Could not cd to ${basejail_dir}."
|
||||
set -- all
|
||||
@ -490,25 +503,11 @@ install)
|
||||
fi
|
||||
done
|
||||
|
||||
# Fill basejail from installed world
|
||||
cd ${ezjail_jailfull} || exerr "Cant access temporary Jail directory."
|
||||
# This mkdir is important, since cpio will create intermediate
|
||||
# directories with permission 0700 which is bad
|
||||
mkdir -p ${ezjail_jailbase}/usr
|
||||
for dir in ${ezjail_dirlist}; do
|
||||
find ${dir} | cpio -d -p -v ${ezjail_jailbase} || exerr "Installation of ${dir} failed."
|
||||
chflags -R noschg ${dir}; rm -r ${dir}; ln -s /basejail/${dir} ${dir}
|
||||
done
|
||||
mkdir basejail
|
||||
# Split basejail and newjail
|
||||
ezjail_splitworld
|
||||
|
||||
# Try to remove the old template jail
|
||||
[ -d ${ezjail_jailtemplate} ] && chflags -R noschg ${ezjail_jailtemplate} && rm -rf ${ezjail_jailtemplate}
|
||||
mv ${ezjail_jailfull} ${ezjail_jailtemplate}
|
||||
|
||||
# If the default flavour example has not yet been copied, do it now
|
||||
[ -d ${ezjail_flavours}/default ] || mkdir -p ${ezjail_flavours} && cp -p -R ${ezjail_examples}/default ${ezjail_flavours}
|
||||
|
||||
# XXX ports stuff still missing
|
||||
# Fill ports, if requested
|
||||
[ "${ezjail_installports} = "YES" ] && ezjail_updateports
|
||||
|
||||
;;
|
||||
######################## ezjail-admin CONFIG ########################
|
||||
|
Loading…
x
Reference in New Issue
Block a user