#!/bin/sh
#
# Johan Adler, May 8, 2011
# alltid@nyfiken.org
#
# Modify Debian netboot.tar.gz for devices using serial console. Hardcoded for
# ttyS0, modify variable SER_PORT if your device will use other ports for
# console. According to the SYSLINUX page acceptable values are 0-3.
#
# This script expects to be executed in the same directory as the tarball
# netboot.tar.gz and will untar this tarball, make the necessary modifications
# and create a new tarball under the name netboot-ttySx.tar.gz where x is
# the number of the serial port.
#
# Tested and working with stable and testing releases of Debian as of 2011-05-08,
# downloaded from the following URL's:
#
# http://ftp.debian.org/debian/dists/stable/main/installer-i386/current/images/netboot/netboot.tar.gz
# http://ftp.debian.org/debian/dists/testing/main/installer-i386/current/images/netboot/netboot.tar.gz
# http://people.debian.org/~joeyh/d-i/images/daily/netboot/netboot.tar.gz
#
###
#	License
###
#     This program is free software: you can redistribute it and/or modify
#     it under the terms of the GNU General Public License as published by
#     the Free Software Foundation, either version 3 of the License, or
#     (at your option) any later version.
#
#     This program is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#     GNU General Public License for more details.
#
#     You should have received a copy of the GNU General Public License
#     along with this program.  If not, see <http://www.gnu.org/licenses/>.

SER_PORT=0

mkdir netboot
cd netboot
tar xzf ../netboot.tar.gz
cd debian-installer/i386/boot-screens/
mv syslinux.cfg syslinux.cfg.old
sed "1a\serial $SER_PORT 38400\nconsole 0" syslinux.cfg.old > syslinux.cfg
rm syslinux.cfg.old
for CONF_FILE in adtxt.cfg rqtxt.cfg txt.cfg
do
	mv $CONF_FILE $CONF_FILE.old
	sed "s/vga=788/console=ttyS$SER_PORT,38400n8/" $CONF_FILE.old > $CONF_FILE
	rm $CONF_FILE.old
done
cd ../../..
tar czf ../netboot-ttyS$SER_PORT.tar.gz .
cd ..
rm -r netboot/
