summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Ball <nullspoon@iohq.net>2016-07-05 08:07:59 -0600
committerAaron Ball <nullspoon@iohq.net>2016-07-05 08:07:59 -0600
commit9eab5b9fc1ede6f260b32c525b462bc398fdc0eb (patch)
treea58d16d5ea5b97d2e5ffd609b3983d21109f9ff1
parent26123b07a262a28ee33c495e72d5bfc4d2a7a6a8 (diff)
downloadbin-9eab5b9fc1ede6f260b32c525b462bc398fdc0eb.tar.gz
bin-9eab5b9fc1ede6f260b32c525b462bc398fdc0eb.tar.xz
Updated quicktype
Added log function that outputs to stdout, and a notification daemon if one is available. Added check_env function to ensure the tools are available to use this script. Moved main operating code into the new 'main' function.
-rwxr-xr-xquicktype71
1 files changed, 60 insertions, 11 deletions
diff --git a/quicktype b/quicktype
index b7872e2..bbbd491 100755
--- a/quicktype
+++ b/quicktype
@@ -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 ${@}

Generated by cgit