Skip to content

Commit

Permalink
vagrantcloud and add debian 9.1
Browse files Browse the repository at this point in the history
  • Loading branch information
maier committed Aug 10, 2017
1 parent a31aba1 commit a18eb41
Show file tree
Hide file tree
Showing 15 changed files with 380 additions and 0 deletions.
34 changes: 34 additions & 0 deletions debian9.1/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## [Debian](http://debian.org) v9.1 (stretch)

* x86_64
* base install
* has VBoxGuestAdditions
* [Packer template](https://github.com/maier/packer-templates/)

## Use

```
#
# Create initial Vagrantfile
#
vagrant init maier/debian-9.1.0-x86_64
#
# Customize
#
vi Vagrantfile
#
# Start the box
#
vagrant up
```


## Changes

* v9.1.0
* initial 9.1 (stretch)
20 changes: 20 additions & 0 deletions debian9.1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## [Debian](http://debian.org)

### Debian 8 (jessie)

* Minimal OS w/VBGA

## Usage notes

None at this time

## Build environment

```shell
⁖ packer version && vagrant -v && vboxmanage --version
Packer v0.12.2
Vagrant 1.9.1
5.1.14r112924
```

`vagrant init maier/debian-8.7.0-x86_64`
14 changes: 14 additions & 0 deletions debian9.1/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
#
Vagrant.configure(2) do |config|
config.vm.define 'debian87' do |debian|
debian.vm.box = 'maier/debian-8.7.0-x86_64'
debian.vm.synced_folder '.', '/vagrant', disabled: false
debian.vm.provider 'virtualbox' do |vb|
vb.name = 'debian87'
vb.cpus = 1
vb.memory = 1024
end
end
end
86 changes: 86 additions & 0 deletions debian9.1/debian-9.1.0-x86_64.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"description": "Build base Debian 9.1 (stretch) x86_64",
"push": {
"name": "maier/debian8",
"vcs": true
},
"variables": {
"vagrantcloud_token": "{{env `VC_TOKEN`}}",
"box_version": "{{ env `VC_BOX_VER`}}",
"box_tag": "{{env `VC_BOX_TAG`}}"
},
"provisioners": [
{
"type": "shell",
"execute_command": "echo 'vagrant' | sudo -S sh '{{.Path}}'",
"scripts": [
"scripts/00base.sh",
"scripts/01networking.sh",
"scripts/02sshd.sh",
"scripts/03vagrant.sh",
"scripts/04sudoers.sh",
"scripts/90virtualbox.sh",
"scripts/99cleanup.sh",
"scripts/99minimize.sh"
]
}
],
"builders": [
{
"type": "virtualbox-iso",
"virtualbox_version_file": ".vbox_version",
"guest_additions_path": "VBoxGuestAdditions_{{.Version}}.iso",

"guest_os_type": "Debian_64",
"headless": false,
"disk_size": 10240,
"http_directory": "http",

"iso_url": "http://cdimage.debian.org/cdimage/release/9.1.0/amd64/iso-cd/debian-9.1.0-amd64-netinst.iso",
"iso_checksum": "c9e070074de83aa22e141f59a423e5210a5019b369ef1efe61a2afd44ba8f371",
"iso_checksum_type": "sha256",

"ssh_username": "vagrant",
"ssh_password": "vagrant",
"ssh_port": 22,
"ssh_wait_timeout": "15m",
"shutdown_command": "echo 'vagrant'|sudo -S shutdown -hP now",

"boot_wait": "10s",
"boot_command": [
"<esc><wait>",
"install<wait>",
" preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg<wait>",
" debian-installer=en_US<wait>",
" auto<wait>",
" locale=en_US<wait>",
" kbd-chooser/method=us<wait>",
" keyboard-configuration/xkb-keymap=us<wait>",
" netcfg/get_hostname=debian-91<wait>",
" netcfg/get_domain=vagrantup.com<wait>",
" fb=false<wait>",
" debconf/frontend=noninteractive<wait>",
" console-setup/ask_detect=false<wait>",
" console-keymaps-at/keymap=us<wait>",
"<enter><wait>"
],

"vboxmanage": [
[ "modifyvm", "{{.Name}}", "--memory", "1024" ],
[ "modifyvm", "{{.Name}}", "--cpus", "1" ]
]
}
],
"post-processors": [
[{
"type": "vagrant",
"output": "output.box"
},
{
"type": "vagrant-cloud",
"access_token": "{{user `vagrantcloud_token`}}",
"box_tag": "{{user `box_tag`}}",
"version": "{{user `box_version`}}"
}]
]
}
49 changes: 49 additions & 0 deletions debian9.1/http/preseed.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
choose-mirror-bin mirror/http/proxy string
d-i apt-setup/use_mirror boolean true
d-i base-installer/kernel/override-image string linux-server
d-i clock-setup/utc boolean true
d-i clock-setup/utc-auto boolean true
d-i finish-install/reboot_in_progress note
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true
d-i grub-installer/bootdev string /dev/sda
d-i keymap select us
d-i mirror/country string manual
d-i mirror/http/directory string /debian
d-i mirror/http/hostname string http.debian.net
d-i mirror/http/proxy string
d-i partman-auto-lvm/guided_size string max
d-i partman-auto/choose_recipe select atomic
d-i partman-auto/method string lvm
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman-lvm/device_remove_lvm boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
d-i partman/confirm_write_new_label boolean true
d-i passwd/root-login boolean false
d-i passwd/root-password-again password vagrant
d-i passwd/root-password password vagrant
d-i passwd/user-fullname string vagrant
d-i passwd/user-uid string 900
d-i passwd/user-password password vagrant
d-i passwd/user-password-again password vagrant
d-i passwd/username string vagrant
# Prevent packaged version of VirtualBox Guest Additions being installed:
d-i preseed/early_command string sed -i \
'/in-target/idiscover(){/sbin/discover|grep -v VirtualBox;}' \
/usr/lib/pre-pkgsel.d/20install-hwpackages
d-i time/zone string UTC
d-i user-setup/allow-password-weak boolean true
d-i user-setup/encrypt-home boolean false
d-i preseed/late_command string sed -i '/^deb cdrom:/s/^/#/' /target/etc/apt/sources.list
apt-cdrom-setup apt-setup/cdrom/set-first boolean false
apt-mirror-setup apt-setup/use_mirror boolean true
popularity-contest popularity-contest/participate boolean false
tasksel tasksel/first multiselect ssh-server
d-i pkgsel/include string openssh-server sudo curl bzip2
d-i pkgsel/install-language-support boolean false
d-i pkgsel/update-policy select unattended-upgrades
d-i pkgsel/upgrade select full-upgrade
19 changes: 19 additions & 0 deletions debian9.1/scripts/00base.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
set -x

