diff options
author | Jesse Luehrs <doy@tozt.net> | 2015-05-13 11:56:28 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2015-05-13 14:38:53 -0400 |
commit | 8701a50b563c2af22ac97f463b1d5c9c3347efe2 (patch) | |
tree | 5c8acc9636451c1a2b63c84efbb65284711edc9b /bin/cryptdir | |
parent | 20cdf09e315924d2cf762315b7e3695dd71c0168 (diff) | |
download | conf-8701a50b563c2af22ac97f463b1d5c9c3347efe2.tar.gz conf-8701a50b563c2af22ac97f463b1d5c9c3347efe2.zip |
randomize the password and ensure the dir gets cleaned up
Diffstat (limited to 'bin/cryptdir')
-rwxr-xr-x | bin/cryptdir | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/bin/cryptdir b/bin/cryptdir index c6b5f65..4434e6e 100755 --- a/bin/cryptdir +++ b/bin/cryptdir @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash if [[ -e /dev/mapper/cryptdir ]]; then echo "only one instance can run at a time" 1>&2 @@ -15,17 +15,23 @@ fi cryptfile=$(mktemp) cryptdir=$(mktemp -d) +pass=$(dd if=/dev/urandom bs=1 count=80 | base64) + +cleanup () { + cd + sudo umount $cryptdir + sudo cryptsetup close cryptdir + rm -f $cryptfile + rmdir $cryptdir +} + +trap cleanup EXIT dd if=/dev/urandom of=$cryptfile bs=$size count=1 -echo "secretpass" | sudo cryptsetup luksFormat $cryptfile - -echo "secretpass" | sudo cryptsetup open $cryptfile cryptdir --key-file - +echo $pass | sudo cryptsetup luksFormat $cryptfile - +echo $pass | sudo cryptsetup open $cryptfile cryptdir --key-file - sudo mkfs.ext2 /dev/mapper/cryptdir sudo mount /dev/mapper/cryptdir $cryptdir sudo chown $USER $cryptdir cd $cryptdir $SHELL -cd -sudo umount $cryptdir -sudo cryptsetup close cryptdir -rm -f $cryptfile -rmdir $cryptdir |