From fd611d3d1a2ab2f46791176e9e59bbde6a542f45 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 2 Mar 2013 16:49:55 -0300 Subject: [PATCH] A whole bunch of tweaks to ubuntu-cloud box --- boxes/ubuntu-cloud/metadata.json | 4 +- boxes/ubuntu-cloud/setup-vagrant-user.sh | 58 +++++++++++++++++++ .../{lxc-ubuntu-cloud => ubuntu-cloud} | 0 3 files changed, 60 insertions(+), 2 deletions(-) create mode 100755 boxes/ubuntu-cloud/setup-vagrant-user.sh rename boxes/ubuntu-cloud/{lxc-ubuntu-cloud => ubuntu-cloud} (100%) diff --git a/boxes/ubuntu-cloud/metadata.json b/boxes/ubuntu-cloud/metadata.json index 45d00b9..230f1f6 100644 --- a/boxes/ubuntu-cloud/metadata.json +++ b/boxes/ubuntu-cloud/metadata.json @@ -1,7 +1,7 @@ { "provider": "lxc", "vagrant-lxc-version": "0.0.1", - "template-name": "lxc-ubuntu-cloud", - "after-create-script": "set-vagrant-user.sh", + "template-name": "ubuntu-cloud", + "after-create-script": "setup-vagrant-user.sh", "tar-cache": "ubuntu-12.10-server-cloudimg-amd64-root.tar.gz" } diff --git a/boxes/ubuntu-cloud/setup-vagrant-user.sh b/boxes/ubuntu-cloud/setup-vagrant-user.sh new file mode 100755 index 0000000..a8f9897 --- /dev/null +++ b/boxes/ubuntu-cloud/setup-vagrant-user.sh @@ -0,0 +1,58 @@ +#!/bin/bash +# Argument = -r -i -k + +CONTAINER_ROOTFS= +CONTAINER_IP= +VAGRANT_PRIVATE_KEY_PATH= + +options=$(getopt -o r:i:k: -- "$@") +eval set -- "$options" + +declare r CONTAINER_ROOTFS \ + i CONTAINER_IP \ + k VAGRANT_PRIVATE_KEY_PATH + +while true +do + case "$1" in + -r) CONTAINER_ROOTFS=$2; shift 2;; + -i) CONTAINER_IP=$2; shift 2;; + -k) VAGRANT_PRIVATE_KEY_PATH=$2; shift 2;; + *) break ;; + esac +done + +if [[ -z $CONTAINER_ROOTFS ]] || [[ -z $CONTAINER_IP ]] || [[ -z $VAGRANT_PRIVATE_KEY_PATH ]] +then + echo 'You forgot an argument!' + exit 1 +fi + +remote_setup_script() { + cat << EOF +useradd -d /home/vagrant -m vagrant -r -s /bin/bash +usermod -a -G admin vagrant +cp /etc/sudoers /etc/sudoers.orig +sed -i -e '/Defaults\s\+env_reset/a Defaults\texempt_group=admin' /etc/sudoers +sed -i -e 's/%admin\s\+ALL=(ALL)\s\+ALL/%admin ALL=NOPASSWD:ALL/g' /etc/sudoers +service sudo restart +sudo su vagrant -c "mkdir -p /home/vagrant/.ssh" +sudo su vagrant -c "curl -s -o /home/vagrant/.ssh/authorized_keys https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub" +EOF +} + +REMOTE_SETUP_SCRIPT_PATH="/tmp/setup-vagrant-user" + +# Ensures the private key has the right permissions +# Might not be needed after: https://github.com/mitchellh/vagrant/commit/d304cca35d19c5bd370330c74f003b6ac46e7f4a +chmod 0600 $VAGRANT_PRIVATE_KEY_PATH + +remote_setup_script > "${CONTAINER_ROOTFS}${REMOTE_SETUP_SCRIPT_PATH}" +chmod +x "${CONTAINER_ROOTFS}${REMOTE_SETUP_SCRIPT_PATH}" + +ssh ubuntu@"$CONTAINER_IP" \ + -o 'StrictHostKeyChecking no' \ + -o 'UserKnownHostsFile /dev/null' \ + -i $VAGRANT_PRIVATE_KEY_PATH \ + -- \ + sudo $REMOTE_SETUP_SCRIPT_PATH diff --git a/boxes/ubuntu-cloud/lxc-ubuntu-cloud b/boxes/ubuntu-cloud/ubuntu-cloud similarity index 100% rename from boxes/ubuntu-cloud/lxc-ubuntu-cloud rename to boxes/ubuntu-cloud/ubuntu-cloud