From 768d7b0577e81831b2c7d6d3462d190fa8f6a8d3 Mon Sep 17 00:00:00 2001 From: Chai Feng Date: Sat, 24 Nov 2018 13:46:35 +0800 Subject: [PATCH] refactor check-install function --- ufw-docker | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/ufw-docker b/ufw-docker index 74ce6ed..32940c3 100755 --- a/ufw-docker +++ b/ufw-docker @@ -274,7 +274,7 @@ function rm-on-exit() { function on-exit() { for file in "${files_to_be_deleted[@]}"; do - [[ -f "$file" ]] && rm -vr "$file" + [[ -f "$file" ]] && rm -r "$file" done files_to_be_deleted=() } @@ -282,12 +282,9 @@ function on-exit() { trap on-exit EXIT INT TERM QUIT ABRT ERR function ufw-docker--check-install() { - local after_rules_tmp - after_rules_tmp="${1:-}" - if [[ -z "$after_rules_tmp" ]]; then - after_rules_tmp="$(mktemp)" - rm-on-exit "$after_rules_tmp" - fi + after_rules_tmp="${after_rules_tmp:-$(mktemp)}" + rm-on-exit "$after_rules_tmp" + sed "/^# BEGIN UFW AND DOCKER/,/^# END UFW AND DOCKER/d" "$after_rules" > "$after_rules_tmp" >> "${after_rules_tmp}" cat <<-\EOF # BEGIN UFW AND DOCKER @@ -318,11 +315,7 @@ function ufw-docker--check-install() { } function ufw-docker--install() { - local after_rules_tmp - after_rules_tmp="$(mktemp)" - rm-on-exit "$after_rules_tmp" - - if ! ufw-docker--check-install "$after_rules_tmp"; then + if ! ufw-docker--check-install; then local after_rules_bak after_rules_bak="${after_rules}-ufw-docker~$(date '+%Y-%m-%d-%H%M%S')~" err "\\nBacking up $after_rules to $after_rules_bak"