diff --git a/zpass/Makefile b/zpass/Makefile index ecdbf7e..a70ce25 100644 --- a/zpass/Makefile +++ b/zpass/Makefile @@ -1,5 +1,5 @@ -zpass: +zpass: src/* lxsh -mo zpass src/main.sh build: zpass diff --git a/zpass/src/archive.sh b/zpass/src/archive.sh index a4e3262..45f423d 100644 --- a/zpass/src/archive.sh +++ b/zpass/src/archive.sh @@ -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 $? diff --git a/zpass/src/config.sh b/zpass/src/config.sh index f543050..8998f10 100644 --- a/zpass/src/config.sh +++ b/zpass/src/config.sh @@ -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 diff --git a/zpass/src/file.sh b/zpass/src/file.sh new file mode 100644 index 0000000..fad9fb7 --- /dev/null +++ b/zpass/src/file.sh @@ -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 +} diff --git a/zpass/src/help.sh b/zpass/src/help.sh index 0a62e9f..8a1db0e 100644 --- a/zpass/src/help.sh +++ b/zpass/src/help.sh @@ -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 Remove files. Shortcut 'rmf' [File Operations]: ls [path] List contents at given path tree List all contents @@ -18,8 +19,7 @@ usage() new Generate a random password at target rm Delete targets mv Move targets - exec Execute the following command inside the archive - rm-file Remove the current file. Shortcut 'rmf' + exec 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' diff --git a/zpass/src/main.sh b/zpass/src/main.sh index 895c0c7..6a52736 100644 --- a/zpass/src/main.sh +++ b/zpass/src/main.sh @@ -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 ;; diff --git a/zpass/src/util.sh b/zpass/src/util.sh index 2eedebc..63153ee 100644 --- a/zpass/src/util.sh +++ b/zpass/src/util.sh @@ -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" ]