mirror of
https://github.com/Llewellynvdm/Tomb.git
synced 2024-11-16 01:27:08 +00:00
parent
b3ff77c4bd
commit
55a14a95d6
22
src/tomb
22
src/tomb
@ -110,6 +110,28 @@ function _failure die()
|
|||||||
option_is_set -q || _msg failure "$1"
|
option_is_set -q || _msg failure "$1"
|
||||||
exit $exitcode
|
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
|
# {{{ - CHECK BINARY DEPENDENCIES
|
||||||
|
@ -30,12 +30,20 @@ if [[ $? != 0 ]]; then
|
|||||||
print "$fg[red][!]$fg[white] Tomb command not found, operation aborted."; exit 1
|
print "$fg[red][!]$fg[white] Tomb command not found, operation aborted."; exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
typeset -A opts
|
key_found() {
|
||||||
typeset -A args
|
# $1 is "url"
|
||||||
|
if option_is_set --machine-parseable; then
|
||||||
|
print -n '[m]'
|
||||||
|
fi
|
||||||
|
print "$fg[white][found] $1"
|
||||||
|
}
|
||||||
|
|
||||||
function undertaker_scheme() {
|
function undertaker_scheme() {
|
||||||
zparseopts -D -print-path=print_path
|
zparseopts -D -print-path=print_path
|
||||||
|
|
||||||
|
local scheme
|
||||||
scheme=$1
|
scheme=$1
|
||||||
|
local keypath
|
||||||
keypath=$2
|
keypath=$2
|
||||||
case $scheme in
|
case $scheme in
|
||||||
bluetooth)
|
bluetooth)
|
||||||
@ -74,7 +82,7 @@ function undertaker_scheme() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
if [[ -n $print_path ]]; then
|
if [[ -n $print_path ]]; then
|
||||||
echo $keypath;
|
key_found $scheme://$keypath;
|
||||||
else
|
else
|
||||||
< $keypath
|
< $keypath
|
||||||
r=$?
|
r=$?
|
||||||
@ -83,12 +91,21 @@ function undertaker_scheme() {
|
|||||||
fi
|
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
|
if ! which undertaker-$scheme &> /dev/null; then
|
||||||
error "url protocol not recognized: $scheme"
|
error "url protocol not recognized: $scheme"
|
||||||
return 64
|
return 64
|
||||||
fi
|
fi
|
||||||
undertaker-$scheme ${(kv)opts} ${scheme}://$keypath
|
undertaker-$scheme ${print_path[@]} ${scheme}://$keypath
|
||||||
return $?
|
return $?
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@ -105,13 +122,20 @@ function main() {
|
|||||||
if [[ -n ${(k)opts[--machine-parseable]} ]]; then
|
if [[ -n ${(k)opts[--machine-parseable]} ]]; then
|
||||||
tomb_opts+='--machine-parseable'
|
tomb_opts+='--machine-parseable'
|
||||||
fi
|
fi
|
||||||
|
local -a under_opts
|
||||||
|
if [[ -n ${(k)opts[--print-path]} ]]; then
|
||||||
|
under_opts+='--print-path'
|
||||||
|
fi
|
||||||
local -A backupopts
|
local -A backupopts
|
||||||
backupopts=${(kv)opts}
|
for a in ${(k)opts}; do
|
||||||
|
backupopts[$a]=${opts[$a]}
|
||||||
|
done
|
||||||
source tomb ${tomb_opts[@]} source
|
source tomb ${tomb_opts[@]} source
|
||||||
opts=${(kv)backupopts}
|
for a in ${(k)backupopts}; do
|
||||||
|
opts[$a]=${backupopts[$a]}
|
||||||
|
done
|
||||||
check_bin
|
check_bin
|
||||||
|
|
||||||
|
|
||||||
notice "Undertaker will look for $1"
|
notice "Undertaker will look for $1"
|
||||||
|
|
||||||
ARG1=${1}
|
ARG1=${1}
|
||||||
@ -121,7 +145,7 @@ function main() {
|
|||||||
if [[ -n ${(k)opts[--poll]} ]]; then
|
if [[ -n ${(k)opts[--poll]} ]]; then
|
||||||
while true; do
|
while true; do
|
||||||
progress poll 0 search
|
progress poll 0 search
|
||||||
undertaker_scheme $scheme $keypath
|
undertaker_scheme ${under_opts[@]} $scheme $keypath
|
||||||
r=$?
|
r=$?
|
||||||
if [[ $r == 64 ]]; then
|
if [[ $r == 64 ]]; then
|
||||||
exit 64
|
exit 64
|
||||||
@ -130,7 +154,7 @@ function main() {
|
|||||||
sleep 3
|
sleep 3
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
undertaker_scheme $scheme $keypath
|
undertaker_scheme ${under_opts[@]} $scheme $keypath
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
main $*
|
main $*
|
||||||
|
Loading…
Reference in New Issue
Block a user