The cirros image was rebuilt against the 3.13.0-83 kernel, drivers e1000e, igbvf...
[packages/trusty/cirros-testvm.git] / cirros-testvm / src-cirros / src / usr / bin / ssh-import-id
diff --git a/cirros-testvm/src-cirros/src/usr/bin/ssh-import-id b/cirros-testvm/src-cirros/src/usr/bin/ssh-import-id
new file mode 100755 (executable)
index 0000000..279b86f
--- /dev/null
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+burl="https://launchpad.net/~%s/+sshkeys"                                       
+
+Usage() {
+   cat <<EOF
+Usage: ${0##*/} user1 [ user2 [ ... ] ]
+   Import ssh keys for the user from http://launchpad.net
+EOF
+}
+[ $# -eq 0 ] && { Usage 1>&2; exit 1; }
+[ "$1" = "-h" -o "$1" == "--help" ] && { Usage; exit 0; }
+cd
+umask 066
+fail() { echo "$@" 1>&2; exit 1; }
+mkdir -m 755 -p .ssh  || { fail "failed to make .ssh dir" 1>&2; exit 1; }
+
+for u in "$@"; do
+       url=$(printf "$burl" "$u") &&
+               out=$(curl --silent - "$url") ||
+               fail "failed to get key for $u [$url]" 1>&2
+       # some keys come back with dos line end
+       out=$(echo "$out" | sed -e '/^$/d' -e '/^\r/d' \
+                       -e ':join /=[ ]/!{ N; s/[\n\r]//g ; b join }' \
+                        -e 's/[^a-zA-Z0-9@: .\/=+-]//g')
+       printf "%s\n" "$out" >> ".ssh/authorized_keys" ||
+               fail "failed to write to .ssh/authorized_keys"
+       echo "Successfully authorized [$u]"
+done
+
+# vi: ts=4 noexpandtab