I couldn't write it in bash, so I had to go with Python. Eventually I'll rewrite locinst.sh to be almost fully Python.