coffin

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

ttab (1844B)


      1 #!/usr/bin/env zsh
      2 #
      3 # Copyright (c) 2016 Dyne.org Foundation
      4 # coffin is written and maintained by Ivan J. <parazyd@dyne.org>
      5 #
      6 # This file is part of coffin
      7 #
      8 # This source code is free software: you can redistribute it and/or modify
      9 # it under the terms of the GNU General Public License as published by
     10 # the Free Software Foundation, either version 3 of the License, or
     11 # (at your option) any later version.
     12 #
     13 # This software is distributed in the hope that it will be useful,
     14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 # GNU General Public License for more details.
     17 #
     18 # You should have received a copy of the GNU General Public License
     19 # along with this source code. If not, see <http://www.gnu.org/licenses/>.
     20 
     21 update-tombs() {
     22 	fn update-tombs $*
     23 	req=(happ)
     24 	local happ="$1"
     25 	ckreq || return 1
     26 
     27 	if [[ $happ == "add" ]]; then
     28 		print "${undertaker}:${keyhash}:${keyuuid}" >> $TOMBS && \
     29 			chmod 600 $TOMBS && \
     30 			act "Added info to $TOMBS"
     31 
     32 	elif [[ $happ == "del" ]]; then
     33 		cp $TOMBS /tmp/$TMPTOMBS
     34 		grep -v "${keyhash}:${keyuuid}" /tmp/$TMPTOMBS > $TOMBS && \
     35 			chmod 600 $TOMBS && \
     36 			act "Removed from $TOMBS"
     37 		rm /tmp/$TMPTOMBS
     38 	fi
     39 }
     40 
     41 ttab-magic() {
     42 	fn ttab-magic
     43 	freq=(TTAB)
     44 	ckreq || return 1
     45 
     46 	notice "Doing ttab magic..."
     47 
     48 	local line=0
     49 	for entry in $(cat $TTAB); do
     50 		let line=$line+1
     51 		act "Found line $line..."
     52 
     53 		[[ ${entry[(ws@:@)3]} == "true" ]] && {
     54 			act "Working on tomb from line $line"
     55 
     56 			undertaker=${entry[(ws@:@)1]}
     57 			tombid=${entry[(ws@:@)2]}
     58 
     59 			compare-key && {
     60 				act "compare-key -> true"
     61 				close-tomb
     62 				update-tombs del
     63 				continue }
     64 
     65 			act "compare-key -> false"
     66 
     67 			open-tomb
     68 
     69 			[[ -d "/media/$tombid" ]] && {
     70 				chmod g+rw /media/$tombid
     71 				update-tombs add
     72 			}
     73 
     74 			check-temptomb
     75 		}
     76 	done
     77 }