aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2013-08-23 03:39:52 +0000
committerbnewbold <bnewbold@robocracy.org>2013-08-23 03:39:52 +0000
commitbc5deea8babc17d472f21c20a0dfb20c7f3fd471 (patch)
tree7d281753d1012f8c91b74f53711abc98f7abe653
parenteffcecdd8d10e2e94ad80bc8f552bf53bb4b7f59 (diff)
downloadbuildroot-novena-bc5deea8babc17d472f21c20a0dfb20c7f3fd471.tar.gz
buildroot-novena-bc5deea8babc17d472f21c20a0dfb20c7f3fd471.zip
initial import of 'polystrap' debian tool
From http://anonscm.debian.org/gitweb/?p=emdebian/polystrap.git;a=summary This imports 83ba112abb8f173254c60611b5a24ca0a72ca58f, from from Tue, 9 Oct 2012 15:36:02 -0400 (21:36 +0200)
-rw-r--r--polystrap/README156
-rw-r--r--polystrap/TODO6
-rw-r--r--polystrap/default/config4
-rw-r--r--polystrap/default/debconfseed.txt23
-rw-r--r--polystrap/default/hooks/create_user2
-rw-r--r--polystrap/default/hooks/empty_password2
-rw-r--r--polystrap/default/hooks/firstboot23
-rw-r--r--polystrap/default/hooks/serial_tty1
-rw-r--r--polystrap/default/multistrap.conf22
-rw-r--r--polystrap/default/packages/audio5
-rw-r--r--polystrap/default/packages/base12
-rw-r--r--polystrap/default/packages/bluez4
-rw-r--r--polystrap/default/packages/games4
-rw-r--r--polystrap/default/packages/net12
-rw-r--r--polystrap/default/packages/wlan2
-rw-r--r--polystrap/default/packages/xorg5
-rw-r--r--polystrap/default/root/etc/apt/apt.conf.d/99no-install-recommends1
-rw-r--r--polystrap/default/root/etc/apt/apt.conf.d/99no-pdiffs1
-rw-r--r--polystrap/default/root/etc/fstab8
-rw-r--r--polystrap/default/root/etc/hostname1
-rw-r--r--polystrap/default/root/etc/hosts2
-rw-r--r--polystrap/default/root/etc/ld.so.conf2
-rw-r--r--polystrap/default/root/etc/network/interfaces2
-rw-r--r--polystrap/default/root/etc/ssh/ssh_host_dsa_key0
-rw-r--r--polystrap/default/root/etc/ssh/ssh_host_ecdsa_key0
-rw-r--r--polystrap/default/root/etc/ssh/ssh_host_rsa_key0
-rwxr-xr-xpolystrap/default/root/usr/sbin/policy-rc.d3
-rwxr-xr-xpolystrap/polystrap-nb58
-rwxr-xr-xpolystrap/polystrap.sh181
29 files changed, 542 insertions, 0 deletions
diff --git a/polystrap/README b/polystrap/README
new file mode 100644
index 000000000..a781bfcad
--- /dev/null
+++ b/polystrap/README
@@ -0,0 +1,156 @@
+Polystrap is a tool to create a foreign architecture rootfs without needing
+superuser privileges by using multistrap, fakeroot, fakechroot and qemu user
+mode emulation from the qemu-user package.
+
+
+QEMU USER MODE
+==============
+
+qemu >= 1.0 is required for this to work out of the box. For older qemu
+versions, the (now outdated) instructions in the rest of this section:
+
+To make qemu user mode emulation work you need to install the packages
+qemu-user and binfmt-support. Until bug #632192 is fixed you will have to
+provide properly filled /etc/qemu-binfmt/$arch/ directories. $arch is a qemu
+arch (eg: arm for arm, armel and armhf). "properly filled" means, that you have
+to provide a root directory tree in that directory that fits the architecture
+you want to bootstrap debian for. There are a couple of ways to achieve that:
+
+1. manually download and `dpkg -x` the required packages into
+/etc/qemu-binfmt/$arch/
+
+2. copy over a just extracted multistrap run for your target system into
+/etc/qemu-binfmt/$arch/
+
+3. run the following multistrap.conf, configured for your target system to
+create a root directory tree that you copy into /etc/qemu-binfmt/$arch/
+
+-%<----------------------------
+[General]
+arch=
+directory=
+cleanup=true
+unpack=true
+noauth=true
+aptsources=Debian
+bootstrap=Debian
+allowrecommends=false
+addimportant=false
+omitrequired=true
+
+[Debian]
+packages=libc6 libselinux1 libacl1 man-db libstdc++6 libfreetype6 libx11-6 libfontconfig1
+source=http://cdn.debian.net/debian
+suite=sid
+omitdebsrc=true
+-%<----------------------------
+
+You can also avoid all this trouble by either waiting for #632192 to be fixed
+or by applying the patch from there to qemu.
+
+Since support for QEMU_LD_PREFIX has now been added upstream it is now already
+part of polystrap.sh
+
+
+FAKEROOT/FAKECHROOT
+===================
+
+Additionally you will need to have copies of libfakechroot.so and
+libfakeroot-sysv.so for your target architecture in /usr/lib/<arch-triplet>/.
+Get the debian packages of fakeroot and fakechroot for your target architecture
+and copy the shared libraries into /usr/lib/<arch-triplet>/. For example for
+armel do:
+
+sudo mkdir -p /usr/lib/arm-linux-gnueabi/
+wget http://ftp.debian.org/debian/pool/main/f/fakeroot/fakeroot_1.18.1-1_armel.deb
+dpkg-deb --fsys-tarfile fakeroot_1.14.5-1_armel.deb | sudo tar -xf - --strip-components=4 -C /usr/lib/arm-linux-gnueabi/ ./usr/lib/libfakeroot/libfakeroot-sysv.so
+wget http://ftp.debian.org/debian/pool/main/f/fakechroot/libfakechroot_2.15-1_armel.deb
+dpkg -x libfakechroot_2.15-1_armel.deb /
+
+Alternatively, since libfakechroot is multiarch you can also do:
+
+apt-get install libfakechroot:armel
+
+if your system supports it instead of the last two lines.
+
+
+INNER WORKINGS
+==============
+
+While I wanted to build without superuser privileges, multistrap would never
+offer mechanisms that would allow me to do so. Hence I wrote this script which
+wraps multistrap. Since I wanted to keep it as simple as possible, a fully
+functional polystrap will need nothing more than a multistrap.conf, a hooks
+directory and a rootfs tree skeleton. Stuff like packages directory, and config
+file are optional and can be replaced by editing multistrap.conf and passing
+commandline options. Without comments the scripts is currently around 120 lines
+and I have no intention to make it much more complex.
+
+Polystrap is invoked as such:
+
+ ./polystrap.sh BOARD
+
+BOARD is a directory that at least contains a multistrap.conf. The
+multistrap.conf may contain variables from polystrap.sh.
+
+In the normal case BOARD will contain some additional bits.
+
+ BOARD/config - A file that is sourced by ./polystrap.sh and
+ contains variable declarations like:
+ SUITE - stable, testing, unstable
+ ARCH - armel, armhf, amd64, i386
+ ROOTDIR - where the rootfs is created
+ MIRROR - debian mirror to use for packages
+ The file is not strictly needed because the options
+ can also be set by commandline arguments and the
+ script will fall back to ./default/config.
+ Correct settings for ARCH and ROOTDIR are necessary
+ for proper operation, whereas other parameters are
+ only used if your multistrap.conf references them.
+ BOARD/debconfseed.txt - as the name suggests
+ BOARD/hooks - A directory that contains files that are sourced by
+ polystrap after packages are installed.
+ BOARD/packages - Contains files with one debian package per line.
+ Grouping packages by that allows easier selection.
+ BOARD/root - Contains a rootfs tree that is copied to the target
+ directory after packages are unpacked by multistrap.
+
+Reasonable examples of how those pieces look like can be found in the defaults
+directory.
+
+Everything from the BOARD/config file can be overwritten by commandline
+options:
+
+ -s suite
+ -a arch
+ -d rootdir
+ -m mirror
+ -v verbose (set -x)
+ -f force (overwrite existing directories)
+
+Additionally the following option allows to specify a list of packages that is
+then used instead of the contents of the BOARD/packages directory:
+
+ -p packages
+
+How the script works:
+
+ *) re-execute itself in fakeroot
+ *) source default/config
+ *) source BOARD/config
+ *) determine package selection by BOARD/packages or commandline argument
+ *) create multistrap.conf in /tmp from BOARD/multistrap.conf
+ *) run multistrap
+ *) copy contents of BOARD/root
+ *) copy qemu usermode binary
+ *) set debconf selections
+ *) run preinst scripts
+ *) configure packages
+ *) source BOARD/hooks
+ *) cleanup
+ *) generate tarball
+
+When creating a directory for a new target one can either just copy the defaut
+directory or use the ./newtarget.sh script which will use symlinks where it
+makes sense, will not copy the whole package selection and will set hostname
+according to the target name.
diff --git a/polystrap/TODO b/polystrap/TODO
new file mode 100644
index 000000000..ff64638aa
--- /dev/null
+++ b/polystrap/TODO
@@ -0,0 +1,6 @@
+ * create debian package
+ * resolve fakechroot bug #611156
+ * make qemu-user not trap itself in cyclic symlinks bug #636035
+ * if gconf2 is to be installed bug #636083
+ * have libfakeroot-sysv.so not in the libfakeroot subdirectory (no idea why
+ the linker doesnt find it otherwise - it works for fakechroot.so in subdir)
diff --git a/polystrap/default/config b/polystrap/default/config
new file mode 100644
index 000000000..78873f4d9
--- /dev/null
+++ b/polystrap/default/config
@@ -0,0 +1,4 @@
+SUITE="sid"
+ARCH="armel"
+ROOTDIR="debian-$SUITE-$ARCH-`date +%F`"
+MIRROR="http://cdn.debian.net/debian"
diff --git a/polystrap/default/debconfseed.txt b/polystrap/default/debconfseed.txt
new file mode 100644
index 000000000..8502a8d81
--- /dev/null
+++ b/polystrap/default/debconfseed.txt
@@ -0,0 +1,23 @@
+locales locales/locales_to_be_generated multiselect en_US.UTF-8 UTF-8
+locales locales/default_environment_locale select en_US.UTF-8
+tzdata tzdata/Zones/Australia select
+tzdata tzdata/Zones/US select
+tzdata tzdata/Zones/Asia select
+tzdata tzdata/Zones/Etc select UTC
+tzdata tzdata/Zones/SystemV select
+tzdata tzdata/Zones/Arctic select
+tzdata tzdata/Zones/Pacific select
+tzdata tzdata/Zones/Antarctica select
+tzdata tzdata/Zones/Europe select Berlin
+tzdata tzdata/Zones/Africa select
+tzdata tzdata/Zones/America select
+tzdata tzdata/Areas select Europe
+tzdata tzdata/Zones/Atlantic select
+tzdata tzdata/Zones/Indian select
+nodm nodm/xinit string /usr/bin/xinit
+nodm nodm/min_session_time string 60
+nodm nodm/enabled boolean true
+nodm nodm/xsession string /etc/X11/Xsession
+nodm nodm/x_options string vt7 -nolisten tcp
+nodm nodm/first_vt string 7
+nodm nodm/user string user
diff --git a/polystrap/default/hooks/create_user b/polystrap/default/hooks/create_user
new file mode 100644
index 000000000..0404ea23b
--- /dev/null
+++ b/polystrap/default/hooks/create_user
@@ -0,0 +1,2 @@
+fakechroot chroot $ROOTDIR useradd user -p `openssl passwd -crypt -salt // ""` -s /bin/bash --create-home
+fakechroot chroot $ROOTDIR usermod -a -G audio,dialout user
diff --git a/polystrap/default/hooks/empty_password b/polystrap/default/hooks/empty_password
new file mode 100644
index 000000000..1c486137a
--- /dev/null
+++ b/polystrap/default/hooks/empty_password
@@ -0,0 +1,2 @@
+sed -i 's/\(root:\)[^:]*\(:\)/\1'`openssl passwd -crypt -salt // "" | sed 's/\(\/\|\\\|&\)/\\\&/g'`'\2/' $ROOTDIR/etc/shadow
+sed -i 's/\(PermitEmptyPasswords\) no/\1 yes/' $ROOTDIR/etc/ssh/sshd_config
diff --git a/polystrap/default/hooks/firstboot b/polystrap/default/hooks/firstboot
new file mode 100644
index 000000000..7f1119e3c
--- /dev/null
+++ b/polystrap/default/hooks/firstboot
@@ -0,0 +1,23 @@
+cat > $ROOTDIR/etc/init.d/firstboot << __END__
+#!/bin/sh -e
+### BEGIN INIT INFO
+# Provides: firstboot
+# Required-Start: \$all
+# Required-Stop:
+# Default-Start: S
+# Default-Stop:
+### END INIT INFO
+
+for f in rsa dsa ecdsa; do rm -rf /etc/ssh/ssh_host_\${f}_key; done
+echo "generating ssh rsa key..."
+ssh-keygen -q -t rsa -f /etc/ssh/ssh_host_rsa_key -C "" -N ""
+echo "generating ssh dsa key..."
+ssh-keygen -q -t dsa -f /etc/ssh/ssh_host_dsa_key -C "" -N ""
+echo "generating ssh ecdsa key..."
+ssh-keygen -q -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -C "" -N ""
+
+update-rc.d -f firstboot remove
+__END__
+
+chmod +x $ROOTDIR/etc/init.d/firstboot
+fakechroot chroot $ROOTDIR update-rc.d firstboot start 99 S
diff --git a/polystrap/default/hooks/serial_tty b/polystrap/default/hooks/serial_tty
new file mode 100644
index 000000000..4066a7377
--- /dev/null
+++ b/polystrap/default/hooks/serial_tty
@@ -0,0 +1 @@
+echo "T0:23:respawn:/sbin/getty -L ttyS0 115200 vt100" >> $ROOTDIR/etc/inittab
diff --git a/polystrap/default/multistrap.conf b/polystrap/default/multistrap.conf
new file mode 100644
index 000000000..e914a7b26
--- /dev/null
+++ b/polystrap/default/multistrap.conf
@@ -0,0 +1,22 @@
+[General]
+arch=$ARCH
+directory=$ROOTDIR
+cleanup=true
+unpack=true
+noauth=true
+bootstrap=Debian_bootstrap
+aptsources=Debian
+allowrecommends=false
+addimportant=false
+
+[Debian_bootstrap]
+packages=$PACKAGES
+source=$MIRROR
+suite=$SUITE
+omitdebsrc=true
+
+[Debian]
+source=http://cdn.debian.net/debian
+keyring=debian-archive-keyring
+suite=$SUITE
+omitdebsrc=true
diff --git a/polystrap/default/packages/audio b/polystrap/default/packages/audio
new file mode 100644
index 000000000..0ee1b96c7
--- /dev/null
+++ b/polystrap/default/packages/audio
@@ -0,0 +1,5 @@
+alsa-base
+alsa-utils
+gstreamer-tools
+gstreamer0.10-plugins-base
+gstreamer0.10-plugins-good
diff --git a/polystrap/default/packages/base b/polystrap/default/packages/base
new file mode 100644
index 000000000..830cf70fa
--- /dev/null
+++ b/polystrap/default/packages/base
@@ -0,0 +1,12 @@
+udev
+kmod
+apt
+locales
+procps
+conspy
+man-db
+fbset
+openssh-server
+screen
+less
+vim
diff --git a/polystrap/default/packages/bluez b/polystrap/default/packages/bluez
new file mode 100644
index 000000000..5b306d277
--- /dev/null
+++ b/polystrap/default/packages/bluez
@@ -0,0 +1,4 @@
+bluez
+bluez-utils
+bluez-alsa
+bluez-gstreamer
diff --git a/polystrap/default/packages/games b/polystrap/default/packages/games
new file mode 100644
index 000000000..ee469f878
--- /dev/null
+++ b/polystrap/default/packages/games
@@ -0,0 +1,4 @@
+numptyphysics
+hex-a-hop
+wesnoth
+wesnoth-music
diff --git a/polystrap/default/packages/net b/polystrap/default/packages/net
new file mode 100644
index 000000000..87d45ae05
--- /dev/null
+++ b/polystrap/default/packages/net
@@ -0,0 +1,12 @@
+curl
+wget
+ntpdate
+vpnc
+rsync
+dhcp3-client
+ifupdown
+net-tools
+iproute
+dnsutils
+iputils-ping
+ppp
diff --git a/polystrap/default/packages/wlan b/polystrap/default/packages/wlan
new file mode 100644
index 000000000..315290135
--- /dev/null
+++ b/polystrap/default/packages/wlan
@@ -0,0 +1,2 @@
+wireless-tools
+wpasupplicant
diff --git a/polystrap/default/packages/xorg b/polystrap/default/packages/xorg
new file mode 100644
index 000000000..2b131f4e5
--- /dev/null
+++ b/polystrap/default/packages/xorg
@@ -0,0 +1,5 @@
+xserver-xorg-input-evdev
+xserver-xorg
+xserver-xorg-video-fbdev
+xterm
+nodm
diff --git a/polystrap/default/root/etc/apt/apt.conf.d/99no-install-recommends b/polystrap/default/root/etc/apt/apt.conf.d/99no-install-recommends
new file mode 100644
index 000000000..25ec2b3a4
--- /dev/null
+++ b/polystrap/default/root/etc/apt/apt.conf.d/99no-install-recommends
@@ -0,0 +1 @@
+APT::Install-Recommends "0";
diff --git a/polystrap/default/root/etc/apt/apt.conf.d/99no-pdiffs b/polystrap/default/root/etc/apt/apt.conf.d/99no-pdiffs
new file mode 100644
index 000000000..07d01de1d
--- /dev/null
+++ b/polystrap/default/root/etc/apt/apt.conf.d/99no-pdiffs
@@ -0,0 +1 @@
+Acquire::PDiffs "0";
diff --git a/polystrap/default/root/etc/fstab b/polystrap/default/root/etc/fstab
new file mode 100644
index 000000000..a8fe557ac
--- /dev/null
+++ b/polystrap/default/root/etc/fstab
@@ -0,0 +1,8 @@
+# <file system> <mount point> <type> <options> <dump> <pass>
+rootfs / auto defaults,errors=remount-ro,noatime 0 1
+proc /proc proc defaults 0 0
+tmpfs /tmp tmpfs defaults,noatime 0 0
+tmpfs /var/lock tmpfs defaults,noatime 0 0
+tmpfs /var/run tmpfs defaults,noatime 0 0
+tmpfs /var/log tmpfs defaults,noatime 0 0
+tmpfs /etc/network/run tmpfs defaults,noatime 0 0
diff --git a/polystrap/default/root/etc/hostname b/polystrap/default/root/etc/hostname
new file mode 100644
index 000000000..4ad96d515
--- /dev/null
+++ b/polystrap/default/root/etc/hostname
@@ -0,0 +1 @@
+default
diff --git a/polystrap/default/root/etc/hosts b/polystrap/default/root/etc/hosts
new file mode 100644
index 000000000..0ec197ba8
--- /dev/null
+++ b/polystrap/default/root/etc/hosts
@@ -0,0 +1,2 @@
+127.0.0.1 localhost
+127.0.0.1 default
diff --git a/polystrap/default/root/etc/ld.so.conf b/polystrap/default/root/etc/ld.so.conf
new file mode 100644
index 000000000..a9d3ffcc7
--- /dev/null
+++ b/polystrap/default/root/etc/ld.so.conf
@@ -0,0 +1,2 @@
+# supply ld.so.conf for fake ldd (running libc6 postinst script will fail)
+include /etc/ld.so.conf.d/*.conf
diff --git a/polystrap/default/root/etc/network/interfaces b/polystrap/default/root/etc/network/interfaces
new file mode 100644
index 000000000..f1bd92ed2
--- /dev/null
+++ b/polystrap/default/root/etc/network/interfaces
@@ -0,0 +1,2 @@
+auto lo
+iface lo inet loopback
diff --git a/polystrap/default/root/etc/ssh/ssh_host_dsa_key b/polystrap/default/root/etc/ssh/ssh_host_dsa_key
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/polystrap/default/root/etc/ssh/ssh_host_dsa_key
diff --git a/polystrap/default/root/etc/ssh/ssh_host_ecdsa_key b/polystrap/default/root/etc/ssh/ssh_host_ecdsa_key
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/polystrap/default/root/etc/ssh/ssh_host_ecdsa_key
diff --git a/polystrap/default/root/etc/ssh/ssh_host_rsa_key b/polystrap/default/root/etc/ssh/ssh_host_rsa_key
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/polystrap/default/root/etc/ssh/ssh_host_rsa_key
diff --git a/polystrap/default/root/usr/sbin/policy-rc.d b/polystrap/default/root/usr/sbin/policy-rc.d
new file mode 100755
index 000000000..85d823ddb
--- /dev/null
+++ b/polystrap/default/root/usr/sbin/policy-rc.d
@@ -0,0 +1,3 @@
+#!/bin/sh
+echo "sysvinit: All runlevel operations denied by policy" >&2
+exit 101
diff --git a/polystrap/polystrap-nb b/polystrap/polystrap-nb
new file mode 100755
index 000000000..6791f9cf1
--- /dev/null
+++ b/polystrap/polystrap-nb
@@ -0,0 +1,58 @@
+#!/bin/sh -ex
+
+dir_depth() {
+ dir="$1"
+ while [ "$dir" != "." ] && [ "$dir" != "/" ]; do
+ dir=`dirname "$dir"`
+ echo -n ../
+ done
+}
+
+if [ "$#" -ne 1 ]; then
+ echo 1>&2 "you have to specify the new board name"
+ exit 1
+fi
+
+BOARD="$1"
+
+if [ -e "$BOARD" ]; then
+ echo 1>&2 "board already exists"
+ exit 1
+fi
+
+mkdir -p $BOARD/
+mkdir -p $BOARD/packages/
+mkdir -p $BOARD/root/etc/network/
+mkdir -p $BOARD/hooks/
+
+cp default/config $BOARD
+cp default/multistrap.conf $BOARD
+cp default/debconfseed.txt $BOARD
+
+for f in packages/base \
+ root/usr/sbin/policy-rc.d \
+ root/usr/bin/ldd \
+ root/etc/apt/apt.conf.d/99no-install-recommends \
+ root/etc/apt/apt.conf.d/99no-pdiffs \
+ root/etc/ld.so.conf \
+ root/etc/ssh/ssh_host_ecdsa_key \
+ root/etc/ssh/ssh_host_rsa_key \
+ root/etc/ssh/ssh_host_dsa_key \
+ root/sbin/ldconfig \
+ hooks/create_user \
+ hooks/serial_tty \
+ hooks/firstboot \
+ hooks/empty_password; do
+ mkdir -p `dirname $BOARD/$f`
+ ln -s `dir_depth $f`default/$f $BOARD/$f
+done
+
+cat << __END__ > $BOARD/root/etc/hosts
+127.0.0.1 localhost
+127.0.0.1 $BOARD
+__END__
+
+echo $BOARD > $BOARD/root/etc/hostname
+
+cp default/root/etc/fstab $BOARD/root/etc/
+cp default/root/etc/network/interfaces $BOARD/root/etc/network/
diff --git a/polystrap/polystrap.sh b/polystrap/polystrap.sh
new file mode 100755
index 000000000..2f1f09163
--- /dev/null
+++ b/polystrap/polystrap.sh
@@ -0,0 +1,181 @@
+#!/bin/sh
+#
+# polystrap - create a foreign architecture rootfs using multistrap, fakeroot,
+# fakechroot and qemu usermode emulation
+#
+# Copyright (C) 2011 by Johannes 'josch' Schauer <j.schauer@email.de>
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+# IN THE SOFTWARE.
+
+usage() {
+ echo "Usage: $0: [-f] [-v] [-n] [-s suite] [-a arch] [-d directory] [-m mirror] [-p packages] platform\n" >&2
+}
+
+export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C
+export PATH=$PATH:/usr/sbin:/sbin
+
+if [ "$FAKEROOTKEY" = "" ]; then
+ echo "I: re-executing script inside fakeroot"
+ fakeroot "$0" "$@";
+ exit
+fi
+
+FORCE=""
+MSTRAP_SIM=
+EXIT_ON_ERROR=true
+while getopts efvs:a:d:m:p:n opt; do
+ case $opt in
+ s) _SUITE="$OPTARG";;
+ a) _ARCH="$OPTARG";;
+ d) _ROOTDIR="$OPTARG";;
+ m) _MIRROR="$OPTARG";;
+ p) _PACKAGES="$OPTARG";;
+ n) MSTRAP_SIM="--simulate";;
+ e) EXIT_ON_ERROR=false;;
+ v) set -x;;
+ f) FORCE=true;;
+ ?) usage; exit 1;;
+ esac
+done
+shift $(($OPTIND - 1))
+
+[ "$#" -ne 1 ] && { echo "too many positional arguments" >&2; usage; exit 1; }
+
+[ "$EXIT_ON_ERROR" = true ] && set -e
+
+BOARD="$1"
+
+[ ! -r "$BOARD" ] && { echo "cannot find target directory: $BOARD" >&2; exit 1; }
+[ ! -r "$BOARD/multistrap.conf" ] && { echo "cannot read multistrap config: $BOARD/multistrap.conf" >&2; exit 1; }
+
+# source default options
+. "default/config"
+
+# overwrite default options by target options
+[ -r "$BOARD/config" ] && . "$BOARD/config"
+
+# overwrite target options by commandline options
+SUITE=${_SUITE:-$SUITE}
+ARCH=${_ARCH:-$ARCH}
+ROOTDIR=$(readlink -m ${_ROOTDIR:-$ROOTDIR})
+MIRROR=${_MIRROR:-$MIRROR}
+
+if [ "$_PACKAGES" = "" ] && [ -r "$BOARD/packages" ]; then
+ # if no packages were given by commandline, read from package files
+ for f in $BOARD/packages/*; do
+ while read line; do PACKAGES="$PACKAGES $line"; done < "$f"
+ done
+else
+ # otherwise set as given by commandline
+ PACKAGES="$_PACKAGES"
+fi
+
+export QEMU_LD_PREFIX="`readlink -m "$ROOTDIR"`"
+export FAKECHROOT_CMD_SUBST=/usr/bin/ldd=/usr/bin/ldd.fakechroot:/sbin/ldconfig=/bin/true
+
+echo "I: --------------------------"
+echo "I: suite: $SUITE"
+echo "I: arch: $ARCH"
+echo "I: rootdir: $ROOTDIR"
+echo "I: mirror: $MIRROR"
+echo "I: pkgs: $PACKAGES"
+echo "I: --------------------------"
+
+[ -e "$ROOTDIR.tar" ] && [ ! "$FORCE" = true ] && { echo "tarball $ROOTDIR.tar still exists" >&2; exit 1; }
+
+# if rootdir exists, either warn and abort or delete and continue
+if [ -e "$ROOTDIR" ]; then
+ if [ "$FORCE" = true ]; then
+ rm -rf $ROOTDIR
+ else
+ echo "root directory $ROOTDIR still exists" >&2
+ exit 1
+ fi
+fi
+
+# create multistrap.conf
+echo "I: create multistrap.conf"
+MULTISTRAPCONF=`tempfile -d . -p multistrap`
+echo -n > "$MULTISTRAPCONF"
+while read line; do
+ eval echo $line >> "$MULTISTRAPCONF"
+done < $BOARD/multistrap.conf
+
+# download and extract packages
+echo "I: run multistrap" >&2
+multistrap $MSTRAP_SIM -f "$MULTISTRAPCONF"
+[ -z "$MSTRAP_SIM" ] || exit 0
+
+rm -f "$MULTISTRAPCONF"
+
+# convert absolute symlinks for fakechroot
+for link in `find $ROOTDIR -type l`; do
+ target=`readlink $link`
+ if [ "${target%%/*}" = "" ]; then # target begins with slash
+ echo "I: convert symlink: ${link#$ROOTDIR} -> $target"
+ rm $link
+ ln -s ${ROOTDIR}$target $link
+ fi
+done
+
+# copy initial directory tree - dereference symlinks
+echo "I: copy initial directory root tree $BOARD/root/ to $ROOTDIR/"
+if [ -r "$BOARD/root" ]; then
+ cp --recursive --dereference $BOARD/root/* $ROOTDIR/
+fi
+
+# preseed debconf
+echo "I: preseed debconf"
+if [ -r "$BOARD/debconfseed.txt" ]; then
+ cp "$BOARD/debconfseed.txt" $ROOTDIR/tmp/
+ fakechroot chroot $ROOTDIR debconf-set-selections /tmp/debconfseed.txt
+ rm $ROOTDIR/tmp/debconfseed.txt
+fi
+
+# run preinst scripts
+for script in $ROOTDIR/var/lib/dpkg/info/*.preinst; do
+ [ "$script" = "$ROOTDIR/var/lib/dpkg/info/vpnc.preinst" ] && continue
+ echo "I: run preinst script ${script##$ROOTDIR}"
+ DPKG_MAINTSCRIPT_NAME=preinst \
+ DPKG_MAINTSCRIPT_PACKAGE="`basename $script .preinst`" \
+ fakechroot chroot $ROOTDIR ${script##$ROOTDIR} install
+done
+
+# run dpkg --configure -a twice because of errors during the first run
+echo "I: configure packages"
+fakechroot chroot $ROOTDIR /usr/bin/dpkg --configure -a || fakechroot chroot $ROOTDIR /usr/bin/dpkg --configure -a
+
+# source hooks
+if [ -r "$BOARD/hooks" ]; then
+ for f in $BOARD/hooks/*; do
+ echo "I: run hook $f"
+ . $f
+ done
+fi
+
+#cleanup
+echo "I: cleanup"
+rm $ROOTDIR/usr/sbin/policy-rc.d
+
+# need to generate tar inside fakechroot so that absolute symlinks are correct
+# tar is clever enough to not try and put the archive inside itself
+TARBALL=$(basename $ROOTDIR).tar
+echo "I: create tarball $TARBALL"
+fakechroot chroot $ROOTDIR tar -cf $TARBALL -C / .
+mv $ROOTDIR/$TARBALL .