echo

echo "removing xll packages (server not desktop...)"
apt-get remove -y libx11.* libqt.*

echo "update remaining packages"
apt-get update

echo "purging packages which are no longer needed"
apt-get autoremove -y

echo "setting up sudo for vagrant user"

echo "vagrant ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/vagrant
chmod 440 /etc/sudoers.d/vagrant

echo "Defaults !requiretty" >> /etc/sudoers
3 changes: 3 additions & 0 deletions debian9.1/scripts/01networking.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set -ex

echo "pre-up sleep 2" >> /etc/network/interfaces
4 changes: 4 additions & 0 deletions debian9.1/scripts/02sshd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set -ex

echo "UseDNS no" >> /etc/ssh/sshd_config
echo "GSSAPIAuthentication no" >> /etc/ssh/sshd_config
13 changes: 13 additions & 0 deletions debian9.1/scripts/03vagrant.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
set -ex

# Vagrant specific
date > /etc/vagrant_box_build_time

if [ $(grep -c vagrant /etc/passwd) -eq 0 ] ; then
useradd vagrant -m
fi

mkdir -pm 700 /home/vagrant/.ssh
curl -o /home/vagrant/.ssh/authorized_keys 'https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub'
chown -R vagrant:vagrant /home/vagrant/.ssh
chmod -R go-rwsx /home/vagrant/.ssh
3 changes: 3 additions & 0 deletions debian9.1/scripts/04sudoers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set -e
# taken care of in 00base
exit 0
31 changes: 31 additions & 0 deletions debian9.1/scripts/90virtualbox.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
set -x

if [ ! -f /home/vagrant/.vbox_version ]; then
echo "/home/vagrant/.vbox_version file not found"
exit 1
fi
vbox_version=$(cat /home/vagrant/.vbox_version)

cd /tmp
vbfile="VBoxGuestAdditions_${vbox_version}.iso"

if [ ! -f /home/vagrant/${vbfile} ]; then
echo "Downloading VirtualBox Guest Additions ISO"
curl "http://download.virtualbox.org/virtualbox/${vbox_version}/${vbfile}" -o /home/vagrant/${vbfile}
if [ $? -ne 0 ]; then
echo "Unable to download VBGA ISO"
exit 1
fi
fi

