diff options
author | V3n3RiX <venerix@redcorelinux.org> | 2017-10-09 18:53:29 +0100 |
---|---|---|
committer | V3n3RiX <venerix@redcorelinux.org> | 2017-10-09 18:53:29 +0100 |
commit | 4f2d7949f03e1c198bc888f2d05f421d35c57e21 (patch) | |
tree | ba5f07bf3f9d22d82e54a462313f5d244036c768 /app-admin/amazon-ec2-init/files |
reinit the tree, so we can have metadata
Diffstat (limited to 'app-admin/amazon-ec2-init/files')
-rw-r--r-- | app-admin/amazon-ec2-init/files/amazon-ec2.init | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/app-admin/amazon-ec2-init/files/amazon-ec2.init b/app-admin/amazon-ec2-init/files/amazon-ec2.init new file mode 100644 index 000000000000..29ce3aabd6a8 --- /dev/null +++ b/app-admin/amazon-ec2-init/files/amazon-ec2.init @@ -0,0 +1,34 @@ +#!/sbin/openrc-run +# Copyright 1999-2010 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +depend() { + before hostname + need net.eth0 +} + +start() { + einfo "Fetching metadata from EC2 servers" + + ebegin " hostname" + local hostname=$(wget -t 2 -T 5 -q -O - http://169.254.169.254/latest/meta-data/local-hostname) + echo "hostname=${hostname}" >> /etc/conf.d/hostname + eend $? + + ebegin " SSH keys" + + mkdir -p /root/.ssh + + local keys=$(wget -t 2 -T 5 -q -O - http://169.254.169.254/latest/meta-data/public-keys/ | cut -d = -f 1 | xargs echo) + [ -n "${keys}" ] && \ + wget -t 2 -T 5 -q -O - $(for key in $keys; do echo "http://169.254.169.254/latest/meta-data/public-keys/$key/openssh-key"; done) \ + >> /root/.ssh/authorized_keys \ + 2>/dev/null + + if [ -f /root/.ssh/authorized_keys ]; then + chown root:root /root/.ssh/authorized_keys + chmod 0600 /root/.ssh/authorized_keys + fi + + eend $? +} |