zpass: fix remote file operations

This commit is contained in:
zawz 2020-10-26 15:49:01 +01:00
parent 72416b2c1a
commit cfcf94d1ef
7 changed files with 46 additions and 12 deletions

View file

@ -1,5 +1,5 @@
zpass:
zpass: src/*
lxsh -mo zpass src/main.sh
build: zpass

View file

@ -76,7 +76,6 @@ create() {
# if remote: file tmp
[ -n "$ZPASS_REMOTE_ADDR" ] && {
file="$TMPDIR/zpass_$(filehash)$ZPASS_EXTENSION"
[ -z "$ZPASS_PATH" ] && datapath="~/.local/share/zpass"
}
# get key
[ -z "$ZPASS_KEY" ] && {
@ -90,6 +89,7 @@ create() {
return 1
}
[ -n "$ZPASS_REMOTE_ADDR" ] && {
ssh "$ZPASS_REMOTE_ADDR" "mkdir -p '$datapath'"
if [ -n "$ZPASS_SSH_ID" ]
then scp -i "$ZPASS_SSH_ID" "$file" "$ZPASS_REMOTE_ADDR:$datapath/$ZPASS_FILE$ZPASS_EXTENSION" >/dev/null || return $?
else scp "$file" "$ZPASS_REMOTE_ADDR:$datapath/$ZPASS_FILE$ZPASS_EXTENSION" >/dev/null || return $?

View file

@ -1,13 +1,13 @@
#!/bin/sh
# XDG config
datapath="~/.local/share/zpass"
cachepath="~/.cache/zpass"
configpath="~/.config/zpass"
[ -n "$XDG_DATA_HOME" ] && datapath="$XDG_DATA_HOME/zpass"
# XDG config/cache
datapath=".local/share/zpass"
cachepath="$HOME/.cache/zpass"
configpath="$HOME/.config/zpass"
[ -n "$XDG_CONFIG_HOME" ] && configpath="$XDG_CONFIG_HOME/zpass"
[ -n "$XDG_CACHE_HOME" ] && cachepath="$XDG_CACHE_HOME/zpass"
[ -z "$CONFIGFILE" ] && CONFIGFILE="$configpath/default.conf"
[ -n "$XDG_DATA_HOME" ] && [ -z "$ZPASS_REMOTE_ADDR" ] && datapath="$XDG_DATA_HOME/zpass"
[ -z "$TMPDIR" ] && TMPDIR=/tmp
@ -33,7 +33,14 @@ rm -f "$tmpenv" 2>/dev/null
[ -z "$ZPASS_UNK_OP_CALL" ] && ZPASS_UNK_OP_CALL=copy
[ -z "$ZPASS_RAND_LEN" ] && ZPASS_RAND_LEN=20
# datapath resolution
# remove tildes
datapath="${datapath#\~/}"
[ "$datapath" = '~' ] && datapath=""
# if not remote and not absolute: add HOME
[ -z "$ZPASS_REMOTE_ADDR" ] && [ "$(echo "$datapath" | cut -c1)" != '/' ] && datapath="$HOME/$datapath"
file="$datapath/$ZPASS_FILE$ZPASS_EXTENSION"
mkdir -p "$datapath" 2>/dev/null || error 1 "Could not create '$datapath'"
[ -z "$ZPASS_REMOTE_ADDR" ] && { mkdir -p "$datapath" 2>/dev/null || error 1 "Could not create '$datapath'"; }
mkdir -p "$cachepath" 2>/dev/null && chmod -R go-rwx "$cachepath" 2>/dev/null

13
zpass/src/file.sh Normal file
View file

@ -0,0 +1,13 @@
#!/bin/sh
list_files() {
_cmd_ "cd '$datapath' 2>/dev/null && find . -maxdepth 1 -type f -regex '.*$ZPASS_EXTENSION\$'" | sed 's/$(escape_chars "$ZPASS_EXTENSION")\$//g; s|.*/||g'
}
remove_files()
{
for N
do
_cmd_ "rm '$datapath/$N$ZPASS_EXTENSION'" || exit $?
done
}

View file

@ -8,6 +8,7 @@ usage()
list-files List eligible files in data path. Shortcut 'lsf'
cache-clear Delete all cached keys. Shortcut 'cc'
help Display help
rm-file <file...> Remove files. Shortcut 'rmf'
[File Operations]:
ls [path] List contents at given path
tree List all contents
@ -18,8 +19,7 @@ usage()
new <path...> Generate a random password at target
rm <path...> Delete targets
mv <path...> Move targets
exec <cmd> Execute the following command inside the archive
rm-file Remove the current file. Shortcut 'rmf'
exec <cmd> Execute the following command inside the archive.
cached Returns wether or not a key is currently cached. Shortcut 'ch'
rm-cache Delete the cached key for this file. Shortcut 'rmc'

View file

@ -14,8 +14,8 @@ shift 1
case $arg in
-h|h|help) usage && exit 1;;
lsf|list-files) find "$datapath" -type f -maxdepth 1 2>/dev/null | grep "$ZPASS_EXTENSION\$" | sed "s/$(escape_chars "$ZPASS_EXTENSION")\$//g" ;;
rmf|rm-file) rm "$file" ;;
lsf|list-files) list_files ;;
rmf|rm-file) remove_files "$@" ;;
cc|cache-clear) clear_cache 2>/dev/null ;;
ch|cached) get_key_cached >/dev/null 2>&1 ;;
rmc|rm-cache) delete_cache 0 >/dev/null 2>&1 ;;

View file

@ -41,6 +41,20 @@ keyfile(){
printf "%s.key" "$(filehash)"
}
_cmd_() {
if [ -n "$ZPASS_REMOTE_ADDR" ]
then
if [ -n "$ZPASS_SSH_ID" ]
then
ssh -i "$ZPASS_SSH_ID" "$ZPASS_REMOTE_ADDR" "$@" || return $?
else
ssh "$ZPASS_REMOTE_ADDR" "$@" || return $?
fi
else
sh -c "$*"
fi
}
# $1 = delay in sec
clipboard_clear() {
if [ -n "$1" ]