Skip to content

Instantly share code, notes, and snippets.

@cyphunk
Created March 9, 2016 15:21
Show Gist options
  • Save cyphunk/c6d7d5714b7624ff2a9e to your computer and use it in GitHub Desktop.
Save cyphunk/c6d7d5714b7624ff2a9e to your computer and use it in GitHub Desktop.
create a password protected zip of files
#!/bin/bash
set -e #exit on any error
if [ $# -lt 1 ]; then
echo "$0 file [file ...]"
exit
fi
FILE1=$(basename "$(readlink -f "$1")")
NAME="${FILE1%.*}"
test -d "$NAME" || mkdir "$NAME"
cp $* "$NAME/."
echo "Provide password for zip \"$NAME.zip\""
p=$(mktemp | tr '[:upper:]' '[:lower:]');
echo -e "For example: \"${p#*.}\"\n"
read -s -p "Password: " PASSWORD
zip --quiet --encrypt --password "$PASSWORD" "$NAME.zip" "$NAME"/*
rm -rf "$NAME"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment