diff --git a/ubuntu-14.04-x86_64/.gitignore b/ubuntu-14.04-x86_64/.gitignore new file mode 100644 index 0000000..5c01878 --- /dev/null +++ b/ubuntu-14.04-x86_64/.gitignore @@ -0,0 +1,3 @@ +packer_cache +*.iso +*.box diff --git a/ubuntu-14.04-x86_64/bare_metal.json b/ubuntu-14.04-x86_64/bare_metal.json new file mode 100644 index 0000000..a69d04b --- /dev/null +++ b/ubuntu-14.04-x86_64/bare_metal.json @@ -0,0 +1,95 @@ +{ + "provisioners": [ + { + "type": "shell", + "scripts": [ + "scripts/base.sh" + ], + "override": { + "virtualbox": { + "execute_command": "echo 'vagrant'|sudo -S bash '{{.Path}}'" + }, + "vmware": { + "execute_command": "echo 'vagrant'|sudo -S bash '{{.Path}}'" + } + } + } + ], + "builders": [ + { + "type": "virtualbox", + "boot_command": [ + "", + "/install/vmlinuz noapic preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg ", + "debian-installer=en_US auto locale=en_US kbd-chooser/method=us ", + "hostname={{ .Name }} ", + "fb=false debconf/frontend=noninteractive ", + "keyboard-configuration/modelcode=SKIP keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false ", + "initrd=/install/initrd.gz -- " + ], + "boot_wait": "4s", + "disk_size": 20480, + "guest_os_type": "Ubuntu_64", + "http_directory": "http", + "iso_checksum": "00a6e0bc6995e703170d940a24e9759c", + "iso_checksum_type": "md5", + "iso_url": "file:///Users/shrink/trusty-server-amd64.iso", + "ssh_username": "vagrant", + "ssh_password": "vagrant", + "ssh_port": 22, + "ssh_wait_timeout": "10000s", + "shutdown_command": "sudo halt -p", + "guest_additions_path": "/tmp/VBoxGuestAdditions.iso", + "guest_additions_url": "/Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso", + "virtualbox_version_file": ".vbox_version", + "vboxmanage": [ + [ + "modifyvm", "{{.Name}}", + "--memory", "512" + ], + [ + "modifyvm", "{{.Name}}", + "--cpus", "2" + ] + ] + }, + { + "type": "vmware", + "boot_command": [ + "", + "/install/vmlinuz noapic preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg ", + "debian-installer=en_US auto locale=en_US kbd-chooser/method=us ", + "hostname={{ .Name }} ", + "fb=false debconf/frontend=noninteractive ", + "keyboard-configuration/modelcode=SKIP keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false ", + "initrd=/install/initrd.gz -- " + ], + "boot_wait": "4s", + "disk_size": 20480, + "guest_os_type": "ubuntu-64", + "http_directory": "http", + "iso_checksum": "de8bb52bb9c5fd9220429499f302c0a3", + "iso_checksum_type": "md5", + "iso_url": "file:///Users/shrink/trusty-server-amd64.iso", + "ssh_username": "vagrant", + "ssh_password": "vagrant", + "ssh_port": 22, + "ssh_wait_timeout": "10000s", + "shutdown_command": "sudo halt -p", + "tools_upload_flavor": "linux", + "tools_upload_path": "/tmp/vmware-tools.iso", + "vmx_data": { + "memsize": "2048", + "numvcpus": "2" + } + } + ] + + , "post-processors": [ + { + "type": "vagrant", + "output": "packer-ubuntu1404_x86_64.{{.Provider}}.box", + "keep_input_artifact": true + } + ] +} diff --git a/ubuntu-14.04-x86_64/full.json b/ubuntu-14.04-x86_64/full.json new file mode 100644 index 0000000..c570dba --- /dev/null +++ b/ubuntu-14.04-x86_64/full.json @@ -0,0 +1,102 @@ +{ + "provisioners": [ + { + "type": "shell", + "scripts": [ + "scripts/base.sh", + "scripts/vagrant.sh", + "scripts/vmware.sh", + "scripts/virtualbox.sh", + "scripts/ruby.sh", + "scripts/puppet.sh", + "scripts/cleanup.sh", + "scripts/zerodisk.sh" + ], + "override": { + "virtualbox-iso": { + "execute_command": "echo 'vagrant'|sudo -S bash '{{.Path}}'" + }, + "vmware-iso": { + "execute_command": "echo 'vagrant'|sudo -S bash '{{.Path}}'" + } + } + } + ], + "builders": [ + { + "type": "virtualbox-iso", + "boot_command": [ + "", + "/install/vmlinuz noapic preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg ", + "debian-installer=en_US auto locale=en_US kbd-chooser/method=us ", + "hostname={{ .Name }} ", + "fb=false debconf/frontend=noninteractive ", + "keyboard-configuration/modelcode=SKIP keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false ", + "initrd=/install/initrd.gz -- " + ], + "boot_wait": "4s", + "disk_size": 20480, + "guest_os_type": "Ubuntu_64", + "http_directory": "http", + "iso_checksum": "00a6e0bc6995e703170d940a24e9759c", + "iso_checksum_type": "md5", + "iso_url": "file:///Users/shrink/trusty-server-amd64.iso", + "ssh_username": "vagrant", + "ssh_password": "vagrant", + "ssh_port": 22, + "ssh_wait_timeout": "10000s", + "shutdown_command": "sudo halt -p", + "guest_additions_path": "/tmp/VBoxGuestAdditions.iso", + "guest_additions_url": "/Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso", + "virtualbox_version_file": ".vbox_version", + "vboxmanage": [ + [ + "modifyvm", "{{.Name}}", + "--memory", "512" + ], + [ + "modifyvm", "{{.Name}}", + "--cpus", "2" + ] + ] + }, + { + "type": "vmware-iso", + "boot_command": [ + "", + "/install/vmlinuz noapic preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg ", + "debian-installer=en_US auto locale=en_US kbd-chooser/method=us ", + "hostname={{ .Name }} ", + "fb=false debconf/frontend=noninteractive ", + "keyboard-configuration/modelcode=SKIP keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false ", + "initrd=/install/initrd.gz -- " + ], + "boot_wait": "4s", + "disk_size": 20480, + "guest_os_type": "ubuntu-64", + "http_directory": "http", + "iso_checksum": "de8bb52bb9c5fd9220429499f302c0a3", + "iso_checksum_type": "md5", + "iso_url": "file:///Users/shrink/trusty-server-amd64.iso", + "ssh_username": "vagrant", + "ssh_password": "vagrant", + "ssh_port": 22, + "ssh_wait_timeout": "10000s", + "shutdown_command": "sudo halt -p", + "tools_upload_flavor": "linux", + "tools_upload_path": "/tmp/vmware-tools.iso", + "vmx_data": { + "memsize": "2048", + "numvcpus": "2" + } + } + ] + + , "post-processors": [ + { + "type": "vagrant", + "output": "packer-ubuntu1404_x86_64.{{.Provider}}.box", + "keep_input_artifact": true + } + ] +} diff --git a/ubuntu-14.04-x86_64/http/preseed.cfg b/ubuntu-14.04-x86_64/http/preseed.cfg new file mode 100644 index 0000000..863c9c4 --- /dev/null +++ b/ubuntu-14.04-x86_64/http/preseed.cfg @@ -0,0 +1,87 @@ +## Options to set on the command line +d-i debian-installer/locale string en_US.utf8 +d-i console-setup/ask_detect boolean false +d-i console-setup/layout string USA + +#d-i netcfg/get_hostname string dummy +d-i netcfg/get_hostname string unassigned-hostname +d-i netcfg/get_domain string unassigned-domain + +# Continue without a default route +# Not working , specify a dummy in the DHCP +#d-i netcfg/no_default_route boolean + +d-i time/zone string UTC +d-i clock-setup/utc-auto boolean true +d-i clock-setup/utc boolean true + +d-i kbd-chooser/method select American English + +d-i netcfg/wireless_wep string + +d-i base-installer/kernel/override-image string linux-server +#d-i base-installer/kernel/override-image string linux-image-2.6.32-21-generic + +# Choices: Dialog, Readline, Gnome, Kde, Editor, Noninteractive +d-i debconf debconf/frontend select Noninteractive + +d-i pkgsel/install-language-support boolean false +tasksel tasksel/first multiselect standard, ubuntu-server + +#d-i partman-auto/method string regular +d-i partman-auto/method string lvm +#d-i partman-auto/purge_lvm_from_device boolean true + +d-i partman-lvm/confirm boolean true +d-i partman-lvm/device_remove_lvm boolean true +d-i partman-auto/choose_recipe select atomic + +d-i partman/confirm_write_new_label boolean true +d-i partman/confirm_nooverwrite boolean true +d-i partman/choose_partition select finish +d-i partman/confirm boolean true + +#http://ubuntu-virginia.ubuntuforums.org/showthread.php?p=9626883 +#Message: "write the changes to disk and configure lvm preseed" +#http://serverfault.com/questions/189328/ubuntu-kickstart-installation-using-lvm-waits-for-input +#preseed partman-lvm/confirm_nooverwrite boolean true + +# Write the changes to disks and configure LVM? +d-i partman-lvm/confirm boolean true +d-i partman-lvm/confirm_nooverwrite boolean true +d-i partman-auto-lvm/guided_size string max + +## Default user, we can get away with a recipe to change this +d-i passwd/user-fullname string vagrant +d-i passwd/username string vagrant +d-i passwd/user-password password vagrant +d-i passwd/user-password-again password vagrant +d-i user-setup/encrypt-home boolean false +d-i user-setup/allow-password-weak boolean true + +## minimum is puppet and ssh and ntp +# Individual additional packages to install +d-i pkgsel/include string openssh-server ntp nfs-common build-essential autoconf zlib1g-dev libssl-dev libreadline-gplv2-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev vim curl wget bzip2 make man perl sudo + +# Whether to upgrade packages after debootstrap. +# Allowed values: none, safe-upgrade, full-upgrade +d-i pkgsel/upgrade select full-upgrade + +d-i grub-installer/only_debian boolean true +d-i grub-installer/with_other_os boolean true +d-i finish-install/reboot_in_progress note + +#For the update +d-i pkgsel/update-policy select none + +# debconf-get-selections --install +#Use mirror +#d-i apt-setup/use_mirror boolean true +#d-i mirror/country string manual +#choose-mirror-bin mirror/protocol string http +#choose-mirror-bin mirror/http/hostname string 192.168.4.150 +#choose-mirror-bin mirror/http/directory string /ubuntu +#choose-mirror-bin mirror/suite select maverick +#d-i debian-installer/allow_unauthenticated string true + +choose-mirror-bin mirror/http/proxy string diff --git a/ubuntu-14.04-x86_64/scripts/base.sh b/ubuntu-14.04-x86_64/scripts/base.sh new file mode 100644 index 0000000..8fbb025 --- /dev/null +++ b/ubuntu-14.04-x86_64/scripts/base.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +apt-get -y install linux-headers-`uname -r` + +# Setup sudoers for user vagrant +cat > /tmp/sudoers_vagrant <> /etc/ssh/sshd_config diff --git a/ubuntu-14.04-x86_64/scripts/chef.sh b/ubuntu-14.04-x86_64/scripts/chef.sh new file mode 100644 index 0000000..5b41883 --- /dev/null +++ b/ubuntu-14.04-x86_64/scripts/chef.sh @@ -0,0 +1,2 @@ + +curl -L https://www.opscode.com/chef/install.sh | bash -s -- -v "11.6.0" diff --git a/ubuntu-14.04-x86_64/scripts/cleanup.sh b/ubuntu-14.04-x86_64/scripts/cleanup.sh new file mode 100644 index 0000000..7ae22bd --- /dev/null +++ b/ubuntu-14.04-x86_64/scripts/cleanup.sh @@ -0,0 +1,18 @@ +# Remove items used for building, since they aren't needed anymore +# apt-get -y remove linux-headers-$(uname -r) build-essential +apt-get -y autoremove + +# Removing leftover leases and persistent rules +echo "cleaning up dhcp leases" +rm /var/lib/dhcp/* + +# Make sure Udev doesn't block our network +# http://6.ptmc.org/?p=164 +echo "cleaning up udev rules" +rm /etc/udev/rules.d/70-persistent-net.rules +mkdir /etc/udev/rules.d/70-persistent-net.rules +rm -rf /dev/.udev/ +rm /lib/udev/rules.d/75-persistent-net-generator.rules + +echo "Adding a 2 sec delay to the interface up, to make the dhclient happy" +echo "pre-up sleep 2" >> /etc/network/interfaces diff --git a/ubuntu-14.04-x86_64/scripts/fixubuntu.sh b/ubuntu-14.04-x86_64/scripts/fixubuntu.sh new file mode 100644 index 0000000..fafe731 --- /dev/null +++ b/ubuntu-14.04-x86_64/scripts/fixubuntu.sh @@ -0,0 +1 @@ +curl -fsSL https://raw.github.com/micahflee/fixubuntu/master/fixubuntu.sh | bash diff --git a/ubuntu-14.04-x86_64/scripts/puppet.sh b/ubuntu-14.04-x86_64/scripts/puppet.sh new file mode 100644 index 0000000..a2ed084 --- /dev/null +++ b/ubuntu-14.04-x86_64/scripts/puppet.sh @@ -0,0 +1,4 @@ + +# install puppet (3.4.4) +apt-get update +apt-get -y install puppet diff --git a/ubuntu-14.04-x86_64/scripts/ruby.sh b/ubuntu-14.04-x86_64/scripts/ruby.sh new file mode 100644 index 0000000..e0dccd6 --- /dev/null +++ b/ubuntu-14.04-x86_64/scripts/ruby.sh @@ -0,0 +1,130 @@ +#!/usr/bin/env bash +# +# chruby script that installs ruby-install which then installs the lastest +# stable versions of Ruby, JRuby and Rubinius into /opt/rubies or ~/.rubies. +# +# !!! +# this is an altered version of +# https://raw.github.com/postmodern/chruby/master/scripts/setup.sh +# which does NOT install all ruby flavors, but MRI only +# also it is simplified to install in global space + +set -e + +# +# Constants +# +export PREFIX="${PREFIX:-/usr/local}" + +SRC_DIR="${SRC_DIR:-/usr/local/src}" + +# +# Functions +# +function log() { + if [[ -t 1 ]]; then + printf "%b>>>%b %b%s%b\n" "\x1b[1m\x1b[32m" "\x1b[0m" \ + "\x1b[1m\x1b[37m" "$1" "\x1b[0m" + else + printf ">>> %s\n" "$1" + fi +} + +function error() { + if [[ -t 1 ]]; then + printf "%b!!!%b %b%s%b\n" "\x1b[1m\x1b[31m" "\x1b[0m" \ + "\x1b[1m\x1b[37m" "$1" "\x1b[0m" >&2 + else + printf "!!! %s\n" "$1" >&2 + fi +} + +function warning() { + if [[ -t 1 ]]; then + printf "%b***%b %b%s%b\n" "\x1b[1m\x1b[33m" "\x1b[0m" \ + "\x1b[1m\x1b[37m" "$1" "\x1b[0m" >&2 + else + printf "*** %s\n" "$1" >&2 + fi +} + +# +# Pre Install +# +install -d "$SRC_DIR" +cd "$SRC_DIR" + + +# +# Install chruby +# +chruby_version="0.3.7" + +log "Downloading chruby ..." +wget -O "chruby-$chruby_version.tar.gz" https://github.com/postmodern/chruby/archive/v$chruby_version.tar.gz + +log "Extracting chruby $chruby_version ..." +tar -xzvf "chruby-$chruby_version.tar.gz" +cd "chruby-$chruby_version/" + +log "Installing chruby ..." +make install + +# +# Pre Install +# +install -d "$SRC_DIR" +cd "$SRC_DIR" + +# +# Install ruby-install (https://github.com/postmodern/ruby-install#readme) +# +ruby_install_version="0.3.0" + +log "Downloading ruby-install ..." +wget -O "ruby-install-$ruby_install_version.tar.gz" "https://github.com/postmodern/ruby-install/archive/v$ruby_install_version.tar.gz" + +log "Extracting ruby-install $ruby_install_version ..." +tar -xzf "ruby-install-$ruby_install_version.tar.gz" +cd "ruby-install-$ruby_install_version/" + +log "Installing ruby-install ..." +make install || (error "installing ruby-install failed"; exit 0) + +# +# Configuration +# +log "Configuring chruby ..." + +config="[ -n \"\$BASH_VERSION\" ] || [ -n \"\$ZSH_VERSION\" ] || return + +source $PREFIX/share/chruby/chruby.sh +source $PREFIX/share/chruby/auto.sh +" + +if [[ -d /etc/profile.d/ ]]; then + # Bash/Zsh + echo "$config" > /etc/profile.d/chruby.sh +else + warning "Could not determine where to add chruby configuration." + warning "Please add the following configuration where appropriate:" + echo + echo "$config" + echo +fi + +# +# Install rubies for vagrant +# +log "Installing MRI ruby 1.9.3 for vagrant ..." +sudo -u vagrant -i $PREFIX/bin/ruby-install ruby 1.9.3-p429 + +log "Installing bundler for vagrant ruby" +sudo -u vagrant -i $PREFIX/bin/chruby-exec ruby 1.9.3-p429 -- gem install bundler + + +# We need to reset $PREFIX so chruby looks for rubies in /opt/rubies, not $PREFIX/opt/rubies +log "Setup complete! Sourcing new config" +PREFIX= eval "$config" + +exit 0 diff --git a/ubuntu-14.04-x86_64/scripts/vagrant.sh b/ubuntu-14.04-x86_64/scripts/vagrant.sh new file mode 100644 index 0000000..dc5d6dc --- /dev/null +++ b/ubuntu-14.04-x86_64/scripts/vagrant.sh @@ -0,0 +1,11 @@ +# Vagrant specific +date > /etc/vagrant_box_build_time + +# Installing vagrant keys +mkdir -pm 700 /home/vagrant/.ssh +wget --no-check-certificate 'https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub' -O /home/vagrant/.ssh/authorized_keys +chmod 0600 /home/vagrant/.ssh/authorized_keys +chown -R vagrant /home/vagrant/.ssh + +# Customize the message of the day +echo 'Welcome to your Vagrant-built virtual machine.' > /etc/motd diff --git a/ubuntu-14.04-x86_64/scripts/virtualbox.sh b/ubuntu-14.04-x86_64/scripts/virtualbox.sh new file mode 100755 index 0000000..785b660 --- /dev/null +++ b/ubuntu-14.04-x86_64/scripts/virtualbox.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +# Bail if we are not running inside VirtualBox. +(lspci | grep -i virtualbox > /dev/null) || { + exit 0 +} + +if [ ! -f /tmp/VBoxGuestAdditions.iso ]; then + echo "VirtualBox Guest Additions iso file missing." + exit 1 +fi + +trap "umount /mnt/virtualbox; rm -rf /mnt/virtualbox /tmp/VBoxGuestAdditions.iso" EXIT + +# Installing the virtualbox guest additions +mkdir -p /mnt/virtualbox +mount -o loop /tmp/VBoxGuestAdditions.iso /mnt/virtualbox + +(sh /mnt/virtualbox/VBoxLinuxAdditions.run --nox11) || { + echo "VirtualBox Guest Additions Installer failed. This may be safely ignored..." >&2 +} diff --git a/ubuntu-14.04-x86_64/scripts/vmware.sh b/ubuntu-14.04-x86_64/scripts/vmware.sh new file mode 100644 index 0000000..8b31243 --- /dev/null +++ b/ubuntu-14.04-x86_64/scripts/vmware.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +# Bail if we are not running inside VMWare. +(lspci | grep -i vmware > /dev/null) || { + exit 0 +} + +if [ ! -f /tmp/vmware-tools.iso ]; then + echo "VMware Tools iso file missing." + exit 1 +fi + +trap "umount /mnt/vmware; rm -rf /mnt/vmware /tmp/vmware-tools.iso /tmp/vmware-tools-distrib" EXIT + +# Install the VMWare Tools from a linux ISO. +mkdir -p /mnt/vmware +mount -o loop /tmp/vmware-tools.iso /mnt/vmware + +cd /tmp +tar xzf /mnt/vmware/VMwareTools-*.tar.gz + +/tmp/vmware-tools-distrib/vmware-install.pl -d diff --git a/ubuntu-14.04-x86_64/scripts/zerodisk.sh b/ubuntu-14.04-x86_64/scripts/zerodisk.sh new file mode 100644 index 0000000..938075a --- /dev/null +++ b/ubuntu-14.04-x86_64/scripts/zerodisk.sh @@ -0,0 +1,3 @@ +# Zero out the free space to save space in the final image: +dd if=/dev/zero of=/EMPTY bs=1M +rm -f /EMPTY