coffin

secure lan file storage on a device
git clone git://parazyd.org/coffin.git
Log | Files | Refs | Submodules | README | LICENSE

commit 6c43eef14904d2a912ce2444cc781ea8b2ed905c
parent cb97a7f533a108720132427c9c185c211851520b
Author: parazyd <parazyd@dyne.org>
Date:   Wed, 27 Jan 2016 17:07:24 +0100

script called by mourner, for our administration

Diffstat:
Abin/sacrist | 90+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 90 insertions(+), 0 deletions(-)

diff --git a/bin/sacrist b/bin/sacrist @@ -0,0 +1,90 @@ +#!/bin/zsh +# +# sacrist - script called by mourner, for our graveyard administration +# +# ~ parazyd + +device=$1 +happenz=$2 +keyuuid=`blkid $device | awk -F\" '{print $2}'` + +tmptombs="/tmp/tombs" +lockfile="/tmp/coffinlock" +keymount="/media/tombkey" +coffindot=".coffin" + +# debugs +echo "Arg1: $1" +echo "Arg2: $2" +echo "Device path is: $device" +echo "Device UUID is: $keyuuid" +echo "I am $happenz" +# end debugs + +_mountkey() { + mkdir -p $keymount + mount $device $keymount +} + +_getundertaker() { + if [[ $1 == "user" ]]; then + undertaker=`cat $keymount/$coffindot/undertaker | awk -F: '{print $1}'` + chown -R $undertaker $keymount/$coffindot + elif [[ $1 == "tombname" ]]; then + tombname=`cat $keymount/$coffindot/undertaker | awk -F: '{print $2}'` + elif [[ $1 == "graveyard" ]]; then + graveyard=`cat $keymount/$coffindot/undertaker | awk -F: '{print $3}'` + fi +} + +_hashkey() { + _getundertaker tombname + cat $keymount/$coffindot/$tombname.key \ + | sha512sum \ + | awk -F" " '{print $1}' +} + +_compare_key() { + keyhash=`_hashkey` + if [[ ( `cat $tmptombs | grep $keyhash` ) ]]; then + happenz=close + else + happenz=open + fi +} +_msg() { + if [[ $1 == "err" ]]; then + echo $fg_bold[red] "[E] $2" + elif [[ $1 == "warn" ]]; then + echo $fg_bold[cyan] "[W] $2" + elif [[ $1 == "info" ]]; then + echo $fg_bold[orange] "[i] $2" + fi +} + +if [[ $happenz == "CREATE" ]]; then + _mountkey + if [[ -f "$keymount/$coffindot/undertaker" ]]; then + _getundertaker user; _msg info "Got undertaker: $undertaker" + + _compare_key + if [[ $happenz == "close" ]]; then + _msg info "Comparekey true" + tombname=`cat $tmptombs | grep $keyhash | awk -F: '{print $3}'`; _msg info "Got tombname: $tombname" + tomb slam $tombname + cat $tmptombs | grep -v $keyhash > $tmptombs; _msg info "Put stuff in $tmptombs" + umount $keymount; rmdir $keymount; _msg info "Unmounted usb" + elif [[ $happenz == "open" ]]; then + _msg info "Comparekey false" + _getundertaker tombname; _getundertaker graveyard; _msg info "Got tombname and graveyard" + + echo "$undertaker:$graveyard:$tombname:$keyhash:$keyuuid" >> $tmptombs ; _msg info "Added it to $tmptombs" + su $undertaker -c "tomb open $graveyard/$tombname -k $keymount/$coffindot/$tombname.key --unsafe --tomb-pwd lalala" + + umount $keymount; rmdir $keymount; _msg info "Unmounted usb" + fi + else + _msg err "No valid .coffin dir!" + umount $keymount; rmdir $keymount; + fi +fi