From 15c0e51cee7825bb27d541923bf7aec7e604d9bb Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Mon, 5 Jul 2021 15:56:35 -0400 Subject: Add patreon to sup --- bin/man1/sup.1 | 3 ++- bin/sup.sh | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/bin/man1/sup.1 b/bin/man1/sup.1 index 4b266e06..b413a468 100644 --- a/bin/man1/sup.1 +++ b/bin/man1/sup.1 @@ -1,4 +1,4 @@ -.Dd February 21, 2021 +.Dd July 5, 2021 .Dt SUP 1 .Os . @@ -34,6 +34,7 @@ The following services are supported: .Cm freebsdbugzilla , .Cm liberapay , .Cm lobsters , +.Cm patreon , .Cm tildenews . . .Pp diff --git a/bin/sup.sh b/bin/sup.sh index b7f28bc7..1772f312 100644 --- a/bin/sup.sh +++ b/bin/sup.sh @@ -10,6 +10,16 @@ generate() { copy() { printf '%s' "$1" | pbcopy } +unwrap() { + sed ' + :x + /=$/ { + N + s/=\n//g + bx + } + ' +} asciinema() { echo 'Fetching CSRF token...' @@ -160,6 +170,43 @@ lobsters() { open "${lobstersBase}/login" } +patreon() { + readonly patreonAPI='https://www.patreon.com/api' + echo 'Submitting form...' + curl -Ss -X POST -d @- \ + -H 'Content-Type: application/vnd.api+json' \ + "${patreonAPI}/auth/forgot-password?json-api-version=1.0" <<-EOF + {"data":{"email":"${email}"}} + EOF + echo 'Waiting for email...' + url=$( + git fetch-email -i -M Trash \ + -F 'password@patreon.com' -T "${email}" \ + -S 'Patreon Password Reset' | + unwrap | + grep -o -m 1 'https://email[.]mailgun[.]patreon[.]com/.*' + ) + echo 'Fetching token...' + location=$(curl -ISs --url "${url}" | grep -i '^Location: ' | tr -d '\r') + u=$(echo "${location}" | sed 's/.*[?&]u=\([^&]*\).*/\1/') + sec=$(echo "${location}" | sed 's/.*[?&]sec=\([^&]*\).*/\1/') + password=$(generate) + echo 'Setting password...' + curl -Ss -X POST -d @- \ + -H 'Content-Type: application/vnd.api+json' \ + "${patreonAPI}/auth/forgot-password/change?json-api-version=1.0" <<-EOF + { + "data":{ + "user_id":"${u}", + "security_token":"${sec}", + "password":"${password}" + } + } + EOF + copy "${password}" + open 'https://www.patreon.com/login' +} + tildenews() { lobstersBase='https://tilde.news' lobstersFrom='nobody@tilde.news' -- cgit 1.4.1 mp;showmsg=1'>unfollow)
Commit message (Collapse)Author
2019-09-12Only GET the final redirect locationJune McEnroe
2019-09-12Consume entire bodyJune McEnroe
Aborting the request and leaving data around may be causing intermittent errors. Just discard the rest of the data.
2019-09-10Add title -v flagJune McEnroe
2019-09-10Use curl error bufferJune McEnroe
2019-09-10Set Accept-Encoding in titleJune McEnroe
Because apparently it's fine for servers to respond with Content-Encoding you didn't ask for, and curl won't decode it if you didn't ask for it.
2019-09-08Set title User-AgentJune McEnroe
Some things don't like you if you don't send one.
2019-09-07Add -x flag to titleJune McEnroe
2019-09-07Ignore SIGPIPE in relayJune McEnroe
Allows restarting consumers safely.
2019-09-07Add A Memory Called EmpireJune McEnroe
2019-09-05Handle lack of Content-TypeJune McEnroe
2019-09-05Use CURLINFO_CONTENT_TYPEJune McEnroe
Oops, didn't see this.
2019-09-05Decode entities in titlesJune McEnroe
2019-09-05Print title as soon as it's availableJune McEnroe
2019-09-05Use CURL_PREFIX to set flagsJune McEnroe
2019-09-05Add titleJune McEnroe
2019-09-04Add Avorter n'est pas tuerJune McEnroe
2019-08-29Unset executable on shell scriptsJune McEnroe
2019-08-29Add long-missing setopt to bin.7June McEnroe
2019-08-29Add editJune McEnroe