diff --git a/.rvmrc b/.rvmrc new file mode 100644 index 0000000..5cc9b05 --- /dev/null +++ b/.rvmrc @@ -0,0 +1,8 @@ +ruby_ver=ruby-1.9.2 +#gemset_name=vagrant +gemset_name=${gemset_name:-$(basename $(pwd))} + + +## The rest is auto... + +rvm_install_on_use_flag=1 rvm --create use ${ruby_ver}@${gemset_name:-$(basename $(pwd))} > /dev/null diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..96fb53b --- /dev/null +++ b/Gemfile @@ -0,0 +1,6 @@ +# A sample Gemfile +source "http://rubygems.org" + +# gem "rails" + +gem "vagrant" \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..06cb2f4 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,35 @@ +GEM + remote: http://rubygems.org/ + specs: + abstract (1.0.0) + archive-tar-minitar (0.5.2) + erubis (2.6.6) + abstract (>= 1.0.0) + ffi (0.6.3) + rake (>= 0.8.7) + i18n (0.5.0) + json (1.4.6) + mario (0.0.6) + net-scp (1.0.4) + net-ssh (>= 1.99.1) + net-ssh (2.1.0) + rake (0.8.7) + thor (0.14.6) + vagrant (0.7.1) + archive-tar-minitar (= 0.5.2) + erubis (~> 2.6.6) + i18n (~> 0.5.0) + json (~> 1.4.6) + mario (~> 0.0.6) + net-scp (~> 1.0.4) + net-ssh (~> 2.1.0) + thor (~> 0.14.6) + virtualbox (~> 0.8.3) + virtualbox (0.8.3) + ffi (~> 0.6.3) + +PLATFORMS + ruby + +DEPENDENCIES + vagrant diff --git a/build-iso b/build-iso index a4660d1..e694e15 100755 --- a/build-iso +++ b/build-iso @@ -8,7 +8,7 @@ for ARCH in $ARCHS do ORIG="ubuntu-$VERSION-$DISTRO-$ARCH.iso" COPY="ubuntu-$VERSION-$DISTRO-$ARCH" - ISO="devstructure-ubuntu-$VERSION-$DISTRO-$ARCH.iso" + ISO="${ISOPREFIX}-ubuntu-$VERSION-$DISTRO-$ARCH.iso" # Download the original ISO if it isn't present already. [ -f "$ORIG" ] || curl -L -o "$ORIG" \ @@ -19,13 +19,16 @@ do # Make a writable copy of the original ISO. This uses the `hdiutil` # command that is specific to Mac OS X. - hdiutil attach -mountpoint "mount" "$ORIG" - rsync -a "mount/" "$COPY" - hdiutil detach "mount" + mkdir -p isomount + sudo mount -o loop,user "${ORIG}" isomount + rsync -a "isomount/" "$COPY" + sudo umount isomount chmod -R +w "$COPY" # Customize the writable copy. - cp "isolinux.cfg" "$COPY/isolinux/" + m4 \ + -D __LABEL__="${LABEL}" \ + "isolinux.cfg.m4" > "$COPY/isolinux/isolinux.cfg" m4 \ -D __HOST__="$HOST" \ -D __DOMAIN__="$DOMAIN" \ @@ -34,22 +37,25 @@ do || echo server )" \ -D __ROOT_PASSWORD__="$ROOT_PASSWORD" \ - -D __USERNAME__="$USERNAME" \ + -D __USER_NAME__="$USER_NAME" \ -D __PASSWORD__="$PASSWORD" \ - "devstructure.seed.m4" >"$COPY/preseed/devstructure.seed" - cp "$PUBLIC_KEY" "setup.sh" "$COPY/" + -D __LABEL__="${LABEL}" \ + -D __NFS_COMPAT__="${NFS_COMPAT}" \ + -D __PROXY_URL__="${PROXY_URL}" \ + "default.seed.m4" >"$COPY/preseed/${LABEL}.seed" + + # cp "$PUBLIC_KEY" "setup.sh" "$COPY/" cp "$PUBLIC_KEY" "sudoers" "$COPY/" m4 \ - -D __USERNAME__="$USERNAME" \ + -D __USER_NAME__="$USER_NAME" \ -D __PUBLIC_KEY__="$PUBLIC_KEY" \ - "devstructure.sh.m4" >"$COPY/devstructure.sh" - + "default.sh.m4" >"$COPY/${LABEL}.sh" # Build a custom ISO. - mkisofs -r -V "Ubuntu $VERSION for DevStructure" \ + mkisofs -r -V "Ubuntu $VERSION for ${LABEL}" \ -cache-inodes -J -l -no-emul-boot \ -b isolinux/isolinux.bin \ -c isolinux/boot.cat \ -boot-load-size 4 -boot-info-table \ -o "$ISO" "$COPY" - + echo "Completed building custom iso for ${LABEL} [${ARCH}]" done diff --git a/build-pxe b/build-pxe new file mode 100755 index 0000000..1a56cb9 --- /dev/null +++ b/build-pxe @@ -0,0 +1,78 @@ +#!/bin/sh + +# PXE BOOT [WVVVVMIP] (Work Very Very Very Very Much in Progress!) +# New script to take the iso image and use it and the parameters defined in the config.sh to setup and use pxe boot for setting up vagrant boxes +# + +set -e + +. "$(dirname $0)/config.sh" + +[ ${VBOX_PXE_BUILD} -eq 1 ] || { + echo "PXE Building is DISABLED. Please enable in config.sh" + exit 2 +} + +for ARCH in $ARCHS +do + ORIG="ubuntu-$VERSION-$DISTRO-$ARCH.iso" + COPY="ubuntu-$VERSION-$DISTRO-$ARCH" + ISO="${ISOPREFIX}-ubuntu-$VERSION-$DISTRO-$ARCH.iso" + VBOX="${LABEL}-ubuntu-$VERSION-$DISTRO-$ARCH" + NETBOOT="ubuntu-$VERSION_NAME-$ARCH-netboot" + NETBOOT_FILE="${NETBOOT}.tar.gz" + NETBOOT_DIR="${VBOX_CONF_HOME}/ubuntu-$VERSION_NAME-netboot" + NETBOOT_URI="http://archive.ubuntu.com/ubuntu/dists/$VERSION_NAME/main/installer-$ARCH/current/images/netboot/netboot.tar.gz" + CURR_DIR=$(pwd) + +# echo $NETBOOT_URI + # Download the original netboot files if it isn't present already. +# echo "${NETBOOT_DIR}" + [ -f "$NETBOOT_FILE" ] || { + curl -L -o "${NETBOOT_FILE}" "${NETBOOT_URI}" + } + [ -d ${NETBOOT_DIR} ] || mkdir -p ${NETBOOT_DIR} + [ -d ${PRESEED_PATH} ] || mkdir -p ${PRESEED_PATH} + + (cd ${NETBOOT_DIR} && tar xzf ${CURR_DIR}/${NETBOOT}.tar.gz) + # Make a e copy of the original ISO. This uses the `hdiutil` + # command that is specific to Mac OS X. + + # Customize the writable copy. + mv "${NETBOOT_DIR}/ubuntu-installer/${ARCH}/boot-screens/syslinux.cfg" "${NETBOOT_DIR}/ubuntu-installer/${ARCH}/boot-screens/syslinux.cfg_ORIG" + m4 \ + -D __LABEL__="${LABEL}" \ + -D __ARCH__="$ARCH" \ + -D __HOST__="$HOST" \ + -D __PRESEED_URI__="${PRESEED_HOST}/${LABEL}.seed" \ + "pxelinux.cfg.m4" > "${NETBOOT_DIR}/ubuntu-installer/${ARCH}/boot-screens/syslinux.cfg" + ln -nfs ${NETBOOT_DIR}/pxelinux.0 ${NETBOOT_DIR}/${VBOX}.pxe + m4 \ + -D __HOST__="$HOST" \ + -D __DOMAIN__="$DOMAIN" \ + -D __KERNEL__="linux-$([ "$ARCH" = "i386" ] \ + && echo generic-pae \ + || echo server + )" \ + -D __ROOT_PASSWORD__="$ROOT_PASSWORD" \ + -D __USER_NAME__="$USER_NAME" \ + -D __PASSWORD__="$PASSWORD" \ + -D __LABEL__="${LABEL}" \ + -D __NFS_COMPAT__="${NFS_COMPAT}" \ + -D __VERSION_NAME__="${VERSION_NAME}" \ + -D __PROXY_URL__="${PROXY_URL}" \ + -D __LOCALE__="en_US" \ + -D __PRESEED_HOST__="${PRESEED_HOST}" \ + "pxe.seed.m4" >"${PRESEED_PATH}/${LABEL}.seed" + + # cp "$PUBLIC_KEY" "setup.sh" "$COPY/" + cp "$PUBLIC_KEY" "sudoers" "${NETBOOT_DIR}/" + tar -czf ${PRESEED_PATH}/setup.tgz "${PUBLIC_KEY}" "sudoers" + m4 \ + -D __LABEL__="$LABEL" \ + -D __PRESEED_HOST__="$PRESEED_HOST" \ + -D __USER_NAME__="$USER_NAME" \ + -D __PUBLIC_KEY__="$PUBLIC_KEY" \ + "perm_setup.sh.m4" >"${PRESEED_PATH}/${LABEL}.sh" + echo "** Completed building custom pxe for ${LABEL} [${ARCH}]" +done diff --git a/build-vagrant b/build-vagrant index a8f415e..de3106c 100755 --- a/build-vagrant +++ b/build-vagrant @@ -6,7 +6,10 @@ set -e for ARCH in $ARCHS do - VBOX="devstructure-ubuntu-$VERSION-$DISTRO-$ARCH" + VBOX="${LABEL}-ubuntu-$VERSION-$DISTRO-$ARCH" + + # Reset to snapshot at time of initial build + VBoxManage snapshot "${VBOX}" restore "AUTO_${LABEL}_base_build__000001" # Start the virtual machine. Spin slowly until SSH is usable. VBoxManage startvm "$VBOX" --type gui @@ -19,11 +22,15 @@ do # Install Ruby, RubyGems, and Chef as Vagrant requires. eval "$SSH \" set -e - sudo apt-get -y install build-essential ruby-dev rubygems + export DEBCONF_FRONTEND=noninteractive + sudo -E apt-get -y install build-essential ruby ruby-dev rubygems sudo gem install --no-rdoc --no-ri chef echo 'PATH=\"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/var/lib/gems/1.8/bin\"' | sudo tee /etc/environment >/dev/null \"" - + # Remove generated udev rule for network device as the mac address on the next instantiation is not going to match + eval "$SSH \" + sudo rm /etc/udev/rules.d/70-persistent-net.rules + \"" # Shutdown the virtual machine. eval "$SSH \"sudo shutdown -h now\"" until VBoxManage showvminfo "$VBOX" | grep "^State: *powered off" @@ -31,12 +38,38 @@ do sleep 1 done + ## Check if vagrant box dir for vagrant drives is hosted on an ext4 fs. If so, ensure hostiocache is enabled to avoid corruption + [ ${HOSTIOCACHE} ] || { + vbox_hd_dir="$HOME/.vagrant/boxes" + HOSTIOCACHE=""; + for dir in ${vbox_hd_dir}; do + vbox_hd_dir_disk=$(df ${dir} | tail -n 1 | cut -d" " -f1); + vbox_hd_dir_fs="$(grep ${vbox_hd_dir_disk} /proc/mounts | awk '{ print $3 }')" + [ "$vbox_hd_dir_fs" = "ext4" ] && { + echo "Auto enabling HOSTIOCACHE due ext4 fs [${dir}]"; + HOSTIOCACHE=" --hostiocache on "; + VBoxManage storagectl "$VBOX" \ + --name SATA ${HOSTIOCACHE} \ + break; + } + done + } + + # Remove the Proxy configuration before packaging a box. Not all vagrant users will be running an apt proxy server on their machines. + [ ${BOX_DISABLE_APT_PROXY} -eq 1 ] && { + eval "$SSH \" + sudo sed -i '/^Acquire::http::Proxy/ d' /etc/apt/apt.conf + \"" + } + # Now build the Vagrant box file. vagrant package --base "$VBOX" mv "package.box" \ - "devstructure$([ "$ARCH" = "i386" ] && echo 32 || echo 64).box" + "${LABEL}$([ "$ARCH" = "i386" ] && echo 32 || echo 64).box" + # Snapshot after vagrant dep install.... + VBoxManage snapshot "${VBOX}" take "AUTO_${LABEL}_vagrant_base__000002" --description "Snapshot taken after installing vagrant dependencies" done # Creating Vagrant boxes ruins the normal VM setup so get rid of them. -eval "$(dirname $0)/clean-vbox" +#eval "$(dirname $0)/clean-vbox" diff --git a/build-vbox b/build-vbox index e581b8e..6f3f8da 100755 --- a/build-vbox +++ b/build-vbox @@ -6,8 +6,25 @@ set -e for ARCH in $ARCHS do - ISO="devstructure-ubuntu-$VERSION-$DISTRO-$ARCH.iso" - VBOX="devstructure-ubuntu-$VERSION-$DISTRO-$ARCH" + ISO="${ISOPREFIX}-ubuntu-$VERSION-$DISTRO-$ARCH.iso" + VBOX="${LABEL}-ubuntu-$VERSION-$DISTRO-$ARCH" + NETBOOT="ubuntu-$VERSION-$ARCH-netboot" + NETBOOT_FILE="${NETBOOT}.tar.gz" + NETBOOT_DIR="${VBOX_CONF_HOME}/ubuntu-$VERSION_NAME-netboot" + NETBOOT_URI="http://archive.ubuntu.com/ubuntu/dists/$VERSION_NAME/main/installer-$ARCH/current/images/netboot/netboot.tar.gz" + CURR_DIR=$(pwd) + + ## Set TFTP Folder based on ARCH + ln -nfs ${NETBOOT_DIR} ${VBOX_CONF_HOME}/TFTP + + # Check if the vm already exists + set +e + VM_EXISTS=$(VBoxManage list vms | grep -c "${VBOX}") + set -e + + if [ ${VM_EXISTS} -lt 1 ]; then + + [ ${VBOX_PXE_BUILD} -eq 1 ] && { pxe_boot_order="--boot1 disk --boot2 net"; } || pxe_boot_order="" # Create and configure a virtual machine through VirtualBox. VBoxManage createvm \ @@ -17,7 +34,7 @@ do || true VBoxManage modifyvm "$VBOX" \ --ostype "Ubuntu$([ "$ARCH" = "i386" ] || echo _64)" \ - --memory 360 \ + --memory 448 \ --vram 12 \ --acpi on --ioapic on \ --cpus 1 \ @@ -31,18 +48,13 @@ do --audio none \ --clipboard disabled \ --usb off --usbehci off \ - --vrdp off \ + --vrde off \ + ${pxe_boot_order} \ --teleporter off - # Mount the custom installation ISO. - VBoxManage openmedium dvd "$PWD/$ISO" || true VBoxManage storagectl "$VBOX" \ --name IDE \ --add ide - VBoxManage storageattach "$VBOX" \ - --storagectl IDE \ - --port 1 --device 0 \ - --type dvddrive --medium "$PWD/$ISO" # Mount a virtual hard disk. VBoxManage createhd \ @@ -50,8 +62,24 @@ do --size 40000 \ --format VMDK \ || true + + ## Check if the current dir for vagrant drives is hosted on an ext4 fs. If so, ensure hostiocache is enabled to avoid corruption + [ ${HOSTIOCACHE} ] || { + vbox_hd_dir="$PWD/$VBOX/"; + HOSTIOCACHE=""; + for dir in ${vbox_hd_dir}; do + vbox_hd_dir_disk=$(df ${dir} | tail -n 1 | cut -d" " -f1); + vbox_hd_dir_fs="$(grep ${vbox_hd_dir_disk} /proc/mounts | awk '{ print $3 }')" + [ "$vbox_hd_dir_fs" = "ext4" ] && { + echo "Auto enabling HOSTIOCACHE due ext4 [${dir}]"; + HOSTIOCACHE=" --hostiocache on "; + break; + } + done + } + VBoxManage storagectl "$VBOX" \ - --name SATA \ + --name SATA ${HOSTIOCACHE} \ --add sata VBoxManage storageattach "$VBOX" \ --storagectl SATA \ @@ -60,42 +88,93 @@ do # Start the virtual machine and the OS installation. This will take # a while so this time it gets a GUI. Spin slowly until SSH is usable. + fi + + if [ ${VBOX_PXE_BUILD} -lt 1 ]; then + # Mount the custom installation ISO. + # VBoxManage openmedium dvd "$PWD/$ISO" || true + + VBoxManage storageattach "$VBOX" \ + --storagectl IDE \ + --port 1 --device 0 \ + --type dvddrive --medium "$PWD/$ISO" + else + VBoxManage storageattach "$VBOX" \ + --storagectl IDE \ + --port 1 --device 0 \ + --type dvddrive --medium "$VBOX_GUEST_ADDITIONS" + + fi + + set +e + VM_RUNS=$(VBoxManage list runningvms | grep -c "${VBOX}") + set -e + + if [ ${VM_RUNS} -lt 1 ]; then + + ## Start a webserver for the preseed files. + [ ${VBOX_PXE_BUILD} -eq 1 -a ${PRESEED_WEBSERVER} -eq 1 ] && { + echo -n "Starting webserver for preseed files..." + cd $PRESEED_PATH && python -m SimpleHTTPServer & + webserver_PID=$! + echo "done" + } + VBoxManage startvm "$VBOX" --type gui + ## Set better perms on the private key to avoid ssh abort + chmod 600 ${PRIVATE_KEY} +# VBoxManage modifyvm "${VBOX}" \ +# --boot1 disk until eval "$SSH exit" do sleep 60 done - + fi # Attach the VBoxGuestAdditions ISO, implicitly detaching the custom # installation ISO in the process. Install the additions and empty # the drive. - VBoxManage storageattach "$VBOX" \ + if [ ${VBOX_PXE_BUILD} -lt 1 ]; then + VBoxManage storageattach "$VBOX" \ --storagectl IDE \ --port 1 --device 0 \ --type dvddrive --medium "$VBOX_GUEST_ADDITIONS" + fi + eval "$SSH \" set -e - sudo apt-get -y install linux-headers-\\\$(uname -r) build-essential + [ $(lsmod | grep -c vboxguest) -eq 1 ] && exit 0; + export DEBCONF_FRONTEND=noninteractive + sudo -E apt-get -y install linux-headers-\\\$(uname -r) build-essential + [ -d /media/cdrom ] || sudo mkdir -p /media/cdrom until sudo mount /dev/cdrom /media/cdrom do sleep 1 done - sudo /media/cdrom/VBoxLinuxAdditions-$([ "$ARCH" = "i386" ] \ - && echo x86 \ - || echo amd64 - ).run + [[ -e /media/cdrom/VBoxLinuxAdditions.run ]] && { + sudo /media/cdrom/VBoxLinuxAdditions.run force + } || { + sudo /media/cdrom/VBoxLinuxAdditions-$([ "$ARCH" = "i386" ] \ + && echo x86 \ + || echo amd64 + ).run force --nox11 + } sudo umount /media/cdrom \"" VBoxManage storageattach "$VBOX" \ --storagectl IDE \ --port 1 --device 0 \ --type dvddrive --medium emptydrive - + + [ ${VBOX_PXE_BUILD} -eq 1 -a ${PRESEED_WEBSERVER} -eq 1 ] && { + echo -n "Stopping webserver for preseed files..." + kill ${webserver_PID} + wait && echo "done" + } # Shutdown the virtual machine. eval "$SSH \"sudo shutdown -h now\"" until VBoxManage showvminfo "$VBOX" | grep "^State: *powered off" do sleep 1 done - + VBoxManage snapshot "${VBOX}" take "AUTO_${LABEL}_base_build__000001" --description "Snapshot taken after initial build to be able to restore back when recreating vagrant boxes" done diff --git a/clean-iso b/clean-iso index f57cfaa..8c05724 100755 --- a/clean-iso +++ b/clean-iso @@ -6,5 +6,5 @@ for ARCH in $ARCHS do - rm -f "devstructure-ubuntu-$VERSION-$DISTRO-$ARCH.iso" + rm -f "${ISOPREFIX}-ubuntu-$VERSION-$DISTRO-$ARCH.iso" done diff --git a/clean-pxe b/clean-pxe new file mode 100755 index 0000000..d06b9fa --- /dev/null +++ b/clean-pxe @@ -0,0 +1,23 @@ +#!/bin/sh + +# set -e # Try our best to finish here. + +. "$(dirname $0)/config.sh" + +for ARCH in $ARCHS +do + NETBOOT="ubuntu-$VERSION_NAME-$ARCH-netboot" + NETBOOT_FILE="${NETBOOT}.tar.gz" + NETBOOT_DIR="${VBOX_CONF_HOME}/ubuntu-$VERSION_NAME-netboot" + NETBOOT_URI="http://archive.ubuntu.com/ubuntu/dists/$VERSION_NAME/main/installer-$ARCH/current/images/netboot/netboot.tar.gz" + CURR_DIR=$(pwd) + + # Remove extracted netboot files + custom configs + rm -rf "${NETBOOT_DIR}" + # Remove the preseed file. + rm -f "${PRESEED_PATH}/${LABEL}.seed" + # Remove the initial user setup script. + rm -f "${PRESEED_PATH}/${LABEL}.sh" + + echo "** Cleaned custom pxe for ${LABEL} [${ARCH}]" +done diff --git a/clean-vagrant b/clean-vagrant index 0c87065..aedaccf 100755 --- a/clean-vagrant +++ b/clean-vagrant @@ -6,5 +6,5 @@ for ARCH in $ARCHS do - rm -f "devstructure$([ "$ARCH" = "i386" ] && echo 32 || echo 64).box" + rm -f "${LABEL}$([ "$ARCH" = "i386" ] && echo 32 || echo 64).box" done diff --git a/clean-vbox b/clean-vbox index d9b4fd3..e5abde1 100755 --- a/clean-vbox +++ b/clean-vbox @@ -6,15 +6,23 @@ for ARCH in $ARCHS do - ISO="devstructure-ubuntu-$VERSION-$DISTRO-$ARCH.iso" - VBOX="devstructure-ubuntu-$VERSION-$DISTRO-$ARCH" - - VBoxManage controlvm "$VBOX" poweroff - VBoxManage storagectl "$VBOX" --name IDE --remove - VBoxManage storagectl "$VBOX" --name SATA --remove - VBoxManage unregistervm "$VBOX" - VBoxManage closemedium dvd "$PWD/$ISO" - VBoxManage closemedium disk "$PWD/$VBOX/$VBOX.vmdk" + ISO="${ISOPREFIX}-ubuntu-$VERSION-$DISTRO-$ARCH.iso" + VBOX="${LABEL}-ubuntu-$VERSION-$DISTRO-$ARCH" + VMLIST=$(VBoxManage list vms) + RUNNING_VMLIST=$(VBoxManage list runningvms) + + ## Power off running vms + [ $(echo "${RUNNING_VMLIST}" | grep -c "${VBOX}") -gt 0 ] && { + echo -n "VBox ${VBOX} is running... Powering off" + VBoxManage controlvm "$VBOX" poweroff + sleep 1 # Lets give the vm to shutdown properly. + [ $? -eq 0 ] && { echo "... done"; } || { echo "... Failed!"; } + } + ## Remove vms if they exist + [ $(echo "${VMLIST}" | grep -c "${VBOX}") -gt 0 ] && { + echo -n "Removing VBox [${VBOX}]..." + VBoxManage unregistervm "$VBOX" --delete + [ $? -eq 0 ] && { echo "... done"; } || { echo "... Failed!"; } + } rm -rf "$VBOX" - done diff --git a/config.sh b/config.sh index 735085d..60ee5ac 100644 --- a/config.sh +++ b/config.sh @@ -1,18 +1,25 @@ # # Arguments given to the download router. -: ${VERSION:="10.10"} : ${DISTRO:="server"} +: ${VERSION:="11.04"} +: ${VERSION_NAME:="natty"} : ${RELEASE:="latest"} +# Generated ISO Prefix +: ${ISOPREFIX:="phatforge"} +: ${LABEL:="phatforge"} + # Architectures being built. : ${ARCHS:="i386 amd64"} +#: ${ARCHS:="amd64"} # Hardcoded host information. -: ${HOST:="devstructure"} +# : ${HOST:="devstructure"} +: ${HOST:="${VERSION_NAME}"} : ${DOMAIN:="vagrantup.com"} : ${ROOT_PASSWORD:="vagrant"} -: ${USERNAME:="vagrant"} +: ${USER_NAME:="vagrant"} : ${PASSWORD:="vagrant"} # SSH key to be authorized in virtual machines. @@ -24,8 +31,37 @@ : ${SSH:="ssh \ -o UserKnownHostsFile=/dev/null \ -o StrictHostKeyChecking=no \ - -l \"$USERNAME\" -i \"$PRIVATE_KEY\" -p 2222 localhost \ + -l \"$USER_NAME\" -i \"$PRIVATE_KEY\" -p 2222 localhost \ "} # Fully-qualified pathname of VBoxGuestAdditions.iso. -: ${VBOX_GUEST_ADDITIONS:="/Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso"} +#: ${VBOX_GUEST_ADDITIONS:="/Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso"} +: ${VBOX_GUEST_ADDITIONS:="/usr/share/virtualbox/VBoxGuestAdditions.iso"} + +#### PXE BUILD SETTINGS +## You need a webserver to serve the preseed file. We currently use python's simpleHTTPServer module, but you can change the path to a full webserver if you want. +## A proxy is recommended! +### +## Enable build via pxe +: ${VBOX_PXE_BUILD:=0} +## VirtualBox config home (Location of the VirtualBox.xml file), for pxe boot support +: ${VBOX_CONF_HOME:="${HOME}/.VirtualBox"} +# Enable a python webserver for the preseed files.(Default on. Disable if you are hosting your preseed files on your own webserver +: ${PRESEED_WEBSERVER:=1} +## Preseed URI address. Default is set to the Host machine ip. This address can be set to a remote url (assuming your VM can access it.) Please see README.PXE +: ${PRESEED_HOST:="http://10.0.2.2:8000"} +: ${PRESEED_PATH:="web-root"} + +# apt-cacher-ng support. If you have a proxy running locally set the ip address here for apt to proxy requests. (10.0.2.2 is the default gateway ip which should be your host) +#: ${PROXY_URL:="http://10.0.2.2:3142"} +# remove apt-proxy config for boxification? To remove the apt config for proxy settings from the box itself +# (i.e. only use it for the OS install not for subsequent vagrant vms afterwards. Do your colleagues run apt-proxy on their host machines?) +: ${BOX_DISABLE_APT_PROXY:=1} +# Add nfs_common packages to vbox for nfs compat with vagrant. Empty string to remove nfs compat. This should make the base image (a bit) smaller, if you don't need nfs support +: ${NFS_COMPAT:="nfs-common"} + +# Enable Host IO cache on ext4 filesystems. Unless explicitly specified here, build-vbox will check both current build dir and home dir (home of vagrant box cache) to see if they are ext4 filesystems +# Enable hostiocache var +#: ${HOSTIOCACHE:=" --hostiocache on"} +# Disable hostiocache var +#: ${HOSTIOCACHE:=""} diff --git a/devstructure.seed.m4 b/default.seed.m4 similarity index 72% rename from devstructure.seed.m4 rename to default.seed.m4 index 10d2729..cdae2c9 100644 --- a/devstructure.seed.m4 +++ b/default.seed.m4 @@ -1,4 +1,4 @@ -# Preseed Ubuntu for DevStructure. +# Preseed Ubuntu for vagrant. # Network. d-i netcfg/get_hostname string __HOST__ @@ -28,20 +28,22 @@ d-i base-installer/kernel/override-image string __KERNEL__ d-i passwd/root-password password __ROOT_PASSWORD__ d-i passwd/root-password-again password __ROOT_PASSWORD__ d-i passwd/user-uid string 1000 -d-i passwd/user-fullname string DevStructure -d-i passwd/username string __USERNAME__ +d-i passwd/user-fullname string VagrantUser +d-i passwd/username string __USER_NAME__ d-i passwd/user-password password __PASSWORD__ d-i passwd/user-password-again password __PASSWORD__ d-i user-setup/allow-password-weak boolean true d-i user-setup/encrypt-home boolean false # Packages and repositories. -d-i mirror/http/proxy string -d-i apt-setup/local0/repository string http://packages.devstructure.com maverick main -d-i apt-setup/local0/source boolean false -d-i apt-setup/local0/key string http://packages.devstructure.com/keyring.gpg +# d-i apt-setup/local0/repository string http://packages.devstructure.com maverick main +# d-i apt-setup/local0/source boolean false +# d-i apt-setup/local0/key string http://packages.devstructure.com/keyring.gpg +# d-i mirror/protocol string http +# d-i mirror/http/hostname string +d-i mirror/http/proxy string __PROXY_URL__ tasksel tasksel/first multiselect -d-i pkgsel/include string curl openssh-server +d-i pkgsel/include string curl openssh-server acpi-support __NFS_COMPAT__ #d-i pkgsel/include string openssh-server sandbox blueprint d-i pkgsel/update-policy select none d-i pkgsel/install-language-support boolean false @@ -54,4 +56,4 @@ d-i cdrom-detect/eject boolean true d-i debian-installer/splash boolean false # Everything else. -d-i preseed/late_command string sh /cdrom/devstructure.sh +d-i preseed/late_command string sh /cdrom/__LABEL__.sh diff --git a/default.sh.m4 b/default.sh.m4 new file mode 100644 index 0000000..4e6baba --- /dev/null +++ b/default.sh.m4 @@ -0,0 +1,23 @@ +set -e + +mkdir /target/home/__USER_NAME__/.ssh +cat /cdrom/__PUBLIC_KEY__ >/target/home/__USER_NAME__/.ssh/authorized_keys +chmod 700 /target/home/__USER_NAME__/.ssh +chown 1000:1000 \ + /target/home/__USER_NAME__/.ssh \ + /target/home/__USER_NAME__/.ssh/authorized_keys + +# cp /cdrom/setup.sh /target/etc/profile.d/ +# chmod 644 /target/etc/profile.d/setup.sh +# chown 0:0 /target/etc/profile.d/setup.sh + +cp /cdrom/sudoers /target/etc/ +chmod 440 /target/etc/sudoers +chown 0:0 /target/etc/sudoers + +chroot /target sh -c ' + set -e + unset DEBCONF_REDIR DEBCONF_FRONTEND DEBIAN_HAS_FRONTEND DEBIAN_FRONTEND + apt-get update + # apt-get -y install sandbox blueprint +' diff --git a/devstructure.sh.m4 b/devstructure.sh.m4 deleted file mode 100644 index cdb2c91..0000000 --- a/devstructure.sh.m4 +++ /dev/null @@ -1,23 +0,0 @@ -set -e - -mkdir /target/home/__USERNAME__/.ssh -cat /cdrom/__PUBLIC_KEY__ >/target/home/__USERNAME__/.ssh/authorized_keys -chmod 700 /target/home/__USERNAME__/.ssh -chown 1000:1000 \ - /target/home/__USERNAME__/.ssh \ - /target/home/__USERNAME__/.ssh/authorized_keys - -cp /cdrom/setup.sh /target/etc/profile.d/ -chmod 644 /target/etc/profile.d/setup.sh -chown 0:0 /target/etc/profile.d/setup.sh - -cp /cdrom/sudoers /target/etc/ -chmod 440 /target/etc/sudoers -chown 0:0 /target/etc/sudoers - -chroot /target sh -c ' - set -e - unset DEBCONF_REDIR DEBCONF_FRONTEND DEBIAN_HAS_FRONTEND DEBIAN_FRONTEND - apt-get update - apt-get -y install sandbox blueprint -' diff --git a/isolinux.cfg b/isolinux.cfg deleted file mode 100644 index c3df7ca..0000000 --- a/isolinux.cfg +++ /dev/null @@ -1,6 +0,0 @@ -default devstructure -timeout 1 -label devstructure - menu label ^Install Ubuntu Server for DevStructure - kernel /install/vmlinuz - append file=/cdrom/preseed/devstructure.seed debian-installer/locale=en_US console-setup/layoutcode=us localechooser/translation/warn-light=true localechooser/translation/warn-severe=true initrd=/install/initrd.gz quiet -- diff --git a/isolinux.cfg.m4 b/isolinux.cfg.m4 new file mode 100644 index 0000000..4ff617b --- /dev/null +++ b/isolinux.cfg.m4 @@ -0,0 +1,6 @@ +default __LABEL__ +timeout 1 +label __LABEL__ + menu label ^Install Ubuntu Server for __LABEL__ + kernel /install/vmlinuz + append file=/cdrom/preseed/__LABEL__.seed debian-installer/locale=en_US console-setup/layoutcode=us localechooser/translation/warn-light=true localechooser/translation/warn-severe=true initrd=/install/initrd.gz quiet -- diff --git a/perm_setup.sh.m4 b/perm_setup.sh.m4 new file mode 100644 index 0000000..5248097 --- /dev/null +++ b/perm_setup.sh.m4 @@ -0,0 +1,26 @@ +set -e + +mkdir -p /opt/__LABEL__-setup/ +cd /opt/__LABEL__-setup/ +curl -L --noproxy * -o "/opt/__LABEL__-setup/setup.tgz" "__PRESEED_HOST__/setup.tgz" +tar xzvf /opt/__LABEL__-setup/setup.tgz + +mkdir /home/__USER_NAME__/.ssh +cat /opt/__LABEL__-setup/__PUBLIC_KEY__ >/home/__USER_NAME__/.ssh/authorized_keys +chmod 700 /home/__USER_NAME__/.ssh +chown 1000:1000 \ + /home/__USER_NAME__/.ssh \ + /home/__USER_NAME__/.ssh/authorized_keys + +# cp /cdrom/setup.sh /etc/profile.d/ +# chmod 644 /etc/profile.d/setup.sh +# chown 0:0 /etc/profile.d/setup.sh + +cp /opt/__LABEL__-setup/sudoers /etc/ +chmod 440 /etc/sudoers +chown 0:0 /etc/sudoers + +unset DEBCONF_REDIR DEBCONF_FRONTEND DEBIAN_HAS_FRONTEND DEBIAN_FRONTEND +apt-get update + +rm -rf /opt/__LABEL__-setup/ diff --git a/pxe.seed.m4 b/pxe.seed.m4 new file mode 100644 index 0000000..cbfd96d --- /dev/null +++ b/pxe.seed.m4 @@ -0,0 +1,74 @@ +# Preseed Ubuntu for vagrant. + +## Add pxe required settings. These shouldn't interfere with iso build versions. +d-i debian-installer/locale string __LOCALE__ +d-i netcfg/choose_interface select auto +# Keyboard selection. +# Disable automatic (interactive) keymap detection. +d-i console-setup/ask_detect boolean false +#d-i console-setup/modelcode string pc105 +d-i console-setup/layoutcode string us +# To select a variant of the selected layout (if you leave this out, the +# basic form of the layout will be used): +#d-i console-setup/variantcode string dvorak + +# Network. +d-i netcfg/get_hostname string __HOST__ +d-i netcfg/get_domain string __DOMAIN__ +d-i netcfg/wireless_wep string + +# Clock. +d-i clock-setup/utc boolean true +d-i time/zone string UTC + +# Partitions. +d-i partman-auto/disk string /dev/sda +d-i partman-auto/method string regular +d-i partman-lvm/device_remove_lvm boolean true +d-i partman-md/device_remove_md boolean true +d-i partman-auto/choose_recipe select atomic +d-i partman/default_filesystem string ext4 +d-i partman/confirm_write_new_label boolean true +d-i partman/choose_partition select finish +d-i partman/confirm boolean true +d-i partman/confirm_nooverwrite boolean true + +# Kernel. +d-i base-installer/kernel/override-image string __KERNEL__ + +# Users. +d-i passwd/root-password password __ROOT_PASSWORD__ +d-i passwd/root-password-again password __ROOT_PASSWORD__ +d-i passwd/user-uid string 1000 +d-i passwd/user-fullname string VagrantUser +d-i passwd/username string __USER_NAME__ +d-i passwd/user-password password __PASSWORD__ +d-i passwd/user-password-again password __PASSWORD__ +d-i user-setup/allow-password-weak boolean true +d-i user-setup/encrypt-home boolean false + +# Packages and repositories. +# d-i apt-setup/local0/repository string http://packages.devstructure.com __VERSION_NAME__ main +# d-i apt-setup/local0/source boolean false +# d-i apt-setup/local0/key string http://packages.devstructure.com/keyring.gpg +# d-i mirror/protocol string http +# d-i mirror/http/hostname string +d-i mirror/http/proxy string __PROXY_URL__ +tasksel tasksel/first multiselect +d-i pkgsel/include string curl openssh-server acpi-support __NFS_COMPAT__ +#d-i pkgsel/include string openssh-server sandbox blueprint +d-i pkgsel/update-policy select none +d-i pkgsel/install-language-support boolean false + +# Grub and reboot. +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 +d-i cdrom-detect/eject boolean true +d-i debian-installer/splash boolean false + +# Everything else. +d-i preseed/late_command string \ + in-target wget --no-proxy __PRESEED_HOST__/__LABEL__.sh -O /opt/__LABEL__.sh ; \ + in-target sh /opt/__LABEL__.sh ; + diff --git a/pxelinux.cfg.m4 b/pxelinux.cfg.m4 new file mode 100644 index 0000000..e64527d --- /dev/null +++ b/pxelinux.cfg.m4 @@ -0,0 +1,6 @@ +default __LABEL__ +timeout 1 +label __LABEL__ + menu label ^Install Ubuntu Server for __LABEL__ + kernel ubuntu-installer/__ARCH__/linux + append auto=true priority=critical url=__PRESEED_URI__ hostname=__HOST__ initrd=ubuntu-installer/__ARCH__/initrd.gz quiet --