Created
January 7, 2017 20:55
-
-
Save masotime/ae56fd2c39d8d211c401fc994e3104b9 to your computer and use it in GitHub Desktop.
Box and Unbox
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
#/bin/bash | |
# Emoji / logging nonsense | |
SPACE=$'\xe2\x80\x83' | |
ERROR=$'\xF0\x9F\x94\xB4'$SPACE | |
INFO=$'\xF0\x9F\x94\xB5'$SPACE | |
OK=$'\xE2\x9C\x85'$SPACE | |
error() { echo "$ERROR $1"; } | |
warn() { echo "$INFO $1"; } | |
ok() { echo "$OK $1"; } | |
if [ -z "$1" ]; then | |
error "Specify the file to decrypt as the first argument" | |
exit 1 | |
fi | |
if [ ! -e "$1" ]; then | |
error "$1 doesn't exist." | |
exit 1 | |
fi | |
OUTPUT=$2 | |
if [ -z "$OUTPUT" ]; then | |
warn "You didn't specify a target folder, will unpack to current folder $(pwd)" | |
OUTPUT=$(pwd) | |
fi | |
if [ ! -e "$OUTPUT" ]; then | |
warn "The output folder $OUTPUT does not exist, creating it" | |
mkdir -p "$OUTPUT" | |
fi | |
tmpfile=$(mktemp $OUTPUT/unpacked-XXXXXX) | |
ok "Decrypt $1 to $tmpfile" | |
openssl enc -d -aes-256-cbc -in "$1" -out "$tmpfile" | |
ok "Unpack $tmpfile to $OUTPUT" | |
tar Jxvf $tmpfile -C $OUTPUT | |
ok "Cleanup temp file $tmpfile" | |
rm $tmpfile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment