From 4ce4363e007f29cef741fde984eb1f6ae8d23023 Mon Sep 17 00:00:00 2001 From: teastep Date: Wed, 1 Nov 2006 00:29:10 +0000 Subject: [PATCH] Fix braindead 'echo' logic; more clean up of generated code git-svn-id: https://shorewall.svn.sourceforge.net/svnroot/shorewall/trunk@4775 fbd18981-670d-0410-9b5c-8dc0c1a9a2bb --- Shorewall/compiler | 36 +++++++++++++++++++++++++++++------- Shorewall/lib.actions | 5 ++++- Shorewall/lib.base | 8 +++++--- Shorewall/lib.nat | 12 ++++++++++-- Shorewall/lib.providers | 3 ++- 5 files changed, 50 insertions(+), 14 deletions(-) diff --git a/Shorewall/compiler b/Shorewall/compiler index 3d1a8e0e9..bba3f5ce1 100755 --- a/Shorewall/compiler +++ b/Shorewall/compiler @@ -896,8 +896,11 @@ setup_tc1() { # # Just in case the file ended with a comment # - [ -n "$COMMENTS" ] && save_command COMMENT= - + if [ -n "$COMMENTS" ]; then + save_command + save_command COMMENT= + save_command + fi # # Link to the TC mangle chains from the main chains # @@ -1005,7 +1008,7 @@ refresh_tc() { # indent >&3 << __EOF__ -$IPTABLES -t mangle -L -n | grep '^Chain excl_' | while read junk chain rest; do +\$IPTABLES -t mangle -L -n | grep '^Chain excl_' | while read junk chain rest; do run_iptables -t mangle -F \$chain run_iptables -t mangle -X \$chain done @@ -1035,7 +1038,11 @@ __EOF__ # # Just in case the file ended with a comment # - [ -n "$COMMENTS" ] && save_command COMMENT= + if [ -n "$COMMENTS" ]; then + save_command + save_command COMMENT= + save_command + fi if [ -n "$TC_SCRIPT" ]; then save_progress_message "Refreshing Traffic Shaping" @@ -2834,8 +2841,11 @@ process_rules() # # Just in case the file ended with a comment # - [ -n "$COMMENTS" ] && save_command COMMENT= - + if [ -n "$COMMENTS" ]; then + save_command + save_command COMMENT= + fi + case $SECTION in ESTABLISHED) finish_section ESTABLISHED,RELATED @@ -4894,6 +4904,17 @@ __EOF__ fi } +# +# Hack to fix up generated object +# +prepare_source() +{ + awk \ + 'BEGIN {blnk=0;}; \ + /^\s*$/ {blnk=1; next; }; \ + { if (blnk == 1 ) print ""; blnk=0; print; }' - +} + # # Compile a Firewall Script # @@ -5181,6 +5202,7 @@ __EOF__ STOPPING= COMMENT= + # # The library requires that ${VARDIR} exist # @@ -5613,7 +5635,7 @@ __EOF__ progress_message3 "Shorewall configuration verified" else INDENT= - cat $(find_file prog.header) $OUTPUT $(find_file prog.footer) > $outfile + cat $(find_file prog.header) $OUTPUT $(find_file prog.footer) | prepare_source > $outfile chmod 700 $outfile if [ -n "$EXPORT" ]; then exec 3>${outfile}.conf diff --git a/Shorewall/lib.actions b/Shorewall/lib.actions index b74d7484b..4a624670d 100644 --- a/Shorewall/lib.actions +++ b/Shorewall/lib.actions @@ -841,6 +841,9 @@ process_action3() { fi done < $TMP_DIR/$f - [ -n "$COMMENTS" ] && save_command COMMENT= + if [ -n "$COMMENTS" ]; then + save_command + save_command COMMENT= + fi } diff --git a/Shorewall/lib.base b/Shorewall/lib.base index 2939960be..ebda4ea85 100644 --- a/Shorewall/lib.base +++ b/Shorewall/lib.base @@ -1355,18 +1355,20 @@ restore_default_route() { # # Determine how to do "echo -e" +# find_echo() { local result result=$(echo "a\tb") - [ ${#result} -eq 3 ] && echo echo + [ ${#result} -eq 3 ] && { echo echo; return; } result=$(echo -e "a\tb") - [ ${#result} -eq 3 ] && echo "echo -e" + [ ${#result} -eq 3 ] && { echo "echo -e"; return; } result=$(which echo) - [ -n "$result" ] && echo "$result -e" + [ -n "$result" ] && { echo "$result -e"; return; } echo echo } + diff --git a/Shorewall/lib.nat b/Shorewall/lib.nat index 11dad98a6..4abb8250a 100644 --- a/Shorewall/lib.nat +++ b/Shorewall/lib.nat @@ -450,7 +450,11 @@ __EOF__ # # Just in case the file ended with a comment # - [ -n "$COMMENTS" ] && save_command COMMENT= + if [ -n "$COMMENTS" ]; then + save_command + save_command COMMENT= + save_command + fi fi } @@ -540,7 +544,11 @@ setup_nat() { progress_message_and_save " Host $internal NAT $external on $interface" done < $TMP_DIR/nat - [ -n "$COMMENTS" ] && save_command COMMENT= + if [ -n "$COMMENTS" ]; then + save_command + save_command COMMENT= + save_command + fi fi } diff --git a/Shorewall/lib.providers b/Shorewall/lib.providers index bb9762eb4..ba3e27d26 100644 --- a/Shorewall/lib.providers +++ b/Shorewall/lib.providers @@ -383,7 +383,7 @@ ${INDENT}cat > /etc/iproute2/rt_tables <