2016-07-28 11:16:45 -04:00
|
|
|
#!/usr/bin/env bash
|
2015-07-16 19:53:12 -04:00
|
|
|
|
|
|
|
source $HOME/.config/rofi-pass/config
|
|
|
|
|
2015-08-21 12:54:12 -04:00
|
|
|
if [[ -n "$3" && "$2" == "--root" ]]; then
|
2015-07-16 19:53:12 -04:00
|
|
|
root="${2}"
|
2015-08-21 12:43:57 -04:00
|
|
|
elif [[ -n $root ]]; then
|
|
|
|
root=$root
|
|
|
|
elif [[ -n $PASSWORD_STORE_DIR ]]; then
|
|
|
|
root=$PASSWORD_STORE_DIR
|
2015-07-16 19:53:12 -04:00
|
|
|
else
|
2015-08-21 12:43:57 -04:00
|
|
|
root="$HOME/.password-store"
|
2015-07-16 19:53:12 -04:00
|
|
|
fi
|
|
|
|
|
2015-12-04 02:48:03 -05:00
|
|
|
if [[ $1 == "--help" || $1 == "-h" ]]; then
|
2015-07-16 21:38:48 -04:00
|
|
|
echo "add pass files for rofi-pass"
|
|
|
|
echo "(C) 2015 Rasmus Steinke <rasi at xssn dot at>"
|
|
|
|
echo ""
|
2015-08-21 12:54:12 -04:00
|
|
|
echo "--name \"foobar\" Mandatory first argument - filename of password file"
|
|
|
|
echo "--root \"foobar\" Optional second argument - Absolute path to password store"
|
2015-07-16 21:38:48 -04:00
|
|
|
echo ""
|
2015-08-21 12:54:12 -04:00
|
|
|
echo "+FIELD \"barbaz\" Every field name has to start with \"+\""
|
|
|
|
echo " Values should be quoted"
|
2015-07-16 21:38:48 -04:00
|
|
|
echo ""
|
|
|
|
echo "Example:"
|
2015-08-21 13:09:55 -04:00
|
|
|
echo "addpass --name \"my password file\" --root \"$HOME/passwords\" +user \"Richard\" +foo \"bar\" +autotype \"foo :tab user :tab pass\""
|
2015-07-16 21:38:48 -04:00
|
|
|
exit
|
|
|
|
else
|
2015-08-21 13:15:45 -04:00
|
|
|
echo "$1"
|
|
|
|
if [[ $1 != "--name" ]]; then
|
2015-08-21 12:54:12 -04:00
|
|
|
echo "Missing --name option. Try --help"
|
2015-07-16 21:38:48 -04:00
|
|
|
exit
|
2015-08-21 13:15:45 -04:00
|
|
|
elif [[ $1 == "--name" ]]; then
|
|
|
|
Name="$2"
|
2015-07-16 21:38:48 -04:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Using database \"$root\""
|
|
|
|
|
2015-07-16 19:53:12 -04:00
|
|
|
OIFS=$IFS;
|
2015-08-21 12:43:57 -04:00
|
|
|
IFS="+";
|
2015-07-16 19:53:12 -04:00
|
|
|
|
|
|
|
fields="$@";
|
|
|
|
fieldsArray=($fields);
|
2017-03-28 12:32:27 -04:00
|
|
|
pass="$(pwgen -sy 32 1)"
|
2015-07-16 19:53:12 -04:00
|
|
|
|
|
|
|
printEntry () {
|
|
|
|
echo -e "$pass\n---"
|
|
|
|
for ((i=1; i<${#fieldsArray[@]}; ++i)); do
|
|
|
|
field=$(echo "${fieldsArray[$i]}" | awk -F' ' '{print $1}')
|
|
|
|
option=$(echo "${fieldsArray[$i]}" | cut -d ' ' -f 2- | sed -e 's/[[:blank:]]\+$//')
|
2015-07-16 21:38:48 -04:00
|
|
|
echo "$field: $option" | grep -Ev 'name:|--root|root:|^:' #${fieldsArray[$i]}";
|
2015-07-16 19:53:12 -04:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2017-03-28 12:32:27 -04:00
|
|
|
printEntry | PASSWORD_STORE_DIR="${root}" pass insert -m "${Name}"
|