2018-11-07 10:36:54 -07:00
#!/bin/sh
2020-04-14 11:52:29 +02:00
#
2020-01-26 09:51:02 -07:00
# Copyright (c) 2018-2020, 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( ) {
2020-08-30 10:57:14 -04:00
error_exit "Usage: bastille bootstrap [release|template] [update|arch]"
2018-11-07 10:36:54 -07:00
}
# Handle special-case commands first.
case " $1 " in
help| -h| --help)
usage
; ;
esac
2019-10-24 17:02:50 -04:00
# Validate ZFS parameters first.
if [ " ${ bastille_zfs_enable } " = "YES" ] ; then
## check for the ZFS pool and bastille prefix
if [ -z " ${ bastille_zfs_zpool } " ] ; then
2020-08-30 10:57:14 -04:00
error_exit "ERROR: Missing ZFS parameters. See bastille_zfs_zpool."
2019-12-08 17:46:15 -04:00
elif [ -z " ${ bastille_zfs_prefix } " ] ; then
2020-08-30 10:57:14 -04:00
error_exit "ERROR: Missing ZFS parameters. See bastille_zfs_prefix."
2019-10-24 17:02:50 -04:00
elif ! zfs list " ${ bastille_zfs_zpool } " > /dev/null 2>& 1; then
2020-08-30 10:57:14 -04:00
error_exit " ERROR: ${ bastille_zfs_zpool } is not a ZFS pool. "
2019-10-24 17:02:50 -04:00
fi
## check for the ZFS dataset prefix if already exist
2020-07-24 10:47:28 -04:00
if [ -d " / ${ bastille_zfs_zpool } / ${ bastille_zfs_prefix } " ] ; then
2019-10-24 17:02:50 -04:00
if ! zfs list " ${ bastille_zfs_zpool } / ${ bastille_zfs_prefix } " > /dev/null 2>& 1; then
2020-08-30 10:57:14 -04:00
error_exit " ERROR: ${ bastille_zfs_zpool } / ${ bastille_zfs_prefix } is not a ZFS dataset. "
2019-10-24 17:02:50 -04:00
fi
fi
fi
2020-02-02 02:42:22 -04:00
validate_release_url( ) {
2020-02-02 19:55:18 -04:00
## check upstream url, else warn user
2020-02-02 02:42:22 -04:00
if [ -n " ${ NAME_VERIFY } " ] ; then
2020-02-02 07:24:16 -04:00
RELEASE = " ${ NAME_VERIFY } "
2020-02-02 02:42:22 -04:00
if ! fetch -qo /dev/null " ${ UPSTREAM_URL } /MANIFEST " 2>/dev/null; then
2020-08-30 10:57:14 -04:00
error_exit "Unable to fetch MANIFEST. See 'bootstrap urls'."
2020-02-02 02:42:22 -04:00
fi
2020-02-08 09:10:17 -04:00
echo -e " ${ COLOR_GREEN } Bootstrapping ${ PLATFORM_OS } distfiles... ${ COLOR_RESET } "
2020-07-24 10:47:28 -04:00
# Alternate RELEASE/ARCH fetch support
2020-08-26 14:47:27 -04:00
if [ " ${ OPTION } " = "--i386" -o " ${ OPTION } " = "--32bit" ] ; then
2020-07-24 10:47:28 -04:00
ARCH = "i386"
RELEASE = " ${ RELEASE } - ${ ARCH } "
fi
2020-02-02 02:42:22 -04:00
bootstrap_directories
bootstrap_release
else
usage
fi
}
2019-06-22 09:28:42 -06:00
bootstrap_directories( ) {
2018-11-24 09:55:16 -07:00
## ensure required directories are in place
2019-06-22 09:28:42 -06:00
## ${bastille_prefix}
if [ ! -d " ${ bastille_prefix } " ] ; then
if [ " ${ bastille_zfs_enable } " = "YES" ] ; then
2020-02-20 18:06:31 -04:00
if [ -n " ${ bastille_zfs_zpool } " ] ; then
zfs create ${ bastille_zfs_options } -o mountpoint = " ${ bastille_prefix } " " ${ bastille_zfs_zpool } / ${ bastille_zfs_prefix } "
2020-03-10 17:15:46 +01:00
chmod 0750 " ${ bastille_prefix } "
2019-06-22 09:28:42 -06:00
fi
else
mkdir -p " ${ bastille_prefix } "
2019-07-15 07:44:45 -06:00
chmod 0750 " ${ bastille_prefix } "
2019-06-22 09:28:42 -06:00
fi
2018-11-07 10:36:54 -07:00
fi
2019-06-22 09:28:42 -06:00
2020-01-26 19:45:26 -04:00
## ${bastille_backupsdir}
if [ ! -d " ${ bastille_backupsdir } " ] ; then
if [ " ${ bastille_zfs_enable } " = "YES" ] ; then
2020-02-20 18:06:31 -04:00
if [ -n " ${ bastille_zfs_zpool } " ] ; then
zfs create ${ bastille_zfs_options } -o mountpoint = " ${ bastille_backupsdir } " " ${ bastille_zfs_zpool } / ${ bastille_zfs_prefix } /backups "
2020-03-10 20:47:33 +01:00
chmod 0750 " ${ bastille_backupsdir } "
2020-01-26 19:45:26 -04:00
fi
else
mkdir -p " ${ bastille_backupsdir } "
chmod 0750 " ${ bastille_backupsdir } "
fi
fi
2019-06-22 09:28:42 -06:00
## ${bastille_cachedir}
if [ ! -d " ${ bastille_cachedir } " ] ; then
if [ " ${ bastille_zfs_enable } " = "YES" ] ; then
2020-02-20 18:06:31 -04:00
if [ -n " ${ bastille_zfs_zpool } " ] ; then
zfs create ${ bastille_zfs_options } -o mountpoint = " ${ bastille_cachedir } " " ${ bastille_zfs_zpool } / ${ bastille_zfs_prefix } /cache "
zfs create ${ bastille_zfs_options } -o mountpoint = " ${ bastille_cachedir } / ${ RELEASE } " " ${ bastille_zfs_zpool } / ${ bastille_zfs_prefix } /cache/ ${ RELEASE } "
2019-06-22 09:28:42 -06:00
fi
else
2019-06-23 08:33:41 -06:00
mkdir -p " ${ bastille_cachedir } / ${ RELEASE } "
2019-06-22 09:28:42 -06:00
fi
2019-10-24 17:02:50 -04:00
## create subsequent cache/XX.X-RELEASE datasets
elif [ ! -d " ${ bastille_cachedir } / ${ RELEASE } " ] ; then
if [ " ${ bastille_zfs_enable } " = "YES" ] ; then
2020-02-20 18:06:31 -04:00
if [ -n " ${ bastille_zfs_zpool } " ] ; then
zfs create ${ bastille_zfs_options } -o mountpoint = " ${ bastille_cachedir } / ${ RELEASE } " " ${ bastille_zfs_zpool } / ${ bastille_zfs_prefix } /cache/ ${ RELEASE } "
2019-10-24 17:02:50 -04:00
fi
else
mkdir -p " ${ bastille_cachedir } / ${ RELEASE } "
fi
2018-11-07 10:36:54 -07:00
fi
2019-06-22 09:28:42 -06:00
## ${bastille_jailsdir}
if [ ! -d " ${ bastille_jailsdir } " ] ; then
if [ " ${ bastille_zfs_enable } " = "YES" ] ; then
2020-02-20 18:06:31 -04:00
if [ -n " ${ bastille_zfs_zpool } " ] ; then
zfs create ${ bastille_zfs_options } -o mountpoint = " ${ bastille_jailsdir } " " ${ bastille_zfs_zpool } / ${ bastille_zfs_prefix } /jails "
2019-06-22 09:28:42 -06:00
fi
else
mkdir -p " ${ bastille_jailsdir } "
fi
2018-11-24 09:55:16 -07:00
fi
2019-06-22 09:28:42 -06:00
## ${bastille_logsdir}
if [ ! -d " ${ bastille_logsdir } " ] ; then
if [ " ${ bastille_zfs_enable } " = "YES" ] ; then
2020-02-20 18:06:31 -04:00
if [ -n " ${ bastille_zfs_zpool } " ] ; then
zfs create ${ bastille_zfs_options } -o mountpoint = " ${ bastille_logsdir } " " ${ bastille_zfs_zpool } / ${ bastille_zfs_prefix } /logs "
2019-06-22 09:28:42 -06:00
fi
else
mkdir -p " ${ bastille_logsdir } "
fi
2018-11-07 10:36:54 -07:00
fi
2019-06-22 09:28:42 -06:00
## ${bastille_templatesdir}
if [ ! -d " ${ bastille_templatesdir } " ] ; then
if [ " ${ bastille_zfs_enable } " = "YES" ] ; then
2020-02-20 18:06:31 -04:00
if [ -n " ${ bastille_zfs_zpool } " ] ; then
zfs create ${ bastille_zfs_options } -o mountpoint = " ${ bastille_templatesdir } " " ${ bastille_zfs_zpool } / ${ bastille_zfs_prefix } /templates "
2019-06-22 09:28:42 -06:00
fi
else
mkdir -p " ${ bastille_templatesdir } "
fi
fi
## ${bastille_releasesdir}
if [ ! -d " ${ bastille_releasesdir } " ] ; then
if [ " ${ bastille_zfs_enable } " = "YES" ] ; then
2020-02-20 18:06:31 -04:00
if [ -n " ${ bastille_zfs_zpool } " ] ; then
zfs create ${ bastille_zfs_options } -o mountpoint = " ${ bastille_releasesdir } " " ${ bastille_zfs_zpool } / ${ bastille_zfs_prefix } /releases "
zfs create ${ bastille_zfs_options } -o mountpoint = " ${ bastille_releasesdir } / ${ RELEASE } " " ${ bastille_zfs_zpool } / ${ bastille_zfs_prefix } /releases/ ${ RELEASE } "
2019-10-24 17:02:50 -04:00
fi
2019-06-22 09:28:42 -06:00
else
2019-06-23 08:33:41 -06:00
mkdir -p " ${ bastille_releasesdir } / ${ RELEASE } "
2019-06-22 09:28:42 -06:00
fi
2020-02-24 19:27:51 -07:00
2019-10-24 17:02:50 -04:00
## create subsequent releases/XX.X-RELEASE datasets
elif [ ! -d " ${ bastille_releasesdir } / ${ RELEASE } " ] ; then
if [ " ${ bastille_zfs_enable } " = "YES" ] ; then
2020-02-20 18:06:31 -04:00
if [ -n " ${ bastille_zfs_zpool } " ] ; then
zfs create ${ bastille_zfs_options } -o mountpoint = " ${ bastille_releasesdir } / ${ RELEASE } " " ${ bastille_zfs_zpool } / ${ bastille_zfs_prefix } /releases/ ${ RELEASE } "
2019-10-24 17:02:50 -04:00
fi
else
mkdir -p " ${ bastille_releasesdir } / ${ RELEASE } "
fi
2019-06-22 09:28:42 -06:00
fi
}
bootstrap_release( ) {
2020-01-18 16:17:10 -04:00
## if release exists quit, else bootstrap additional distfiles
2019-06-22 09:28:42 -06:00
if [ -f " ${ bastille_releasesdir } / ${ RELEASE } /COPYRIGHT " ] ; then
2020-01-18 16:17:10 -04:00
## check distfiles list and skip existing cached files
bastille_bootstrap_archives = $( echo " ${ bastille_bootstrap_archives } " | sed "s/base//" )
2020-02-20 18:06:31 -04:00
bastille_cached_files = $( ls " ${ bastille_cachedir } / ${ RELEASE } " | grep -v "MANIFEST" | tr -d ".txz" )
2020-01-18 16:17:10 -04:00
for distfile in ${ bastille_cached_files } ; do
2020-02-20 18:06:31 -04:00
bastille_bootstrap_archives = $( echo " ${ bastille_bootstrap_archives } " | sed " s/ ${ distfile } // " )
2020-01-18 16:17:10 -04:00
done
## check if release already bootstrapped, else continue bootstrapping
if [ -z " ${ bastille_bootstrap_archives } " ] ; then
2020-08-30 10:57:14 -04:00
error_exit "Bootstrap appears complete."
2020-01-18 16:17:10 -04:00
else
echo -e " ${ COLOR_GREEN } Bootstrapping additional distfiles... ${ COLOR_RESET } "
fi
2019-05-22 21:50:29 -06:00
fi
2019-06-22 09:28:42 -06:00
for _archive in ${ bastille_bootstrap_archives } ; do
2019-10-24 17:02:50 -04:00
## check if the dist files already exists then extract
2019-11-08 02:37:45 -04:00
FETCH_VALIDATION = "0"
2019-06-22 09:28:42 -06:00
if [ -f " ${ bastille_cachedir } / ${ RELEASE } / ${ _archive } .txz " ] ; then
2020-02-11 17:43:52 -04:00
echo -e " ${ COLOR_GREEN } Extracting ${ PLATFORM_OS } ${ RELEASE } ${ _archive } .txz. ${ COLOR_RESET } "
2020-02-24 19:27:51 -07:00
if /usr/bin/tar -C " ${ bastille_releasesdir } / ${ RELEASE } " -xf " ${ bastille_cachedir } / ${ RELEASE } / ${ _archive } .txz " ; then
## silence motd at container login
touch " ${ bastille_releasesdir } / ${ RELEASE } /root/.hushlogin "
touch " ${ bastille_releasesdir } / ${ RELEASE } /usr/share/skel/dot.hushlogin "
else
2020-08-30 10:57:14 -04:00
error_exit " Failed to extract ${ _archive } .txz. "
2019-11-08 02:37:45 -04:00
fi
2019-10-24 17:02:50 -04:00
else
2020-02-24 19:27:51 -07:00
## get the manifest for dist files checksum validation
if [ ! -f " ${ bastille_cachedir } / ${ RELEASE } /MANIFEST " ] ; then
fetch " ${ UPSTREAM_URL } /MANIFEST " -o " ${ bastille_cachedir } / ${ RELEASE } /MANIFEST " || FETCH_VALIDATION = "1"
fi
2019-11-02 16:05:49 -04:00
2020-02-24 19:27:51 -07:00
if [ " ${ FETCH_VALIDATION } " -ne "0" ] ; then
## perform cleanup only for stale/empty directories on failure
if [ " ${ bastille_zfs_enable } " = "YES" ] ; then
if [ -n " ${ bastille_zfs_zpool } " ] ; then
if [ ! " $( ls -A " ${ bastille_cachedir } / ${ RELEASE } " ) " ] ; then
zfs destroy " ${ bastille_zfs_zpool } / ${ bastille_zfs_prefix } /cache/ ${ RELEASE } "
2019-11-08 02:37:45 -04:00
fi
2020-02-24 19:27:51 -07:00
if [ ! " $( ls -A " ${ bastille_releasesdir } / ${ RELEASE } " ) " ] ; then
zfs destroy " ${ bastille_zfs_zpool } / ${ bastille_zfs_prefix } /releases/ ${ RELEASE } "
2019-11-08 02:37:45 -04:00
fi
fi
fi
2020-02-24 19:27:51 -07:00
if [ -d " ${ bastille_cachedir } / ${ RELEASE } " ] ; then
if [ ! " $( ls -A " ${ bastille_cachedir } / ${ RELEASE } " ) " ] ; then
rm -rf " ${ bastille_cachedir } / ${ RELEASE } "
fi
fi
if [ -d " ${ bastille_releasesdir } / ${ RELEASE } " ] ; then
if [ ! " $( ls -A " ${ bastille_releasesdir } / ${ RELEASE } " ) " ] ; then
rm -rf " ${ bastille_releasesdir } / ${ RELEASE } "
fi
fi
2020-08-30 10:57:14 -04:00
error_exit "Bootstrap failed."
2020-02-24 19:27:51 -07:00
fi
2019-11-08 02:37:45 -04:00
2019-10-24 17:02:50 -04:00
## fetch for missing dist files
if [ ! -f " ${ bastille_cachedir } / ${ RELEASE } / ${ _archive } .txz " ] ; then
2020-02-20 18:06:31 -04:00
fetch " ${ UPSTREAM_URL } / ${ _archive } .txz " -o " ${ bastille_cachedir } / ${ RELEASE } / ${ _archive } .txz "
if [ " $? " -ne 0 ] ; then
2019-11-08 02:37:45 -04:00
## alert only if unable to fetch additional dist files
2020-08-30 10:57:14 -04:00
error_notify " Failed to fetch ${ _archive } .txz. "
2019-11-08 02:37:45 -04:00
fi
2019-10-24 17:02:50 -04:00
fi
2019-11-02 16:05:49 -04:00
## compare checksums on the fetched dist files
if [ -f " ${ bastille_cachedir } / ${ RELEASE } / ${ _archive } .txz " ] ; then
2020-02-20 18:06:31 -04:00
SHA256_DIST = $( grep -w " ${ _archive } .txz " " ${ bastille_cachedir } / ${ RELEASE } /MANIFEST " | awk '{print $2}' )
SHA256_FILE = $( sha256 -q " ${ bastille_cachedir } / ${ RELEASE } / ${ _archive } .txz " )
2019-11-02 16:05:49 -04:00
if [ " ${ SHA256_FILE } " != " ${ SHA256_DIST } " ] ; then
2020-02-20 18:06:31 -04:00
rm " ${ bastille_cachedir } / ${ RELEASE } / ${ _archive } .txz "
2020-08-30 10:57:14 -04:00
error_exit " Failed validation for ${ _archive } .txz. Please retry bootstrap! "
2019-11-23 12:56:21 -07:00
else
echo -e " ${ COLOR_GREEN } Validated checksum for ${ RELEASE } : ${ _archive } .txz. ${ COLOR_RESET } "
echo -e " ${ COLOR_GREEN } MANIFEST: ${ SHA256_DIST } ${ COLOR_RESET } "
echo -e " ${ COLOR_GREEN } DOWNLOAD: ${ SHA256_FILE } ${ COLOR_RESET } "
2019-11-02 16:05:49 -04:00
fi
fi
2019-10-24 17:02:50 -04:00
## extract the fetched dist files
if [ -f " ${ bastille_cachedir } / ${ RELEASE } / ${ _archive } .txz " ] ; then
2020-02-11 17:43:52 -04:00
echo -e " ${ COLOR_GREEN } Extracting ${ PLATFORM_OS } ${ RELEASE } ${ _archive } .txz. ${ COLOR_RESET } "
2020-02-24 19:27:51 -07:00
if /usr/bin/tar -C " ${ bastille_releasesdir } / ${ RELEASE } " -xf " ${ bastille_cachedir } / ${ RELEASE } / ${ _archive } .txz " ; then
## silence motd at container login
touch " ${ bastille_releasesdir } / ${ RELEASE } /root/.hushlogin "
touch " ${ bastille_releasesdir } / ${ RELEASE } /usr/share/skel/dot.hushlogin "
else
2020-08-30 10:57:14 -04:00
error_exit " Failed to extract ${ _archive } .txz. "
2019-11-08 02:37:45 -04:00
fi
2019-10-24 17:02:50 -04:00
fi
2019-06-23 08:33:41 -06:00
fi
2019-06-22 09:28:42 -06:00
done
echo
2018-11-07 10:36:54 -07:00
2019-06-22 09:28:42 -06:00
echo -e " ${ COLOR_GREEN } Bootstrap successful. ${ COLOR_RESET } "
echo -e " ${ COLOR_GREEN } See 'bastille --help' for available commands. ${ COLOR_RESET } "
echo
2018-11-07 10:36:54 -07:00
}
2018-11-28 21:02:42 -07:00
bootstrap_template( ) {
2019-11-21 16:49:00 -07:00
## ${bastille_templatesdir}
if [ ! -d " ${ bastille_templatesdir } " ] ; then
if [ " ${ bastille_zfs_enable } " = "YES" ] ; then
2020-02-20 18:06:31 -04:00
if [ -n " ${ bastille_zfs_zpool } " ] ; then
zfs create ${ bastille_zfs_options } -o mountpoint = " ${ bastille_templatesdir } " " ${ bastille_zfs_zpool } / ${ bastille_zfs_prefix } /templates "
2019-11-21 16:49:00 -07:00
fi
else
mkdir -p " ${ bastille_templatesdir } "
fi
fi
2018-11-28 21:02:42 -07:00
## define basic variables
_url = ${ BASTILLE_TEMPLATE_URL }
_user = ${ BASTILLE_TEMPLATE_USER }
_repo = ${ BASTILLE_TEMPLATE_REPO }
_template = ${ bastille_templatesdir } /${ _user } /${ _repo }
## support for non-git
2019-12-11 20:35:05 +01:00
if [ ! -x " $( which git) " ] ; then
2020-08-30 10:57:14 -04:00
error_notify "Git not found."
error_exit "Not yet implemented."
2019-12-11 20:35:05 +01:00
elif [ -x " $( which git) " ] ; then
2018-11-28 21:02:42 -07:00
if [ ! -d " ${ _template } /.git " ] ; then
2019-12-07 17:48:39 -07:00
$( which git) clone " ${ _url } " " ${ _template } " || \
2020-08-30 10:57:14 -04:00
error_notify "Clone unsuccessful."
2018-11-28 21:02:42 -07:00
elif [ -d " ${ _template } /.git " ] ; then
2020-02-20 18:06:31 -04:00
cd " ${ _template } " && $( which git) pull || \
2020-08-30 10:57:14 -04:00
error_notify "Template update unsuccessful."
2018-11-28 21:02:42 -07:00
fi
fi
2020-02-20 18:06:31 -04:00
bastille verify " ${ _user } / ${ _repo } "
2018-11-28 21:02:42 -07:00
}
2019-05-22 21:50:29 -06:00
HW_MACHINE = $( sysctl hw.machine | awk '{ print $2 }' )
HW_MACHINE_ARCH = $( sysctl hw.machine_arch | awk '{ print $2 }' )
2019-11-08 02:37:45 -04:00
RELEASE = " ${ 1 } "
2020-08-26 14:47:27 -04:00
OPTION = " ${ 2 } "
2020-07-24 10:47:28 -04:00
# Alternate RELEASE/ARCH fetch support(experimental)
2020-08-26 14:47:27 -04:00
if [ -n " ${ OPTION } " ] && [ " ${ OPTION } " != " ${ HW_MACHINE } " ] && [ " ${ OPTION } " != "update" ] ; then
2020-07-24 10:47:28 -04:00
# Supported architectures
2020-08-26 14:47:27 -04:00
if [ " ${ OPTION } " = "--i386" -o " ${ OPTION } " = "--32bit" ] ; then
2020-07-24 10:47:28 -04:00
HW_MACHINE = "i386"
HW_MACHINE_ARCH = "i386"
else
2020-08-30 10:57:14 -04:00
error_exit "Unsupported architecture."
2020-07-24 10:47:28 -04:00
fi
fi
2019-05-22 21:50:29 -06:00
2019-11-08 02:37:45 -04:00
## Filter sane release names
2018-11-28 21:02:42 -07:00
case " ${ 1 } " in
2020-08-28 14:13:54 -06:00
*-CURRENT| *-current)
## check for FreeBSD releases name
NAME_VERIFY = $( echo " ${ RELEASE } " | grep -iwE '^([1-9]{2,2})\.[0-9](-CURRENT)$' | tr '[:lower:]' '[:upper:]' )
UPSTREAM_URL = $( echo " ${ bastille_url_freebsd } ${ HW_MACHINE } / ${ HW_MACHINE_ARCH } / ${ NAME_VERIFY } " | sed 's/releases/snapshots/' )
PLATFORM_OS = "FreeBSD"
validate_release_url
; ;
2019-11-08 02:37:45 -04:00
*-RELEASE| *-release| *-RC1| *-rc1| *-RC2| *-rc2)
2020-02-02 02:42:22 -04:00
## check for FreeBSD releases name
NAME_VERIFY = $( echo " ${ RELEASE } " | grep -iwE '^([1-9]{2,2})\.[0-9](-RELEASE|-RC[1-2])$' | tr '[:lower:]' '[:upper:]' )
2020-02-02 06:50:58 -04:00
UPSTREAM_URL = " ${ bastille_url_freebsd } ${ HW_MACHINE } / ${ HW_MACHINE_ARCH } / ${ NAME_VERIFY } "
2020-02-08 09:10:17 -04:00
PLATFORM_OS = "FreeBSD"
2020-02-02 02:42:22 -04:00
validate_release_url
2018-11-28 21:02:42 -07:00
; ;
2019-11-08 02:37:45 -04:00
*-stable-LAST| *-STABLE-last| *-stable-last| *-STABLE-LAST)
2020-02-02 02:42:22 -04:00
## check for HardenedBSD releases name(previous infrastructure, keep for reference)
2020-02-08 09:10:17 -04:00
NAME_VERIFY = $( echo " ${ RELEASE } " | grep -iwE '^([1-9]{2,2})(-stable-last)$' | sed 's/STABLE/stable/g' | sed 's/last/LAST/g' )
2020-02-02 06:50:58 -04:00
UPSTREAM_URL = " ${ bastille_url_hardenedbsd } ${ HW_MACHINE } / ${ HW_MACHINE_ARCH } /hardenedbsd- ${ NAME_VERIFY } "
2020-02-08 09:10:17 -04:00
PLATFORM_OS = "HardenedBSD"
2020-02-02 02:42:22 -04:00
validate_release_url
2019-12-05 03:38:33 -04:00
; ;
2020-02-02 02:42:22 -04:00
*-stable-build-[ 0-9] *| *-STABLE-BUILD-[ 0-9] *)
## check for HardenedBSD(specific stable build releases)
2020-02-08 09:10:17 -04:00
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' )
2020-04-12 19:06:27 -06:00
NAME_RELEASE = $( echo " ${ NAME_VERIFY } " | sed 's/-build-[0-9]\{1,3\}//g' )
2020-02-20 18:06:31 -04:00
NAME_BUILD = $( echo " ${ NAME_VERIFY } " | sed 's/[0-9]\{1,2\}-stable-//g' )
2020-02-02 02:42:22 -04:00
UPSTREAM_URL = " ${ bastille_url_hardenedbsd } ${ NAME_RELEASE } / ${ HW_MACHINE } / ${ HW_MACHINE_ARCH } / ${ NAME_BUILD } "
2020-02-08 09:10:17 -04:00
PLATFORM_OS = "HardenedBSD"
2020-02-02 02:42:22 -04:00
validate_release_url
; ;
2020-02-11 17:27:02 -04:00
*-stable-build-latest| *-stable-BUILD-LATEST| *-STABLE-BUILD-LATEST)
2020-02-02 02:42:22 -04:00
## check for HardenedBSD(latest stable build release)
2020-02-08 09:10:17 -04:00
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' )
2020-02-20 18:06:31 -04:00
NAME_RELEASE = $( echo " ${ NAME_VERIFY } " | sed 's/-BUILD-LATEST//g' )
NAME_BUILD = $( echo " ${ NAME_VERIFY } " | sed 's/[0-9]\{1,2\}-stable-//g' )
2020-02-02 02:42:22 -04:00
UPSTREAM_URL = " ${ bastille_url_hardenedbsd } ${ NAME_RELEASE } / ${ HW_MACHINE } / ${ HW_MACHINE_ARCH } / ${ NAME_BUILD } "
2020-02-08 09:10:17 -04:00
PLATFORM_OS = "HardenedBSD"
2020-02-02 02:42:22 -04:00
validate_release_url
; ;
2020-02-08 09:10:17 -04:00
current-build-[ 0-9] *| CURRENT-BUILD-[ 0-9] *)
2020-02-02 02:42:22 -04:00
## check for HardenedBSD(specific current build releases)
2020-02-08 09:10:17 -04:00
NAME_VERIFY = $( echo " ${ RELEASE } " | grep -iwE '(current-build)-([0-9]{1,3})' | sed 's/BUILD/build/g' | sed 's/CURRENT/current/g' )
2020-02-20 18:06:31 -04:00
NAME_RELEASE = $( echo " ${ NAME_VERIFY } " | sed 's/current-.*/current/g' )
NAME_BUILD = $( echo " ${ NAME_VERIFY } " | sed 's/current-//g' )
2020-02-02 02:42:22 -04:00
UPSTREAM_URL = " ${ bastille_url_hardenedbsd } ${ NAME_RELEASE } / ${ HW_MACHINE } / ${ HW_MACHINE_ARCH } / ${ NAME_BUILD } "
2020-02-08 09:10:17 -04:00
PLATFORM_OS = "HardenedBSD"
2020-02-02 02:42:22 -04:00
validate_release_url
; ;
2020-02-11 17:27:02 -04:00
current-build-latest| current-BUILD-LATEST| CURRENT-BUILD-LATEST)
2020-02-02 02:42:22 -04:00
## check for HardenedBSD(latest current build release)
2020-02-08 09:10:17 -04:00
NAME_VERIFY = $( echo " ${ RELEASE } " | grep -iwE '(current-build-latest)' | sed 's/CURRENT/current/g' | sed 's/build/BUILD/g' | sed 's/latest/LATEST/g' )
2020-02-20 18:06:31 -04:00
NAME_RELEASE = $( echo " ${ NAME_VERIFY } " | sed 's/current-.*/current/g' )
NAME_BUILD = $( echo " ${ NAME_VERIFY } " | sed 's/current-//g' )
2020-02-02 02:42:22 -04:00
UPSTREAM_URL = " ${ bastille_url_hardenedbsd } ${ NAME_RELEASE } / ${ HW_MACHINE } / ${ HW_MACHINE_ARCH } / ${ NAME_BUILD } "
2020-02-08 09:10:17 -04:00
PLATFORM_OS = "HardenedBSD"
2020-02-02 02:42:22 -04:00
validate_release_url
2018-11-28 21:02:42 -07:00
; ;
2019-06-23 08:33:41 -06:00
http?://github.com/*/*| http?://gitlab.com/*/*)
2018-11-28 21:02:42 -07:00
BASTILLE_TEMPLATE_URL = ${ 1 }
BASTILLE_TEMPLATE_USER = $( echo " ${ 1 } " | awk -F / '{ print $4 }' )
BASTILLE_TEMPLATE_REPO = $( echo " ${ 1 } " | awk -F / '{ print $5 }' )
bootstrap_template
; ;
2018-11-07 10:36:54 -07:00
*)
usage
; ;
esac
2019-11-20 19:57:18 -07:00
2020-08-26 14:47:27 -04:00
case " ${ OPTION } " in
2019-11-23 12:56:21 -07:00
update)
bastille update " ${ RELEASE } "
; ;
esac