2015-07-16 19:53:12 -04:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
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-07-16 21:38:48 -04:00
|
|
|
if [[ $1 == "--help" || $1 == "=h" ]]; then
|
|
|
|
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);
|
2015-07-16 21:38:48 -04:00
|
|
|
read -p "Enter password for entry \"${Name}\" > " -s pass
|
2015-07-16 19:53:12 -04:00
|
|
|
|
2015-08-21 12:43:57 -04:00
|
|
|
cd "${root}"
|
2015-07-16 19:53:12 -04:00
|
|
|
group=$(find -type d -not -iwholename '*.git*' -printf '%d\t%P\n' | sort -r -nk1 | cut -f2- | rofi -dmenu -p "Choose Group > ")
|
|
|
|
|
2015-07-16 21:38:48 -04:00
|
|
|
echo -e "\n\nStoring file ${Name} in group ${group}"
|
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
|
|
|
|
}
|
|
|
|
|
2015-08-21 13:09:55 -04:00
|
|
|
printEntry | PASSWORD_STORE_DIR="${root}" pass insert -m "${group}/${Name}"
|
2015-07-16 21:38:48 -04:00
|
|
|
|