#!/usr/bin/gawk -f # # sf4sf-extract-settings -- 2008-06-07, last edit 2008-06-28 # # extract the user settings from sf4sf program file, this script saves # user custom settings from existing sf4sf script and is designed to # be used prior to upgrading to a later version of sf4sf # # Copyright (C) Grant Coady 2008 GPLv2 # # Suggested usage: # # sf4sf-extract-settings /path/to/sf4sf > /etc/sf4sf.conf # # Example: Running sf4sf with saved user settings: # # tail -f /var/log/messages | sf4sf -f /etc/sf4sf.conf [options] # # Options: # o You may add a comment on the command line that will be saved in the # settings file: sf4sf-extract-settings -v comment="this is a comment" ... # BEGIN { print "# SlackFire! sf4sf user settings -- ", strftime("%F.%T") print "BEGIN {" print sprintf("\tprint \"\\t## %s %s\"", \ "Read custom settings created at", strftime("%F.%T")) if (comment) print sprintf("\tprint \"\\t## %s\"", comment) print "" } NR < 5 { next } /^BEGIN/,/^#XXXX/ { if ($1 == "BEGIN") next # strip comments gsub(/^[\t ]*#.*$/, "") sub(/#.*$/, "") $0 = $0; if (!$0) next # strip trailing whitespace sub(/[\t ]*$/, "") # remove ansi colour table, this shouldn't be changed by user if ($1 ~ /red|green|yellow|blue|magenta|cyan|white|normal/) next # print variable assignments s = $3 for (i = 4; i <= NF; i++) s = s " " $i printf "\t%-30s = %s\n", $1, s } END { print "}" }