Created
July 19, 2024 07:03
-
-
Save Roy-Orbison/10ab882af122fa3fb7ba3cdafc809c62 to your computer and use it in GitHub Desktop.
A simple tool for decoding & encoding data saved in acme.sh conf files, denoted by __ACME_BASE64__START_ & __ACME_BASE64__END_.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
ts=__ACME_BASE64__START_ | |
te=__ACME_BASE64__END_ | |
case $# in | |
0) | |
# loop ensures no final newline is added to input | |
printf '%s%s%s\n' "$ts" "$( | |
q=false | |
f='%s' | |
until $q; do | |
IFS= read -r l || q=true | |
printf "$f" "$l" | |
f='\n%s' | |
done | base64 -w0 | |
)" "$te" | |
;; | |
1) | |
if ! [ "$1" = -d ]; then | |
echo 'only understand the option "-d" for decode' >&2 | |
exit 1 | |
fi | |
grep -Po "$ts\K.*?(?=$te)" | head -n1 | base64 -d | |
;; | |
*) | |
echo 'too many options' >&2 | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It reads from stdin, and writes to stdout. See what the current value is with the decode option, e.g. this reads the first one found in a conf file:
./acmebase64 -d < .acme.sh/domain.example_ecc/domain.example.conf
This encodes a command, omitting the trailing newline like acme does:
Confirm the correct input was encoded by piping the result to
./acmebase64 -d
, again., and inspecting its output.