Add force stop option to bastille destroy, minor code cleanup
This commit is contained in:
@@ -69,7 +69,6 @@ fi
|
|||||||
validate_release_url() {
|
validate_release_url() {
|
||||||
## check upstream url, else switch to alternate url
|
## check upstream url, else switch to alternate url
|
||||||
if [ -n "${NAME_VERIFY}" ]; then
|
if [ -n "${NAME_VERIFY}" ]; then
|
||||||
RELEASE="${NAME_VERIFY}"
|
|
||||||
if ! fetch -qo /dev/null "${UPSTREAM_URL}/MANIFEST" 2>/dev/null; then
|
if ! fetch -qo /dev/null "${UPSTREAM_URL}/MANIFEST" 2>/dev/null; then
|
||||||
## try an alternate url
|
## try an alternate url
|
||||||
UPSTREAM_URL="${UPSTREAM_ALT}"
|
UPSTREAM_URL="${UPSTREAM_ALT}"
|
||||||
@@ -425,14 +424,14 @@ case "${1}" in
|
|||||||
*-RELEASE|*-release|*-RC1|*-rc1|*-RC2|*-rc2)
|
*-RELEASE|*-release|*-RC1|*-rc1|*-RC2|*-rc2)
|
||||||
## check for FreeBSD releases name
|
## check for FreeBSD releases name
|
||||||
NAME_VERIFY=$(echo "${RELEASE}" | grep -iwE '^([1-9]{2,2})\.[0-9](-RELEASE|-RC[1-2])$' | tr '[:lower:]' '[:upper:]')
|
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_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}/${RELEASE}"
|
UPSTREAM_ALT="ftp://ftp.freebsd.org/pub/FreeBSD/releases/${HW_MACHINE}/${HW_MACHINE_ARCH}/${NAME_VERIFY}"
|
||||||
validate_release_url
|
validate_release_url
|
||||||
;;
|
;;
|
||||||
*-stable-LAST|*-STABLE-last|*-stable-last|*-STABLE-LAST)
|
*-stable-LAST|*-STABLE-last|*-stable-last|*-STABLE-LAST)
|
||||||
## check for HardenedBSD releases name(previous infrastructure, keep for reference)
|
## 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')
|
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/"
|
UPSTREAM_ALT="http://ftp.freebsd.org/pub/FreeBSD/releases/"
|
||||||
validate_release_url
|
validate_release_url
|
||||||
;;
|
;;
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
. /usr/local/etc/bastille/bastille.conf
|
. /usr/local/etc/bastille/bastille.conf
|
||||||
|
|
||||||
usage() {
|
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
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,9 +41,13 @@ destroy_jail() {
|
|||||||
bastille_jail_log="${bastille_logsdir}/${TARGET}_console.log" ## file
|
bastille_jail_log="${bastille_logsdir}/${TARGET}_console.log" ## file
|
||||||
|
|
||||||
if [ "$(jls name | awk "/^${TARGET}$/")" ]; then
|
if [ "$(jls name | awk "/^${TARGET}$/")" ]; then
|
||||||
echo -e "${COLOR_RED}Jail running.${COLOR_RESET}"
|
if [ "${FORCE_STOP}" = "1" ]; then
|
||||||
echo -e "${COLOR_RED}See 'bastille stop ${TARGET}'.${COLOR_RESET}"
|
bastille stop ${TARGET}
|
||||||
exit 1
|
else
|
||||||
|
echo -e "${COLOR_RED}Jail running.${COLOR_RESET}"
|
||||||
|
echo -e "${COLOR_RED}See 'bastille stop ${TARGET}'.${COLOR_RESET}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -d "${bastille_jail_base}" ]; then
|
if [ ! -d "${bastille_jail_base}" ]; then
|
||||||
@@ -136,11 +140,28 @@ help|-h|--help)
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [ $# -gt 1 ] || [ $# -lt 1 ]; then
|
OPTION="${1}"
|
||||||
usage
|
TARGET="${2}"
|
||||||
fi
|
|
||||||
|
|
||||||
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
|
## check what should we clean
|
||||||
case "${TARGET}" in
|
case "${TARGET}" in
|
||||||
|
|||||||
Reference in New Issue
Block a user