Skip to content

Instantly share code, notes, and snippets.

@developish
Created August 5, 2019 18:04
Show Gist options
  • Save developish/849c8966777b200c51864d2d0f20362a to your computer and use it in GitHub Desktop.
Save developish/849c8966777b200c51864d2d0f20362a to your computer and use it in GitHub Desktop.
A script for managing an encrypted volume at ~/Secrets (Mac OS X)
#!/usr/bin/env sh
program=$(basename $0)
command=$1
help() {
echo "Usage: $program <subcommand>"
echo ""
echo "Subcommands:"
echo " create Create an encrypted volume"
echo " mount Mount the encrypted volume"
echo " unmount Unmount the encrypted volume"
echo ""
}
sub_mount() {
hdiutil attach ~/Documents/Secrets.dmg -mountroot ~
}
sub_unmount() {
hdiutil unmount ~/Secrets
}
sub_create() {
mkdir ~/Secrets
hdiutil create \
-format UDRW \
-encryption AES-256 -megabytes 100 \
-srcfolder ~/Secrets ~/Documents/Secrets.dmg
rmdir ~/Secrets
}
case $command in
"" | "-h" | "--help")
help
;;
*)
shift
sub_${command} $@
if [ $? = 127 ]; then
echo "Error: '$command' is not a known command." >&2
echo " Run '$program --help' for a list of commands." >&2
exit 1
fi
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment