coffin

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

commit 27f1af84b6f04cf5686dcdef46dca46a4f796810
parent 7689b3271deae39655d3114d5264c47adb23bf1a
Author: parazyd <parazyd@dyne.org>
Date:   Wed,  2 Mar 2016 15:11:53 +0100

obscure zsh builtins

Diffstat:
Mbin/sacrist | 54++++++++++++++++++++++++++++++------------------------
1 file changed, 30 insertions(+), 24 deletions(-)

diff --git a/bin/sacrist b/bin/sacrist @@ -8,6 +8,10 @@ device=$1 happenz=$2 keyuuid=$(blkid $device | awk -F\" '{print $2}') + +typeset -H keypass +typeset -H undertaker + # Vars graveyard="/home/graveyard" # Our graveyard, with all the tombs tombs="$graveyard/tombs" # Info about opened tombs, holds keyuuid, keyhash and tombid @@ -23,10 +27,10 @@ tombpasswd="$graveyard/passwd" # create:username:tombname:tombsize:passphrase # Debugs -echo "Arg1: $1" -echo "Arg2: $2" -echo "Device path is: $device" -echo "Device UUID is: $keyuuid" +print "Arg1: $1" +print "Arg2: $2" +print "Device path is: $device" +print "Device UUID is: $keyuuid" # {{{ Functions _mountkey() { @@ -43,12 +47,12 @@ _ttabmagic() { let line=$line+1 _msg info "Found line $line..." - if [[ $(echo $entry | awk -F: '{print $3}') == "true" ]]; then + if [[ ${entry[(ws@:@)3]} == "true" ]]; then _msg info "Working on tomb from line $line..." - undertaker=$(echo $entry | awk -F: '{print $1}') - echo "Username: $undertaker" - tombid=$(echo $entry | awk -F: '{print $2}') - echo "Tomb name: $tombid.tomb" + undertaker=${entry[(ws@:@)1]} + print "Username: $undertaker" + tombid=${entry[(ws@:@)2]} + print "Tomb name: $tombid.tomb" _comparekey if [[ $happenz == "close" ]]; then @@ -62,12 +66,12 @@ _ttabmagic() { _msg warn "Comparekey false" keypass=$(cat $tombpasswd | grep $keyhash | awk -F: '{print $2}') - echo "Tomb passphrase: $keypass" + print "Tomb passphrase: $keypass" sudo -u $undertaker $tomb open $graveyard/$tombid.tomb -k $coffindot/$tombid.key \ - --unsafe --tomb-pwd "$keypass" # Deal with this shit somehow! + --unsafe --tomb-pwd "$keypass" # Deal with this if [[ -d "/media/$tombid" ]]; then - echo "$undertaker:$keyhash:$keyuuid" >> $tombs && chmod 600 $tombs && _msg info "Added info to $tombs" + print "$undertaker:$keyhash:$keyuuid" >> $tombs && chmod 600 $tombs && _msg info "Added info to $tombs" else _msg warn "Nothing added to $tombs" fi @@ -96,11 +100,11 @@ _hooks() { _msg info "Found hook $hook..." # Check what's hook supposed to do - if [[ $(echo $entry | awk -F: '{print $1}') == "create" ]]; then + if [[ ${entry[(ws@:@)1]} == "create" ]]; then _create_new_tomb - elif [[ $(echo $entry | awk -F: '{print $1}') == "delete" ]]; then + elif [[ ${entry[(ws@:@)1]} == "delete" ]]; then #DELETE TOMB - elif [[ $(echo $entry | awk -F: '{print $1}') == "foo" ]]; then + elif [[ ${entry[(ws@:@)1]} == "foo" ]]; then # do foo else _msg error "No valid hook syntax on hook $hook" @@ -111,15 +115,17 @@ _hooks() { _create_new_tomb() { _msg info "Creating new tomb!" - undertaker=$(echo $entry | awk -F: '{print $2}') - tombid=$(echo $entry | awk -F: '{print $3}') - tombsize=$(echo $entry| awk -F: '{print $4}') - keypass=$(echo $entry | awk -F: '{print $5}') + undertaker=${entry[(ws@:@)2]} + tombid=${entry[(ws@:@)3]} + tombsize=${entry[(ws@:@)4]} + keypass=${entry[(ws@:@)5]} if ! [[ ( $(id $undertaker) ) ]]; then _msg warn "No user called $undertaker found. Creating..." useradd -G tombox -m -s /bin/bash $undertaker _msg info "Created user $undertaker" + else + _msg warn "User $undertaker exists. Continuing..." fi sudo -u $undertaker $tomb dig -s $tombsize $graveyard/$tombid.tomb @@ -129,9 +135,9 @@ _create_new_tomb() { mv $graveyard/$tombid.key $coffindot/ && chown $undertaker:$undertaker $coffindot/$tombid.key && \ _msg info "Moved and chowned keyfile" - echo "$undertaker:${tombid}:true" >> $ttab + print "$undertaker:${tombid}:true" >> $ttab keyhash=$(_hashkey) - echo "${keyhash}:${keypass}" >> $tombpasswd + print "${keyhash}:${keypass}" >> $tombpasswd _msg info "Wrote to $ttab and $tombpasswd" # rm $createme && _msg info "Removed $createme" } @@ -142,11 +148,11 @@ _endgame() { _msg() { if [[ $1 == "error" ]]; then - echo -e "\e[1;31m[E] \e[0;31m$2 \e[0m" + print "\e[1;31m[E] \e[0;31m$2 \e[0m" elif [[ $1 == "warn" ]]; then - echo -e "\e[1;33m[W] \e[0;33m$2 \e[0m" + print "\e[1;33m[W] \e[0;33m$2 \e[0m" elif [[ $1 == "info" ]]; then - echo -e "\e[1;34m[i] \e[0;34m$2 \e[0m" + print "\e[1;34m[i] \e[0;34m$2 \e[0m" fi } # }}}