Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve debug capabilities when using bash #2546

Merged
merged 1 commit into from Nov 3, 2019

Conversation

@JohnVillalovos
Copy link
Contributor

JohnVillalovos commented Oct 15, 2019

When calling the _debug() function will print the filename, function
name, and line number when running under bash

@JohnVillalovos

This comment has been minimized.

Copy link
Contributor Author

JohnVillalovos commented Oct 15, 2019

It will look something like:

[Tue Oct 15 16:46:42 PDT 2019] acme.sh:_process:6941                    Running cmd: issue
@JohnVillalovos JohnVillalovos force-pushed the JohnVillalovos:master branch 3 times, most recently from 8d1c2e8 to 879f05f Oct 15, 2019
acme.sh Outdated
__debug_bash_helper() {
# Return extra debug info when running with bash, otherwise return empty
# string.
local bash_debug=""

This comment has been minimized.

Copy link
@Neilpang

Neilpang Oct 20, 2019

Owner

don't use local keyword, it's bash only.

This comment has been minimized.

Copy link
@JohnVillalovos

JohnVillalovos Oct 20, 2019

Author Contributor

Thanks for the feedback. Fixed it to not use local until have determined that it is a bash shell.

@JohnVillalovos JohnVillalovos force-pushed the JohnVillalovos:master branch 2 times, most recently from 7936856 to 50bceaa Oct 20, 2019
@Neilpang

This comment has been minimized.

Copy link
Owner

Neilpang commented Oct 21, 2019

please remove all the local keyword.

Thanks.

@JohnVillalovos JohnVillalovos force-pushed the JohnVillalovos:master branch from 50bceaa to c969e42 Oct 21, 2019
@JohnVillalovos

This comment has been minimized.

Copy link
Contributor Author

JohnVillalovos commented Oct 21, 2019

please remove all the local keyword.

Done. Changed the variable names to be what I hope will be unique and won't accidentally clobber any declared variable names. This was done by using _dbh_ as the prefix for the variable names.

acme.sh Outdated
@@ -273,7 +299,8 @@ _debug() {
_syslog "$SYSLOG_DEBUG" "$@"
fi
if [ "${DEBUG:-$DEBUG_LEVEL_NONE}" -ge "$DEBUG_LEVEL_1" ]; then
_printargs "$@" >&2
local bash_debug=$(__debug_bash_helper)

This comment has been minimized.

Copy link
@Neilpang

Neilpang Oct 21, 2019

Owner

I mean remove ALL the local keyword in this whole file.

This comment has been minimized.

Copy link
@JohnVillalovos

JohnVillalovos Oct 21, 2019

Author Contributor

I mean remove ALL the local keyword in this whole file.

Sorry I got tunnel vision and was focused on the one function and forgot about my other changes. I have removed all use of local from my patch. Hopefully I got it this time :)

@JohnVillalovos JohnVillalovos force-pushed the JohnVillalovos:master branch from c969e42 to ec09b55 Oct 21, 2019
@Neilpang

This comment has been minimized.

Copy link
Owner

Neilpang commented Oct 23, 2019

which OS did you test ?

I just tried on my Ubuntu. But I got the following error:

./acme.sh: 278: ./acme.sh: caller: not found
./acme.sh: 1: eval: Syntax error: "(" unexpected
[Wed 23 Oct 2019 01:41:30 PM UTC] Lets find script dir.
./acme.sh: 278: ./acme.sh: caller: not found
./acme.sh: 1: eval: Syntax error: "(" unexpected
[Wed 23 Oct 2019 01:41:30 PM UTC] _SCRIPT_='./acme.sh'
./acme.sh: 278: ./acme.sh: caller: not found
./acme.sh: 1: eval: Syntax error: "(" unexpected
[Wed 23 Oct 2019 01:41:30 PM UTC] _script='/home/neil/acme.sh/acme.sh'
./acme.sh: 278: ./acme.sh: caller: not found
./acme.sh: 1: eval: Syntax error: "(" unexpected
[Wed 23 Oct 2019 01:41:30 PM UTC] _script_home='/home/neil/acme.sh'

@Neilpang

This comment has been minimized.

Copy link
Owner

Neilpang commented Oct 23, 2019

And the env variable BASH_VERSION is not found.

@JohnVillalovos

This comment has been minimized.

Copy link
Contributor Author

JohnVillalovos commented Oct 23, 2019

I was testing on Fedora. Let me spin up a Docker container of Ubuntu and do some testing. Seems odd what you are seeing. Hopefully I can reproduce it.

@JohnVillalovos

This comment has been minimized.

Copy link
Contributor Author

JohnVillalovos commented Oct 23, 2019

In my Ubuntu 18.04 Docker container I am so far unable to reproduce. The install detected that we had bash and changed the shebang. I also tried with sh aka dash and no errors and no extra debug info.

So I admit to being confused :(

Here is the output with bash as the shell

# echo ${BASH_VERSION}
4.4.20(1)-release
# head ~/.acme.sh/acme.sh -n 2
#!/bin/bash

# acme.sh --issue --debug 1 -d example.com --dns dns_cf
[Wed Oct 23 16:56:32 UTC 2019] /root/.acme.sh/acme.sh:__initHome:2365   Lets find script dir.
[Wed Oct 23 16:56:32 UTC 2019] /root/.acme.sh/acme.sh:__initHome:2366   _SCRIPT_='/root/.acme.sh/acme.sh'
[Wed Oct 23 16:56:32 UTC 2019] /root/.acme.sh/acme.sh:__initHome:2368   _script='/root/.acme.sh/acme.sh'
[Wed Oct 23 16:56:32 UTC 2019] acme.sh:__initHome:2370                  _script_home='/root/.acme.sh'
[Wed Oct 23 16:56:32 UTC 2019] acme.sh:__initHome:2397                  Using config home:/root/.acme.sh
https://github.com/Neilpang/acme.sh
v2.8.4
[Wed Oct 23 16:56:32 UTC 2019] acme.sh:_process:6942                    Running cmd: issue
[Wed Oct 23 16:56:32 UTC 2019] acme.sh:issue:3841                       _main_domain='example.com'
[Wed Oct 23 16:56:32 UTC 2019] acme.sh:issue:3842                       _alt_domains='no'
[Wed Oct 23 16:56:32 UTC 2019] acme.sh:__initHome:2397                  Using config home:/root/.acme.sh
[Wed Oct 23 16:56:32 UTC 2019] acme.sh:_initpath:2540                   ACME_DIRECTORY='https://acme-v02.api.letsencrypt.org/directory'
[Wed Oct 23 16:56:32 UTC 2019] acme.sh:_initpath:2612                   DOMAIN_PATH='/root/.acme.sh/example.com'
[Wed Oct 23 16:56:32 UTC 2019] acme.sh:issue:3876                       Using ACME_DIRECTORY: https://acme-v02.api.letsencrypt.org/directory
[Wed Oct 23 16:56:32 UTC 2019] acme.sh:_initAPI:2424                    _init api for server: https://acme-v02.api.letsencrypt.org/directory
[Wed Oct 23 16:56:32 UTC 2019] acme.sh:_get:1837                        GET
[Wed Oct 23 16:56:32 UTC 2019] acme.sh:_get:1841                        url='https://acme-v02.api.letsencrypt.org/directory'
[Wed Oct 23 16:56:32 UTC 2019] acme.sh:_get:1842                        timeout=
[Wed Oct 23 16:56:32 UTC 2019] acme.sh:_get:1876                        _WGET='wget -q --content-on-error '
[Wed Oct 23 16:56:33 UTC 2019] acme.sh:_get:1894                        ret='0'
[Wed Oct 23 16:56:33 UTC 2019] acme.sh:_initAPI:2492                    ACME_KEY_CHANGE='https://acme-v02.api.letsencrypt.org/acme/key-change'
[Wed Oct 23 16:56:33 UTC 2019] acme.sh:_initAPI:2493                    ACME_NEW_AUTHZ
[Wed Oct 23 16:56:33 UTC 2019] acme.sh:_initAPI:2494                    ACME_NEW_ORDER='https://acme-v02.api.letsencrypt.org/acme/new-order'
[Wed Oct 23 16:56:33 UTC 2019] acme.sh:_initAPI:2495                    ACME_NEW_ACCOUNT='https://acme-v02.api.letsencrypt.org/acme/new-acct'
[Wed Oct 23 16:56:33 UTC 2019] acme.sh:_initAPI:2496                    ACME_REVOKE_CERT='https://acme-v02.api.letsencrypt.org/acme/revoke-cert'
[Wed Oct 23 16:56:33 UTC 2019] acme.sh:_initAPI:2497                    ACME_AGREEMENT='https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf'
[Wed Oct 23 16:56:33 UTC 2019] acme.sh:_initAPI:2498                    ACME_NEW_NONCE='https://acme-v02.api.letsencrypt.org/acme/new-nonce'
[Wed Oct 23 16:56:33 UTC 2019] acme.sh:_initAPI:2499                    ACME_VERSION='2'
[Wed Oct 23 16:56:33 UTC 2019] acme.sh:issue:3882                       Le_NextRenewTime
[Wed Oct 23 16:56:33 UTC 2019] acme.sh:_on_before_issue:3186            _on_before_issue
[Wed Oct 23 16:56:33 UTC 2019] acme.sh:_on_before_issue:3187            _chk_main_domain='example.com'
[Wed Oct 23 16:56:33 UTC 2019] acme.sh:_on_before_issue:3188            _chk_alt_domains
[Wed Oct 23 16:56:33 UTC 2019] acme.sh:_on_before_issue:3207            Le_LocalAddress
[Wed Oct 23 16:56:33 UTC 2019] acme.sh:_on_before_issue:3216            d='example.com'
[Wed Oct 23 16:56:33 UTC 2019] acme.sh:_on_before_issue:3220            Check for domain='example.com'
[Wed Oct 23 16:56:33 UTC 2019] acme.sh:_on_before_issue:3222            _currentRoot='dns_cf'
[Wed Oct 23 16:56:33 UTC 2019] acme.sh:_on_before_issue:3216            d
[Wed Oct 23 16:56:33 UTC 2019] acme.sh:_read_conf:2123                  config file is empty, can not read CA_KEY_HASH
[Wed Oct 23 16:56:33 UTC 2019] acme.sh:__initHome:2397                  Using config home:/root/.acme.sh
[Wed Oct 23 16:56:33 UTC 2019] acme.sh:_initpath:2540                   ACME_DIRECTORY='https://acme-v02.api.letsencrypt.org/directory'
[Wed Oct 23 16:56:33 UTC 2019] acme.sh:_initAPI:2424                    _init api for server: https://acme-v02.api.letsencrypt.org/directory
[Wed Oct 23 16:56:33 UTC 2019] Only RSA or EC key is supported. keyfile=/root/.acme.sh/ca/acme-v02.api.letsencrypt.org/account.key
[Wed Oct 23 16:56:33 UTC 2019] acme.sh:_on_issue_err:3279               _on_issue_err
[Wed Oct 23 16:56:33 UTC 2019] Please add '--debug' or '--log' to check more details.
[Wed Oct 23 16:56:33 UTC 2019] See: https://github.com/Neilpang/acme.sh/wiki/How-to-debug-acme.sh
[Wed Oct 23 16:56:33 UTC 2019] acme.sh:_dlg_versions:212                socat doesn't exists.
[Wed Oct 23 16:56:33 UTC 2019] acme.sh:_on_issue_err:3321               Diagnosis versions:
openssl:openssl
OpenSSL 1.1.1  11 Sep 2018
apache:
apache doesn't exists.
nginx:
nginx doesn't exists.
socat:

Here is the output with sh aka dash as the shell. Changed the shebang from #!/usr/bin/bash to #!/usr/bin/sh

# head ~/.acme.sh/acme.sh -n 2
#!/bin/sh

# acme.sh --issue --debug 1 -d example.com --dns dns_cf
[Wed Oct 23 10:14:14 PDT 2019] Lets find script dir.
[Wed Oct 23 10:14:14 PDT 2019] _SCRIPT_='/root/.acme.sh/acme.sh'
[Wed Oct 23 10:14:14 PDT 2019] _script='/root/.acme.sh/acme.sh'
[Wed Oct 23 10:14:14 PDT 2019] _script_home='/root/.acme.sh'
[Wed Oct 23 10:14:14 PDT 2019] Using config home:/root/.acme.sh
https://github.com/Neilpang/acme.sh
v2.8.4
[Wed Oct 23 10:14:14 PDT 2019] Running cmd: issue
[Wed Oct 23 10:14:14 PDT 2019] _main_domain='example.com'
[Wed Oct 23 10:14:14 PDT 2019] _alt_domains='no'
[Wed Oct 23 10:14:14 PDT 2019] Using config home:/root/.acme.sh
[Wed Oct 23 10:14:14 PDT 2019] ACME_DIRECTORY='https://acme-v02.api.letsencrypt.org/directory'
[Wed Oct 23 10:14:14 PDT 2019] DOMAIN_PATH='/root/.acme.sh/example.com'
[Wed Oct 23 10:14:14 PDT 2019] Using ACME_DIRECTORY: https://acme-v02.api.letsencrypt.org/directory
[Wed Oct 23 10:14:14 PDT 2019] _init api for server: https://acme-v02.api.letsencrypt.org/directory
[Wed Oct 23 10:14:14 PDT 2019] GET
[Wed Oct 23 10:14:14 PDT 2019] url='https://acme-v02.api.letsencrypt.org/directory'
[Wed Oct 23 10:14:14 PDT 2019] timeout=
[Wed Oct 23 10:14:14 PDT 2019] _WGET='wget -q --content-on-error '
[Wed Oct 23 10:14:14 PDT 2019] ret='0'
[Wed Oct 23 10:14:14 PDT 2019] ACME_KEY_CHANGE='https://acme-v02.api.letsencrypt.org/acme/key-change'
[Wed Oct 23 10:14:14 PDT 2019] ACME_NEW_AUTHZ
[Wed Oct 23 10:14:14 PDT 2019] ACME_NEW_ORDER='https://acme-v02.api.letsencrypt.org/acme/new-order'
[Wed Oct 23 10:14:14 PDT 2019] ACME_NEW_ACCOUNT='https://acme-v02.api.letsencrypt.org/acme/new-acct'
[Wed Oct 23 10:14:14 PDT 2019] ACME_REVOKE_CERT='https://acme-v02.api.letsencrypt.org/acme/revoke-cert'
[Wed Oct 23 10:14:14 PDT 2019] ACME_AGREEMENT='https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf'
[Wed Oct 23 10:14:14 PDT 2019] ACME_NEW_NONCE='https://acme-v02.api.letsencrypt.org/acme/new-nonce'
[Wed Oct 23 10:14:14 PDT 2019] ACME_VERSION='2'
[Wed Oct 23 10:14:14 PDT 2019] Le_NextRenewTime
[Wed Oct 23 10:14:14 PDT 2019] _on_before_issue
[Wed Oct 23 10:14:14 PDT 2019] _chk_main_domain='example.com'
[Wed Oct 23 10:14:14 PDT 2019] _chk_alt_domains
[Wed Oct 23 10:14:14 PDT 2019] Le_LocalAddress
[Wed Oct 23 10:14:14 PDT 2019] d='example.com'
[Wed Oct 23 10:14:14 PDT 2019] Check for domain='example.com'
[Wed Oct 23 10:14:14 PDT 2019] _currentRoot='dns_cf'
[Wed Oct 23 10:14:14 PDT 2019] d
[Wed Oct 23 10:14:14 PDT 2019] config file is empty, can not read CA_KEY_HASH
[Wed Oct 23 10:14:14 PDT 2019] Using config home:/root/.acme.sh
[Wed Oct 23 10:14:14 PDT 2019] ACME_DIRECTORY='https://acme-v02.api.letsencrypt.org/directory'
[Wed Oct 23 10:14:14 PDT 2019] _init api for server: https://acme-v02.api.letsencrypt.org/directory
[Wed Oct 23 10:14:14 PDT 2019] Only RSA or EC key is supported. keyfile=/root/.acme.sh/ca/acme-v02.api.letsencrypt.org/account.key
[Wed Oct 23 10:14:14 PDT 2019] _on_issue_err
[Wed Oct 23 10:14:14 PDT 2019] Please add '--debug' or '--log' to check more details.
[Wed Oct 23 10:14:14 PDT 2019] See: https://github.com/Neilpang/acme.sh/wiki/How-to-debug-acme.sh
[Wed Oct 23 10:14:14 PDT 2019] socat doesn't exists.
[Wed Oct 23 10:14:14 PDT 2019] Diagnosis versions:
openssl:openssl
OpenSSL 1.1.1  11 Sep 2018
apache:
apache doesn't exists.
nginx:
nginx doesn't exists.
socat:
@Neilpang

This comment has been minimized.

Copy link
Owner

Neilpang commented Oct 25, 2019

Thanks. I will check more soon.

but I think check the BASH_VERSION is not a good idea, because I don't see it in my bash:

root@gd:~# bash
root@gd:~# env | grep -i bash
SHELL=/bin/bash

root@gd:~# bash --version
bash --version
GNU bash, version 4.4.20(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

@JohnVillalovos

This comment has been minimized.

Copy link
Contributor Author

JohnVillalovos commented Oct 25, 2019

Thanks! Please let me know what you find out.

So I don't think BASH_VERSION is an exported variable. It appears to only be available inside the shell scripts.

$ echo ${BASH_VERSION}
4.4.19(1)-release
$ env | grep BASH_VERSION
$ set | grep BASH_VERSION
BASH_VERSION='4.4.19(1)-release'
$ bash --version
GNU bash, version 4.4.19(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Man page on bash describes BASH_VERSION: https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Bash-Variables

BASH_VERSION

    The version number of the current instance of Bash.
@Neilpang

This comment has been minimized.

Copy link
Owner

Neilpang commented Oct 26, 2019

can you please make this available only for --debug 3 ?

@JohnVillalovos

This comment has been minimized.

Copy link
Contributor Author

JohnVillalovos commented Oct 26, 2019

can you please make this available only for --debug 3 ?

Sure

@JohnVillalovos JohnVillalovos force-pushed the JohnVillalovos:master branch 3 times, most recently from 4ce8448 to 5eb299e Oct 26, 2019
@JohnVillalovos

This comment has been minimized.

Copy link
Contributor Author

JohnVillalovos commented Oct 26, 2019

can you please make this available only for --debug 3 ?

Now when doing debug 1 or 2, Output is as before this patch. When debug is 3, then all debug output will have the filename, function name, and line # added.

When calling the _debug3() function will print the filename, function
name, and line number when running under bash
@JohnVillalovos JohnVillalovos force-pushed the JohnVillalovos:master branch from 5eb299e to bba5376 Oct 26, 2019
@@ -265,6 +265,37 @@ _usage() {
printf "\n" >&2
}

__debug_bash_helper() {
# At this point only do for --debug 3
if [ "${DEBUG:-$DEBUG_LEVEL_NONE}" -lt "$DEBUG_LEVEL_3" ]; then

This comment has been minimized.

Copy link
@Neilpang

Neilpang Oct 27, 2019

Owner

we don't need to check DEBUG value here.

This comment has been minimized.

Copy link
@JohnVillalovos

JohnVillalovos Oct 27, 2019

Author Contributor

The reason I did it that was is to that when someone selects "--debug 3" then all the debug lines will get the filename, function name and line no. If we do it the other way then the "debug 1" and "debug 2" lines will never have the filename, function name, and line no even when debug 3 is used.

@@ -273,7 +304,8 @@ _debug() {
_syslog "$SYSLOG_DEBUG" "$@"
fi
if [ "${DEBUG:-$DEBUG_LEVEL_NONE}" -ge "$DEBUG_LEVEL_1" ]; then
_printargs "$@" >&2
_bash_debug=$(__debug_bash_helper)

This comment has been minimized.

Copy link
@Neilpang

Neilpang Oct 27, 2019

Owner

just remove these.

This comment has been minimized.

Copy link
@JohnVillalovos

JohnVillalovos Oct 27, 2019

Author Contributor

The reason I did it that was is to that when someone selects "--debug 3" then all the debug lines will get the filename, function name and line no. If we do it the other way then the "debug 1" and "debug 2" lines will never have the filename, function name, and line no even when debug 3 is used.

@@ -306,7 +338,8 @@ _debug2() {
_syslog "$SYSLOG_DEBUG" "$@"
fi
if [ "${DEBUG:-$DEBUG_LEVEL_NONE}" -ge "$DEBUG_LEVEL_2" ]; then
_printargs "$@" >&2
_bash_debug=$(__debug_bash_helper)

This comment has been minimized.

Copy link
@Neilpang

Neilpang Oct 27, 2019

Owner

and remove these

This comment has been minimized.

Copy link
@JohnVillalovos

JohnVillalovos Oct 27, 2019

Author Contributor

The reason I did it that was is to that when someone selects "--debug 3" then all the debug lines will get the filename, function name and line no. If we do it the other way then the "debug 1" and "debug 2" lines will never have the filename, function name, and line no even when debug 3 is used.

@Neilpang

This comment has been minimized.

Copy link
Owner

Neilpang commented Nov 3, 2019

thanks

@Neilpang Neilpang merged commit eb62387 into Neilpang:dev Nov 3, 2019
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.