summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChuck Short <zulcss@ubuntu.com>2009-03-05 16:09:38 +0000
committerBazaar Package Importer <jamesw@ubuntu.com>2009-03-05 16:09:38 +0000
commit79741c046d91b3e28e7129a5e93f56579f34a4f7 (patch)
tree31824cd5b9112f731a75b9ca990f6ab1b4557e91
parentc48c7e5366083028d59ef1cb7c1f4107e410eb35 (diff)
downloadcloud-init-git-79741c046d91b3e28e7129a5e93f56579f34a4f7.tar.gz
* ec2-fetch-credentials.py:ubuntu-0.3.3ubuntu4
- Allow user to choose which user they wish to configure for. - Allow user to disable root user if they wish to. * ec2-set-defaults.py: - Set default timezone to UTC. - Set locale depending on zone. * debian/init: - Removed nash plugin. - Add ec2-set-defaults.
-rw-r--r--.ec2-fetch-credentials.py.swpbin0 -> 12288 bytes
-rw-r--r--debian/changelog32
-rw-r--r--debian/ec2-config.cfg2
-rw-r--r--debian/init20
-rwxr-xr-xec2-fetch-credentials.py47
-rwxr-xr-xec2-run-user-data.py8
-rwxr-xr-xec2-set-defaults.py51
7 files changed, 125 insertions, 35 deletions
diff --git a/.ec2-fetch-credentials.py.swp b/.ec2-fetch-credentials.py.swp
new file mode 100644
index 00000000..52a749de
--- /dev/null
+++ b/.ec2-fetch-credentials.py.swp
Binary files differ
diff --git a/debian/changelog b/debian/changelog
index 1a80137f..7f8f947f 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,9 +1,37 @@
+ec2-init (0.3.3ubuntu4) jaunty; urgency=low
+
+ * ec2-fetch-credentials.py:
+ - Allow user to choose which user they wish to configure for.
+ - Allow user to disable root user if they wish to.
+ * ec2-set-defaults.py:
+ - Set default timezone to UTC.
+ - Set locale depending on zone.
+ * debian/init:
+ - Removed nash plugin.
+ - Add ec2-set-defaults.
+
+ -- Chuck Short <zulcss@ubuntu.com> Wed, 04 Mar 2009 08:33:01 -0500
+
+ec2-init (0.3.3ubuntu3~intrepid4) intrepid; urgency=low
+
+ * set distro to intrepid.
+
+ -- Chuck Short <zulcss@ubuntu.com> Thu, 26 Feb 2009 10:28:06 -0500
+
+ec2-init (0.3.3ubuntu3) jaunty; urgency=low
+
+ * debian/ec2-init: Log results of ec2-run-user-data to syslog.
+ * ec2-run-user-data.py :Dont leave files around and log the
+ output to syslog.
+
+ -- Chuck Short <zulcss@ubuntu.com> Thu, 26 Feb 2009 10:24:35 -0500
+
ec2-init (0.3.3ubuntu2) jaunty; urgency=low
- * debian/ec2-set-apt-sources.py:
+ * ec2-set-apt-sources.py:
- Use the ec2 mirrors. (LP: #317065, #333897)
- Update the /etc/apt/sources.list (LP: #333904)
- * debian/ec2-fetch-credentials.py:
+ * ec2-fetch-credentials.py:
- Better error checking (LP: #325067)
-- Chuck Short <zulcss@ubuntu.com> Tue, 24 Feb 2009 14:02:37 -0500
diff --git a/debian/ec2-config.cfg b/debian/ec2-config.cfg
index aa6757e2..4af39f0c 100644
--- a/debian/ec2-config.cfg
+++ b/debian/ec2-config.cfg
@@ -1,2 +1,2 @@
user="ubuntu"
-distro="jaunty"
+distro="intrepid"
diff --git a/debian/init b/debian/init
index 59fe686b..ea4f0acf 100644
--- a/debian/init
+++ b/debian/init
@@ -22,6 +22,14 @@ fi
case "$1" in
start)
+ log_daemon_msg "Setting EC2 defaults"
+ if ec2-set-defaults 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
@@ -31,23 +39,13 @@ case "$1" in
fi
log_daemon_msg "Running EC2 user data"
- if ec2-run-user-data 2>&1 | tee /var/log/ec2-user-data.log
+ if ec2-run-user-data 2>&1 | logger -t "user-data"
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
log_daemon_msg "Setting hostname to EC2 public_hostname"
if ec2-set-hostname 2> /dev/null
then
diff --git a/ec2-fetch-credentials.py b/ec2-fetch-credentials.py
index e8216ec4..33b4fb02 100755
--- a/ec2-fetch-credentials.py
+++ b/ec2-fetch-credentials.py
@@ -20,9 +20,15 @@
#
import urllib
import os
+from configobj import ConfigObj
api_ver = '2008-02-01'
metadata = None
+filename='/etc/ec2-init/ec2-config.cfg'
+
+config = ConfigObj(filename)
+user = config['user']
+config_root = config['DISABLE_ROOT']
def get_ssh_keys():
base_url = 'http://169.254.169.254/%s/meta-data' % api_ver
@@ -30,23 +36,32 @@ def get_ssh_keys():
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)
+def setup_user_keys(k,user):
+ if not os.path.exists('/home/%s/.ssh' %(user)):
+ os.mkdir('/home/%s/.ssh' %(user))
-if not os.path.exists('/home/ubuntu/.ssh'):
- os.mkdir('/home/ubuntu/.ssh')
+ authorized_keys = '/home/%s/.ssh/authorized_keys' % user
+ fp = open(authorized_keys, 'a')
+ fp.write(''.join(['%s\n' % key for key in keys]))
+ fp.close()
+ os.system('chown -R %s:%s /home/%s/.ssh' %(user,user,user))
-if not os.path.exists('/root/.ssh'):
- os.mkdir('/root/.ssh')
+def setup_root_user(k,root_config):
+ if root_config == "1":
+ fp = open('/root/.ssh/authorized_keys', 'a')
+ fp.write("command=\"echo \'Please ssh to the ubuntu user on this host instead of root\';echo;sleep 10\" ")
+ fp.write(''.join(['%s\n' % key for key in keys]))
+ fp.close()
+ elif root_config == "0":
+ print "You choose to disable the root user, god help you."
+ else:
+ print "%s - I dont understand that opion."
-fp = open('/home/ubuntu/.ssh/authorized_keys', 'a')
-fp.write(''.join(['%s\n' % key for key in keys]))
-fp.close()
-
-os.system('chown -R ubuntu:ubuntu /home/ubuntu/.ssh')
+os.umask(077)
+if user == "":
+ print "User must exist in %s" %(filename)
+ sys.exit(0)
-fp = open('/root/.ssh/authorized_keys', 'a')
-fp.write("command=\"echo \'Please ssh to the ubuntu user on this host instead of root\';echo;sleep 10\" ")
-fp.write(''.join(['%s\n' % key for key in keys]))
-fp.close()
+keys = get_ssh_keys()
+setup_user_keys(keys,user)
+setup_root_user(keys,config_root)
diff --git a/ec2-run-user-data.py b/ec2-run-user-data.py
index 63820bed..56e5e538 100755
--- a/ec2-run-user-data.py
+++ b/ec2-run-user-data.py
@@ -47,16 +47,14 @@ filename = '/var/ec2/.already-ran.%s' % amiId
if os.path.exists(filename):
print "ec2-run-user-data already ran for this instance."
sys.exit(0)
-else:
- if user_data.startswith('#!'):
+elif user_data.startswith('#!'):
# run it
(fp, path) = tempfile.mkstemp()
os.write(fp,user_data)
os.close(fp);
os.chmod(path, 0700)
- os.system('cp %s /var/ec2/user-data' %(path))
- status = os.system('%s' % path)
+ status = os.system('%s | logger -t "user-data" ' % path)
os.unlink(path)
- os.system('touch /var/ec2/$s' %(filename))
+ os.system('touch %s' %(filename))
sys.exit(0)
diff --git a/ec2-set-defaults.py b/ec2-set-defaults.py
new file mode 100755
index 00000000..129c46db
--- /dev/null
+++ b/ec2-set-defaults.py
@@ -0,0 +1,51 @@
+#!/usr/bin/python
+#
+# Fetch the availabity zone and create the sources.list
+# Copyright 2009 Canonical Ltd.
+#
+# Author: Chuck Short <chuck.short@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
+filename='/etc/ec2-init/ec2-config.cfg'
+
+base_url = 'http://169.254.169.254/%s/meta-data' % api_ver
+zone = urllib.urlopen('%s/placement/availability-zone' % base_url).read()
+
+if zone.startswith("us"):
+ archive = "http://us.ec2.archive.ubuntu.com/ubuntu"
+elif zone.startswith("eu"):
+ archive = "http://eu.ec2.archive.ubuntu.com/ubuntu"
+
+def set_utc_clock():
+ os.system('ln -s -f /usr/share/zoneinfo/UTC /etc/localime')
+
+def set_language(location):
+ if location.startswith("us"):
+ lang='en_US.UTF-8'
+ os.system('locale-gen %s' %(lang))
+ os.system('update-locale %s' %(lang))
+ elif location.startswith("eu"):
+ lang='en_GB.UTF-8'
+ os.system('locale-gen %s' %(lang))
+ os.system('update-locale %s' %(lang))
+
+set_utc_clock()
+set_language(zone)