pkg_list="make gcc linux-headers-$(uname -r)"

apt-get install -y $pkg_list

mount -o loop /home/vagrant/${vbfile} /mnt
sh /mnt/VBoxLinuxAdditions.run
umount /mnt

apt-get remove --purge -y $pkg_list

exit 0
22 changes: 22 additions & 0 deletions debian9.1/scripts/99cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
set -x

apt-get -y --purge remove linux-headers-$(uname -r)
apt-get -y --purge autoremove
apt-get -y purge $(dpkg --list |grep '^rc' |awk '{print $2}')
apt-get -y purge $(dpkg --list |egrep 'linux-image-[0-9]' |awk '{print $3,$2}' |sort -nr |tail -n +2 |grep -v $(uname -r) |awk '{ print $2}')
apt-get -y clean

echo "cleaning up dhcp leases"
rm /var/lib/dhcp/* 2>/dev/null

echo "cleaning up udev rules"
rm /etc/udev/rules.d/70-persistent-net.rules 2>/dev/null
mkdir /etc/udev/rules.d/70-persistent-net.rules
rm /lib/udev/rules.d/75-persistent-net-generator.rules 2>/dev/null
rm -rf /dev/.udev/ 2>/dev/null

echo "cleaning bash history"
unset HISTFILE
rm ~/.bash_history /home/vagrant/.bash_history 2>/dev/null

exit 0
5 changes: 5 additions & 0 deletions debian9.1/scripts/99minimize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set -x

dd if=/dev/zero of=/EMPTY bs=1M
rm -f /EMPTY

18 changes: 18 additions & 0 deletions debian9.1/sh_vars
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
dist_name="debian"
dist_vers="9.1.0"
dist_arch="x86_64"

# what type of build to perform:
#
# 'remote'
# run 'packer push --create <template>' to send
# the template up to Atlas for building.
#
# 'local'
# - remote -- 'packer push --create <template>'
# - local -- 'packer build' resulting box is uploaded to atlas
#
build_type="local"

# END
59 changes: 59 additions & 0 deletions vagrantcloud.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env bash

#set -eux

function die_var_unset {
echo "ERROR: Variable '$1' is required to be set. Please edit $0 and set."
exit 1
}

[ -f sh_vars ] || { echo "User variables file 'sh_vars' not found."; exit 1; }

source sh_vars

[ -z "$dist_name" ] && die_var_unset "dist_name"
[ -z "$dist_vers" ] && die_var_unset "dist_vers"
[ -z "$dist_arch" ] && die_var_unset "dist_arch"
[ -z "$build_type" ] && die_var_unset "build_type"
[ -z "$VAGRANTCLOUD_USER" ] && die_var_unset "VAGRANTCLOUD_USER"
[ -z "$VAGRANTCLOUD_TOKEN" ] && die_var_unset "VAGRANTCLOUD_TOKEN"
[ -z "$BOX_NAME" ] && BOX_NAME="${dist_name}-${dist_vers}-${dist_arch}"
[ -z "$BOX_VERSION" ] && BOX_VERSION="${dist_vers}"

template_name="${BOX_NAME}.json"

if [ ! -f $template_name ]; then
echo "No template '$template_name' found!"
echo "Creating skeleton, edit and run $0 again."
if [ -f skeltempl.json ]; then
mv skeltempl.json $template_name
[ $? -eq 0 ] || { echo "Unable to 'mv skeltempl.json $template_name'."; exit 3; }
else
curl -sSo $template_name "https://raw.githubusercontent.com/maier/packer-templates/master/skel/skeltempl.json"
[ $? -eq 0 ] || { echo "Unable retrieve 'skeltempl.json' from github repository."; exit 3; }
fi
exit 2
fi

case $build_type in
remote)
echo "Pushing $template_name to VagrantCloud/Atlas for remote build. (and making it public)"
packer push $template_name
;;
local)
export VC_BOX_TAG="${VAGRANTCLOUD_USER}/${BOX_NAME}"
export VC_BOX_VER=$BOX_VERSION
export VC_TOKEN=$VAGRANTCLOUD_TOKEN
echo "Build box locally then push box to VagrantCloud."
packer build $template_name
unset VC_TOKEN
unset VC_BOX_VER
unset VC_BOX_TAG
;;
* )
echo "Unknown build type '$build_type'"
exit 1
;;
esac

# END

0 comments on commit a18eb41

Please sign in to comment.