Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
OnApp template creator for Ubuntu 14.04 Trusty Tahr
## OnApp template creator Makefile for Ubuntu 14.04
## Creates an OnApp compatible template from the Ubuntu cloud base image
## You can run this script continiously to update the image
## You will want to customise the timezone and mirror
## Version 0.1 2014-05-07
## Trent Lloyd <>
## (1) Create a new directory, e.g. 'template-builder'
## (2) Download this file and name it Makefile
## (3) Make template/ directory, copy fstab.xen from an existing Ubuntu template (e.g. 12.04)
## (4) Create template/resolv.conf with your nameservers
## (5) Ensure you are running OnApp 3.1 (this assumes using /onapp/backups/templaets unpacking from OnApp 3.1)
## (6) You must run this script on a backup server with access to templates and backups
## (7) run 'make'
release ?= trusty
arch ?= amd64
unexport LANG
export DEBIAN_FRONTEND=noninteractive
$(release): .$(release)-clean .$(release)-prepare .$(release)-final .$(release)-package .$(release)-clean
wget -N$(release)/current/$(baseimage).tar.gz
mkdir -p $(tmpdir)
tar -xzp --xattrs --numeric-owner -f $(baseimage).tar.gz -C $(tmpdir)/
cp --remove-destination template/fstab.xen $(tmpdir)/etc/fstab
cp --remove-destination template/resolv.conf $(tmpdir)/etc
rm -f $(tmpdir)/boot/grub/menu.lst $(tmpdir)/boot/grub/grub.cfg
sed -i 's/' $(tmpdir)/etc/apt/sources.list
sed -i 's/' $(tmpdir)/etc/apt/sources.list
sed -i 's/^PermitRootLogin without-password/PermitRootLogin yes/g' $(tmpdir)/etc/ssh/sshd_config
sed -i 's/^PasswordAuthentication no/PasswordAuthentication yes/g' $(tmpdir)/etc/ssh/sshd_config
mount -t proc proc $(tmpdir)/proc
chroot $(tmpdir) dpkg-divert --add --rename --local /usr/sbin/invoke-rc.d
chroot $(tmpdir) ln -s /bin/true /usr/sbin/invoke-rc.d
chroot $(tmpdir) apt-get -y update
chroot $(tmpdir) apt-get -y install linux-virtual grub
chroot $(tmpdir) update-grub -y
echo "Australia/Perth" > $(tmpdir)/etc/timezone
chroot $(tmpdir) dpkg-reconfigure -fnoninteractive tzdata
chroot $(tmpdir) apt-get remove cloud-guest-utils cloud-init --purge -y
mv $(tmpdir)/boot/grub/menu.lst $(tmpdir)/boot/grub/menu.lst.xen
mv $(tmpdir)/etc/fstab $(tmpdir)/etc/fstab.xen
chroot $(tmpdir) rm /usr/sbin/invoke-rc.d
chroot $(tmpdir) dpkg-divert --remove --rename /usr/sbin/invoke-rc.d
umount $(tmpdir)/proc
rm -f /onapp/templates/$(baseimage)
tar -czp --xattrs --numeric-owner -f /onapp/templates/$(baseimage) -C $(tmpdir)/ .
mv /onapp/templates/$(baseimage) /onapp/templates/$(baseimage).tar.gz
mkdir -p /onapp/backups/templates/$(baseimage).tar.gz
rsync --numeric-ids -xaAX --delete $(tmpdir)/ /onapp/backups/templates/$(baseimage).tar.gz/
umount $(tmpdir)/proc || true
rm -rf $(tmpdir)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment