Skip to content

Instantly share code, notes, and snippets.

@leonid-shevtsov
Last active December 4, 2022 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leonid-shevtsov/f1e99ac76027d4c2f3b2fb5caee806a1 to your computer and use it in GitHub Desktop.
Save leonid-shevtsov/f1e99ac76027d4c2f3b2fb5caee806a1 to your computer and use it in GitHub Desktop.
#!/bin/sh
GITHUB_PAT_TOKEN=github_pat_xxx
REPO=myuser/myrepo
FILEPATH=online.txt
# echo -n '...' | base64
INCREMENT='Li4u'
FILEINFO=$(curl \
-X GET \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_PAT_TOKEN" \
"https://api.github.com/repos/$REPO/contents/$FILEPATH" | tr '\n' ' ' | sed 's/\\n//')
SHA=$(echo "$FILEINFO" | sed -E 's/.*"sha": "([^"]*)".*/\1/')
CONTENT=$(echo "$FILEINFO" | sed -E 's/.*"content": "([^"]*)".*/\1/' )
NEWCONTENT="$CONTENT$INCREMENT"
if [ "${#NEWCONTENT}" -gt 32 ]; then
NEWCONTENT=''
fi
curl \
-X PUT \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_PAT_TOKEN" \
"https://api.github.com/repos/$REPO/contents/$FILEPATH" \
-d "{\"message\":\"i am online\",\"content\":\"$NEWCONTENT\",\"sha\":\"$SHA\"}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment