diff options
Diffstat (limited to 'quicktype')
-rwxr-xr-x | quicktype | 71 |
1 files changed, 60 insertions, 11 deletions
@@ -13,21 +13,70 @@ # * The username can be anywhere in the file, but the line must look like # 'username: <password>' # -# Requirements: -# pass -# xdotool +# Depends on: pass xdotool # + export PASSWORD_STORE_DIR=~/.password-store -# Ensure password is specified -[[ -z ${1} ]] && echo "Please specify a password to be typed" && exit 1 +# +# Writes log output to terminal and notification daemon, if one is present. +# +function log { + local msg="${@}" + + if [[ $(type -p notify-send) != '' ]]; then + notify-send "$(basename ${0}):" "${msg}" + fi + echo ${msg} +} + + +# +# Ensures required tools are available, returning code 1 and log if any of them +# are not. +# +function check_env { + # Verify pass is installed and in the PATH. + if [[ $(type -p pass) == '' ]]; then + log "Error: Could not find pass." && return 1 + fi + + # Verify xdotool is installed and in the path + if [[ $(type -p xdotool) == '' ]]; then + log "Error: Could not find xdotool." && return 1 + fi + + # Verify /dev/null is a character device, on the off chance someone with root + # access is trying to capture output redirected there. + local devstat=$(ls -l /dev/null) + if [[ ${devstat:0:1} != 'c' ]]; then + log "Error: /dev/null is not a character device." + return 1 + fi + + return 0 +} + + +function main { + # Exit failure if no password was specified + [[ -z ${1} ]] && log "Please specify a password to be typed" && exit 1 -# Ensure xdotool and pass binaries can be found -[[ ! $(type -p xdotool) ]] && echo "ERROR: xdotool not found." && exit 1 -[[ ! $(type -p pass) ]] && echo "ERROR: pass not found." && exit 1 + check_env || exit 0 + + # Check if the password exists in the store + pass ${@} &> /dev/null + [[ $? -gt 0 ]] && log "Error: '${@}' is not in the password store" && exit 1 + + # Parse pass output into appropriate variables + local passfile="$(pass ${@})" + local username=$(echo -e "${passfile}" | sed -n 's/username: \(.*\)/\1/p' | head -n 1) + local pass=$(echo -e "${passfile}" | head -n 1) + + # Type the password + xdotool type --delay 15 "${username} ${pass}" +} -username=$(pass ${@} | sed -n 's/username: \(.*\)/\1/p' | head -n 1) -pass=$(pass ${@} | head -n 1) -xdotool type --delay 15 "${username} ${pass}" +main ${@} |