mirror of
https://github.com/hackacad/bastille.git
synced 2025-12-24 03:01:01 +01:00
Merge branch 'BastilleBSD:master' into patch-2
This commit is contained in:
@@ -28,6 +28,9 @@
|
||||
# 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.
|
||||
|
||||
# Source config file
|
||||
. /usr/local/etc/bastille/bastille.conf
|
||||
|
||||
COLOR_RED=
|
||||
COLOR_GREEN=
|
||||
COLOR_YELLOW=
|
||||
@@ -51,11 +54,18 @@ if [ -z "${NO_COLOR}" ] && [ -t 1 ]; then
|
||||
enable_color
|
||||
fi
|
||||
|
||||
# Notify message on error, but do not exit
|
||||
# Error/Info functions
|
||||
error_notify() {
|
||||
echo -e "${COLOR_RED}$*${COLOR_RESET}" 1>&2
|
||||
}
|
||||
|
||||
error_continue() {
|
||||
error_notify "$@"
|
||||
# Disabling this shellcheck as we only ever call it inside of a loop
|
||||
# shellcheck disable=SC2104
|
||||
continue
|
||||
}
|
||||
|
||||
# Notify message on error and exit
|
||||
error_exit() {
|
||||
error_notify "$@"
|
||||
@@ -70,6 +80,33 @@ warn() {
|
||||
echo -e "${COLOR_YELLOW}$*${COLOR_RESET}"
|
||||
}
|
||||
|
||||
check_target_exists() {
|
||||
local _TARGET="${1}"
|
||||
if [ ! -d "${bastille_jailsdir}"/"${_TARGET}" ]; then
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
check_target_is_running() {
|
||||
local _TARGET="${1}"
|
||||
if [ ! "$(/usr/sbin/jls name | awk "/^${_TARGET}$/")" ]; then
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
check_target_is_stopped() {
|
||||
local _TARGET="${1}"
|
||||
if [ "$(/usr/sbin/jls name | awk "/^${_TARGET}$/")" ]; then
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
generate_static_mac() {
|
||||
local jail_name="${1}"
|
||||
local external_interface="${2}"
|
||||
@@ -136,6 +173,43 @@ EOF
|
||||
fi
|
||||
}
|
||||
|
||||
set_target() {
|
||||
local _TARGET="${1}"
|
||||
if [ "${_TARGET}" = ALL ] || [ "${_TARGET}" = all ]; then
|
||||
target_all_jails
|
||||
else
|
||||
check_target_exists "${_TARGET}" || error_exit "Jail not found \"${_TARGET}\""
|
||||
JAILS="${_TARGET}"
|
||||
TARGET="${_TARGET}"
|
||||
export JAILS
|
||||
export TARGET
|
||||
fi
|
||||
}
|
||||
|
||||
set_target_single() {
|
||||
local _TARGET="${1}"
|
||||
if [ "${_TARGET}" = ALL ] || [ "${_TARGET}" = all ]; then
|
||||
error_exit "[all|ALL] not supported with this command."
|
||||
else
|
||||
check_target_exists "${_TARGET}" || error_exit "Jail not found \"${_TARGET}\""
|
||||
JAILS="${_TARGET}"
|
||||
TARGET="${_TARGET}"
|
||||
export JAILS
|
||||
export TARGET
|
||||
fi
|
||||
}
|
||||
|
||||
target_all_jails() {
|
||||
local _JAILS="$(bastille list jails)"
|
||||
JAILS=""
|
||||
for _jail in ${_JAILS}; do
|
||||
if [ -d "${bastille_jailsdir}/${_jail}" ]; then
|
||||
JAILS="${JAILS} ${_jail}"
|
||||
fi
|
||||
done
|
||||
export JAILS
|
||||
}
|
||||
|
||||
checkyesno() {
|
||||
## copied from /etc/rc.subr -- cedwards (20231125)
|
||||
## issue #368 (lowercase values should be parsed)
|
||||
@@ -156,3 +230,4 @@ checkyesno() {
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user