more parametrization in preseed.cfg, automagically get user values from terom + prompt for password
--- a/pkvlm-create Thu Jan 05 16:47:04 2012 +0200
+++ b/pkvlm-create Fri Jan 27 10:39:08 2012 +0200
@@ -155,7 +155,9 @@
define_opt ip $(resolve_name ${opt_name}.${opt_dns_domain})
fi
-### State
+
+
+### Preseed content
## Guest info
GUEST_NAME=$opt_name
@@ -182,10 +184,58 @@
GUEST_DISK=$opt_guest_disk
## Network
+# Network configuration, for /etc/network/interfaces
+NET_DOMAIN=paivola.fi
NET_HOSTNAME=$opt_hostname
NET_BRIDGE=$opt_bridge
NET_IPADDR=$opt_ip
+NET_NETMASK=255.255.255.0
+NET_GATEWAY=194.197.235.1
+NET_NAMESERVERS=( 194.197.235.210 194.197.235.252 )
+## Clock/time
+TIME_ZONE='Europe/Helsinki'
+
+# only used during install, not stored in target
+TIME_NTP_SERVER=ntp.paivola.fi # XXX: harcoded
+
+## User account
+function getent_user_attr () {
+ local user=$1
+ local db=$2
+ local attr=$3
+
+ line=$(getent $db $user) || die "Unable to read $db database for $user"
+
+ echo "$line" | cut -d ':' -f $attr
+}
+function user_fullname () {
+ local user=$1
+
+ getent_user_attr $user passwd 5
+}
+function user_shadow () {
+ local user=$1
+
+ if [ $UID -eq 0 ]; then
+ log_debug "Get user password from shadow: $user"
+ getent_user_attr $user shadow 2
+ else
+ echo -n "Install target login ($user) " >&2
+ mkpasswd -m sha-512
+ fi
+}
+
+# XXX: hardcoded
+USER_CREATE='true'
+USER_NAME=$USER
+USER_FULLNAME=$(user_fullname $USER_NAME)
+USER_SHADOW=$(user_shadow $USER_NAME)
+USER_GROUPS=(cdrom sudo adm)
+
+
+
+### Installer setup
## Installation image
# Original Debian Installer image (iso)
INSTALLER_NAME="debian-6.0.3-amd64"
@@ -200,29 +250,32 @@
INSTALL_TREE="images/${INSTALL_NAME}"
INSTALL_ISO="iso-out/${INSTALL_NAME}.iso"
+## Preseed files
# Preseed output file in install tree
+PRESEED_NAME="preseed.cfg"
# Preseed source template
-PRESEED_NAME="preseed.cfg"
PRESEED_TEMPLATE="preseed/${PRESEED_NAME}"
PRESEED_FILE="${INSTALL_TREE}/${PRESEED_NAME}"
PRESEED_ISOLINUX="preseed/isolinux.cfg"
PRESEED_INCLUDES=("preseed/passwords.cfg" "preseed/host.cfg")
-
PRESEED_CHECKSUM= # set later
# installer boot args
INSTALL_BOOT_ARGS="auto=true priority=critical preseed/file=/cdrom/${PRESEED_NAME} preseed/file/checksum=${PRESEED_CHECKSUM} -- quiet console=ttyS0"
-## External progs
-# Bootable .iso for Debian isolinux-based installer CDs
+
+
+### External progs
+## Bootable .iso for Debian isolinux-based installer CDs
GENISOIMAGE=/usr/bin/genisoimage
GENISOIMAGE_OPTS="-r -J -no-emul-boot -boot-load-size 4 -boot-info-table -b isolinux/isolinux.bin -c isolinux/boot.cat"
-# LVM
+## LVM
LVM=/sbin/lvm
-# Libvirt --connect URL
+## Libvirt
+# --connect URL
LIBVIRT=qemu:///system
VIRSH=/usr/bin/virsh
@@ -233,13 +286,15 @@
# type of guest to create
LIBVIRT_TYPE=kvm
-# virt-install
+## virt-install
VIRT_INSTALL="/usr/bin/virt-install"
## SELinux?
#SEMANAGE=/usr/sbin/semanage
#RESTORECON=/sbin/restorecon
+
+
### Prepare
if [ $DO_SHOWSPEC ]; then
cat <<END
@@ -269,6 +324,11 @@
Bridge:
Name: $NET_BRIDGE
+User:
+ username: $USER_NAME
+ fullname: $USER_FULLNAME
+ shadow: $USER_SHADOW
+
Installer:
Name: $INSTALLER_NAME
ISO: $INSTALLER_ISO
@@ -295,11 +355,6 @@
# Parameters given?
[ -z $NET_IPADDR ] && die "net: No IP-address given: ip"
-# VM exists?
-if cmd virsh domid ${GUEST_NAME} > /dev/null 2> /dev/null; then
- die "Virtual machine already exists: ${GUEST_NAME}"
-fi
-
# Installer exists?
if cmd test ! -f ${INSTALLER_ISO}; then
die "Installer not found: ${INSTALLER_ISO}"
@@ -351,6 +406,12 @@
### Create virtual machine
if [ $DO_VIRTINSTALL ]; then
+ ## Check
+ # VM exists?
+ if cmd virsh domid ${GUEST_NAME} > /dev/null 2> /dev/null; then
+ die "Virtual machine already exists: ${GUEST_NAME}"
+ fi
+
## Disk
# Create LV (unless it already exists)
[ -e $DISK_PATH ] || cmd_confirm sudo $LVM lvcreate -L $DISK_SIZE -n $DISK_NAME $DISK_VG
--- a/preseed/preseed.cfg Thu Jan 05 16:47:04 2012 +0200
+++ b/preseed/preseed.cfg Fri Jan 27 10:39:08 2012 +0200
@@ -38,11 +38,11 @@
## Static network configuration.
# XXX: this is for asdf.paivola.fi
d-i netcfg/get_hostname string {NET_HOSTNAME}
-d-i netcfg/get_domain string paivola.fi
+d-i netcfg/get_domain string {NET_DOMAIN}
d-i netcfg/get_ipaddress string {NET_IPADDR}
-d-i netcfg/get_netmask string 255.255.255.0
-d-i netcfg/get_gateway string 194.197.235.1
-d-i netcfg/get_nameservers string 194.197.235.210 194.197.235.252
+d-i netcfg/get_netmask string {NET_NETMASK}
+d-i netcfg/get_gateway string {NET_GATEWAY}
+d-i netcfg/get_nameservers string {NET_NAMESERVERS[*]}
d-i netcfg/confirm_static boolean true
# Disable that annoying WEP key dialog?
@@ -87,8 +87,9 @@
### Account setup
# Skip creation of a root account (normal user account will be able to use sudo).
#d-i passwd/root-login boolean false
-# Alternatively, to skip creation of a normal user account.
-#d-i passwd/make-user boolean false
+
+# Alternatively, to skip creation of a normal user account, set to false
+d-i passwd/make-user boolean {USER_CREATE}
# Root password, MD5 hash
# $ printf "r00tme" | mkpasswd -s -m md5
@@ -96,33 +97,37 @@
#d-i passwd/root-password-crypted password [MD5 hash]
# To create a normal user account.
-d-i passwd/user-fullname string Tero Marttila
-d-i passwd/username string terom
+d-i passwd/user-fullname string {USER_FULLNAME}
+d-i passwd/username string {USER_NAME}
+
# From passwords.cfg
#d-i passwd/user-password-crypted password [MD5 hash]
+
# Create the first user with the specified UID instead of the default.
#d-i passwd/user-uid string 1010
# The user account will be added to some standard initial groups. To
# override that, use this.
-d-i passwd/user-default-groups string cdrom sudo adm
+d-i passwd/user-default-groups string {USER_GROUPS[*]}
### Clock and time zone setup
# Controls whether or not the hardware clock is set to UTC.
-d-i clock-setup/utc boolean true
+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 Europe/Helsinki
+d-i time/zone string {TIME_ZONE}
# Use NTP during install
-d-i clock-setup/ntp boolean true
+d-i clock-setup/ntp boolean true
# NTP server to use
-d-i clock-setup/ntp-server string ntp.paivola.fi
+d-i clock-setup/ntp-server string {TIME_NTP_SERVER}
+
+
### Partitioning
#