add tmpdir delete to stop

This commit is contained in:
zawz 2021-08-04 22:11:48 +02:00
parent de97427032
commit df51b595f5
4 changed files with 17 additions and 14 deletions

View file

@ -43,20 +43,20 @@ archive_exec()
{ {
err=0 err=0
# tmp files # tmp files
tmpdir="$TMPDIR/zpass_$(randalnum 20)" archive_tmpdir="$TMPDIR/zpass_$(randalnum 20)"
keyfile="$tmpdir/$(randalnum 20).key" keyfile="$archive_tmpdir/$(randalnum 20).key"
# operation # operation
( (
# unpack # unpack
unpack "$tmpdir/archive" "$keyfile" || exit $? unpack "$archive_tmpdir/archive" "$keyfile" || exit $?
# execute # execute
(cd "$tmpdir/archive" && "$@") || exit $? (cd "$archive_tmpdir/archive" && "$@") || exit $?
# repack # repack
[ -z "$__NOPACK" ] && { pack "$tmpdir/archive" "$keyfile" || exit $?; } [ -z "$__NOPACK" ] && { pack "$archive_tmpdir/archive" "$keyfile" || exit $?; }
exit 0 exit 0
) || err=$? ) || err=$?
# cleanup # cleanup
rm -rf "$tmpdir" rm -rf "$archive_tmpdir"
return $err return $err
} }
@ -64,11 +64,11 @@ archive_exec()
create_file() { create_file() {
if [ -f "$file" ] if [ -f "$file" ]
then then
tmpdir="$TMPDIR/zpass_$(randalnum 20)" archive_tmpdir="$TMPDIR/zpass_$(randalnum 20)"
# pack n repack with no tmp key: create new # pack n repack with no tmp key: create new
unpack "$tmpdir" || return $? unpack "$archive_tmpdir" || return $?
pack "$tmpdir" || { echo "Encryption error" >&2 && return 1 ; } pack "$archive_tmpdir" || { echo "Encryption error" >&2 && return 1 ; }
rm -rf "$tmpdir" rm -rf "$archive_tmpdir"
else else
# if remote: file tmp and try to get file # if remote: file tmp and try to get file
[ -n "$remote_host" ] && { [ -n "$remote_host" ] && {

View file

@ -12,7 +12,6 @@ write_cache() {
} }
get_key_cached() { get_key_cached() {
[ ! -f "$file" ] && return 0
cat "$cachepath/$(keyfile)" 2>/dev/null cat "$cachepath/$(keyfile)" 2>/dev/null
} }

View file

@ -1,5 +1,10 @@
#!/bin/lxsh #!/bin/lxsh
_stop() {
stty echo
rm -rf "$archive_tmpdir"
}
[ "$DEBUG" = true ] && set -x [ "$DEBUG" = true ] && set -x
%include util.sh config.sh *.sh %include util.sh config.sh *.sh
@ -7,7 +12,7 @@
## pre exec ## pre exec
clean_cache 2>/dev/null clean_cache 2>/dev/null
[ $# -lt 1 ] && usage && return 1 [ $# -lt 1 ] && usage && exit 1
arg=$1 arg=$1
shift 1 shift 1

View file

@ -4,8 +4,7 @@
console_prompt_hidden() console_prompt_hidden()
{ {
( (
_tty_on() { stty echo; } trap _stop INT
trap _tty_on INT
local prompt local prompt
printf "%s" "$1" >&2 printf "%s" "$1" >&2
stty -echo stty -echo