2018-11-07 10:36:54 -07:00
#!/bin/sh
2020-04-14 11:52:29 +02:00
#
2022-01-15 11:32:28 -04:00
# Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
2018-11-07 10:36:54 -07:00
# All rights reserved.
2020-04-14 11:52:29 +02:00
#
2018-11-07 10:36:54 -07:00
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
2020-04-14 11:52:29 +02:00
#
2018-11-07 10:36:54 -07:00
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
2020-04-14 11:52:29 +02:00
#
2018-11-07 10:36:54 -07:00
# * 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.
2020-04-14 11:52:29 +02:00
#
2018-11-07 10:36:54 -07:00
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
2020-04-14 11:52:29 +02:00
#
2018-11-07 10:36:54 -07:00
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
2020-08-30 10:57:14 -04:00
. /usr/local/share/bastille/common.sh
2018-11-07 10:36:54 -07:00
. /usr/local/etc/bastille/bastille.conf
usage( ) {
2021-07-12 14:54:00 -04:00
# Build an independent usage for the create command
# If no option specified, will create a thin container by default
2021-07-13 04:49:25 -04:00
error_notify "Usage: bastille create [option(s)] name release ip [interface]"
2021-07-12 14:54:00 -04:00
cat << EOF
Options:
-E | --empty -- Creates an empty container, intended for custom jail builds ( thin/thick/linux or unsupported) .
-L | --linux -- This option is intended for testing with Linux jails, this is considered experimental.
-T | --thick -- Creates a thick container, they consume more space as they are self contained and independent.
-V | --vnet -- Enables VNET, VNET containers are attached to a virtual bridge interface for connectivity.
2022-01-15 11:32:28 -04:00
-C | --clone -- Creates a clone container, they are duplicates of the base release, consume low space and preserves changing data.
2021-12-02 15:22:08 +01:00
-B | --bridge -- Enables VNET, VNET containers are attached to a specified, already existing external bridge.
2021-07-12 14:54:00 -04:00
EOF
exit 1
2020-05-09 15:31:15 -04:00
}
2018-11-07 10:36:54 -07:00
running_jail( ) {
2021-12-17 19:09:49 -07:00
if [ -n " $( /usr/sbin/jls name | awk " /^ ${ NAME } $/ " ) " ] ; then
2020-08-30 10:57:14 -04:00
error_exit "A running jail matches name."
2019-12-29 23:04:19 -04:00
elif [ -d " ${ bastille_jailsdir } / ${ NAME } " ] ; then
2020-08-30 10:57:14 -04:00
error_exit " Jail: ${ NAME } already created. "
2020-05-09 15:31:15 -04:00
fi
}
validate_name( ) {
local NAME_VERIFY = ${ NAME }
local NAME_SANITY = $( echo " ${ NAME_VERIFY } " | tr -c -d 'a-zA-Z0-9-_' )
2021-01-10 18:55:02 -04:00
if [ -n " $( echo " ${ NAME_SANITY } " | awk " /^[-_].* $/ " ) " ] ; then
error_exit "Container names may not begin with (-|_) characters!"
elif [ " ${ NAME_VERIFY } " != " ${ NAME_SANITY } " ] ; then
2020-08-30 10:57:14 -04:00
error_exit "Container names may not contain special characters!"
2019-12-29 23:04:19 -04:00
fi
2018-11-07 10:36:54 -07:00
}
validate_ip( ) {
2021-08-07 19:57:53 +02:00
ipx_addr = "ip4.addr"
ip = " $1 "
ip6 = $( echo " ${ ip } " | grep -E '^(([a-fA-F0-9:]+$)|([a-fA-F0-9:]+\/[0-9]{1,3}$)|SLAAC)' )
2020-02-16 13:22:32 -04:00
if [ -n " ${ ip6 } " ] ; then
2020-11-25 21:19:08 -05:00
info " Valid: ( ${ ip6 } ). "
2021-08-07 19:57:53 +02:00
ipx_addr = "ip6.addr"
2020-02-16 13:22:32 -04:00
IP6_MODE = "new"
2018-11-07 10:36:54 -07:00
else
2021-08-07 19:57:53 +02:00
if [ " ${ ip } " = "DHCP" ] ; then
info " Valid: ( ${ ip } ). "
else
local IFS
if echo " ${ ip } " | grep -Eq '^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))?$' ; then
TEST_IP = $( echo " ${ ip } " | cut -d / -f1)
IFS = .
set ${ TEST_IP }
for quad in 1 2 3 4; do
if eval [ \$ $quad -gt 255 ] ; then
echo " Invalid: ( ${ TEST_IP } ) "
exit 1
fi
done
2022-12-04 05:47:15 -06:00
if ifconfig | grep -qwF " ${ TEST_IP } " ; then
2021-08-07 19:57:53 +02:00
warn " Warning: IP address already in use ( ${ TEST_IP } ). "
else
info " Valid: ( ${ ip } ). "
2020-02-16 13:22:32 -04:00
fi
else
2021-08-07 19:57:53 +02:00
error_exit " Invalid: ( ${ ip } ). "
2020-02-16 13:22:32 -04:00
fi
2021-08-07 19:57:53 +02:00
fi
fi
if echo " ${ ip } " | grep -qvE '(SLAAC|DHCP|0[.]0[.]0[.]0)' ; then
if [ " ${ ipx_addr } " = "ip4.addr" ] ; then
IP4_ADDR = " ${ ip } "
2023-05-02 09:55:35 -04:00
IP4_DEFINITION = " ${ ipx_addr } = ${ ip } ; "
2020-02-16 13:22:32 -04:00
else
2021-08-07 19:57:53 +02:00
IP6_ADDR = " ${ ip } "
2023-05-02 09:55:35 -04:00
IP6_DEFINITION = " ${ ipx_addr } = ${ ip } ; "
2020-02-16 13:22:32 -04:00
fi
2018-11-07 10:36:54 -07:00
fi
}
2021-08-07 19:57:53 +02:00
validate_ips( ) {
IP6_MODE = "disable"
IP4_DEFINITION = ""
IP6_DEFINITION = ""
IP4_ADDR = ""
IP6_ADDR = ""
for ip in ${ IP } ; do
validate_ip " ${ ip } "
done
}
2018-11-07 10:36:54 -07:00
2019-10-24 17:02:50 -04:00
validate_netif( ) {
local LIST_INTERFACES = $( ifconfig -l)
2020-01-28 17:36:17 -07:00
if echo " ${ LIST_INTERFACES } VNET " | grep -qwo " ${ INTERFACE } " ; then
2020-11-25 21:19:08 -05:00
info " Valid: ( ${ INTERFACE } ). "
2019-10-24 17:02:50 -04:00
else
2020-08-30 10:57:14 -04:00
error_exit " Invalid: ( ${ INTERFACE } ). "
2019-10-24 17:02:50 -04:00
fi
}
2019-11-20 16:09:26 -04:00
validate_netconf( ) {
2020-04-12 17:04:37 -06:00
if [ -n " ${ bastille_network_loopback } " ] && [ -n " ${ bastille_network_shared } " ] ; then
2020-08-30 10:57:14 -04:00
error_exit "Invalid network configuration."
2019-11-20 16:09:26 -04:00
fi
}
2020-02-02 02:42:22 -04:00
validate_release( ) {
2021-07-15 16:30:36 -04:00
## ensure the user set the Linux(experimental) option explicitly
if [ -n " ${ UBUNTU } " ] ; then
if [ -z " ${ LINUX_JAIL } " ] ; then
usage
fi
fi
2020-02-02 02:42:22 -04:00
## check release name match, else show usage
if [ -n " ${ NAME_VERIFY } " ] ; then
RELEASE = " ${ NAME_VERIFY } "
else
usage
fi
}
2020-04-18 18:02:11 -04:00
generate_minimal_conf( ) {
cat << EOF > " ${ bastille_jail_conf } "
${ NAME } {
host.hostname = ${ NAME } ;
mount.fstab = ${ bastille_jail_fstab } ;
path = ${ bastille_jail_path } ;
}
EOF
touch " ${ bastille_jail_fstab } "
}
2020-02-16 15:20:31 -07:00
generate_jail_conf( ) {
2020-02-20 18:06:31 -04:00
cat << EOF > " ${ bastille_jail_conf } "
2020-02-16 15:20:31 -07:00
${ NAME } {
devfs_ruleset = 4;
enforce_statfs = 2;
exec.clean;
exec.consolelog = ${ bastille_jail_log } ;
exec.start = '/bin/sh /etc/rc' ;
exec.stop = '/bin/sh /etc/rc.shutdown' ;
host.hostname = ${ NAME } ;
mount.devfs;
mount.fstab = ${ bastille_jail_fstab } ;
path = ${ bastille_jail_path } ;
securelevel = 2;
interface = ${ bastille_jail_conf_interface } ;
2021-08-07 19:57:53 +02:00
${ IP4_DEFINITION }
${ IP6_DEFINITION }
2020-02-16 15:22:32 -07:00
ip6 = ${ IP6_MODE } ;
2020-02-16 15:20:31 -07:00
}
EOF
}
2021-07-12 14:45:37 -04:00
generate_linux_jail_conf( ) {
cat << EOF > " ${ bastille_jail_conf } "
${ NAME } {
host.hostname = ${ NAME } ;
mount.fstab = ${ bastille_jail_fstab } ;
path = ${ bastille_jail_path } ;
devfs_ruleset = 4;
2022-03-04 08:16:33 -08:00
enforce_statfs = 1;
2021-07-12 14:54:00 -04:00
2021-07-12 14:45:37 -04:00
exec.start = '/bin/true' ;
exec.stop = '/bin/true' ;
persist;
2021-07-12 14:54:00 -04:00
2021-07-12 14:45:37 -04:00
allow.mount;
allow.mount.devfs;
2021-07-12 14:54:00 -04:00
2021-07-12 14:45:37 -04:00
interface = ${ bastille_jail_conf_interface } ;
2022-11-02 21:17:05 -06:00
${ ipx_addr } = ${ IP } ;
2021-07-12 14:45:37 -04:00
ip6 = ${ IP6_MODE } ;
}
EOF
}
2020-02-16 15:20:31 -07:00
generate_vnet_jail_conf( ) {
2022-01-09 19:22:16 -08:00
NETBLOCK = $( generate_vnet_jail_netblock " $NAME " " ${ VNET_JAIL_BRIDGE } " " ${ bastille_jail_conf_interface } " )
2020-02-20 18:06:31 -04:00
cat << EOF > " ${ bastille_jail_conf } "
2020-02-16 15:20:31 -07:00
${ NAME } {
devfs_ruleset = 13;
enforce_statfs = 2;
exec.clean;
exec.consolelog = ${ bastille_jail_log } ;
exec.start = '/bin/sh /etc/rc' ;
exec.stop = '/bin/sh /etc/rc.shutdown' ;
host.hostname = ${ NAME } ;
mount.devfs;
mount.fstab = ${ bastille_jail_fstab } ;
path = ${ bastille_jail_path } ;
securelevel = 2;
2022-01-09 19:22:16 -08:00
${ NETBLOCK }
2020-02-16 15:20:31 -07:00
}
EOF
}
2022-01-15 11:32:28 -04:00
post_create_jail( ) {
# Common config checks and settings.
# Using relative paths here.
# MAKE SURE WE'RE IN THE RIGHT PLACE.
cd " ${ bastille_jail_path } "
echo
if [ ! -f " ${ bastille_jail_conf } " ] ; then
if [ -z " ${ bastille_network_loopback } " ] && [ -n " ${ bastille_network_shared } " ] ; then
local bastille_jail_conf_interface = ${ bastille_network_shared }
fi
if [ -n " ${ bastille_network_loopback } " ] && [ -z " ${ bastille_network_shared } " ] ; then
local bastille_jail_conf_interface = ${ bastille_network_loopback }
fi
if [ -n " ${ INTERFACE } " ] ; then
local bastille_jail_conf_interface = ${ INTERFACE }
fi
fi
if [ ! -f " ${ bastille_jail_fstab } " ] ; then
if [ -z " ${ THICK_JAIL } " ] && [ -z " ${ CLONE_JAIL } " ] ; then
echo -e " ${ bastille_releasesdir } / ${ RELEASE } ${ bastille_jail_base } nullfs ro 0 0 " > " ${ bastille_jail_fstab } "
else
touch " ${ bastille_jail_fstab } "
fi
fi
# Generate the jail configuration file.
if [ -n " ${ VNET_JAIL } " ] ; then
generate_vnet_jail_conf
else
generate_jail_conf
fi
}
2018-11-07 10:36:54 -07:00
create_jail( ) {
bastille_jail_base = " ${ bastille_jailsdir } / ${ NAME } /root/.bastille " ## dir
bastille_jail_template = " ${ bastille_jailsdir } / ${ NAME } /root/.template " ## dir
bastille_jail_path = " ${ bastille_jailsdir } / ${ NAME } /root " ## dir
bastille_jail_fstab = " ${ bastille_jailsdir } / ${ NAME } /fstab " ## file
bastille_jail_conf = " ${ bastille_jailsdir } / ${ NAME } /jail.conf " ## file
bastille_jail_log = " ${ bastille_logsdir } / ${ NAME } _console.log " ## file
2019-05-22 21:50:29 -06:00
bastille_jail_rc_conf = " ${ bastille_jailsdir } / ${ NAME } /root/etc/rc.conf " ## file
2018-11-07 10:36:54 -07:00
bastille_jail_resolv_conf = " ${ bastille_jailsdir } / ${ NAME } /root/etc/resolv.conf " ## file
2019-06-22 09:28:42 -06:00
if [ ! -d " ${ bastille_jailsdir } / ${ NAME } " ] ; then
if [ " ${ bastille_zfs_enable } " = "YES" ] ; then
2020-02-20 18:06:31 -04:00
if [ -n " ${ bastille_zfs_zpool } " ] ; then
2020-02-15 07:57:33 -04:00
## create required zfs datasets, mountpoint inherited from system
2022-01-15 11:32:28 -04:00
if [ -z " ${ CLONE_JAIL } " ] ; then
zfs create ${ bastille_zfs_options } " ${ bastille_zfs_zpool } / ${ bastille_zfs_prefix } /jails/ ${ NAME } "
fi
if [ -z " ${ THICK_JAIL } " ] && [ -z " ${ CLONE_JAIL } " ] ; then
2020-02-20 18:06:31 -04:00
zfs create ${ bastille_zfs_options } " ${ bastille_zfs_zpool } / ${ bastille_zfs_prefix } /jails/ ${ NAME } /root "
2019-11-18 03:51:06 -04:00
fi
2019-06-22 09:28:42 -06:00
fi
else
2020-04-18 18:02:11 -04:00
mkdir -p " ${ bastille_jailsdir } / ${ NAME } /root "
2019-06-22 09:28:42 -06:00
fi
fi
2022-01-15 11:32:28 -04:00
2021-07-12 14:45:37 -04:00
## PoC for Linux jails @hackacad
if [ -n " ${ LINUX_JAIL } " ] ; then
2022-01-15 11:32:28 -04:00
info "\nCreating a linuxjail. This may take a while...\n"
2021-07-12 14:45:37 -04:00
if [ ! -d " ${ bastille_jail_base } " ] ; then
mkdir -p " ${ bastille_jail_base } "
fi
mkdir -p " ${ bastille_jail_path } /dev "
mkdir -p " ${ bastille_jail_path } /proc "
mkdir -p " ${ bastille_jail_path } /sys "
mkdir -p " ${ bastille_jail_path } /home "
2021-07-12 14:54:00 -04:00
mkdir -p " ${ bastille_jail_path } /tmp "
2021-07-12 14:45:37 -04:00
touch " ${ bastille_jail_path } /dev/shm "
touch " ${ bastille_jail_path } /dev/fd "
cp -RPf ${ bastille_releasesdir } /${ RELEASE } /* ${ bastille_jail_path } /
2021-07-15 21:26:35 +10:00
echo " ${ NAME } " > ${ bastille_jail_path } /etc/hostname
2019-06-22 09:28:42 -06:00
2021-07-12 14:45:37 -04:00
if [ ! -d " ${ bastille_jail_template } " ] ; then
mkdir -p " ${ bastille_jail_template } "
fi
if [ ! -f " ${ bastille_jail_fstab } " ] ; then
touch " ${ bastille_jail_fstab } "
fi
2021-07-15 20:52:16 +10:00
echo -e " devfs ${ bastille_jail_path } /dev devfs rw 0 0 " >> " ${ bastille_jail_fstab } "
echo -e " tmpfs ${ bastille_jail_path } /dev/shm tmpfs rw,size=1g,mode=1777 0 0 " >> " ${ bastille_jail_fstab } "
echo -e " fdescfs ${ bastille_jail_path } /dev/fd fdescfs rw,linrdlnk 0 0 " >> " ${ bastille_jail_fstab } "
echo -e " linprocfs ${ bastille_jail_path } /proc linprocfs rw 0 0 " >> " ${ bastille_jail_fstab } "
echo -e " linsysfs ${ bastille_jail_path } /sys linsysfs rw 0 0 " >> " ${ bastille_jail_fstab } "
echo -e " /tmp ${ bastille_jail_path } /tmp nullfs rw 0 0 " >> " ${ bastille_jail_fstab } "
2021-07-12 14:54:00 -04:00
## removed temporarely / only for X11 jails? @hackacad
2021-07-15 20:52:16 +10:00
#echo -e "/home ${bastille_jail_path}/home nullfs rw 0 0" >> "${bastille_jail_fstab}"
2021-07-12 14:45:37 -04:00
if [ ! -f " ${ bastille_jail_conf } " ] ; then
if [ -z " ${ bastille_network_loopback } " ] && [ -n " ${ bastille_network_shared } " ] ; then
local bastille_jail_conf_interface = ${ bastille_network_shared }
fi
if [ -n " ${ bastille_network_loopback } " ] && [ -z " ${ bastille_network_shared } " ] ; then
local bastille_jail_conf_interface = ${ bastille_network_loopback }
fi
if [ -n " ${ INTERFACE } " ] ; then
local bastille_jail_conf_interface = ${ INTERFACE }
fi
fi
fi
if [ -z " ${ EMPTY_JAIL } " ] && [ -z " ${ LINUX_JAIL } " ] ; then
2022-01-15 11:32:28 -04:00
if [ -z " ${ THICK_JAIL } " ] && [ -z " ${ CLONE_JAIL } " ] ; then
if [ ! -d " ${ bastille_jail_base } " ] ; then
mkdir -p " ${ bastille_jail_base } "
fi
if [ ! -d " ${ bastille_jail_template } " ] ; then
mkdir -p " ${ bastille_jail_template } "
fi
2019-11-17 18:15:19 -04:00
fi
2018-11-07 10:36:54 -07:00
2020-04-18 18:02:11 -04:00
if [ ! -d " ${ bastille_jail_path } /usr/local " ] ; then
mkdir -p " ${ bastille_jail_path } /usr/local "
2020-02-16 15:20:31 -07:00
fi
2018-11-07 10:36:54 -07:00
2022-01-15 11:32:28 -04:00
# Check and apply required settings.
post_create_jail
2018-11-07 10:36:54 -07:00
2022-01-15 11:32:28 -04:00
if [ -z " ${ THICK_JAIL } " ] && [ -z " ${ CLONE_JAIL } " ] ; then
2021-07-07 05:05:38 -04:00
LINK_LIST = "bin boot lib libexec rescue sbin usr/bin usr/include usr/lib usr/lib32 usr/libdata usr/libexec usr/sbin usr/share usr/src"
2022-01-15 11:32:28 -04:00
info "Creating a thinjail...\n"
2020-05-07 22:50:43 -04:00
for _link in ${ LINK_LIST } ; do
2020-04-18 18:02:11 -04:00
ln -sf /.bastille/${ _link } ${ _link }
done
2022-01-15 11:32:28 -04:00
2021-07-07 05:05:38 -04:00
# Properly link shared ports on thin jails in read-write.
2021-01-08 22:37:18 -04:00
if [ -d " ${ bastille_releasesdir } / ${ RELEASE } /usr/ports " ] ; then
if [ ! -d " ${ bastille_jail_path } /usr/ports " ] ; then
2021-07-07 05:05:38 -04:00
mkdir ${ bastille_jail_path } /usr/ports
2021-01-08 22:37:18 -04:00
fi
2021-07-07 05:05:38 -04:00
echo -e " ${ bastille_releasesdir } / ${ RELEASE } /usr/ports ${ bastille_jail_path } /usr/ports nullfs rw 0 0 " >> " ${ bastille_jail_fstab } "
2021-01-08 22:37:18 -04:00
fi
2020-04-18 18:02:11 -04:00
fi
2019-11-18 03:51:06 -04:00
2022-01-15 11:32:28 -04:00
if [ -z " ${ THICK_JAIL } " ] && [ -z " ${ CLONE_JAIL } " ] ; then
2020-04-18 18:02:11 -04:00
## rw
## copy only required files for thin jails
FILE_LIST = ".cshrc .profile COPYRIGHT dev etc media mnt net proc root tmp var usr/obj usr/tests"
for files in ${ FILE_LIST } ; do
if [ -f " ${ bastille_releasesdir } / ${ RELEASE } / ${ files } " ] || [ -d " ${ bastille_releasesdir } / ${ RELEASE } / ${ files } " ] ; then
2021-07-14 13:57:09 -04:00
if ! cp -a " ${ bastille_releasesdir } / ${ RELEASE } / ${ files } " " ${ bastille_jail_path } / ${ files } " ; then
2020-04-18 18:02:11 -04:00
## notify and clean stale files/directories
bastille destroy " ${ NAME } "
2020-08-30 10:57:14 -04:00
error_exit "Failed to copy release files. Please retry create!"
2020-04-18 18:02:11 -04:00
fi
fi
done
else
if [ " ${ bastille_zfs_enable } " = "YES" ] ; then
if [ -n " ${ bastille_zfs_zpool } " ] ; then
2022-01-15 11:32:28 -04:00
if [ -n " ${ CLONE_JAIL } " ] ; then
info "Creating a clonejail...\n"
## clone the release base to the new basejail
SNAP_NAME = " bastille-clone- $( date +%Y-%m-%d-%H%M%S) "
zfs snapshot " ${ bastille_zfs_zpool } / ${ bastille_zfs_prefix } /releases/ ${ RELEASE } " @" ${ SNAP_NAME } "
zfs clone -p " ${ bastille_zfs_zpool } / ${ bastille_zfs_prefix } /releases/ ${ RELEASE } " @" ${ SNAP_NAME } " \
" ${ bastille_zfs_zpool } / ${ bastille_zfs_prefix } /jails/ ${ NAME } /root "
# Check and apply required settings.
post_create_jail
elif [ -n " ${ THICK_JAIL } " ] ; then
info "Creating a thickjail. This may take a while...\n"
## perform release base replication
## sane bastille zfs options
ZFS_OPTIONS = $( echo ${ bastille_zfs_options } | sed 's/-o//g' )
## take a temp snapshot of the base release
SNAP_NAME = " bastille- $( date +%Y-%m-%d-%H%M%S) "
zfs snapshot " ${ bastille_zfs_zpool } / ${ bastille_zfs_prefix } /releases/ ${ RELEASE } " @" ${ SNAP_NAME } "
## replicate the release base to the new thickjail and set the default mountpoint
zfs send -R " ${ bastille_zfs_zpool } / ${ bastille_zfs_prefix } /releases/ ${ RELEASE } " @" ${ SNAP_NAME } " | \
zfs receive " ${ bastille_zfs_zpool } / ${ bastille_zfs_prefix } /jails/ ${ NAME } /root "
zfs set ${ ZFS_OPTIONS } mountpoint = none " ${ bastille_zfs_zpool } / ${ bastille_zfs_prefix } /jails/ ${ NAME } /root "
zfs inherit mountpoint " ${ bastille_zfs_zpool } / ${ bastille_zfs_prefix } /jails/ ${ NAME } /root "
## cleanup temp snapshots initially
zfs destroy " ${ bastille_zfs_zpool } / ${ bastille_zfs_prefix } /releases/ ${ RELEASE } " @" ${ SNAP_NAME } "
zfs destroy " ${ bastille_zfs_zpool } / ${ bastille_zfs_prefix } /jails/ ${ NAME } /root " @" ${ SNAP_NAME } "
fi
2020-04-18 18:02:11 -04:00
if [ " $? " -ne 0 ] ; then
## notify and clean stale files/directories
bastille destroy " ${ NAME } "
2020-08-30 10:57:14 -04:00
error_exit "Failed release base replication. Please retry create!"
2020-04-18 18:02:11 -04:00
fi
fi
else
## copy all files for thick jails
cp -a " ${ bastille_releasesdir } / ${ RELEASE } / " " ${ bastille_jail_path } "
2020-02-20 18:06:31 -04:00
if [ " $? " -ne 0 ] ; then
2019-11-18 03:51:06 -04:00
## notify and clean stale files/directories
2020-02-20 18:06:31 -04:00
bastille destroy " ${ NAME } "
2020-08-30 10:57:14 -04:00
error_exit "Failed to copy release files. Please retry create!"
2019-11-18 03:51:06 -04:00
fi
fi
2019-11-17 18:15:19 -04:00
fi
2021-07-12 14:54:00 -04:00
2021-07-12 14:45:37 -04:00
if [ -z " ${ LINUX_JAIL } " ] ; then
## create home directory if missing
if [ ! -d " ${ bastille_jail_path } /usr/home " ] ; then
mkdir -p " ${ bastille_jail_path } /usr/home "
fi
## link home properly
if [ ! -L "home" ] ; then
ln -s usr/home home
fi
2021-07-12 14:54:00 -04:00
2021-12-12 12:10:39 -05:00
## TZ: configurable (default: empty to use host's time zone)
if [ -z " ${ bastille_tzdata } " ] ; then
2021-12-12 12:38:05 -05:00
# Note that if host has no time zone, FreeBSD assumes UTC anyway
if [ -e /etc/localtime ] ; then
# uses cp as a way to prevent issues with symlinks if the host happens to use that for tz configuration
cp /etc/localtime etc/localtime
fi
2021-12-12 12:10:39 -05:00
else
ln -s " /usr/share/zoneinfo/ ${ bastille_tzdata } " etc/localtime
fi
2021-07-12 14:54:00 -04:00
2021-07-12 14:45:37 -04:00
# Post-creation jail misc configuration
# Create a dummy fstab file
touch "etc/fstab"
# Disables adjkerntz, avoids spurious error messages
sed -i '' 's|[0-9],[0-9]\{2\}.*[0-9]-[0-9].*root.*kerntz -a|#& # Disabled by bastille|' "etc/crontab"
fi
2021-07-12 14:54:00 -04:00
2020-11-26 12:44:40 -05:00
## VNET specific
if [ -n " ${ VNET_JAIL } " ] ; then
## VNET requires jib script
if [ ! " $( command -v jib) " ] ; then
if [ -f /usr/share/examples/jails/jib ] && [ ! -f /usr/local/bin/jib ] ; then
install -m 0544 /usr/share/examples/jails/jib /usr/local/bin/jib
2020-02-18 17:04:06 -04:00
fi
fi
2020-02-16 15:20:31 -07:00
fi
2021-07-12 14:45:37 -04:00
elif [ -n " ${ LINUX_JAIL } " ] ; then
2021-07-12 14:54:00 -04:00
## Generate configuration for Linux jail
2021-07-12 14:45:37 -04:00
generate_linux_jail_conf
2021-07-12 14:54:00 -04:00
elif [ -n " ${ EMPTY_JAIL } " ] ; then
2020-04-18 18:02:11 -04:00
## Generate minimal configuration for empty jail
generate_minimal_conf
fi
2020-07-24 15:37:50 -04:00
# Set strict permissions on the jail by default
chmod 0700 " ${ bastille_jailsdir } / ${ NAME } "
2020-11-26 12:44:40 -05:00
# Jail must be started before applying the default template. -- cwells
2021-01-08 02:05:30 -04:00
if [ -z " ${ EMPTY_JAIL } " ] ; then
bastille start " ${ NAME } "
2021-01-08 20:26:31 -04:00
elif [ -n " ${ EMPTY_JAIL } " ] ; then
# Don't start empty jails unless a template defined.
if [ -n " ${ bastille_template_empty } " ] ; then
bastille start " ${ NAME } "
fi
2021-01-08 02:05:30 -04:00
fi
2021-07-12 14:54:00 -04:00
2020-11-26 12:44:40 -05:00
if [ -n " ${ VNET_JAIL } " ] ; then
2021-01-08 22:37:18 -04:00
if [ -n " ${ bastille_template_vnet } " ] ; then
2020-11-26 12:44:40 -05:00
## rename interface to generic vnet0
uniq_epair = $( grep vnet.interface " ${ bastille_jailsdir } / ${ NAME } /jail.conf " | awk '{print $3}' | sed 's/;//' )
_gateway = ''
2021-07-26 11:13:04 +02:00
_gateway6 = ''
2021-08-07 19:57:53 +02:00
_ifconfig_inet = ''
_ifconfig_inet6 = ''
if echo " ${ IP } " | grep -qE '(0[.]0[.]0[.]0|DHCP)' ; then
# Enable DHCP if requested
_ifconfig_inet = SYNCDHCP
else
# Else apply the default gateway
2020-11-26 12:44:40 -05:00
if [ -n " ${ bastille_network_gateway } " ] ; then
_gateway = " ${ bastille_network_gateway } "
else
2021-08-07 19:57:53 +02:00
_gateway = " $( netstat -rn | awk '/default/ {print $2}' ) "
fi
fi
# Add IPv4 address (this is empty if DHCP is used)
if [ -n " ${ IP4_ADDR } " ] ; then
_ifconfig_inet = " ${ _ifconfig_inet } inet ${ IP4_ADDR } "
fi
# Enable IPv6 if used
if [ " ${ IP6_MODE } " != "disable" ] ; then
_ifconfig_inet6 = 'inet6 -ifdisabled'
if echo " ${ IP } " | grep -qE 'SLAAC' ; then
# Enable SLAAC if requested
_ifconfig_inet6 = " ${ _ifconfig_inet6 } accept_rtadv "
else
# Else apply the default gateway
if [ -n " ${ bastille_network_gateway6 } " ] ; then
_gateway6 = " ${ bastille_network_gateway6 } "
2021-07-12 14:54:00 -04:00
else
2021-08-07 19:57:53 +02:00
_gateway6 = " $( netstat -6rn | awk '/default/ {print $2}' ) "
2021-07-12 14:54:00 -04:00
fi
2020-11-26 12:44:40 -05:00
fi
fi
2021-08-07 19:57:53 +02:00
# Add IPv6 address (this is empty if SLAAC is used)
if [ -n " ${ IP6_ADDR } " ] ; then
_ifconfig_inet6 = " ${ _ifconfig_inet6 } ${ IP6_ADDR } "
fi
# Join together IPv4 and IPv6 parts of ifconfig
_ifconfig = " ${ _ifconfig_inet } ${ _ifconfig_inet6 } "
2021-07-26 11:13:04 +02:00
bastille template " ${ NAME } " ${ bastille_template_vnet } --arg BASE_TEMPLATE = " ${ bastille_template_base } " --arg HOST_RESOLV_CONF = " ${ bastille_resolv_conf } " --arg EPAIR = " ${ uniq_epair } " --arg GATEWAY = " ${ _gateway } " --arg GATEWAY6 = " ${ _gateway6 } " --arg IFCONFIG = " ${ _ifconfig } "
2020-11-26 12:44:40 -05:00
fi
elif [ -n " ${ THICK_JAIL } " ] ; then
2021-01-08 20:26:31 -04:00
if [ -n " ${ bastille_template_thick } " ] ; then
2020-11-26 12:44:40 -05:00
bastille template " ${ NAME } " ${ bastille_template_thick } --arg BASE_TEMPLATE = " ${ bastille_template_base } " --arg HOST_RESOLV_CONF = " ${ bastille_resolv_conf } "
fi
2022-01-15 11:32:28 -04:00
elif [ -n " ${ CLONE_JAIL } " ] ; then
if [ -n " ${ bastille_template_clone } " ] ; then
bastille template " ${ NAME } " ${ bastille_template_clone } --arg BASE_TEMPLATE = " ${ bastille_template_base } " --arg HOST_RESOLV_CONF = " ${ bastille_resolv_conf } "
fi
2020-11-26 12:44:40 -05:00
elif [ -n " ${ EMPTY_JAIL } " ] ; then
2021-01-08 20:26:31 -04:00
if [ -n " ${ bastille_template_empty } " ] ; then
bastille template " ${ NAME } " ${ bastille_template_empty } --arg BASE_TEMPLATE = " ${ bastille_template_base } " --arg HOST_RESOLV_CONF = " ${ bastille_resolv_conf } "
2020-11-26 12:44:40 -05:00
fi
2021-07-12 14:45:37 -04:00
## Using templating function to fetch necessary packges @hackacad
elif [ -n " ${ LINUX_JAIL } " ] ; then
info "Fetching packages..."
jexec -l " ${ NAME } " /bin/bash -c "DEBIAN_FRONTEND=noninteractive rm /var/cache/apt/archives/rsyslog*.deb"
jexec -l " ${ NAME } " /bin/bash -c "DEBIAN_FRONTEND=noninteractive dpkg --force-depends --force-confdef --force-confold -i /var/cache/apt/archives/*.deb"
jexec -l " ${ NAME } " /bin/bash -c "DEBIAN_FRONTEND=noninteractive dpkg --force-depends --force-confdef --force-confold -i /var/cache/apt/archives/*.deb"
jexec -l " ${ NAME } " /bin/bash -c "chmod 777 /tmp"
jexec -l " ${ NAME } " /bin/bash -c "apt update"
2021-07-12 14:54:00 -04:00
else
# Thin jail.
2021-01-08 20:26:31 -04:00
if [ -n " ${ bastille_template_thin } " ] ; then
2020-11-26 12:44:40 -05:00
bastille template " ${ NAME } " ${ bastille_template_thin } --arg BASE_TEMPLATE = " ${ bastille_template_base } " --arg HOST_RESOLV_CONF = " ${ bastille_resolv_conf } "
fi
fi
# Apply values changed by the template. -- cwells
2021-07-12 14:45:37 -04:00
if [ -z " ${ EMPTY_JAIL } " ] && [ -z " ${ LINUX_JAIL } " ] ; then
2021-01-08 02:05:30 -04:00
bastille restart " ${ NAME } "
2021-01-08 20:26:31 -04:00
elif [ -n " ${ EMPTY_JAIL } " ] ; then
# Don't restart empty jails unless a template defined.
if [ -n " ${ bastille_template_empty } " ] ; then
bastille restart " ${ NAME } "
fi
2021-01-08 02:05:30 -04:00
fi
2018-11-07 10:36:54 -07:00
}
# Handle special-case commands first.
case " $1 " in
help| -h| --help)
usage
; ;
esac
2023-03-16 20:58:11 +01:00
bastille_root_check
2020-02-20 18:06:31 -04:00
if echo " $3 " | grep '@' ; then
BASTILLE_JAIL_IP = $( echo " $3 " | awk -F@ '{print $2}' )
BASTILLE_JAIL_INTERFACES = $( echo " $3 " | awk -F@ '{print $1}' )
2019-07-15 07:44:45 -06:00
fi
2020-02-18 17:04:06 -04:00
## reset this options
2020-04-18 18:02:11 -04:00
EMPTY_JAIL = ""
2020-02-18 17:04:06 -04:00
THICK_JAIL = ""
2022-01-15 11:32:28 -04:00
CLONE_JAIL = ""
2020-02-18 17:04:06 -04:00
VNET_JAIL = ""
2021-07-12 14:45:37 -04:00
LINUX_JAIL = ""
2020-02-18 17:04:06 -04:00
2021-07-07 05:22:35 -04:00
# Handle and parse options
while [ $# -gt 0 ] ; do
2020-02-18 17:04:06 -04:00
case " ${ 1 } " in
2020-04-18 18:02:11 -04:00
-E| --empty| empty)
2021-07-07 05:21:28 -04:00
EMPTY_JAIL = "1"
2021-07-07 05:22:35 -04:00
shift
2020-04-18 18:02:11 -04:00
; ;
2021-07-12 14:45:37 -04:00
-L| --linux| linux)
2021-07-12 14:52:25 -04:00
LINUX_JAIL = "1"
2021-07-12 14:54:00 -04:00
shift
2021-07-12 14:45:37 -04:00
; ;
2020-02-19 19:53:25 -04:00
-T| --thick| thick)
2021-07-07 05:21:28 -04:00
THICK_JAIL = "1"
2021-07-07 05:22:35 -04:00
shift
2020-02-19 19:53:25 -04:00
; ;
-V| --vnet| vnet)
2021-07-07 05:21:28 -04:00
VNET_JAIL = "1"
2021-07-07 05:22:35 -04:00
shift
2020-02-19 19:53:25 -04:00
; ;
2021-12-02 15:06:47 +01:00
-B| --bridge| bridge)
VNET_JAIL = "1"
VNET_JAIL_BRIDGE = "1"
shift
; ;
2022-01-15 11:32:28 -04:00
-C| --clone| clone)
CLONE_JAIL = "1"
shift
; ;
2021-07-07 05:22:35 -04:00
-*| --*)
2020-08-30 10:57:14 -04:00
error_notify "Unknown Option."
2020-02-18 17:04:06 -04:00
usage
2020-02-19 19:53:25 -04:00
; ;
2021-07-07 05:22:35 -04:00
*)
break
; ;
2020-02-18 17:04:06 -04:00
esac
2021-07-07 05:22:35 -04:00
done
## validate for combined options
2021-07-12 14:54:00 -04:00
if [ -n " ${ EMPTY_JAIL } " ] ; then
2022-01-15 11:32:28 -04:00
if [ -n " ${ CLONE_JAIL } " ] || [ -n " ${ THICK_JAIL } " ] || [ -n " ${ VNET_JAIL } " ] || [ -n " ${ LINUX_JAIL } " ] ; then
2021-07-07 05:22:35 -04:00
error_exit "Error: Empty jail option can't be used with other options."
fi
2021-07-12 14:54:00 -04:00
elif [ -n " ${ LINUX_JAIL } " ] ; then
2022-01-15 11:32:28 -04:00
if [ -n " ${ EMPTY_JAIL } " ] || [ -n " ${ VNET_JAIL } " ] || [ -n " ${ THICK_JAIL } " ] || [ -n " ${ CLONE_JAIL } " ] ; then
2021-07-12 14:54:00 -04:00
error_exit "Error: Linux jail option can't be used with other options."
fi
2022-01-15 11:32:28 -04:00
elif [ -n " ${ CLONE_JAIL } " ] && [ -n " ${ THICK_JAIL } " ] ; then
error_exit "Error: Clonejail and Thickjail can't be used together."
2020-02-18 17:04:06 -04:00
fi
2018-11-07 10:36:54 -07:00
2020-02-19 19:53:25 -04:00
NAME = " $1 "
RELEASE = " $2 "
IP = " $3 "
INTERFACE = " $4 "
2020-04-18 18:02:11 -04:00
if [ -n " ${ EMPTY_JAIL } " ] ; then
if [ $# -ne 1 ] ; then
usage
fi
else
if [ $# -gt 4 ] || [ $# -lt 3 ] ; then
usage
fi
2020-02-19 19:53:25 -04:00
fi
2020-05-09 15:31:15 -04:00
## validate jail name
if [ -n " ${ NAME } " ] ; then
validate_name
2019-11-19 13:10:24 -04:00
fi
2021-07-12 14:45:37 -04:00
if [ -n " ${ LINUX_JAIL } " ] ; then
case " ${ RELEASE } " in
bionic| ubuntu_bionic| ubuntu| ubuntu-bionic)
## check for FreeBSD releases name
NAME_VERIFY = ubuntu_bionic
; ;
focal| ubuntu_focal| ubuntu-focal)
## check for FreeBSD releases name
NAME_VERIFY = ubuntu_focal
; ;
2023-07-10 12:04:40 +02:00
jammy| ubuntu_jammy| ubuntu-jammy)
2021-07-23 12:07:21 -05:00
## check for FreeBSD releases name
2023-07-10 12:04:40 +02:00
NAME_VERIFY = ubuntu_jammy
2021-07-23 12:07:21 -05:00
; ;
2021-07-30 07:40:01 -05:00
debian_buster| buster| debian-buster)
## check for FreeBSD releases name
NAME_VERIFY = buster
; ;
2021-12-22 18:35:49 -07:00
debian_bullseye| bullseye| debian-bullseye)
## check for FreeBSD releases name
NAME_VERIFY = bullseye
; ;
2023-07-10 12:04:40 +02:00
debian_bookworm| bookworm| debian-bookworm)
## check for FreeBSD releases name
NAME_VERIFY = bookworm
; ;
2021-07-12 14:45:37 -04:00
*)
error_notify "Unknown Linux."
usage
; ;
esac
fi
2020-04-18 18:02:11 -04:00
if [ -z " ${ EMPTY_JAIL } " ] ; then
## verify release
case " ${ RELEASE } " in
2021-02-26 16:55:56 -05:00
2.[ 0-9] *)
## check for MidnightBSD releases name
NAME_VERIFY = $( echo " ${ RELEASE } " )
validate_release
; ;
2020-08-28 14:13:54 -06:00
*-CURRENT| *-CURRENT-I386| *-CURRENT-i386| *-current)
## check for FreeBSD releases name
NAME_VERIFY = $( echo " ${ RELEASE } " | grep -iwE '^([1-9]{2,2})\.[0-9](-CURRENT|-CURRENT-i386)$' | tr '[:lower:]' '[:upper:]' | sed 's/I/i/g' )
validate_release
; ;
2021-02-14 17:29:29 +01:00
*-RELEASE| *-RELEASE-I386| *-RELEASE-i386| *-release| *-RC1| *-rc1| *-RC2| *-rc2| *-BETA1| *-BETA2| *-BETA3| *-BETA4| *-BETA5)
2020-04-18 18:02:11 -04:00
## check for FreeBSD releases name
2021-02-14 17:35:23 +01:00
NAME_VERIFY = $( echo " ${ RELEASE } " | grep -iwE '^([1-9]{2,2})\.[0-9](-RELEASE|-RELEASE-i386|-RC[1-2]|-BETA[1-5])$' | tr '[:lower:]' '[:upper:]' | sed 's/I/i/g' )
2020-04-18 18:02:11 -04:00
validate_release
; ;
*-stable-LAST| *-STABLE-last| *-stable-last| *-STABLE-LAST)
## check for HardenedBSD releases name(previous infrastructure)
NAME_VERIFY = $( echo " ${ RELEASE } " | grep -iwE '^([1-9]{2,2})(-stable-last)$' | sed 's/STABLE/stable/g' | sed 's/last/LAST/g' )
validate_release
; ;
*-stable-build-[ 0-9] *| *-STABLE-BUILD-[ 0-9] *)
## check for HardenedBSD(specific stable build releases)
NAME_VERIFY = $( echo " ${ RELEASE } " | grep -iwE '([0-9]{1,2})(-stable-build)-([0-9]{1,3})$' | sed 's/BUILD/build/g' | sed 's/STABLE/stable/g' )
validate_release
; ;
*-stable-build-latest| *-stable-BUILD-LATEST| *-STABLE-BUILD-LATEST)
## check for HardenedBSD(latest stable build release)
NAME_VERIFY = $( echo " ${ RELEASE } " | grep -iwE '([0-9]{1,2})(-stable-build-latest)$' | sed 's/STABLE/stable/g' | sed 's/build/BUILD/g' | sed 's/latest/LATEST/g' )
validate_release
; ;
current-build-[ 0-9] *| CURRENT-BUILD-[ 0-9] *)
## check for HardenedBSD(specific current build releases)
NAME_VERIFY = $( echo " ${ RELEASE } " | grep -iwE '(current-build)-([0-9]{1,3})' | sed 's/BUILD/build/g' | sed 's/CURRENT/current/g' )
validate_release
; ;
current-build-latest| current-BUILD-LATEST| CURRENT-BUILD-LATEST)
## check for HardenedBSD(latest current build release)
NAME_VERIFY = $( echo " ${ RELEASE } " | grep -iwE '(current-build-latest)' | sed 's/CURRENT/current/g' | sed 's/build/BUILD/g' | sed 's/latest/LATEST/g' )
validate_release
; ;
2021-07-12 14:45:37 -04:00
ubuntu_bionic| bionic| ubuntu-bionic)
2021-07-15 16:30:36 -04:00
UBUNTU = "1"
2021-07-12 14:45:37 -04:00
NAME_VERIFY = Ubuntu_1804
validate_release
; ;
ubuntu_focal| focal| ubuntu-focal)
2021-07-15 16:30:36 -04:00
UBUNTU = "1"
2021-07-12 14:45:37 -04:00
NAME_VERIFY = Ubuntu_2004
validate_release
; ;
2021-07-30 07:40:01 -05:00
debian_buster| buster| debian-buster)
NAME_VERIFY = Debian10
validate_release
; ;
2021-12-22 18:35:49 -07:00
debian_bullseye| bullseye| debian-bullseye)
NAME_VERIFY = Debian11
validate_release
; ;
2023-07-10 12:08:47 +02:00
debian_bookworm| bookworm| debian-bookworm)
NAME_VERIFY = Debian12
validate_release
; ;
2020-04-18 18:02:11 -04:00
*)
2020-08-30 10:57:14 -04:00
error_notify "Unknown Release."
2020-04-18 18:02:11 -04:00
usage
; ;
esac
2018-11-07 10:36:54 -07:00
2020-04-18 18:02:11 -04:00
## check for name/root/.bastille
if [ -d " ${ bastille_jailsdir } / ${ NAME } /root/.bastille " ] ; then
2020-08-30 10:57:14 -04:00
error_exit " Jail: ${ NAME } already created. ${ NAME } /root/.bastille exists. "
2020-04-18 18:02:11 -04:00
fi
2018-11-07 10:36:54 -07:00
2020-04-18 18:02:11 -04:00
## check for required release
if [ ! -d " ${ bastille_releasesdir } / ${ RELEASE } " ] ; then
2020-08-30 10:57:14 -04:00
error_exit "Release must be bootstrapped first; see 'bastille bootstrap'."
2020-04-18 18:02:11 -04:00
fi
2019-06-22 09:28:42 -06:00
2020-04-18 18:02:11 -04:00
## check if ip address is valid
if [ -n " ${ IP } " ] ; then
2021-08-07 19:57:53 +02:00
validate_ips
2020-04-18 18:02:11 -04:00
else
usage
fi
2018-11-07 10:36:54 -07:00
2020-04-18 18:02:11 -04:00
## check if interface is valid
2020-11-26 12:44:40 -05:00
if [ -n " ${ INTERFACE } " ] ; then
2020-04-18 18:02:11 -04:00
validate_netif
validate_netconf
2021-01-12 23:15:39 -04:00
elif [ -n " ${ VNET_JAIL } " ] ; then
if [ -z " ${ INTERFACE } " ] ; then
if [ -z " ${ bastille_network_shared } " ] ; then
# User must specify interface on vnet jails.
error_exit "Error: Network interface not defined."
else
validate_netconf
fi
2021-01-08 20:26:31 -04:00
fi
2020-04-18 18:02:11 -04:00
else
validate_netconf
fi
2019-10-24 17:02:50 -04:00
else
2020-11-25 21:19:08 -05:00
info " Creating empty jail: ${ NAME } . "
2019-10-24 17:02:50 -04:00
fi
2020-04-18 18:02:11 -04:00
## check if a running jail matches name or already exist
if [ -n " ${ NAME } " ] ; then
running_jail
2018-11-07 10:36:54 -07:00
fi
2020-11-26 12:44:40 -05:00
# May not exist on deployments created before Bastille 0.7.20200714, so creating it. -- cwells
if [ ! -e " ${ bastille_templatesdir } /default " ] ; then
ln -s " ${ bastille_sharedir } /templates/default " " ${ bastille_templatesdir } /default "
fi
# These variables were added after Bastille 0.7.20200714, so they may not exist in the user's config.
# We're checking for existence of the variables rather than empty since empty is a valid value. -- cwells
if [ -z ${ bastille_template_base +x } ] ; then
bastille_template_base = 'default/base'
fi
if [ -z ${ bastille_template_empty +x } ] ; then
bastille_template_empty = 'default/empty'
fi
2021-07-12 14:45:37 -04:00
if [ -z ${ bastille_template_linux +x } ] ; then
2021-07-12 14:54:00 -04:00
bastille_template_linux = 'default/linux'
2021-07-12 14:45:37 -04:00
fi
2020-11-26 12:44:40 -05:00
if [ -z ${ bastille_template_thick +x } ] ; then
bastille_template_thick = 'default/thick'
fi
2022-01-15 11:32:28 -04:00
if [ -z ${ bastille_template_clone +x } ] ; then
bastille_template_clone = 'default/clone'
fi
2020-11-26 12:44:40 -05:00
if [ -z ${ bastille_template_thin +x } ] ; then
bastille_template_thin = 'default/thin'
fi
if [ -z ${ bastille_template_vnet +x } ] ; then
bastille_template_vnet = 'default/vnet'
fi
2020-02-20 18:06:31 -04:00
create_jail " ${ NAME } " " ${ RELEASE } " " ${ IP } " " ${ INTERFACE } "