tsacrist - coffin - secure lan file storage on a device
 (HTM) git clone git://parazyd.org/coffin.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Submodules
 (DIR) README
 (DIR) LICENSE
       ---
       tsacrist (2745B)
       ---
            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 coffin_version=0.4
           22 
           23 DEBUG=${DEBUG:-0}
           24 QUIET=${QUIET:-0}
           25 LOG=${LOG:-""}
           26 
           27 swapoff -a ## I feel so safe
           28 
           29 R="$(dirname $0)"
           30 source $R/../share/zuper/zuper
           31 
           32 # USB key
           33 vars+=(device keyuuid)
           34 vars+=(GRAVEYARD TOMBS TMPTOMBS TOMBPASSWD)
           35 vars+=(KEYMOUNT COFFINDOT TTAB HOOKS)
           36 vars+=(keypass undertaker tombid)
           37 vars+=(happenz device keyuuid)
           38 
           39 ## zsh magic
           40 path+=()
           41 
           42 source $R/../share/zlibs/feature-ssh
           43 source $R/../share/zlibs/feature-webdav
           44 source $R/../share/zlibs/hooks
           45 source $R/../share/zlibs/keyops
           46 source $R/../share/zlibs/mounts
           47 source $R/../share/zlibs/tombops
           48 source $R/../share/zlibs/ttab
           49 
           50 source $R/../share/zuper/zuper.init
           51 
           52 LOCK=$R/.lock
           53 [[ -f $LOCK ]] && { warn "Lock found. Wait until finished." && exit }
           54 touch $LOCK
           55 
           56 # Check for a configuration file
           57 # [[ -f ".coffinrc" ]] && parse-config
           58 
           59 device=$1
           60 happenz=$2
           61 keyuuid=$(lsblk -no uuid $device)
           62 
           63 GRAVEYARD="/home/graveyard" # Our graveyard, with all the tombs
           64 TOMBS="$GRAVEYARD/tombs" # Info about opened tombs, holds keyuuid, keyhash and tombid
           65 TMPTOMBS="$GRAVEYARD/tmptombs" # Temp tempfile, for updating $tombs
           66 TOMBPASSWD="$GRAVEYARD/passwd"
           67 KEYMOUNT="/media/tombkey" # Directory where keys get mounted
           68 COFFINDOT="$KEYMOUNT/coffin" # .coffin directory on the usb key
           69 TTAB="$COFFINDOT/ttab" # Our ttab
           70 HOOKS="$COFFINDOT/hook"
           71 TOMB="$R/tomb"
           72 
           73 # Main
           74 req=(happenz device)
           75 ckreq || {
           76         die "Not called through mourner. Exiting..."
           77         #clean
           78         exit 1
           79 }
           80 
           81 notice "Coffin v${coffin_version}, Cryptographic office filer for important nuggets"
           82 
           83 [[ $happenz == "CREATE" ]] && {
           84         mount-key $device || { die "Key not mounted successfully." && exit 1 }
           85 
           86         if [[ -d "$COFFINDOT" ]]; then
           87                 act "Found .coffin"
           88                 [[ -f "$HOOKS" ]] && check-hooks
           89                 [[ -f "$TTAB" ]]  && ttab-magic
           90         else
           91                 warn "No .coffin directory"
           92         fi
           93 
           94         umount-key $device
           95         rm -f $LOCK && exit 0 || exit 1
           96         # cleanup & exit
           97 }
           98 
           99 [[ $happenz == "DELETE" ]] && {
          100         # TODO: Some kind of endgame
          101         rm -f $LOCK && exit 0 || exit 1
          102 }
          103 
          104 exit 1