Advertisement
Guest User

Untitled

a guest
Jul 19th, 2016
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. OP, it's written in Bourne shell, not bash:
  2.  
  3. #!/usr/bin/env sh
  4.  
  5. So +1 for cross-platform compatibility. And -1,000,000 for writing 2,916 lines of shell.
  6.  
  7. 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.
  8.  
  9. 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.
  10.  
  11. But the real question is...why in the name of all that's holy would you write this in shell? Ugh.
  12.  
  13. _normalizeJson() {
  14. sed "s/\" *: *\([\"{\[]\)/\":\1/g" | sed "s/^ *\([^ ]\)/\1/" | tr -d "\r\n"
  15. }
  16.  
  17. That's why we have json libraries and people don't write this stuff in sh.
  18.  
  19. if echo "$nchelp" | grep "GNU netcat" >/dev/null && echo "$nchelp" | grep "\-c, \-\-close" >/dev/null ; then
  20.  
  21. Boy that must have been fun to debug.
  22.  
  23. echo "$text" | sed "s|^$__opt$__sep.*$|$__opt$__sep$__val$__end|" > "$__conf"
  24.  
  25. Oh just go get fucked.
  26.  
  27. _setShebang() {
  28. _file="$1"
  29. _shebang="$2"
  30. if [ -z "$_shebang" ] ; then
  31. _err "Usage: file shebang"
  32. return 1
  33. fi
  34. cp "$_file" "$_file.tmp"
  35. echo "$_shebang" > "$_file"
  36. sed -n 2,99999p "$_file.tmp" >> "$_file"
  37. rm -f "$_file.tmp"
  38. }
  39.  
  40. Ooooohkey then, I think we're done here because that is just ridiculously poor code.
  41.  
  42. 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.
  43.  
  44. This looks like a brittle, extremely difficult to maintain mess.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement