| 1 |
#!/usr/bin/env bash |
| 2 |
|
| 3 |
# Sample wrapper program for simplying the use of keyringer. |
| 4 |
# This wrapper assumes you are using one key file with many |
| 5 |
# stored secrets. It helps users find keys and appends new |
| 6 |
# keys in a standard format. |
| 7 |
# |
| 8 |
# You can copy this program into your bin directory and then |
| 9 |
# modify as needed. |
| 10 |
# |
| 11 |
# Usage |
| 12 |
# Search for a matching secret in your key file: |
| 13 |
# pass <search-string> |
| 14 |
# |
| 15 |
# Add a new secret to your key file, responding to prompts: |
| 16 |
# pass |
| 17 |
|
| 18 |
# modify these variables |
| 19 |
keyring=mfpl |
| 20 |
file=mfpl.asc |
| 21 |
remote_git_repo=mfpl |
| 22 |
remote_git_branch=master |
| 23 |
|
| 24 |
if [ -z "$1" ]; then |
| 25 |
echo |
| 26 |
echo "Adding a new secret. You will need to enter your passphrase" |
| 27 |
echo "twice. Once to decrypt, and again to re-encrypt." |
| 28 |
echo |
| 29 |
# collect variables |
| 30 |
read -p "Host/Description: " |
| 31 |
host="$REPLY" |
| 32 |
read -p "User: " |
| 33 |
user="$REPLY" |
| 34 |
default_password=$(pwgen -s 15 1) |
| 35 |
read -p "Password [$default_password]: " |
| 36 |
pass="$REPLY" |
| 37 |
[ -z "$pass" ] && pass="$default_password" |
| 38 |
echo "$host : $user : $pass" | keyringer "$keyring" append-batch "$file" |
| 39 |
read -p "Commit changes? [Yn] " |
| 40 |
if [ "$REPLY" = "y" ] || [ "$REPLY" = "Y" ] || [ -z "$REPLY" ]; then |
| 41 |
keyringer "$keyring" git commit "keys/$file" |
| 42 |
keyringer "$keyring" git push "$remote_git_repo" "$remote_git_branch" |
| 43 |
else |
| 44 |
echo "Not committing changes." |
| 45 |
fi |
| 46 |
|
| 47 |
else |
| 48 |
keyringer "$keyring" decrypt "$file" | egrep -i "$1" |
| 49 |
fi |
| 50 |
echo |