aboutsummaryrefslogtreecommitdiff
path: root/passwd
blob: 34f59872f1861f5b74e2ea6eca9deb21ff1688e2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env bash

cd $(dirname $0)

function usage {
	echo "Usage: $0 <cluster name> <username>"
	echo "The cluster name must be the name of a subdirectory of cluster/"
	exit 1
}

CLUSTER="$1"
if [ -z "$CLUSTER" ] || [ ! -d "cluster/$CLUSTER" ]; then
	usage
fi

USERNAME="$2"
if [ -z "$USERNAME" ]; then
	usage
fi

PREFIX="deuxfleurs/cluster/$CLUSTER"

EXISTING_PASSWORDS=$(mktemp)
pass $PREFIX/passwords | egrep -v "^$USERNAME:" > $EXISTING_PASSWORDS

echo "Enter new password for user $USERNAME:"
NEW_PASSWD=$(openssl passwd -6)

(cat $EXISTING_PASSWORDS; echo $USERNAME:$NEW_PASSWD) | pass insert -m $PREFIX/passwords

rm $EXISTING_PASSWORDS