Skip to content

Instantly share code, notes, and snippets.

@Roy-Orbison
Created July 19, 2024 07:03
Show Gist options
  • Save Roy-Orbison/10ab882af122fa3fb7ba3cdafc809c62 to your computer and use it in GitHub Desktop.
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_.
#!/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
@Roy-Orbison
Copy link
Author

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:

printf '%s' '/path/to/my/script -x -y '\''z z z'\'' foo.bar' | ./acmebase64

Confirm the correct input was encoded by piping the result to ./acmebase64 -d, again., and inspecting its output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment