bin/sign: Don't continue processing after encountering a directive.
[ssh-ca] / bin / sign
index ecd139e..c1f7c62 100755 (executable)
--- a/bin/sign
+++ b/bin/sign
@@ -2,6 +2,7 @@
 
 set -e
 . lib/func.sh
+orig_domain=$domain date=$(date +%Y-%m-%d)
 
 ## The key types are adorned with bit lengths.  Work out the raw key type
 ## names.
@@ -13,7 +14,7 @@ done
 ## Start a new output directory.
 rm -rf publish.new
 mkdir publish.new
-exec 3<etc/hosts 4>publish.new/hosts.list
+exec 3<etc/hosts 4>publish.new/hosts.list 5>publish.new/known_hosts
 echo ":certificate-authority" >&4
 for kt in $rawkeytypes; do
   cp ca/ca-$kt.pub publish.new/
@@ -25,6 +26,8 @@ done
 
 ## Sign the various host keys.
 last=%%%
+idomain=$domain
+echo >&5 "### BEGIN $idomain KEYS (generated $date)"
 while read line <&3; do
 
   ## Ignore comments and empty lines.
@@ -36,6 +39,10 @@ while read line <&3; do
 
   ## Read the host line.
   set -- $line
+  case "$1" in
+    @domain) domain=$2; continue ;;
+    @*) echo >&2 "$0: unknown directive \`$1'"; exit 1 ;;
+  esac
   host=$1
   names=""
   nicks=""
@@ -66,11 +73,14 @@ while read line <&3; do
       publish.new/$host-$kt.pub
     mv publish.new/$host-$kt-cert.pub \
       publish.new/$host-$kt.cert
-    { printf "%s " $names; cat host/$host-$kt.pub; } >&4
+    for fd in 4 5; do
+      { printf "%s " $names; cat host/$host-$kt.pub; } >&$fd
+    done
     ssh-keygen -lv -fhost/$host-$kt.pub | sed 's,^,| ,' >&4
   done
 done
-exec 3>&- 4>&-
+echo >&5 "### END $idomain KEYS"
+exec 3>&- 4>&- 5>&-
 
 ## Sign the list.
 run_gpg --armor -o publish.new/hosts.asc \