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

_egrep_o implementation problem #1364

Closed
StephenPCG opened this issue Mar 14, 2018 · 1 comment
Closed

_egrep_o implementation problem #1364

StephenPCG opened this issue Mar 14, 2018 · 1 comment

Comments

@StephenPCG
Copy link

Steps to reproduce

docker run -it --rm \
    --name acme.sh \
    -v "$(pwd)/acme.sh":/acme.sh \
    neilpang/acme.sh \
    --issue --staging \
    --dns dns_dp -d *.a.mydomain.com

It can successfully sign cert, but failed to remove the txt record afterwards:

...
[Wed Mar 14 03:21:15 UTC 2018] Verifying:*.a.mydomain.com
[Wed Mar 14 03:21:19 UTC 2018] Success
[Wed Mar 14 03:21:19 UTC 2018] Removing DNS records.
[Wed Mar 14 03:21:20 UTC 2018] Can not get record id.
[Wed Mar 14 03:21:20 UTC 2018] Error removing txt for domain:_acme-challenge.a.mydomain.com
[Wed Mar 14 03:21:20 UTC 2018] Verify finished, start to sign.
[Wed Mar 14 03:21:23 UTC 2018] Cert success.
...

I added set -x in dns_dp.sh->dns_dp_rm(), and get the following log:

+ grep -- No records
+ echo {"status":{"code":"1","message":"Action completed successful","created_at":"2018-03-14 14:07:35"},"domain":{"id":********,"name":"mydomain.com","punycode":"mydomain.com","grade":"DP_Free","owner":"abcdefg@mydomain.com","ext_status":"","ttl":600,"min_ttl":600,"dnspod_ns":["f1g1ns1.dnspod.net","f1g1ns2.dnspod.net"],"status":"enable"},"info":{"sub_domains":"22","record_total":"1"},"records":[{"id":"349985086","ttl":"600","value":"HEeM6vgfoSAO6XETuIDy7vkWcNLmavWCha52pggFx98","enabled":"1","status":"enabled","updated_on":"2018-03-14 14:05:27","name":"_acme-challenge.a","line":"\u9ed8\u8ba4","line_id":"0","type":"TXT","weight":null,"monitor_status":"","remark":"","use_aqb":"no","mx":"0"}]}
+ cut -d : -f 2
+ _egrep_o {[^{]*"value":"HEeM6vgfoSAO6XETuIDy7vkWcNLmavWCha52pggFx98"
+ egrep -o {[^{]*"value":"HEeM6vgfoSAO6XETuIDy7vkWcNLmavWCha52pggFx98"+
tr -d "
+ cut -d , -f 1
+ sed -n s/.*\({[^{]*"value":"HEeM6vgfoSAO6XETuIDy7vkWcNLmavWCha52pggFx98"\).*/\1/p
+ record_id=
+ _debug record_id
+ [ 1 -ge 1 ]
+ _log record_id
+ [ -z  ]
+ return
+ [ 0 -ge 7 ]
+ [ 0 -ge 1 ]
+ [ -z  ]
+ _err Can not get record id.
+ _syslog user.error Can not get record id.
+ [ 0 = 0 ]
+ return
+ _log Can not get record id.

If I take out value of response and txtvalue and run manually:

/ # _egrep_o() {
  if ! egrep -o "$1" 2>/dev/null; then
    sed -n 's/.*\('"$1"'\).*/\1/p'
  fi
}
/ # echo $response | egrep -o "$txtvalue"
egrep: bad regex '{[^{]*"value":"HEeM6vgfoSAO6XETuIDy7vkWcNLmavWCha52pggFx98"': Repetition not preceded by valid expression
/ # echo $response | sed -n 's/.*\('"$txtvalue"'\).*/\1/p'
{"id":"349985086","ttl":"600","value":"HEeM6vgfoSAO6XETuIDy7vkWcNLmavWCha52pggFx98"
/ # echo $response | _egrep_o "$txtvalue"
/ # echo $?

As we can see, sed command is correct, but in _egrep_o(), egrep has already consumed stdin, so sed just get nothing input.

I changed _egrep_o() to:

_egrep_o() {
  stdin=$(cat)
  if ! echo "$stdin" | egrep -o "$1" 2>/dev/null; then
    echo "$stdin" | sed -n 's/.*\('"$1"'\).*/\1/p'
  fi
}

And now the script can remove records successfully.

@kqkq
Copy link

kqkq commented Jan 28, 2019

Ran into the same problem.

What's the progress on this issue? How about the pull request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants