base64 varies on different platforms
The base64 binary that ships with alpine linux considers --decode an invalid option. Instead, it prefers the short flag: -d.
Simply changing to -d would make the script incompatible with Mac OS, which prefers --decode or -D.
Since awscli is already a prerequisite, I suppose we can assume python is installed, so perhaps this could be replaced with python -m base64 -d
Also, can we be certain that every OS will have base64?
@nicholaides It's a builtin: https://docs.python.org/3/library/base64.html
Sorry-- I meant, the shell command/executable base64. I was wondering how certain we can be that it's available on every OS. Brian's point that we can rely on Python being installed makes Python seem like a good solution.
It's part of gnu coreutils, so it's on any GNU/linux based distro (just as cat is). Another option would be to require coreutils on OS/X to get the gnu version (brew install coreutils)
e.g. on an ubuntu box:
$ dpkg -S /bin/cat
coreutils: /bin/cat
$ dpkg -S /usr/bin/base64
coreutils: /usr/bin/base64
I wouldn't recommend python for this if we didn't already have awscli as a requirement.
What's also interesting is that OS/X (the only outlier) lists lowercase d in the first line of the help message, so this could be called a bug in the OS/X base64
$ /usr/bin/base64 --help
Usage: /usr/bin/base64 [-dhvD] [-b num] [-i in_file] [-o out_file]
-h, --help display this message
-D, --decode decodes input
-b, --break break encoded string into num character lines
-i, --input input file (default: "-" for stdin)
-o, --output output file (default: "-" for stdout)
On second thought, maybe we can just skip base64 encoding entirely.
Newer versions of base64 on OS/X supports both -D and -d for decoding:
Usage: base64 [-hvDd] [-b num] [-i in_file] [-o out_file]
-h, --help display this message
-Dd, --decode decodes input
-b, --break break encoded string into num character lines
-i, --input input file (default: "-" for stdin)
-o, --output output file (default: "-" for stdout)
I can attest @fabriziofortino
Even on Big Sur man base64
-d
-D
--decode Decode incoming Base64 stream into binary data.
This issue just bit me today on Ubuntu 22.04: base64: invalid option -- 'D'
The only supported options are:
base64 --help
Usage: base64 [OPTION]... [FILE]
Base64 encode or decode FILE, or standard input, to standard output.
With no FILE, or when FILE is -, read standard input.
Mandatory arguments to long options are mandatory for short options too.
-d, --decode decode data
-i, --ignore-garbage when decoding, ignore non-alphabet characters
-w, --wrap=COLS wrap encoded lines after COLS character (default 76).
Use 0 to disable line wrapping
--help display this help and exit
--version output version information and exit
The data are encoded as described for the base64 alphabet in RFC 4648.
When decoding, the input may contain newlines in addition to the bytes of
the formal base64 alphabet. Use --ignore-garbage to attempt to recover
from any other non-alphabet bytes in the encoded stream.
GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Full documentation <https://www.gnu.org/software/coreutils/base64>
or available locally via: info '(coreutils) base64 invocation'