check ufw status first

This commit is contained in:
Chai Feng 2018-10-02 16:12:34 +08:00
parent a167d3e4ab
commit 89b3aaa5aa
No known key found for this signature in database
GPG Key ID: 2DCD9A24E523FFD2

View File

@ -162,10 +162,14 @@ function err() {
} }
function die() { function die() {
err "Fatal:" "$@" err "ERROR:" "$@"
exit 1 exit 1
} }
if ! ufw status 2>/dev/null | grep -Fq "Status: active" ; then
die "UFW is disabled or you are not root user."
fi
case "$UFW_ACTION" in case "$UFW_ACTION" in
delete) delete)
shift || true shift || true
@ -176,10 +180,6 @@ case "$UFW_ACTION" in
list|allow) list|allow)
shift || true shift || true
if ! ufw status | grep -F "Status: active" &>/dev/null; then
die "UFW is not actived or your are not root user."
fi
INSTANCE_ID="${1:?Docker instance name/ID cannot be empty.}" INSTANCE_ID="${1:?Docker instance name/ID cannot be empty.}"
INSTANCE_NAME="$(ufw-docker--instance-name "$INSTANCE_ID")" INSTANCE_NAME="$(ufw-docker--instance-name "$INSTANCE_ID")"
shift || true shift || true