Add force stop option to bastille destroy, minor code cleanup

This commit is contained in:
Jose
2020-02-02 06:50:58 -04:00
parent 5aba0d36f5
commit 9681254d76
2 changed files with 32 additions and 12 deletions

View File

@@ -69,7 +69,6 @@ fi
validate_release_url() {
## check upstream url, else switch to alternate url
if [ -n "${NAME_VERIFY}" ]; then
RELEASE="${NAME_VERIFY}"
if ! fetch -qo /dev/null "${UPSTREAM_URL}/MANIFEST" 2>/dev/null; then
## try an alternate url
UPSTREAM_URL="${UPSTREAM_ALT}"
@@ -425,14 +424,14 @@ case "${1}" in
*-RELEASE|*-release|*-RC1|*-rc1|*-RC2|*-rc2)
## check for FreeBSD releases name
NAME_VERIFY=$(echo "${RELEASE}" | grep -iwE '^([1-9]{2,2})\.[0-9](-RELEASE|-RC[1-2])$' | tr '[:lower:]' '[:upper:]')
UPSTREAM_URL="${bastille_url_freebsd}${HW_MACHINE}/${HW_MACHINE_ARCH}/${RELEASE}"
UPSTREAM_ALT="ftp://ftp.freebsd.org/pub/FreeBSD/releases/${HW_MACHINE}/${HW_MACHINE_ARCH}/${RELEASE}"
UPSTREAM_URL="${bastille_url_freebsd}${HW_MACHINE}/${HW_MACHINE_ARCH}/${NAME_VERIFY}"
UPSTREAM_ALT="ftp://ftp.freebsd.org/pub/FreeBSD/releases/${HW_MACHINE}/${HW_MACHINE_ARCH}/${NAME_VERIFY}"
validate_release_url
;;
*-stable-LAST|*-STABLE-last|*-stable-last|*-STABLE-LAST)
## check for HardenedBSD releases name(previous infrastructure, keep for reference)
NAME_VERIFY=$(echo "${RELEASE}" | grep -iwE '^([1-9]{2,2})(-stable-LAST|-STABLE-last|-stable-last|-STABLE-LAST)$' | sed 's/STABLE/stable/g' | sed 's/last/LAST/g')
UPSTREAM_URL="${bastille_url_hardenedbsd}${HW_MACHINE}/${HW_MACHINE_ARCH}/hardenedbsd-${RELEASE}"
UPSTREAM_URL="${bastille_url_hardenedbsd}${HW_MACHINE}/${HW_MACHINE_ARCH}/hardenedbsd-${NAME_VERIFY}"
UPSTREAM_ALT="http://ftp.freebsd.org/pub/FreeBSD/releases/"
validate_release_url
;;

View File

@@ -32,7 +32,7 @@
. /usr/local/etc/bastille/bastille.conf
usage() {
echo -e "${COLOR_RED}Usage: bastille destroy [container|release]${COLOR_RESET}"
echo -e "${COLOR_RED}Usage: bastille destroy [option] | [container|release]${COLOR_RESET}"
exit 1
}
@@ -41,9 +41,13 @@ destroy_jail() {
bastille_jail_log="${bastille_logsdir}/${TARGET}_console.log" ## file
if [ "$(jls name | awk "/^${TARGET}$/")" ]; then
echo -e "${COLOR_RED}Jail running.${COLOR_RESET}"
echo -e "${COLOR_RED}See 'bastille stop ${TARGET}'.${COLOR_RESET}"
exit 1
if [ "${FORCE_STOP}" = "1" ]; then
bastille stop ${TARGET}
else
echo -e "${COLOR_RED}Jail running.${COLOR_RESET}"
echo -e "${COLOR_RED}See 'bastille stop ${TARGET}'.${COLOR_RESET}"
exit 1
fi
fi
if [ ! -d "${bastille_jail_base}" ]; then
@@ -136,11 +140,28 @@ help|-h|--help)
;;
esac
if [ $# -gt 1 ] || [ $# -lt 1 ]; then
usage
fi
OPTION="${1}"
TARGET="${2}"
TARGET="$1"
## handle additional options
case "${OPTION}" in
-f|--forcestop)
if [ $# -gt 2 ] || [ $# -lt 2 ]; then
usage
fi
FORCE_STOP="1"
;;
-*)
echo -e "${COLOR_RED}Unknown Option.${COLOR_RESET}"
usage
;;
*)
if [ $# -gt 1 ] || [ $# -lt 1 ]; then
usage
fi
TARGET="${1}"
;;
esac
## check what should we clean
case "${TARGET}" in