Add a local copy of the lua source file. Re-organize the sh code to avoid duplication and add (a little) clarity.