Skip to content

Commit

Permalink
force add
Browse files Browse the repository at this point in the history
  • Loading branch information
tschettervictor authored Dec 30, 2024
1 parent 3976b4f commit 7894941
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions usr/local/share/bastille/network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ usage() {
cat << EOF
Options:
-r | --restart Restart jail on completion.
-f | --force Stop the jail if it is running.
-s | --start Start jail on completion.
-v | --vnet Adds a VNET interface to an existing jail.
-b | --bridge Adds a bridged VNET interface to an existing jail.
Expand All @@ -47,7 +48,7 @@ EOF

# Handle options.
FORCE=0
RESTART=0
START=0
VNET_JAIL=0
BRIDGE_VNET_JAIL=0
while [ "$#" -gt 0 ]; do
Expand All @@ -60,14 +61,14 @@ while [ "$#" -gt 0 ]; do
shift
;;
-r|--restart)
RESTART=1
START=1
shift
;;
-v|--vnet)
-v|-V|--vnet)
VNET_JAIL=1
shift
;;
-b|--bridge)
-b|-B|--bridge)
BRIDGE_VNET_JAIL=1
shift
;;
Expand Down Expand Up @@ -102,6 +103,12 @@ IP="${4}"

bastille_root_check
set_target_single "${TARGET}"
check_target_is_stopped "${TARGET}" || if [ "${FORCE}" -eq 1 ]; then
bastille stop "${TARGET}"
else
error_notify "Jail is running."
error_continue "Use [-f|--force] to force stop the jail."
fi

validate_ip() {
local ip="${1}"
Expand Down Expand Up @@ -342,17 +349,17 @@ case "${ACTION}" in
error_exit "\"${INTERFACE}\" is a bridge interface."
else
add_vnet_interface_block "${TARGET}" "${INTERFACE}" "${IP}"
if [ "${RESTART}" -eq 1 ]; then
bastille restart "${TARGET}"
if [ "${START}" -eq 1 ]; then
bastille start "${TARGET}"
fi
fi
elif [ "${BRIDGE_VNET_JAIL}" -eq 1 ]; then
if ! ifconfig | grep "${INTERFACE}" | grep -q bridge; then
error_exit "\"${INTERFACE}\" is not a bridge interface."
else
add_bridge_interface_block "${TARGET}" "${INTERFACE}" "${IP}"
if [ "${RESTART}" -eq 1 ]; then
bastille restart "${TARGET}"
if [ "${START}" -eq 1 ]; then
bastille start "${TARGET}"
fi
fi
fi
Expand All @@ -365,13 +372,13 @@ case "${ACTION}" in
else
if grep "${INTERFACE}" ${bastille_jailsdir}/${TARGET}/jail.conf 2>/dev/null | grep -qE '[[:blank:]]bastille[0-9]+'; then
remove_vnet_interface_block "${TARGET}" "${INTERFACE}"
if [ "${RESTART}" -eq 1 ]; then
bastille restart "${TARGET}"
if [ "${START}" -eq 1 ]; then
bastille start "${TARGET}"
fi
elif grep "${INTERFACE}" ${bastille_jailsdir}/${TARGET}/jail.conf 2>/dev/null | grep -qE '[[:blank:]]epair[0-9]+'; then
remove_bridge_interface_block "${TARGET}" "${INTERFACE}"
if [ "${RESTART}" -eq 1 ]; then
bastille restart "${TARGET}"
if [ "${START}" -eq 1 ]; then
bastille start "${TARGET}"
fi
fi
fi
Expand All @@ -380,3 +387,4 @@ case "${ACTION}" in
error_exit "Only [add|remove] are supported."
;;
esac

0 comments on commit 7894941

Please sign in to comment.