Add ssh-keys example hook
[ext/instance-debootstrap.git] / examples / hooks / ssh-keys
diff --git a/examples/hooks/ssh-keys b/examples/hooks/ssh-keys
new file mode 100755 (executable)
index 0000000..667b721
--- /dev/null
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+if [ -z "$TARGET" -o ! -d "$TARGET" ]; then
+  echo "Missing target directory"
+  exit 1
+fi
+
+# user to give access to. can be hardcoded or fetched from some other place
+: ${USER:="myuser"}
+# keytype: rsa or dsa
+: ${KEYTYPE:="rsa"}
+
+if [ -f /home/$USER/.ssh/id_$KEYTYPE.pub ]; then
+  install -D -m 0700 -o root -g root \
+    /home/$USER/.ssh/id_$KEYTYPE.pub $TARGET/root/.ssh/authorized_keys
+fi
+
+exit 0