Skip to content

Instantly share code, notes, and snippets.

@jedisct1
Created March 19, 2012 19:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jedisct1/2125545 to your computer and use it in GitHub Desktop.
Save jedisct1/2125545 to your computer and use it in GitHub Desktop.
ldns-signzone wrapper that understands $INCLUDE statements #dnssec #nsd
#! /bin/sh
LDNS_SIGNZONE="ldns-signzone"
errx() {
echo "$1" >&2
exit 1
}
parse_opts() {
opts=''
output=''
while [ $# -gt 0 ]; do
case $1 in
-[eioE]) opts="$opts $1"; shift ;;
-f) shift; output=$1; shift ;;
--) shift; break ;;
-*) ;;
*) break ;;
esac
opts="$opts $1"; shift
done
[ $# -lt 2 ] && exit 1
zonefile=$1; shift
keys=$*
[ "$output" = '' ] && output="${zonefile}.signed"
echo "$opts"; echo "$zonefile"; echo "$keys"; echo "$output"
}
preprocess_include() {
file="$1"
line="$2"
echo "$line" | {
read include_statement included_file
if [ -f "$included_file" ]; then
preprocess_file "$included_file"
else
alt_included_file=$(dirname "$file")/$(basename "$included_file")
[ -f "$alt_included_file" ] || \
errx "Nonexistent file: [$included_file] included from [$file]"
preprocess_file "$alt_included_file"
fi
}
}
preprocess_file() {
file="$1"
while read line; do
case "$line" in
\$[Ii][Nn][Cc][Ll][Uu][Dd][Ee][[:blank:]]*)
preprocess_include "$file" "$line" || exit $?
;;
*) echo "$line" ;;
esac
done < "$file" | egrep -v "^[[:blank:]]*$"
}
parse_opts $* | {
read opts; read zonefile; read keys; read output
[ -z "$zonefile" -o -z "$keys" -o -z "$output" ] && \
errx "Usage: $0 [opts] zonefile key [key [key]]"
preprocess_file $zonefile | "$LDNS_SIGNZONE" -f "$output" $opts -- - $keys
}
@hudecof
Copy link

hudecof commented May 30, 2018

parsing args is wrong, try -n -e 1530361036 -o test.hudecof.net -f /etc/nsd/zones.d/test.hudecof.net.signed /etc/nsd/zones.d/test.hudecof.net.tmp /etc/nsd/dnssec/keydir/Ktest.hudecof.net.+013+03562 /etc/nsd/dnssec/keydir/Ktest.hudecof.net.+013+19981

the problem is -f) shift; output=$1; shift ;;. The arg next to -f (the output variable is filled good) is added to the $opts and skipped
for me works this code

parse_opts() {
  opts=''
  output=''
  while [ $# -gt 0 ]; do
    case $1 in
      -[eioEkKast])
        opts="$opts $1 $2"
        shift
        shift
        ;;
      -f)
        shift;
        output=$1
        shift
        ;;
      --)
        shift
        break
        ;;
      -*)
        opts="$opts $1"
        shift
        ;;
      *)
        break;;
    esac
  done
  [ $# -lt 2 ] && exit 1
  zonefile=$1; shift
  keys=$*
  [ "$output" = '' ] && output="${zonefile}.signed"
  echo "$opts"; echo "$zonefile"; echo "$keys"; echo "$output"
}

@hudecof
Copy link

hudecof commented May 30, 2018

or just call continue after the -f arg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment