#
#Generic Kickstart template for Ubuntu
#Platform: x86 and x86-64
#
# Customized for xubuntu 14.04 minimal vm install
#
# Usage:
# - Look through config for any changes you want to do. You may want to change
#   the initial admin user. Currently username is "alid" and password is
#   "ChangeMe". Also may want to change the list of installed packages. Tried to
#   keep it as minimal as possible.
# - Place this somewhere that the vm will be able to see. Web server on LAN
#   would work best.
# - OPTIONAL: If you are going to make a bunch of these then may want to setup
#   a local apt proxy. Install apt-cacher-ng on some system and edit the line
#   below.
# - Create a vm with 8gb drive. You can make a larger one but should have 8
#   minimum. Also tip for people setting up in vmware the kernel has support
#   for VMXNET3 compiled in so you can use it for initial install.
# - Boot up from iso.
# - Hit F4 and choose 'Install a minimal virtual machine'
#   - This is required even though we set it below.
# - Press F6 and hit escape so you edit the boot line. Add the following to the
#   end before the --. For example if you did include the '--' the end of boot
#   line would be:
#
#       ks=http://your-server.example.com/ks-minimalvm.cfg ksdevice=eth0 --
# NOTE if installation fails change ksdevice=eth0 to ksdevice=eth1
#
# - That's it! It will grab an ip via dhcp on eth0 and setup the system.
#
# Tweaks:
# - Some people would argue I made too many partitions. Feel free to adjust if
#   you set things up differently. I highly recommend at least a /var and /home
#   to make sure neither of those filling up will halt the whole system.
# - After partitioning with an 8gb volume you'll have about 1gb left in lvm to
#   either expand one of the existing vms or to add a new partition. Again my
#   suggesting is a second drive for /opt and/or /srv. If you mess up the OS
#   you can unmount the second drive and mount it on a new vm that has the OS
#   rebuilt on it.
# - The post script adds the noatime,nodev to options. In some circumstances
#   you need the access time (most common use is the mail spool to know when
#   you last checked for mail). In those instances you may want to change it to
#   relatime for home and/or var.
# - The post script will set the default umask from 022 to 027. This means
#   files created will not be world-readable. This is good to have for security
#   but if you don't want that comment it out.
#
# License:
# I'm pretty sure this falls under being so small it's not copyrightable but
# just in case anyone is worried I am licensing this under creative commons
# CC-0 (public domain), the full license text is availabe at
# https://creativecommons.org/publicdomain/zero/1.0/
#
# References:
# - http://petersmithphotog.no-ip.biz/wiki/index.php/Unattended_Install
# - https://help.ubuntu.com/14.04/installation-guide/amd64/ch04s06.html
# - https://help.ubuntu.com/lts/installation-guide/i386/apbs01.html

# Load the minimal server preseed off cdrom
# This should be done when you follow directions above
### Minimal server VM
preseed preseed/file=/cdrom/preseed/ubuntu-server-minimalvm.seed

### Minimal server
#preseed preseed/file=/cdrom/preseed/ubuntu-server-minimal.seed

# Use proxy. Install apt-cacher-ng somewhere. Uncomment this and adjust the
# url as appropriate (default port is 3142)
#preseed mirror/http/proxy string http://192.168.1.2:3142/

# System language
lang it_IT

# Language modules to install
langsupport it_IT

# System keyboard
keyboard it

# System mouse
mouse

# System timezone
timezone Europe/Rome

# Root password
rootpw --disabled

# Initial user (will have sudo so no need for root)
#To skip initial user (root only).
#  user --disabled
#user jdoe --fullname "John Doe" --password hunter2
user alid --fullname "Amministratore" --password ChangeMe
user studente --fullname "Studente" --password studente

# Reboot after installation
reboot

# Use text mode install
text

# Install OS instead of upgrade
install

# Installation media
cdrom

# Ignore errors about unmounting current drive (happens if reinstalling)
# BUG: this just seems to default the selection to yes?
# Both without owner:
#preseed partman/unmount_active boolean true
# And with owner:
#preseed --owner partman-base partman/unmount_active boolean true
# When I run the debconf-get-selections --installer it shows the owner as unknown

# System bootloader configuration
bootloader --location=mbr

# Clear the Master Boot Record
zerombr yes

# Partition clearing information
clearpart --all --initlabel

# Alternatively, you may specify a disk to partition. If the system has only
# one disk the installer will default to using that, but otherwise the device
# name must be given in traditional, non-devfs format (so e.g. /dev/hda or
# /dev/sda, and not e.g. /dev/discs/disc0/disc).
# For example, to use the first SCSI/SATA hard disk:
#d-i partman-auto/disk string /dev/sda
# In addition, you'll need to specify the method to use.
# The presently available methods are:
# - regular: use the usual partition types for your architecture
# - lvm:     use LVM to partition the disk
# - crypto:  use LVM within an encrypted partition
preseed partman-auto/method string regular

# You can choose one of the three predefined partitioning recipes:
# - atomic: all files in one partition
# - home:   separate /home partition
# - multi:  separate /home, /usr, /var, and /tmp partitions
preseed partman-auto/choose_recipe select atomic


# Advanced partition
# The last lv specified will take up the remaining space of the vg. To get
# around that add up all your disk sizes and set this value. It appears to
# factor in the size of non lvm partitions as well.
#preseed partman-auto-lvm/guided_size string 7680MB
#part /boot --fstype=ext4 --size=512 --asprimary
#part pv.1 --grow --size=1 --asprimary
#volgroup vg0 --pesize=4096 pv.1
#logvol / --fstype=ext4 --name=root --vgname=vg0 --size=1024
#logvol /usr --fstype=ext4 --name=usr --vgname=vg0 --size=2048
#logvol /var --fstype=ext4 --name=var --vgname=vg0 --size=1536
#logvol swap --name=swap --vgname=vg0 --size=2048 --maxsize=2048
#logvol /home --fstype=ext4 --name=home --vgname=vg0 --size=512

# The full recipe format is documented in the file partman-auto-recipe.txt
# included in the 'debian-installer' package or available from D-I source
# repository. This also documents how to specify settings such as file
# system labels, volume group names and which physical devices to include
# in a volume group.

# This makes partman automatically partition without confirmation, provided
# that you told it what to do using one of the methods above.
preseed partman-partitioning/confirm_write_new_label boolean true
preseed partman/choose_partition select finish
preseed partman/confirm boolean true
preseed partman/confirm_nooverwrite boolean true

# Don't install recommended items by default
preseed base-installer/install-recommends boolean false

#Setup NTP
preseed clock-setup/ntp boolean true
preseed clock-setup/ntp-server string pool.ntp.org

# System authorization infomation
# The enablemd5 has to be there although it will still use salted sha256
auth  --useshadow  --enablemd5

# Network information
# network devices are detected randomly so we set dhcp for both
# NOTE if installation fails change ksdevice=eth0 to ksdevice=eth1
network --bootproto=dhcp 
#network --bootproto=dhcp --device=eth0 
#network --device=eth1 --bootproto=static --ip=192.168.56.254 --netmask=255.255.255.0 \
#        --nameserver=192.168.56.1 --gateway=192.168.56.1
#
# If you want to force a hostname, regardless of what either the DHCP
# server returns or what the reverse DNS entry for the IP is, uncomment
# and adjust the following line.
preseed netcfg/hostname string alidtux

# Firewall configuration
firewall --disabled --trust=eth0 --ssh

# Policy for applying updates. May be "none" (no automatic updates),
# "unattended-upgrades" (install security updates automatically), or
# "landscape" (manage system with Landscape).
preseed pkgsel/update-policy select unattended-upgrades

# Do not configure the X Window System
#skipx

# Additional packages to install
# - Uncomment the open-vm-tools line if this is going to run in vmware and are
#   not going to use vmware-tools that's distributed with it. Don't think the
#   --no-install-recommends is needed to not install desktop tools but doesn't
#   hurt anything
%packages
# Since I don't install recommended it leaves out some things that should
# probably be installed like openssl and python 2.7
ca-certificates
openssl
python
wget
tcpd
# End all the recommended packages that are still useful
openssh-server
#open-vm-tools --no-install-recommends
curl
screen
vim
iptables
#Xorg
xserver-xorg 
xserver-xorg-core 
xfonts-base 
xinit 
x11-xserver-utils
# XFCE metapackage (or single selection)
xubuntu-desktop
#xfwm4 
#xfce4-panel 
#xfce4-settings 
#xfce4-session 
#xfce4-terminal 
#xfdesktop4 
#xfce4-taskmanager 
#tango-icon-theme

# DM
lightdm 
lightdm-gtk-greeter

#Educational meta-package
edubuntu-desktop

# file manager
thunar
# manage USB keys
gvfs 
gvfs-backends 
policykit-1 
udisks2 
#gstreamer + pulseaudio
gstreamer0.10-plugins-base 
gstreamer0.10-plugins-good 
gstreamer0.10-plugins-bad 
pulseaudio 
gstreamer0.10-pulseaudio 
pavucontrol
#Firefox
firefox
firefox-gnome-support
firefox-locale-en
firefox-locale-it

#Flash player
flashplugin-installer
#dkms?
dkms
# libreoffice
libreoffice 

gcompris
gcompris-data          
gcompris-sound-en

%post --nochroot
%end

%post
# Why vim doens't just set background=dark by default is beyond me
echo "set background=dark" >>/etc/vim/vimrc.local

# Change default umask from 022 to 027 (not world readable). Remove this line
# if you don't want that
sed -i -e 's/^\(UMASK\W*\)[0-9]\+$/\1027/' /etc/login.defs

# customize guest session
# https://help.ubuntu.com/community/CustomizeGuestSession
#

# This is the trick — automatically switch to 6th console
# and redirect all input/output
exec < /dev/tty6 > /dev/tty6 2> /dev/tty6
chvt 6

echo "I need input here"
read value

echo "you gave me $value"

# We can break into a shell prompt
/bin/sh

# Or even run a python script
#python << __EOF__
# Any other Python code can come here
#print "This is pre-install shell"
#__EOF__

# Then switch back to Anaconda on the first console
chvt 1
exec < /dev/tty1 > /dev/tty1 2> /dev/tty1


# Clean up
apt-get -qq -y autoremove
apt-get clean
rm -f /var/cache/apt/*cache.bin
rm -f /var/lib/apt/lists/*
