diff options
author | Freya Murphy <freya@freyacat.org> | 2023-12-30 15:23:30 -0500 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2023-12-30 15:23:30 -0500 |
commit | 9ea034f42095bb1a61d1e8ee628575cb2bbee7e6 (patch) | |
tree | 123e5758aa4b078eea5dce59ebe4f1afaf7ec523 /lib | |
parent | stubnet (diff) | |
download | freyanet-9ea034f42095bb1a61d1e8ee628575cb2bbee7e6.tar.gz freyanet-9ea034f42095bb1a61d1e8ee628575cb2bbee7e6.tar.bz2 freyanet-9ea034f42095bb1a61d1e8ee628575cb2bbee7e6.zip |
refactor
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/config.awk | 35 | ||||
-rwxr-xr-x | lib/inet2.sh | 22 |
2 files changed, 57 insertions, 0 deletions
diff --git a/lib/config.awk b/lib/config.awk new file mode 100755 index 0000000..9d0a117 --- /dev/null +++ b/lib/config.awk @@ -0,0 +1,35 @@ +#!/usr/bin/awk -f + +BEGIN { + FS = "[ ]"; # use a single space as field separator and don't trim input + ind = 0; # indentation level + last = ARGC - 3; # last argument index + exitcode = 1; # whether anything has been matched + if(last < 0) { # there should be at least one argument after the filename + exit 1; + } + ARGC = 2; # don't read ARGV[2] and onward as files +} + +END { + exit exitcode; +} + +$0 != "" { # exit when the indentation block is exited + for(i = 0; i < ind; i++) { + if(! sub(/^\t/, "")) { + exit exitcode; + } + } +} + +# if on the last argument, interpret it as a key and print the value +ind == last && $1 == ARGV[ind + 2] { + exitcode = 0; + print substr($0, length($1) + 2); +} +# if not on the last argument, find the string exactly and increment indentation +ind != last && $0 == ARGV[ind + 2] { + ind++; +} + diff --git a/lib/inet2.sh b/lib/inet2.sh new file mode 100755 index 0000000..672286e --- /dev/null +++ b/lib/inet2.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env sh + +run() { + printf '$ \x1b[32;1m%s\x1b[0m\n' "$*" + "$@" +} +step() { + printf '\x1b[34;1m>> %s\x1b[0m\n' "$*" +} + +getval() { + /var/lib/inet2/config.awk /etc/inet2.conf "$@" +} + +haskey() { + getval interface | while read -r inter; do + if getval "interface $inter" "$1"; then + echo "true" + return + fi + done +} |