Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- OP, it's written in Bourne shell, not bash:
- #!/usr/bin/env sh
- So +1 for cross-platform compatibility. And -1,000,000 for writing 2,916 lines of shell.
- First, the code isn't even all that good...e.g., line 475 doesn't quote the echo (which is legal), but line 503 does. Some functions are separated_by_spaces and others have camelCase. Apparently getopt(1) is a mystery to the author as he's written an extensive option-parsing function. I enjoyed _exists() and its lack of the 'which' command. _debug() and _debug2(). _math() which is nothing because an expr alias because...? All those slow return statements instead of return variables. Strings for 0 and 1 used as boolean. Tons and tons of quickie cut calls that could have been consoldiated down to awk. Etc.
- And, um, why is there a variable called APAHECTL when it's an alias for apachectl? It's used repeatedly so the misspelling is...intentional? It appears at 1108 and also in 1171 and I'm skeptical that 1171 isn't a bug due to variable scope.
- But the real question is...why in the name of all that's holy would you write this in shell? Ugh.
- _normalizeJson() {
- sed "s/\" *: *\([\"{\[]\)/\":\1/g" | sed "s/^ *\([^ ]\)/\1/" | tr -d "\r\n"
- }
- That's why we have json libraries and people don't write this stuff in sh.
- if echo "$nchelp" | grep "GNU netcat" >/dev/null && echo "$nchelp" | grep "\-c, \-\-close" >/dev/null ; then
- Boy that must have been fun to debug.
- echo "$text" | sed "s|^$__opt$__sep.*$|$__opt$__sep$__val$__end|" > "$__conf"
- Oh just go get fucked.
- _setShebang() {
- _file="$1"
- _shebang="$2"
- if [ -z "$_shebang" ] ; then
- _err "Usage: file shebang"
- return 1
- fi
- cp "$_file" "$_file.tmp"
- echo "$_shebang" > "$_file"
- sed -n 2,99999p "$_file.tmp" >> "$_file"
- rm -f "$_file.tmp"
- }
- Ooooohkey then, I think we're done here because that is just ridiculously poor code.
- I'm sure someone could write a great web browser in assembler, but why would you? This could have been simpler and more maintainable if it was written in, say, perl - which is just as cross-platform as shell in 2016. It's in the Linux LSB and it's installled by default on all BSD boxes. And really, the author could have used python, go, or whatever - since he's already requiring people to install a variety of packages.
- This looks like a brittle, extremely difficult to maintain mess.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement