#!/bin/bash HOME_DIR="$HOME/Library/Passwords/" # gpg only GNUPG=1 GNUPG_FILE="$HOME/.pwm-gnupg" # help if [ -z "$*" ]; then echo "No arguments supplied. Usage:" echo "pwm list - list all services and accounts" echo "pwm example.com - list all accounts for service" echo "pwm example.com johndoe - decrypt and copy password to clipboard" exit fi # we want the gpg type if [ "$GNUPG" == "1" ]; then if [ ! -f "$GNUPG_FILE" ]; then echo "Enter GNUPG Mail: (e.g. johndoe@example.com):" read -s GNUPG_NAME echo "$GNUPG_NAME" >"$GNUPG_FILE" else GNUPG_NAME=$(cat "$GNUPG_FILE") fi fi # Create passwords dir if we don't exist if [ ! -d "$HOME_DIR" ]; then mkdir -p "$HOME_DIR" fi if [ $# == 1 ]; then # list password contents if [ $1 == "list" ]; then tree "$HOME_DIR" exit else echo "Available logins:" ls "$HOME_DIR/$1" exit fi fi # checking if a password exists if [ -f "$HOME_DIR/$1/$2" ]; then # put into the X clipboard if [ "$GNUPG" == "1" ]; then gpg --decrypt "$HOME_DIR/$1/$2" | xclip -selection c else cat "$HOME_DIR/$1/$2" | openssl aes-256-cbc -d -pbkdf2 -a | xclip -selection c fi else # encrypt this shiat printf "Password for $1 doesn't exist. Enter a NEW pass now:\n" read -s PASSPHRASE mkdir -p "$HOME_DIR/$1" if [ "$GNUPG" == "1" ]; then echo "$PASSPHRASE" | gpg --encrypt --armor -r "$GNUPG_NAME" > "$HOME_DIR/$1/$2" else echo "$PASSPHRASE" | openssl enc -aes256 -pbkdf2 -base64 > "$HOME_DIR/$1/$2" fi fi