Table of contents
- 1. Use TurnKey Core to apply and develop patches
- 2. Updating the configuration console usage text
- 3. Configuring a custom hostname
- 4. Enabling a repository (ie. component)
- 5. Preseeding a Debian package
- 6. Inithooks
- 7.
- 8. Functions (for use with tklpatch .92+)
- 8.1. Install:
- 8.2. Install .tar.gz:
- 8.3. Cleanup apt-get:
Use TurnKey Core to apply and develop patches
While you can install tklpatch on any system that has the required dependencies we recommend using TurnKey Core in a VM if possible because it is verified to work. Different versions of the tklpatch's dependencies on other systems (e.g., Gentoo) may behave a bit differently and break things. Also this way you can avoid issues created by conflicts between servers on your development box (e.g., MySQL or PostgreSQL) and the patch chroot.
Updating the configuration console usage text
The recommended way is to use the overlay, as its simpler than tweaking the file using something like sed, and less error prone. The confconsole usage template is located at:
/etc/confconsole/usage.txt
Configuring a custom hostname
It's a nice touch to set a custom hostname that is more specific to the appliance being created:
HOSTNAME=newname echo "$HOSTNAME" > /etc/hostname sed -i "s|127.0.1.1 \(.*\)|127.0.1.1 $HOSTNAME|" /etc/hosts
Enabling a repository (ie. component)
If there is a need to enabled a repository that is currently disabled by default (such as multiverse), it can be done like this:
APT_SOURCES=/etc/apt/sources.list.d sed -i "/hardy multiverse/ s/# //" $APT_SOURCES/sources.list # note, you might also want to uncomment updates and security sed -i "/hardy-updates multiverse/ s/# //" $APT_SOURCES/sources.list sed -i "/hardy-security multiverse/ s/# //" $APT_SOURCES/security.sources.list
Preseeding a Debian package
Preseeding provides a way to set answers to questions asked during the package installation process, without having to manually enter the answers while the installation is running. This makes it possible to fully automate package installation.
The following example would accept license of the sun-java6 packages:
debconf-set-selections << END sun-java6-jdk shared/accepted-sun-dlj-v1-1 boolean true sun-java6-jre shared/accepted-sun-dlj-v1-1 boolean true sun-java6-bin shared/accepted-sun-dlj-v1-1 boolean true END
Inithooks
A simple initialization mechanism built into all TurnKey appliances. What it does is provide the means to run various configuration and initialization scripts on first boot.
http://code.turnkeylinux.org/inithooks/docs/README
You want each instance to have a unique set of secret keys (e.g., SSH, SSL). You also want to have a way to set passwords for various accounts.
If you're installing a TurnKey appliance via the Live CD build target then there's an interactive installer that can do that for you, but in a VM deployment scenario you don't have an installer - so to get around
that inithooks is configured to trigger these installer hooks on first boot.
Currently we are including the following hooks:
/usr/lib/inithooks/firstboot.d/
20live-installer - executes the live-installer scripts
30rootpass - sets the root password
30mysqlpass* - sets the mysql root password
30pgsqlpass* - sets the pgsql postgres password
* - only included in appliances when relevant
For example, here's what the firstboot scripts look like for the TurnKey
LAMP appliance::
$ cd /usr/lib/inithooks/firstboot.d
$ ls
20live-installer 30mysqlpass 30rootpass
$ cat 20live-installer
#!/bin/sh
. /etc/default/inithooks
. $INITHOOKS_PATH/functions
exec_scripts /usr/lib/live-installer.d
$ cd /usr/lib/live-installer.d
$ ls
20regen-sshkeys 25regen-sslcert 40regen-pmapass 90unset_firstboot
Configuring passwords
Passwords can be configured through /etc/inithooks.conf, which is just a shell script fragment that is sourced from inithooks and provides arguments to the executed hooks.
Example /etc/inithooks.conf::
export ROOTPASS=p4ssw0rd
export MYSQLPASS=myp4ss
export PGSQLPASS=pgp4ss
Note that in most cases you probably don't want to leave /etc/inithooks.conf around after initialization. You can take care of that with a clean-up script::
cat > /usr/lib/inithooks/firstboot.d/99cleanup<<EOF
#!/bin/sh
rm -f /etc/inithooks.conf
EOF
chmod +x /usr/lib/inithooks/firstboot.d/99cleanup
Functions (for use with tklpatch .92+)
Install:
install()
{
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get -y \
-o DPkg::Options::=--force-confdef \
-o DPkg::Options::=--force-confold \
install $@
}
Install .tar.gz:
(works only if .tar.gz extracts to a single directory)
#args: file_to_extract, destination
#ex: install_targz /tmp/MyApp.tar.gz /usr/share/myapp
install_targz()
{
tar zxvf $1 -C /tmp
mkdir $2
mv /tmp/$(tar tf $1 | head -1)/* $2
rm -r /tmp/$(tar tf $1 | head -1)
}
Cleanup apt-get:
usefull for reducing the size of the generated iso.
cleanup_apt()
{
rm -r /var/cache/apt/*
mkdir /var/cache/apt/archives
mkdir /var/cache/apt/archives/partial
}
If you have come across any tips that helped you during development, please consider adding them here.

Comments