-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add bbb: a smart wraper around base64 -d
- Loading branch information
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env bash | ||
# A smart wrapper for base64 decoding. | ||
|
||
set -euo pipefail | ||
|
||
stderr() { | ||
echo "${@}" 1>&2 | ||
} | ||
|
||
fail() { | ||
stderr "${1}" | ||
stderr "" | ||
stderr "Exiting …" | ||
exit "${2:-1}" | ||
} | ||
|
||
missing_dependencies=false | ||
declare -r dependencies=( | ||
base64 | ||
) | ||
for dep in "${dependencies[@]}"; do | ||
if ! command -v "${dep}" &> /dev/null; then | ||
stderr "❌ ERROR: Missing dependency ${dep}" | ||
missing_dependencies=true | ||
fi | ||
done | ||
if ${missing_dependencies}; then | ||
fail 'Please install the missing dependencies!' | ||
fi | ||
|
||
if [[ $# -eq 0 ]]; then | ||
# no args => stdin | ||
base64 -d ; echo | ||
else | ||
echo -n "${*}" | base64 -d ; echo | ||
fi |