#### Contents of the preconfiguration file (for squeeze)
### Localization
d-i debian-installer/locale string en_US.UTF-8

# Keyboard selection.
# Disable automatic (interactive) keymap detection.
d-i console-setup/ask_detect boolean false
d-i keyboard-configuration/layoutcode string us

### Network configuration
# Disable network configuration entirely. This is useful for cdrom
# installations on non-networked devices where the network questions,
# warning and long timeouts are a nuisance.

# netcfg will choose an interface that has link if possible. This makes it
# skip displaying a list if there is more than one interface.
d-i netcfg/choose_interface select auto
<% if (typeof hostname !== 'undefined') { %>
d-i netcfg/get_hostname string <%=hostname%>
<% } %>
<% if (typeof domain !== 'undefined') { %>
d-i netcfg/get_domain string <%=domain%>
<%} %>


# Disable that annoying WEP key dialog.
d-i netcfg/wireless_wep string
### Mirror settings
# If you select ftp, the mirror/country string does not need to be set.
d-i mirror/country string manual
# Get server:port from repo
<% var repoHostname = repo.match(/^(https?:\/\/)?([a-zA-Z0-9\.:-]+)/)[2] -%>
d-i mirror/http/hostname string <%=repoHostname%>
# Get directory from repo
<% var repoDirectory = repo.replace(/^(https?:\/\/)?([a-zA-Z0-9\.:-]+)/g,"") -%>
d-i mirror/http/directory string <%=repoDirectory%>

d-i preseed/early_command string \
<%_ if( typeof progressMilestones !== 'undefined' && progressMilestones.preConfigUri ) { _%>
wget 'http://<%=server%>:<%=port%><%-progressMilestones.preConfigUri%>' || true; \
<%_ } _%>
umount /media || true;

d-i apt-setup/restricted boolean false
d-i mirror/http/proxy string
d-i apt-setup/universe boolean false
d-i apt-setup/backports boolean false
d-i apt-setup/proposed boolean false
d-i apt-setup/security_host string
d-i apt-setup/local0/repository string deb <%=repo%> <%=version%> main restricted universe multiverse
d-i apt-setup/local0/source boolean false
d-i debian-installer/allow_unauthenticated boolean true

### Clock and time zone setup
# Controls whether or not the hardware clock is set to UTC.
d-i clock-setup/utc boolean true

# You may set this to any valid setting for $TZ; see the contents of
# /usr/share/zoneinfo/ for valid values.
d-i time/zone string US/Pacific

# Controls whether to use NTP to set the clock during the install
d-i clock-setup/ntp boolean true

### Partitioning
d-i partman/early_command string \
<%_ if( typeof progressMilestones !== 'undefined' && progressMilestones.startPartitionUri ) { _%>
wget 'http://<%=server%>:<%=port%><%-progressMilestones.startPartitionUri%>' || true;
<%_ } _%>

d-i partman-auto/disk string <%=installDisk%>
d-i partman-auto/method string lvm

d-i partman-lvm/device_remove_lvm boolean true
d-i partman-md/device_remove_md boolean true
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true

d-i partman-auto/init_automatically_partition \
	select Guided - use entire disk and set up LVM

d-i partman-auto-lvm/guided_size string max
d-i partman-auto-lvm/new_vg_name string vg00
#d-i partman-auto/choose_recipe select atomic
# recipe should be a template substitiution
d-i partman-auto/choose_recipe select /lib/partman/recipes/30atomic
#d-i partman-auto/expert_recipe string                         \
#      boot-root ::                                            \
#              64 128 128 ext4                                 \
#                      $primary{ } $bootable{ }                \
#                      method{ format } format{ }              \
#                      use_filesystem{ } filesystem{ ext4 }    \
#                      mountpoint{ /boot }                     \
##              .                                               \
#              128 512 200% linux-swap                         \
#                      method{ swap } format{ }                \
#              .                                               \
#              512 512 512 ext4                                \
#                      method{ format } format{ } $lvmok{ }    \
#                      use_filesystem{ } filesystem{ ext4 }    \
#                      mountpoint{ / }                         \
##              .                                               \
#              256 256 256 ext4                                \
#                      method{ format } format{ } $lvmok{ }    \
#                      use_filesystem{ } filesystem{ ext4 }    \
#                      mountpoint{ /home }                     \
#              .                                               \
#              256 512 512 ext4                                \
#                      method{ format } format{ } $lvmok{ }    \
#                      use_filesystem{ } filesystem{ ext4 }    \
#                      mountpoint{ /tmp }                      \
#              .                                               \
#              2048 4096 4096 ext4                             \
#                      method{ format } format{ } $lvmok{ }    \
#                      use_filesystem{ } filesystem{ ext4 }    \
#                      mountpoint{ /usr }                      \
#              .                                               \
#              2048 4096 -1 ext4                               \
#                      method{ format } format{ } $lvmok{ }    \
#                      use_filesystem{ } filesystem{ ext4 }    \
#                      mountpoint{ /var }                      \
#              .
#
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


# If you just want to change the default filesystem from ext3 to something
# else, you can do that without providing a full recipe.
d-i partman/default_filesystem string ext4

### Account setup
# Skip creation of a root account (normal user account will be able to
# use sudo). The default is false; pretemplate this to true if you want to set
# a root password.
d-i passwd/root-login boolean true
# Alternatively, to skip creation of a normal user account.
d-i passwd/make-user boolean false

# Root password, either in clear text
# or encrypted using an MD5 hash.
d-i passwd/root-password-crypted password <%=rootEncryptedPassword%>

### Package selection
tasksel tasksel/first multiselect ubuntu-server

# Individual additional packages to install
<% var pkgs = ((typeof kvm === 'undefined' || !kvm) ? '' : 'qemu-kvm virt-manager libvirt0 python-libvirt bridge-utils') -%>
# Minimum packages (see postinstall.sh)
d-i pkgsel/include string openssh-server wget curl ssl-cert vlan
d-i pkgsel/upgrade select safe-upgrade
d-i pkgsel/update-policy select none
d-i pkgsel/language-packs multiselect en
d-i pkgsel/install-language-support boolean false
# Policy for applying updates. May be "none" (no automatic updates),
# "unattended-upgrades" (install security updates automatically), or
# "landscape" (manage system with Landscape).
d-i pkgsel/update-policy select none

# This is fairly safe to set, it makes grub install automatically to the MBR
# if no other operating system is detected on the machine.
d-i grub-installer/only_debian boolean true

# This one makes grub-installer install to the MBR if it also finds some other
# OS, which is less safe as it might not be able to boot that other OS.
d-i grub-installer/with_other_os boolean true

d-i grub-installer/bootdev string <%=installDisk%>

# Avoid that last message about the install being complete.
d-i finish-install/reboot_in_progress note

# Monitor autodetection is recommended.
xserver-xorg xserver-xorg/autodetect_monitor boolean true
#### Advanced options
### Running custom commands during the installation
# d-i preseeding is inherently not secure. Nothing in the installer checks
# for attempts at buffer overflows or other exploits of the values of a
# preconfiguration file like this one. Only use preconfiguration files from
# trusted locations! To drive that home, and because it's generally useful,
# here's a way to run any shell command you'd like inside the installer,
# automatically.

# This first command is run as early as possible, just after
# preseed is read.
#d-i preseed/early_command string anna-install some-udeb
# This command is run immediately before the partitioner starts. It may be
# useful to apply dynamic partitioner preseeding that depends on the state
# of the disks (which may not be visible when preseed/early_command runs).
#d-i partman/early_command
#       string debconf-set partman-auto/disk "$(list-devices disk | head -n1)"
# This command is run just before the install finishes, but when there is
# still a usable /target directory. You can chroot to /target and use it
# directly, or use the apt-install and in-target commands to easily install
# packages and run commands in the target system.
#d-i preseed/late_command string apt-install zsh; in-target chsh -s /bin/zsh

d-i preseed/late_command string \
<%_ if( typeof progressMilestones !== 'undefined' && progressMilestones.postConfigUri ) { _%>
in-target curl -X POST -H 'Content-Type:application/json' 'http://<%=server%>:<%=port%><%-progressMilestones.postConfigUri%>' || true; \
<%_ } _%>

#enable root ssh
in-target sed -i 's/PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config; \

#Enable Network standards that supports VLANs
#Load the 8021q module into the kernel
in-target modprobe 8021q; \
in-target su -c 'echo "8021q" >> /etc/modules'; \

#config vlan
<%_ if (typeof networkDevices !== 'undefined' && networkDevices.length > 0) { _%>
<%_ networkDevices.forEach(function(n) { _%>
    <%_ for (p in n) { _%>
        <%_ ip = n[p]; _%>
        <%_ if (['ipv4','ipv6'].indexOf(p) === -1 || undefined == ip) continue; _%>
        <%_ if (undefined !== ip.vlanIds) { _%>
            <%_ ip.vlanIds.forEach(function(vid) { _%>
in-target vconfig add ip.device <%=vid%>; \
            <%_ }); _%>
        <%_ } _%>
    <%_ } _%>
<%_ }); _%>
wget http://<%=server%>:<%=port%>/api/current/templates/ubuntu-interfaces?nodeId=<%=nodeId%> -O /etc/network/interfaces; \
<%_ } _%>
in-target wget http://<%=server%>:<%=port%>/api/current/templates/post-install-ubuntu.sh?nodeId=<%=nodeId%> -O ./post-install.sh; \
in-target chmod +x ./post-install.sh; \
in-target ./post-install.sh; \
in-target wget http://<%=server%>:<%=port%>/api/current/templates/ubuntu-sources?nodeId=<%=nodeId%> -O /etc/apt/sources.list; \
in-target wget http://<%=server%>:<%=port%>/api/current/templates/<%=rackhdCallbackScript%>?nodeId=<%=nodeId%> -O /etc/rc2.d/S99callback; \
in-target chmod +x /etc/rc2.d/S99callback; \
in-target curl -X POST -H 'Content-Type:application/json' http://<%=server%>:<%=port%>/api/current/notification?nodeId=<%=nodeId%>
