Commit 5abc2b82 authored by Srikanth Raju's avatar Srikanth Raju Committed by Leigh B Stoller

Some error handling in export script

parent af9ed869
...@@ -3,18 +3,14 @@ ...@@ -3,18 +3,14 @@
class EmulabExport class EmulabExport
def finalize() def finalize()
system("rm -Rf ec2-ami-tools-") system("rm -Rf ec2-ami-tools- > /dev/null 2>&1")
system("rm") system("rm > /dev/null 2>&1")
end end
def create_image() def create_image()
raise 'Must run as root' unless Process.uid == 0
ObjectSpace.define_finalizer(self, self.method(:finalize))
raise "Failed fetching ec2-utils" unless raise "Failed fetching ec2-utils" unless
system("wget") system("wget")
raise "Failed untaring ec2-utils" unless raise "Failed unzippinging ec2-utils" unless
system("unzip") system("unzip")
$: << Dir.pwd + "/ec2-ami-tools-" $: << Dir.pwd + "/ec2-ami-tools-"
...@@ -22,53 +18,70 @@ class EmulabExport ...@@ -22,53 +18,70 @@ class EmulabExport
excludes = ['/tmp/image', '/dev', '/media', '/mnt', '/proc', '/sys', '/', '/proc/sys/fs/binfmt_misc', '/dev/pts'] excludes = ['/tmp/image', '/dev', '/media', '/mnt', '/proc', '/sys', '/', '/proc/sys/fs/binfmt_misc', '/dev/pts']
image ="/", image ="/",
"/tmp/image", "/tmp/image",
10* 1024, 10* 1024,
excludes, excludes,
[], [],
true, true,
nil, nil,
true) true)
image.make image.make
end end
def check_prereqs()
raise "No unzip found. Please install unzip" unless system("command -v fo >/dev/null 2>&1")
def get_kernel() def get_kernel()
version_crap = `uname -a` version = `uname -a`
version = version_crap.split[2] version = version.split[2]
if File.exists?("/boot/vmlinuz-" + version) if File.exists?("/boot/vmlinuz-" + version)
system("cp /boot/vmlinuz-" + version + " kernel") raise "Couldn't copy kernel" unless
system("cp /boot/vmlinuz-" + version + " kernel")
end end
if File.exists?("/boot/initramfs-" + version + ".img") if File.exists?("/boot/initramfs-" + version + ".img")
system("cp /boot/initramfs-" + version + ".img initrd") raise "Couldn't copy initramfs" unless
system("cp /boot/initramfs-" + version + ".img initrd")
end end
end end
def get_bootopts() def get_bootopts()
system("cat /proc/cmdline > bootopts") raise "Couldn't get bootopts" unless
system("cat /proc/cmdline > bootopts")
end end
def gen_tar() def gen_tar()
system("tar -cvzf emulab.tar.gz /tmp/image kernel initrd bootopts") raise "Couldn't tar" unless
system("tar -cvzf emulab.tar.gz kernel initrd bootopts -C /tmp/ image 2>&1")
end end
#TODO: Perhaps pull this from a specific emulab server, auto generate
def inject_pubkey() def inject_pubkey()
f ="~") + "/.ssh/authorized_keys", "a+") f ="~") + "/.ssh/authorized_keys", "a+")
f.write("ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAyHww/vuwQ4adLRzUCKdP5/DubwWJjg/YcGwumuHB24Y0u53KX0qd3oprntw0o/ngntlKXdmAuQ/9lb74Vqpoy0LFVU7adPhNRj1z6WbvRo4cwt5BUBxWlTLQFKs3118kATAkMSKFZbXs54y7GvyFWPTdrgfquEizSaKaPcT3Un0FjWobmK81B7etfSZaaD8fMyWuUHHKYq67ZKDJUc4URRHLMZR f.write("ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAyHww/vuwQ4adLRzUCKdP5/DubwWJjg/YcGwumuHB24Y0u53KX0qd3oprntw0o/ngntlKXdmAuQ/9lb74Vqpoy0LFVU7adPhNRj1z6WbvRo4cwt5BUBxWlTLQFKs3118kATAkMSKFZbXs54y7GvyFWPTdrgfquEizSaKaPcT3Un0FjWobmK81B7etfSZaaD8fMyWuUHHKYq67ZKDJUc4URRHLMZRIHk7wzbMBV0MEeR7y3se1vBKQDV4IzsTnQF4Mur0HBBc2Kif9oDFh8pykatslvSSjAc8J/t9Lp1RADxon3LHX7TFbvHEgAt0t9g8udOOtw4vB7t9l2VrgV5ZLuw==\n")
f.close f.close
end end
end end
if __FILE__ == $0 if __FILE__ == $0
raise 'Must run as root' unless Process.uid == 0
ex = ex =
ex.create_image begin
ex.get_kernel ex.check_prereqs
ex.get_bootopts ex.create_image
ex.gen_tar ex.get_kernel
ex.inject_pubkey ex.get_bootopts
rescue Exception => e
print "Error while creating an image: ", e, "\n"
end end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment