zpass: fix remote file operations
This commit is contained in:
parent
72416b2c1a
commit
cfcf94d1ef
7 changed files with 46 additions and 12 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
zpass:
|
zpass: src/*
|
||||||
lxsh -mo zpass src/main.sh
|
lxsh -mo zpass src/main.sh
|
||||||
|
|
||||||
build: zpass
|
build: zpass
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,6 @@ create() {
|
||||||
# if remote: file tmp
|
# if remote: file tmp
|
||||||
[ -n "$ZPASS_REMOTE_ADDR" ] && {
|
[ -n "$ZPASS_REMOTE_ADDR" ] && {
|
||||||
file="$TMPDIR/zpass_$(filehash)$ZPASS_EXTENSION"
|
file="$TMPDIR/zpass_$(filehash)$ZPASS_EXTENSION"
|
||||||
[ -z "$ZPASS_PATH" ] && datapath="~/.local/share/zpass"
|
|
||||||
}
|
}
|
||||||
# get key
|
# get key
|
||||||
[ -z "$ZPASS_KEY" ] && {
|
[ -z "$ZPASS_KEY" ] && {
|
||||||
|
|
@ -90,6 +89,7 @@ create() {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
[ -n "$ZPASS_REMOTE_ADDR" ] && {
|
[ -n "$ZPASS_REMOTE_ADDR" ] && {
|
||||||
|
ssh "$ZPASS_REMOTE_ADDR" "mkdir -p '$datapath'"
|
||||||
if [ -n "$ZPASS_SSH_ID" ]
|
if [ -n "$ZPASS_SSH_ID" ]
|
||||||
then scp -i "$ZPASS_SSH_ID" "$file" "$ZPASS_REMOTE_ADDR:$datapath/$ZPASS_FILE$ZPASS_EXTENSION" >/dev/null || return $?
|
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 $?
|
else scp "$file" "$ZPASS_REMOTE_ADDR:$datapath/$ZPASS_FILE$ZPASS_EXTENSION" >/dev/null || return $?
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# XDG config
|
# XDG config/cache
|
||||||
datapath="~/.local/share/zpass"
|
datapath=".local/share/zpass"
|
||||||
cachepath="~/.cache/zpass"
|
cachepath="$HOME/.cache/zpass"
|
||||||
configpath="~/.config/zpass"
|
configpath="$HOME/.config/zpass"
|
||||||
[ -n "$XDG_DATA_HOME" ] && datapath="$XDG_DATA_HOME/zpass"
|
|
||||||
[ -n "$XDG_CONFIG_HOME" ] && configpath="$XDG_CONFIG_HOME/zpass"
|
[ -n "$XDG_CONFIG_HOME" ] && configpath="$XDG_CONFIG_HOME/zpass"
|
||||||
[ -n "$XDG_CACHE_HOME" ] && cachepath="$XDG_CACHE_HOME/zpass"
|
[ -n "$XDG_CACHE_HOME" ] && cachepath="$XDG_CACHE_HOME/zpass"
|
||||||
[ -z "$CONFIGFILE" ] && CONFIGFILE="$configpath/default.conf"
|
[ -z "$CONFIGFILE" ] && CONFIGFILE="$configpath/default.conf"
|
||||||
|
[ -n "$XDG_DATA_HOME" ] && [ -z "$ZPASS_REMOTE_ADDR" ] && datapath="$XDG_DATA_HOME/zpass"
|
||||||
|
|
||||||
[ -z "$TMPDIR" ] && TMPDIR=/tmp
|
[ -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_UNK_OP_CALL" ] && ZPASS_UNK_OP_CALL=copy
|
||||||
[ -z "$ZPASS_RAND_LEN" ] && ZPASS_RAND_LEN=20
|
[ -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"
|
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
|
mkdir -p "$cachepath" 2>/dev/null && chmod -R go-rwx "$cachepath" 2>/dev/null
|
||||||
|
|
|
||||||
13
zpass/src/file.sh
Normal file
13
zpass/src/file.sh
Normal 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
|
||||||
|
}
|
||||||
|
|
@ -8,6 +8,7 @@ usage()
|
||||||
list-files List eligible files in data path. Shortcut 'lsf'
|
list-files List eligible files in data path. Shortcut 'lsf'
|
||||||
cache-clear Delete all cached keys. Shortcut 'cc'
|
cache-clear Delete all cached keys. Shortcut 'cc'
|
||||||
help Display help
|
help Display help
|
||||||
|
rm-file <file...> Remove files. Shortcut 'rmf'
|
||||||
[File Operations]:
|
[File Operations]:
|
||||||
ls [path] List contents at given path
|
ls [path] List contents at given path
|
||||||
tree List all contents
|
tree List all contents
|
||||||
|
|
@ -18,8 +19,7 @@ usage()
|
||||||
new <path...> Generate a random password at target
|
new <path...> Generate a random password at target
|
||||||
rm <path...> Delete targets
|
rm <path...> Delete targets
|
||||||
mv <path...> Move targets
|
mv <path...> Move targets
|
||||||
exec <cmd> Execute the following command inside the archive
|
exec <cmd> Execute the following command inside the archive.
|
||||||
rm-file Remove the current file. Shortcut 'rmf'
|
|
||||||
cached Returns wether or not a key is currently cached. Shortcut 'ch'
|
cached Returns wether or not a key is currently cached. Shortcut 'ch'
|
||||||
rm-cache Delete the cached key for this file. Shortcut 'rmc'
|
rm-cache Delete the cached key for this file. Shortcut 'rmc'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,8 @@ shift 1
|
||||||
|
|
||||||
case $arg in
|
case $arg in
|
||||||
-h|h|help) usage && exit 1;;
|
-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" ;;
|
lsf|list-files) list_files ;;
|
||||||
rmf|rm-file) rm "$file" ;;
|
rmf|rm-file) remove_files "$@" ;;
|
||||||
cc|cache-clear) clear_cache 2>/dev/null ;;
|
cc|cache-clear) clear_cache 2>/dev/null ;;
|
||||||
ch|cached) get_key_cached >/dev/null 2>&1 ;;
|
ch|cached) get_key_cached >/dev/null 2>&1 ;;
|
||||||
rmc|rm-cache) delete_cache 0 >/dev/null 2>&1 ;;
|
rmc|rm-cache) delete_cache 0 >/dev/null 2>&1 ;;
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,20 @@ keyfile(){
|
||||||
printf "%s.key" "$(filehash)"
|
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
|
# $1 = delay in sec
|
||||||
clipboard_clear() {
|
clipboard_clear() {
|
||||||
if [ -n "$1" ]
|
if [ -n "$1" ]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue