aboutsummaryrefslogtreecommitdiff
path: root/passwd
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-04-20 15:41:54 +0200
committerAlex Auvolat <alex@adnab.me>2022-04-20 15:41:54 +0200
commit6c22f5fdfad8752006c2245b503313973766c31c (patch)
tree4eb8943999a88135adee687aa03fc06a4cf681cf /passwd
parent226fbabf655656f16ca883c8489a2360abdb8367 (diff)
downloadnixcfg-6c22f5fdfad8752006c2245b503313973766c31c.tar.gz
nixcfg-6c22f5fdfad8752006c2245b503313973766c31c.zip
Add scripts to manage passwords
Diffstat (limited to 'passwd')
-rwxr-xr-xpasswd30
1 files changed, 30 insertions, 0 deletions
diff --git a/passwd b/passwd
new file mode 100755
index 0000000..7cc80b6
--- /dev/null
+++ b/passwd
@@ -0,0 +1,30 @@
+#!/usr/bin/env sh
+
+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"
+
+if ! EXISTING_PASSWORDS=$(pass $PREFIX/passwords | egrep -v "^$USERNAME:"); then
+ EXISTING_PASSWORDS=""
+fi
+
+echo "Enter new password for user $USERNAME:"
+NEW_PASSWD=$(openssl passwd -6)
+
+(echo $EXISTING_PASSWORDS; echo $USERNAME:$NEW_PASSWD) | pass insert -m $PREFIX/passwords