Last active
August 6, 2022 17:37
-
-
Save lionello/6bb597fc600932c6c737aab3b402147c to your computer and use it in GitHub Desktop.
base64url: wrapper script for base64
This file contains 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
#!/usr/bin/env bash | |
# Source: https://gist.github.com/lionello/6bb597fc600932c6c737aab3b402147c | |
ignore=0 | |
decode=0 | |
dashdash=0 | |
args=() | |
files=() | |
while [ $# -gt 0 ]; do | |
if [ $dashdash -eq 1 ]; then | |
files+=("$1") | |
else | |
case $1 in | |
-D|-d|--decode) #decode data | |
decode=1 | |
;; | |
-i|--ignore-garbage) #when decoding, ignore non-alphabet characters | |
ignore=1 | |
;; | |
--help) | |
base64 --help | sed 's/\(Usage:.base64\)/\1url/' | |
exit 0 | |
;; | |
--) | |
dashdash=1 | |
;; | |
-*) | |
args+=("$1") | |
;; | |
-|*) | |
files+=("$1") | |
;; | |
esac | |
fi | |
shift | |
done | |
if [ $decode -eq 0 ]; then | |
base64 "${args[@]}" -- "${files[@]}" | sed 's!\+!-!g;s!/!_!g;s!=*$!!g' | |
elif [ $ignore -eq 1 ]; then | |
sed 's!-!\+!g;s!_!/!g' "${files[@]}" | base64 --decode -i "${args[@]}" 2> /dev/null | |
else | |
sed 's!-!\+!g;s!_!/!g' "${files[@]}" | base64 --decode "${args[@]}" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment