mirror of
https://github.com/hackacad/bastille.git
synced 2025-12-19 16:51:00 +01:00
template: Implement new functions
This commit is contained in:
@@ -33,8 +33,16 @@
|
|||||||
. /usr/local/share/bastille/common.sh
|
. /usr/local/share/bastille/common.sh
|
||||||
. /usr/local/etc/bastille/bastille.conf
|
. /usr/local/etc/bastille/bastille.conf
|
||||||
|
|
||||||
bastille_usage() {
|
usage() {
|
||||||
error_exit "Usage: bastille template TARGET|--convert project/template"
|
error_notify "Usage: bastille template [option(s)] TARGET [--convert|project/template]"
|
||||||
|
cat << EOF
|
||||||
|
Options:
|
||||||
|
|
||||||
|
-a | --auto Auto mode. Start/stop jail(s) if required.
|
||||||
|
-x | --debug Enable debug mode.
|
||||||
|
|
||||||
|
EOF
|
||||||
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
post_command_hook() {
|
post_command_hook() {
|
||||||
@@ -107,26 +115,51 @@ render() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Handle special-case commands first.
|
# Handle options.
|
||||||
case "$1" in
|
AUTO=0
|
||||||
help|-h|--help)
|
while [ "$#" -gt 0 ]; do
|
||||||
bastille_usage
|
case "${1}" in
|
||||||
|
-h|--help|help)
|
||||||
|
usage
|
||||||
|
;;
|
||||||
|
-a|--auto)
|
||||||
|
AUTO=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-x|--debug)
|
||||||
|
enable_debug
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-*)
|
||||||
|
for _opt in $(echo ${1} | sed 's/-//g' | fold -w1); do
|
||||||
|
case ${_opt} in
|
||||||
|
a) AUTO=1 ;;
|
||||||
|
x) enable_debug ;;
|
||||||
|
*) error_exit "Unknown Option: \"${1}\"" ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
break
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
if [ $# -lt 1 ]; then
|
if [ $# -lt 2 ]; then
|
||||||
bastille_usage
|
bastille_usage
|
||||||
fi
|
fi
|
||||||
|
|
||||||
bastille_root_check
|
TARGET="${1}"
|
||||||
|
TEMPLATE="${2}"
|
||||||
## global variables
|
|
||||||
TEMPLATE="${1}"
|
|
||||||
bastille_template=${bastille_templatesdir}/${TEMPLATE}
|
bastille_template=${bastille_templatesdir}/${TEMPLATE}
|
||||||
if [ -z "${HOOKS}" ]; then
|
if [ -z "${HOOKS}" ]; then
|
||||||
HOOKS='LIMITS INCLUDE PRE FSTAB PF PKG OVERLAY CONFIG SYSRC SERVICE CMD RENDER'
|
HOOKS='LIMITS INCLUDE PRE FSTAB PF PKG OVERLAY CONFIG SYSRC SERVICE CMD RENDER'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
bastille_root_check
|
||||||
|
|
||||||
|
# We set the target only if it is not --convert
|
||||||
# Special case conversion of hook-style template files into a Bastillefile. -- cwells
|
# Special case conversion of hook-style template files into a Bastillefile. -- cwells
|
||||||
if [ "${TARGET}" = '--convert' ]; then
|
if [ "${TARGET}" = '--convert' ]; then
|
||||||
if [ -d "${TEMPLATE}" ]; then # A relative path was provided. -- cwells
|
if [ -d "${TEMPLATE}" ]; then # A relative path was provided. -- cwells
|
||||||
@@ -174,6 +207,8 @@ if [ "${TARGET}" = '--convert' ]; then
|
|||||||
|
|
||||||
info "Template converted: ${TEMPLATE}"
|
info "Template converted: ${TEMPLATE}"
|
||||||
exit 0
|
exit 0
|
||||||
|
else
|
||||||
|
set_target "${TARGET}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case ${TEMPLATE} in
|
case ${TEMPLATE} in
|
||||||
@@ -201,10 +236,6 @@ case ${TEMPLATE} in
|
|||||||
error_exit "Template name/URL not recognized."
|
error_exit "Template name/URL not recognized."
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [ -z "${JAILS}" ]; then
|
|
||||||
error_exit "Container ${TARGET} is not running."
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check for an --arg-file parameter. -- cwells
|
# Check for an --arg-file parameter. -- cwells
|
||||||
for _script_arg in "$@"; do
|
for _script_arg in "$@"; do
|
||||||
case ${_script_arg} in
|
case ${_script_arg} in
|
||||||
@@ -226,7 +257,16 @@ if [ -n "${ARG_FILE}" ] && [ ! -f "${ARG_FILE}" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
for _jail in ${JAILS}; do
|
for _jail in ${JAILS}; do
|
||||||
|
|
||||||
info "[${_jail}]:"
|
info "[${_jail}]:"
|
||||||
|
|
||||||
|
check_target_is_running "${_jail}" || if [ "${AUTO}" -eq 1 ]; then
|
||||||
|
bastille start "${_jail}"
|
||||||
|
else
|
||||||
|
error_notify "Jail is not running."
|
||||||
|
error_continue "Use [-a|--auto] to auto-start the jail."
|
||||||
|
fi
|
||||||
|
|
||||||
info "Applying template: ${TEMPLATE}..."
|
info "Applying template: ${TEMPLATE}..."
|
||||||
|
|
||||||
## get jail ip4 and ip6 values
|
## get jail ip4 and ip6 values
|
||||||
|
|||||||
Reference in New Issue
Block a user