Skip to content

Instantly share code, notes, and snippets.

@mcenirm
Created June 15, 2017 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcenirm/aaa0777f8524ea4ee02e9316ae617d51 to your computer and use it in GitHub Desktop.
Save mcenirm/aaa0777f8524ea4ee02e9316ae617d51 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
set -u
Usage () { cat >&2 <<EOF
Usage: $0
Convert proftpd.conf to naive JSON version
EOF
}
if [ $# -gt 0 ] ; then
Usage
exit 1
fi
actions=(
-e 's/#.*$//'
-e 's/^[ ]*//'
-e 's/[ ]*$//'
-e '/^$/d'
-e 's/\\/\\\\/g'
-e 's/\"/\\"/g'
-e 's#^</.*$#}#'
-e 's#^<\([^/][^ ]*\)[ ][ ]*\([^>]*\)>$#,"\1 \2":{"__":""#'
-e 's#^<\([^/][^>]*\)>$#,"\1":{"__":""#'
-e 's#^\(LogFormat\)[ ][ ]*\([^ ]*\)[ ][ ]*\([^ ].*\)$#,"\1 \2":"\3"#'
-e 's#^\([^,}][^ ]*\)[ ][ ]*\([^ ].*\)$#,"\1":"\2"#'
-e 's#^\([^,}].*\)$#,"\1":true#'
)
echo '{"__":""'
sed "${actions[@]}"
echo '}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment