[type/__mail_alias] Fixes (mostly mawk compatibility)

This commit is contained in:
Dennis Camera 2020-05-30 22:07:20 +02:00
parent a5f3f3cdaf
commit 988f277ad6
3 changed files with 11 additions and 12 deletions

View file

@ -22,13 +22,11 @@
aliases_file=$("${__type_explorer}/aliases_file") aliases_file=$("${__type_explorer}/aliases_file")
test -r "${aliases_file}" || exit 0 test -r "${aliases_file}" || exit 0
name=$__object_id awk -F ':[ \t]*' '
awk -F ':[[:blank:]]*' '
function print_aliases(aliases, matches) { function print_aliases(aliases, matches) {
split(aliases, matches, /,[[:blank:]]*/) split(aliases, matches, /,[ \t]*/)
for (i in matches) { for (i in matches) {
gsub(/^[[:blank:]]*|[[:blank:]]*$/, "", matches[i]) gsub(/^[ \t]*|[ \t]*$/, "", matches[i])
print matches[i] print matches[i]
} }
} }
@ -40,7 +38,7 @@ function print_aliases (aliases, matches) {
{ {
cont = ($0 ~ /\\$/) cont = ($0 ~ /\\$/)
if (cont) sub(/[[:blank:]]*\\$/, "", $0) if (cont) sub(/[ \t]*\\$/, "", $0)
} }
/^[[:blank:]]/ || cont { /^[[:blank:]]/ || cont {

0
type/__mail_alias/explorer/aliases_file Normal file → Executable file
View file

View file

@ -23,7 +23,7 @@ state_should=$(cat "${__object}/parameter/state")
case $state_should case $state_should
in in
(present) (present)
if cmp "${__object}/explorer/aliases" "${__object}/parameter/alias" if cmp -s "${__object}/explorer/aliases" "${__object}/parameter/alias"
then then
# all good! # all good!
exit 0 exit 0
@ -57,7 +57,8 @@ printf 'mode=%u\n' "${mode}"
printf "aliases_file='%s'\n" "${aliases_file}" printf "aliases_file='%s'\n" "${aliases_file}"
cat <<'EOF' cat <<'EOF'
awk -F ':[[:blank:]]*' -v mode="${mode}" ' test -f "${aliases_file}" || touch "${aliases_file}"
awk -F ':[ \t]*' -v mode="${mode}" '
function sepafter(f, default, _) { function sepafter(f, default, _) {
_ = substr($0, length($f) + 1, index(substr($0, length($f)+1), $(f+1)) - 1) _ = substr($0, length($f) + 1, index(substr($0, length($f)+1), $(f+1)) - 1)
if (_) return _ if (_) return _
@ -90,10 +91,10 @@ BEGIN {
{ {
cont = ($0 ~ /\\$/) cont = ($0 ~ /\\$/)
if (cont) sub(/[[:blank:]]*\\$/, "", $0) if (cont) sub(/[ \t]*\\$/, "", $0)
} }
/^[[:blank:]]/ || cont { /^[ \t]/ || cont {
# continuation line # continuation line
if (select) next if (select) next
} }
@ -118,7 +119,7 @@ END {
exit 1 exit 1
} }
if ! cmp "${aliases_file}" "${aliases_file}.tmp" if ! cmp -s "${aliases_file}" "${aliases_file}.tmp"
then then
mv "${aliases_file}.tmp" "${aliases_file}" mv "${aliases_file}.tmp" "${aliases_file}"
newaliases newaliases