diff options
author | Soren Hansen <soren@ubuntu.com> | 2008-10-10 19:25:14 +0100 |
---|---|---|
committer | Bazaar Package Importer <jamesw@ubuntu.com> | 2008-10-10 19:25:14 +0100 |
commit | d61ffd7fb8434e76d2be555de834420232d2006e (patch) | |
tree | 30dbfd125417c96a30f31239440fc05ecbf45ee1 | |
download | vyos-cloud-init-d61ffd7fb8434e76d2be555de834420232d2006e.tar.gz vyos-cloud-init-d61ffd7fb8434e76d2be555de834420232d2006e.zip |
Initial release (LP: #269434).
-rw-r--r-- | .bzr-builddeb/default.conf | 2 | ||||
-rw-r--r-- | debian/changelog | 6 | ||||
-rw-r--r-- | debian/compat | 1 | ||||
-rw-r--r-- | debian/control | 13 | ||||
-rw-r--r-- | debian/copyright | 27 | ||||
-rw-r--r-- | debian/init | 61 | ||||
-rw-r--r-- | debian/install | 1 | ||||
-rwxr-xr-x | debian/rules | 10 | ||||
-rwxr-xr-x | ec2-fetch-credentials.py | 43 | ||||
-rwxr-xr-x | ec2-run-user-data.py | 48 |
10 files changed, 212 insertions, 0 deletions
diff --git a/.bzr-builddeb/default.conf b/.bzr-builddeb/default.conf new file mode 100644 index 00000000..3a08d607 --- /dev/null +++ b/.bzr-builddeb/default.conf @@ -0,0 +1,2 @@ +[BUILDDEB] +native = True diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 00000000..7a90e732 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,6 @@ +ec2-init (0.1) intrepid; urgency=low + + * Initial release (LP: #269434). + + -- Soren Hansen <soren@ubuntu.com> Fri, 12 Sep 2008 15:30:32 +0200 + diff --git a/debian/compat b/debian/compat new file mode 100644 index 00000000..7ed6ff82 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +5 diff --git a/debian/control b/debian/control new file mode 100644 index 00000000..c579e89e --- /dev/null +++ b/debian/control @@ -0,0 +1,13 @@ +Source: ec2-init +Section: admin +Priority: extra +Maintainer: Soren Hansen <soren@ubuntu.com> +Build-Depends: cdbs, debhelper (>= 5) +Standards-Version: 3.8.0 + +Package: ec2-init +Architecture: all +Depends: python, procps +Description: Init scripts for EC2 instances + EC2 instances need special scripts to run during initialisation + to retrieve and install ssh keys and to let the user run various scripts. diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 00000000..d02e3598 --- /dev/null +++ b/debian/copyright @@ -0,0 +1,27 @@ +This package was debianized by Soren Hansen <soren@ubuntu.com> on +Thu, 04 Sep 2008 12:49:15 +0200. + +Upstream Author: + + Soren Hansen <soren@canonical.com> + +Copyright: + + Copyright 2008 Canonical Ltd. + +License: + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + +The complete text of the GPL version 3 can be seen in /usr/share/common-licenses/GPL. diff --git a/debian/init b/debian/init new file mode 100644 index 00000000..d084c568 --- /dev/null +++ b/debian/init @@ -0,0 +1,61 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: ec2-init +# Required-Start: $network $local_fs +# Required-Stop: +# Should-Start: $named +# Should-Stop: +# Default-Start: S +# Default-Stop: 1 +# Short-Description: Initialises system for use on Amazon EC2 +# Description: Fetches login credentials and handles various quirks +### END INIT INFO + +PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin +NAME=ec2-init + +. /lib/lsb/init-functions + +case "$1" in + start) + log_daemon_msg "Running EC2 user data" + if ec2-run-user-data 2> /dev/null + then + log_end_msg 0 + else + log_end_msg 1 + fi + + log_daemon_msg "Fetching EC2 login credentials" + if ec2-fetch-credentials 2> /dev/null + then + log_end_msg 0 + else + log_end_msg 1 + fi + + if pgrep nash-hotplug > /dev/null + then + log_daemon_msg "Killing nash-hotplug" + if pkill nash-hotplug; + then + log_end_msg 0 + else + log_end_msg 1 + fi + fi + ;; + stop) + exit 0 + ;; + restart|force-reload) + exec $0 start + ;; + *) + N=/etc/init.d/$NAME + echo "Usage: $N {start|stop|force-stop|restart|force-reload|status}" >&2 + exit 1 + ;; +esac + +exit 0 diff --git a/debian/install b/debian/install new file mode 100644 index 00000000..54a21487 --- /dev/null +++ b/debian/install @@ -0,0 +1 @@ +debian/tmp/usr/sbin/* diff --git a/debian/rules b/debian/rules new file mode 100755 index 00000000..8c9f1074 --- /dev/null +++ b/debian/rules @@ -0,0 +1,10 @@ +#!/usr/bin/make -f + +include /usr/share/cdbs/1/rules/debhelper.mk + +DEB_UPDATE_RCD_PARAMS:=start 90 S . + +build/ec2-init:: + install -d debian/tmp/usr/sbin + install -m 775 ec2-fetch-credentials.py debian/tmp/usr/sbin/ec2-fetch-credentials + install -m 775 ec2-run-user-data.py debian/tmp/usr/sbin/ec2-run-user-data diff --git a/ec2-fetch-credentials.py b/ec2-fetch-credentials.py new file mode 100755 index 00000000..80980924 --- /dev/null +++ b/ec2-fetch-credentials.py @@ -0,0 +1,43 @@ +#!/usr/bin/python +# +# Fetch login credentials for EC2 +# Copyright 2008 Canonical Ltd. +# +# Author: Soren Hansen <soren@canonical.com> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +import urllib +import os + +api_ver = '2008-02-01' +metadata = None + +def get_ssh_keys(): + base_url = 'http://169.254.169.254/%s/meta-data' % api_ver + data = urllib.urlopen('%s/public-keys/' % base_url).read() + keyids = [line.split('=')[0] for line in data.split('\n')] + return [urllib.urlopen('%s/public-keys/%d/openssh-key' % (base_url, int(keyid))).read().rstrip() for keyid in keyids] + +keys = get_ssh_keys() + +os.umask(077) + +if not os.path.exists('/root/.ssh'): + os.mkdir('/root/.ssh') + +fp = open('/root/.ssh/authorized_keys', 'a') +fp.write(''.join(['%s\n' % key for key in keys])) +fp.close() + diff --git a/ec2-run-user-data.py b/ec2-run-user-data.py new file mode 100755 index 00000000..6638ef37 --- /dev/null +++ b/ec2-run-user-data.py @@ -0,0 +1,48 @@ +#!/usr/bin/python +# +# Fetch and run user-data from EC2 +# Copyright 2008 Canonical Ltd. +# +# Author: Soren Hansen <soren@canonical.com> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +import os +import sys +import tempfile +import urllib + +api_ver = '2008-02-01' +metadata = None + +def get_user_data(): + url = 'http://169.254.169.254/%s/user-data' % api_ver + fp = urllib.urlopen(url) + data = fp.read() + fp.close() + return data + +user_data = get_user_data() + +if user_data.startswith('#!'): + (fp, path) = tempfile.mkstemp() + fp.write(data) + fp.close() + os.chmod(path, 0700) + status = os.system('%s' % path) + os.unlink(path) + sys.exit(os.WIFEXITSTATUS(status)) + +sys.exit(0) |