tomb

the crypto undertaker
git clone git://parazyd.org/tomb.git
Log | Files | Refs | README | LICENSE

commit 55a14a95d683f80d8149e62bbb906d9a80803300
parent b3ff77c4bdd248926b851ba364e139383d6a44c4
Author: boyska <piuttosto@logorroici.org>
Date:   Wed, 16 Nov 2011 22:49:08 +0100

Undertaker: add mounted:///, key_found, fixes

refs #71

Diffstat:
Msrc/tomb | 22++++++++++++++++++++++
Msrc/undertaker | 42+++++++++++++++++++++++++++++++++---------
2 files changed, 55 insertions(+), 9 deletions(-)

diff --git a/src/tomb b/src/tomb @@ -110,6 +110,28 @@ function _failure die() option_is_set -q || _msg failure "$1" exit $exitcode } +progress() { + # $1 is "what is progressing" + # $2 is "percentage" + # $3 is (eventually blank) status + # Example: if creating a tomb, it could be sth like + # progress create 0 filling with random data + # progress create 40 generating key + # progress keygen 0 please move the mouse + # progress keygen 30 please move the mouse + # progress keygen 60 please move the mouse + # progress keygen 100 key generated + # progress create 80 please enter password + # progress create 90 formatting the tomb + # progress create 100 tomb created successfully + local -a prog_opts + zparseopts -a prog_opts -D -E -machine-parseable + if ! option_is_set --machine-parseable; then + return + fi + print "[m][P][$1][$2][$3]" >&2 + +} # }}} # {{{ - CHECK BINARY DEPENDENCIES diff --git a/src/undertaker b/src/undertaker @@ -30,12 +30,20 @@ if [[ $? != 0 ]]; then print "$fg[red][!]$fg[white] Tomb command not found, operation aborted."; exit 1 fi -typeset -A opts -typeset -A args +key_found() { + # $1 is "url" + if option_is_set --machine-parseable; then + print -n '[m]' + fi + print "$fg[white][found] $1" +} + function undertaker_scheme() { zparseopts -D -print-path=print_path + local scheme scheme=$1 + local keypath keypath=$2 case $scheme in bluetooth) @@ -74,7 +82,7 @@ function undertaker_scheme() { return 1 fi if [[ -n $print_path ]]; then - echo $keypath; + key_found $scheme://$keypath; else < $keypath r=$? @@ -83,12 +91,21 @@ function undertaker_scheme() { fi ;; + mounted) + for mountpoint in `cut -f2 /etc/mtab -d ' ' | sort -u`; do + undertaker_scheme ${print_path[@]} file ${mountpoint}/${keypath} + ret=$? + if [[ $ret == 0 ]]; then + return 0 + fi + done + ;; *) if ! which undertaker-$scheme &> /dev/null; then error "url protocol not recognized: $scheme" return 64 fi - undertaker-$scheme ${(kv)opts} ${scheme}://$keypath + undertaker-$scheme ${print_path[@]} ${scheme}://$keypath return $? ;; esac @@ -105,13 +122,20 @@ function main() { if [[ -n ${(k)opts[--machine-parseable]} ]]; then tomb_opts+='--machine-parseable' fi + local -a under_opts + if [[ -n ${(k)opts[--print-path]} ]]; then + under_opts+='--print-path' + fi local -A backupopts - backupopts=${(kv)opts} + for a in ${(k)opts}; do + backupopts[$a]=${opts[$a]} + done source tomb ${tomb_opts[@]} source - opts=${(kv)backupopts} + for a in ${(k)backupopts}; do + opts[$a]=${backupopts[$a]} + done check_bin - notice "Undertaker will look for $1" ARG1=${1} @@ -121,7 +145,7 @@ function main() { if [[ -n ${(k)opts[--poll]} ]]; then while true; do progress poll 0 search - undertaker_scheme $scheme $keypath + undertaker_scheme ${under_opts[@]} $scheme $keypath r=$? if [[ $r == 64 ]]; then exit 64 @@ -130,7 +154,7 @@ function main() { sleep 3 done else - undertaker_scheme $scheme $keypath + undertaker_scheme ${under_opts[@]} $scheme $keypath fi } main $*