Multiple bugfixes

fixed remote copy command
fixed problem with code-remote when jail_enable wasn't in rc.conf
fixed problem with code-remote when jail_list wasn't in rc.conf
added check to see if /etc/devfs.rules exists before trying to use it
added dependency on __directory/usr/jail
This commit is contained in:
Jake Guffey 2012-04-11 14:53:28 -04:00
parent f5437ccce6
commit 847fc9d8c1
3 changed files with 59 additions and 8 deletions

View file

@ -29,6 +29,6 @@ jailbase="/usr/jail/jailbase.tgz"
basepresent="$(cat "$__object/explorer/basepresent")" basepresent="$(cat "$__object/explorer/basepresent")"
if [ "$basepresent" = "NONE" ]; then if [ "$basepresent" = "NONE" ]; then
echo "$__remote_copy" "$__object/files/jailbase.tgz" "${target_host}:${jailbase}" echo "$__remote_copy" "$__type/files/jailbase.tgz" "$__target_host:${jailbase}"
fi fi

View file

@ -212,6 +212,16 @@ EOF
# Add the jail_$name_* lines to rc.conf # Add the jail_$name_* lines to rc.conf
cat <<EOF cat <<EOF
# first check to see whether jail_enable="YES" exists in rc.conf or not and add it
# if necessary
jail_enable="\$(grep '^jail_enable=' /etc/rc.conf | cut -d= -f2)"
if [ -z "\$jail_enable" ]; then # no jail_enable line in rc.conf at all
echo "jail_enable=\"YES\"" >>/etc/rc.conf
elif [ ! "\$(echo \$jail_enable | tr '[a-z]' '[A-Z]')" = "YES" ]; then # jail_enable="NO"
sed -i '.bak' 's/^jail_enable=.*$/jail_enable="YES"/g' /etc/rc.conf # fix this -^
rm -f /etc/rc.conf.bak
fi
cat >>/etc/rc.conf <<END cat >>/etc/rc.conf <<END
jail_${name}_rootdir="${jaildir}/${name}" jail_${name}_rootdir="${jaildir}/${name}"
jail_${name}_hostname="${hostname}" jail_${name}_hostname="${hostname}"
@ -243,6 +253,9 @@ if [ "$devfsenable" = "true" ]; then
jail_${name}_devfs_ruleset="${devfsruleset}" jail_${name}_devfs_ruleset="${devfsruleset}"
END END
if [ "${devfsruleset}" = "jailrules" ]; then # The default ruleset is to be used if [ "${devfsruleset}" = "jailrules" ]; then # The default ruleset is to be used
if [ ! -f /etc/devfs.rules ]; then
touch /etc/devfs.rules
fi
if [ -z "\$(grep '\[jailrules=' /etc/devfs.rules)" ]; then # The default ruleset doesn't exist if [ -z "\$(grep '\[jailrules=' /etc/devfs.rules)" ]; then # The default ruleset doesn't exist
# Get the highest-numbered ruleset # Get the highest-numbered ruleset
highest="\$(sed -n 's/\[.*=\([0-9]*\)\]/\1/pg' /etc/devfs.rules | sort -u | tail -n 1)" || true highest="\$(sed -n 's/\[.*=\([0-9]*\)\]/\1/pg' /etc/devfs.rules | sort -u | tail -n 1)" || true
@ -263,17 +276,20 @@ fi
# Add $name to jail_list if $onboot=true # Add $name to jail_list if $onboot=true
if [ "$onboot" = "true" ]; then if [ "$onboot" = "true" ]; then
# first check to see whether jail_enable="YES" exists in rc.conf or not and add it
# if necessary
cat <<EOF cat <<EOF
eval \$(grep '^jail_list=' /etc/rc.conf) jail_list="\$(grep '^jail_enable=' /etc/rc.conf | cut -d= -f2)"
jail_list="\${jail_list} ${name}" if [ -z "\$jail_list" ]; then # no jail_list line in rc.conf at all
grep -q '^jail_list=' /etc/rc.conf echo "jail_list=\"${name}\"" >>/etc/rc.conf
if [ "\$?" -eq "0" ]; then
sed -i '.bak' "s/^jail_list=\".*\"/jail_list=\"\${jail_list}\"/" /etc/rc.conf
else else
echo jail_list=\"\${jail_list}\" >>/etc/rc.conf jail_list="\${jail_list} ${name}"
sed -i '.bak' "s/^jail_list=\".*\"/jail_list=\"\${jail_list}\"/" /etc/rc.conf
rm -f /etc/rc.conf.bak
fi fi
unset jail_list unset jail_list
rm -f /etc/rc.conf.bak
EOF EOF
fi fi

35
conf/type/__jail/manifest Executable file
View file

@ -0,0 +1,35 @@
#!/bin/sh
#
# 2012 Jake Guffey (jake.guffey at eprotex.com)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
#
# The __jail type creates, configures, and deletes FreeBSD jails for use as
# virtual machines.
#
# Debug
#exec >&2
#set -x
jaildir="/usr/jail"
__directory ${jaildir} --parents yes
# Debug
#set +x