This commit is based on the original pull request by tcocca in https://github.com/Neilpang/acme.sh/pull/1297 The script has been revised to pass the ShellCheck and some refactoring to reduce duplicate code.