/ updateOID.sh
updateOID.sh
 1  #/bin/sh
 2  URL='https://www.cs.auckland.ac.nz/~pgut001/dumpasn1.cfg'
 3  if [ -x /usr/bin/fetch ]; then
 4      /usr/bin/fetch -m --no-verify-peer $URL
 5  elif [ -x /usr/bin/wget ]; then
 6      /usr/bin/wget -N --no-check-certificate $URL
 7  elif [ ! -r dumpasn1.cfg ]; then
 8      echo Please download $URL in this directory.
 9      exit 1
10  fi
11  cat dumpasn1.cfg | \
12  tr -d '\r' | \
13  awk -v apos="'" -v q='"' -v url="$URL" '
14      function clean() {
15          oid = "";
16          comment = "";
17          description = "";
18          warning = "";
19      }
20      BEGIN {
21          FS = "= *";
22          clean();
23          print "// Converted from: " url;
24          print "// which is made by Peter Gutmann and whose license states:";
25          print "//   You can use this code in whatever way you want,";
26          print "//   as long as you don" apos "t try to claim you wrote it.";
27          print "export const oids = {";
28      }
29      /^OID/         { oid = $2; }
30      /^Comment/     { comment = $2; }
31      /^Description/ { description = $2; }
32      /^Warning/     { warning = ", \"w\": true"; }
33      /^$/ {
34          if (length(oid) > 0) {
35              gsub(" ", ".", oid);
36              gsub("\"", "\\\"", description);
37              gsub("\"", "\\\"", comment);
38              if (++seen[oid] > 1)
39                  print "Duplicate OID in line " NR ": " oid > "/dev/stderr";
40              else
41                  printf "\"%s\": { \"d\": \"%s\", \"c\": \"%s\"%s },\n", oid, description, comment, warning;
42              clean();
43          }
44      }
45      END {
46          print "};"
47      }
48  ' >oids.js
49  echo Conversion completed.