=== modified file 'bin/fileset.awk' --- bin/fileset.awk 2015-12-09 08:05:43 +0000 +++ bin/fileset.awk 2015-11-27 18:19:20 +0000 @@ -8,8 +8,6 @@ # clean the filter file printf "" >ENVIRON["RSFILTER"] } - - func_num=0 } function escaped(str) { @@ -117,12 +115,12 @@ } if(cchar == "o") { - print_i("o "crest) + print_d("chown "crest" "fname) continue } if(cchar == "m") { - print_i("m "crest) + print_d("chmod "crest" "fname) continue } @@ -164,35 +162,20 @@ # last line, if not already present printf_fmt = crest ~ /n/ || (crest !~ /N/ && content !~ /\n$/) ? \ "%s\\n" : "%s" - - func_name = "f_" func_name++ - funcs[func_name] = "\tprintf '"printf_fmt"' "quoted(content) - - if(crest ~ /a/) { - print_b("if ! $check_only; then") - print_i(func_name " >>" fname) - print_e("fi") - } else { - print_i("c " func_name) - } + printf_redir = (crest ~ /a/ ? ">>" : ">") fname + # print_i("content="quoted(content)) + # print_d("printf "printf_redir" '"printf_fmt"' \"$content\"") + print_d("printf "printf_redir" '"printf_fmt"' "quoted(content)) continue } # binary, base64; decodes the arguments and changes file content if(cchar ~ /[bB]/) { - shellfunc("f", crest) + shellfunc("f 1", crest) content = get_argument(cchar == "B") - func_name = "f_" func_name++ - funcs[func_name] = "\tbase64 <<<"quoted(content) - - if(crest ~ /a/) { - print_b("if ! $check_only; then") - print_i(func_name " >>" fname) - print_e("fi") - } else { - print_i("c " func_name) - } + base64_redir = (crest ~ /a/ ? ">>" : ">") fname + print_d("base64 "base64_redir" <<<"quoted(content)) continue } @@ -203,34 +186,25 @@ if(crest ~ /c/) { shellfunc("f", crest) } else { - shellfunc("req type_or_missing f", crest) + shellfunc("f 1", crest) } print_d("{ "statement"\n} <"fname" >"fname".tmp.$$") print_d("cat >"fname" "fname".tmp.$$") - print_i("c cat "fname".tmp.$$") print_d("rm "fname".tmp.$$") # use file as Input } else if(crest ~ /i/) { - print_b("if ! $check_only; then") print_d("{ "statement"\n} <"fname) - print_e("fi") # use file as Output } else if(crest ~ /o/) { - shellfunc("req type_or_missing f", crest) - print_b("if ! $check_only; then") + shellfunc("f 1", crest) print_d("{ "statement"\n} >"fname) - print_e("fi") # Append to file } else if(crest ~ /a/) { - shellfunc("req type_or_missing f", crest) - print_b("if ! $check_only; then") + shellfunc("f 1", crest) print_d("{ "statement"\n} >>"fname) - print_e("fi") # do nothing special with file } else { - print_b("if ! $check_only; then") print_d("{ "statement"\n}") - print_e("fi") } statement = "" continue @@ -257,25 +231,6 @@ } } -function print_functions() { - for( func_name in funcs ) { - print func_name "(){\n" funcs[func_name] "\n}\n" - } -} - -BEGIN { - print_b("check_main() {" -} - { parse_line($0) } -END { - process_statement() - print_e("}") - print_b("check_main() {") - print_i("true") - print_e("}") - print - print_functions() - print_i "req main" -} +END { process_statement() } === modified file 'bin/fileset_inc.sh' --- bin/fileset_inc.sh 2015-12-09 08:05:43 +0000 +++ bin/fileset_inc.sh 2015-04-21 11:44:26 +0000 @@ -18,197 +18,85 @@ } # TODO: search $PATH -if ! test -x /bin/readlink -o -x /usr/bin/readlink; then - # Hackity hack. If you know of better way, let me know. - if test -x /bin/rsync -o -x /usr/bin/rsync; then - readlink() { - rsync -l8 --list-only "$1" | sed 's|^.* ->||' - } - else - readlink() { - ls -ld "$1" | sed 's|^.* ->||' - } - fi +if test -x /bin/readlink -o -x /usr/bin/readlink; then + has_readlink=true +else + has_readlink=false fi -: ${check_only:=false} - -req() { - if ! "check_$@"; then - if $check_only; then - die "check failed on $filename: $*" - else - "do_$1" || die "action failed on $filename: $*" - check_only=true - req "$@" - check_only=false - fi - fi -} - - -check_p() { - test -d "$(dirname "$filename")" -} - -do_p() { - mkdir -p "$(dirname "$fname")" || exit $? -} - - -check_type_or_missing() { - test '!' -e "$fname" -o "-$1" "$fname" -} - -do_type_or_missing() { - if $f_r; then - if $f_f; then - rm -rf "$fname" || exit $? - else - rm -r "$fname" || exit $? - fi - elif test -d "$fname"; then - rmdir "$fname" +rm_flags() { + if $f_f; then + rm -f$1 "$fname" || exit $? + elif test -n "$1"; then + rm -$1 "$fname" || exit $? else - if $f_f; then - rm -f "$fname" || exit $? - else - rm "$fname" || exit $? - fi - fi -} - - -do_l() { + rm "$fname" || exit $? + fi +} + +mkdir_p() { + if $f_p; then + mkdir -p "$(dirname "$fname")" || exit $? + fi +} + +l() { if test -L "$fname"; then - rm "$fname" + if $has_readlink && test x"$(readlink "$fname")" = x"$1"; then + return + elif $f_f; then + rm_flags + fi elif test -e "$fname"; then - die "already present but not a symbolic link: $fname" + if $f_bang; then + rm_flags r + else + die "already present but not a symbolic link: $fname" + fi fi + mkdir_p ln -s "$1" "$fname" || exit $? } -check_l() { - if $f_p; then - req p - fi - if $f_bang; then - req type_or_missing L - fi - test -L "$fname" && test x"$(readlink "$fname")" = x"$1" -} - -l() { - req l "$@" -} - - -check_r() { - test -e "$fname" -o -L "$fname" -} - -do_r() { - do_type_or_missing -} - r() { - req r "$@" -} - - -check_m() { - test -e "$fname" -o -L "$fname" && \ - test 0 -lt $(find "$fname" -prune -perm "$1" | wc -l) -} - -do_m() { - chmod "$1" "$fname" -} - -m() { - req m "$@" -} - - -check_o() { - test -e "$fname" -o -L "$fname" || return 1 - case "$1" in - (*:*) test 0 -lt $( \ - find "$fname" -prune -user "${1%:*}" -group "${1#*:}" | wc -l \ - ) - return $?;; - (*) test 0 -lt $(find "$fname" -prune -user "$1" | wc -l) - return $?;; - esac -} - -do_o() { - chown "$1" "$fname" -} - -o() { - req o "$@" -} - - -check_f() { + if test -e "$fname" -o -L "$fname"; then + if $f_r; then + rm_flags r + else + rm_flags + fi + fi +} + +f() { if test -f "$fname"; then - return 0 - fi - if $f_p; then - req p - fi - if $f_bang; then - req type_or_missing f + return elif test -e "$fname" -o -L "$fname"; then - die "already present but not a file: $fname" - fi - return 1 -} - -do_f() { - touch "$fname" -} - -f() { - req f "$@" -} - - -check_d() { + if $f_bang; then + rm_flags r + else + die "already present but not a file: $fname" + fi + fi + mkdir_p + if test -z "$1"; then + touch "$fname" || exit $? + fi +} + +d() { if test -d "$fname"; then - return 0 - fi - if $f_bang; then - req type_or_missing f + return elif test -e "$fname" -o -L "$fname"; then - die "already present but not a directory: $fname" + if $f_bang; then + rm_flags + else + die "already present but not a directory: $fname" + fi fi - return 1 -} - -do_d() { if $f_p; then - mkdir -p "$fname" + mkdir -p "$fname" || exit $? else - mkdir "$fname" + mkdir "$fname" || exit $? fi } - -d() { - req d "$@" -} - - -check_c() { - req f - "$@" | cmp -s - "$fname" -} - -do_c() { - "$@" > "$fname" -} - -c() { - req c "$@" -}