2011-06-22 07:50:36 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2014-06-21 13:18:34 +00:00
|
|
|
# polystrap - create a foreign architecture rootfs using multistrap, proot,
|
|
|
|
# and qemu usermode emulation
|
2011-06-22 07:50:36 +00:00
|
|
|
#
|
|
|
|
# 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() {
|
2012-03-13 14:54:52 +00:00
|
|
|
echo "Usage: $0: [-f] [-v] [-n] [-s suite] [-a arch] [-d directory] [-m mirror] [-p packages] platform\n" >&2
|
2011-06-22 07:50:36 +00:00
|
|
|
}
|
|
|
|
|
2014-06-21 13:18:34 +00:00
|
|
|
CHROOTQEMUCMD="proot -q qemu-arm -v -1 -0 -b /dev -b /sys -b /proc"
|
|
|
|
CHROOTCMD="proot -v -1 -0"
|
|
|
|
|
2011-06-22 07:50:36 +00:00
|
|
|
export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C
|
2011-06-29 08:47:48 +00:00
|
|
|
export PATH=$PATH:/usr/sbin:/sbin
|
2011-06-22 07:50:36 +00:00
|
|
|
|
2014-06-21 13:18:34 +00:00
|
|
|
#if [ "$FAKEROOTKEY" = "" ]; then
|
|
|
|
# echo "I: re-executing script inside fakeroot"
|
|
|
|
# fakeroot "$0" "$@";
|
|
|
|
# exit
|
|
|
|
#fi
|
2011-06-22 07:50:36 +00:00
|
|
|
|
2012-03-13 14:54:52 +00:00
|
|
|
FORCE=""
|
2011-06-30 06:52:44 +00:00
|
|
|
MSTRAP_SIM=
|
2012-03-15 10:25:22 +00:00
|
|
|
EXIT_ON_ERROR=true
|
|
|
|
while getopts efvs:a:d:m:p:n opt; do
|
2011-06-22 07:50:36 +00:00
|
|
|
case $opt in
|
|
|
|
s) _SUITE="$OPTARG";;
|
|
|
|
a) _ARCH="$OPTARG";;
|
|
|
|
d) _ROOTDIR="$OPTARG";;
|
|
|
|
m) _MIRROR="$OPTARG";;
|
|
|
|
p) _PACKAGES="$OPTARG";;
|
2011-06-30 06:52:44 +00:00
|
|
|
n) MSTRAP_SIM="--simulate";;
|
2012-03-15 10:25:22 +00:00
|
|
|
e) EXIT_ON_ERROR=false;;
|
2012-03-13 14:54:52 +00:00
|
|
|
v) set -x;;
|
|
|
|
f) FORCE=true;;
|
2011-06-22 07:50:36 +00:00
|
|
|
?) usage; exit 1;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $(($OPTIND - 1))
|
|
|
|
|
2011-06-29 08:45:57 +00:00
|
|
|
[ "$#" -ne 1 ] && { echo "too many positional arguments" >&2; usage; exit 1; }
|
2011-06-22 07:50:36 +00:00
|
|
|
|
2012-03-15 10:25:22 +00:00
|
|
|
[ "$EXIT_ON_ERROR" = true ] && set -e
|
|
|
|
|
2011-07-17 11:48:06 +00:00
|
|
|
BOARD="$1"
|
2011-06-22 07:50:36 +00:00
|
|
|
|
2011-07-17 11:48:06 +00:00
|
|
|
[ ! -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; }
|
2011-06-22 07:50:36 +00:00
|
|
|
|
|
|
|
# source default options
|
|
|
|
. "default/config"
|
|
|
|
|
|
|
|
# overwrite default options by target options
|
2011-07-17 11:48:06 +00:00
|
|
|
[ -r "$BOARD/config" ] && . "$BOARD/config"
|
2011-06-22 07:50:36 +00:00
|
|
|
|
|
|
|
# overwrite target options by commandline options
|
|
|
|
SUITE=${_SUITE:-$SUITE}
|
|
|
|
ARCH=${_ARCH:-$ARCH}
|
2012-10-08 08:07:32 +00:00
|
|
|
ROOTDIR=$(readlink -m ${_ROOTDIR:-$ROOTDIR})
|
2011-06-22 07:50:36 +00:00
|
|
|
MIRROR=${_MIRROR:-$MIRROR}
|
|
|
|
|
2011-07-17 11:48:06 +00:00
|
|
|
if [ "$_PACKAGES" = "" ] && [ -r "$BOARD/packages" ]; then
|
2011-06-22 07:50:36 +00:00
|
|
|
# if no packages were given by commandline, read from package files
|
2011-07-17 11:48:06 +00:00
|
|
|
for f in $BOARD/packages/*; do
|
2011-06-22 07:50:36 +00:00
|
|
|
while read line; do PACKAGES="$PACKAGES $line"; done < "$f"
|
|
|
|
done
|
|
|
|
else
|
|
|
|
# otherwise set as given by commandline
|
|
|
|
PACKAGES="$_PACKAGES"
|
|
|
|
fi
|
|
|
|
|
2011-10-18 14:34:59 +00:00
|
|
|
export QEMU_LD_PREFIX="`readlink -m "$ROOTDIR"`"
|
2014-06-21 13:18:34 +00:00
|
|
|
#export FAKECHROOT_CMD_SUBST=/usr/bin/ldd=/usr/bin/ldd.fakechroot:/sbin/ldconfig=/bin/true
|
2011-10-18 14:34:59 +00:00
|
|
|
|
2011-07-03 07:41:01 +00:00
|
|
|
echo "I: --------------------------"
|
|
|
|
echo "I: suite: $SUITE"
|
|
|
|
echo "I: arch: $ARCH"
|
|
|
|
echo "I: rootdir: $ROOTDIR"
|
|
|
|
echo "I: mirror: $MIRROR"
|
|
|
|
echo "I: pkgs: $PACKAGES"
|
|
|
|
echo "I: --------------------------"
|
2011-06-22 07:50:36 +00:00
|
|
|
|
2012-03-13 14:54:52 +00:00
|
|
|
[ -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
|
2011-06-22 07:50:36 +00:00
|
|
|
|
|
|
|
# create multistrap.conf
|
2011-07-03 07:41:01 +00:00
|
|
|
echo "I: create multistrap.conf"
|
2011-06-24 22:07:21 +00:00
|
|
|
MULTISTRAPCONF=`tempfile -d . -p multistrap`
|
|
|
|
echo -n > "$MULTISTRAPCONF"
|
2011-06-22 07:50:36 +00:00
|
|
|
while read line; do
|
2011-06-30 06:49:28 +00:00
|
|
|
eval echo $line >> "$MULTISTRAPCONF"
|
2011-07-17 11:48:06 +00:00
|
|
|
done < $BOARD/multistrap.conf
|
2011-06-22 07:50:36 +00:00
|
|
|
|
|
|
|
# download and extract packages
|
2011-06-29 09:03:43 +00:00
|
|
|
echo "I: run multistrap" >&2
|
2014-06-21 13:18:34 +00:00
|
|
|
proot -0 multistrap $MSTRAP_SIM -f "$MULTISTRAPCONF"
|
2011-06-30 06:52:44 +00:00
|
|
|
[ -z "$MSTRAP_SIM" ] || exit 0
|
|
|
|
|
2011-06-24 22:07:21 +00:00
|
|
|
rm -f "$MULTISTRAPCONF"
|
2011-06-22 07:50:36 +00:00
|
|
|
|
2014-06-21 13:18:34 +00:00
|
|
|
## 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
|
2012-03-15 10:21:13 +00:00
|
|
|
|
2011-06-22 07:50:36 +00:00
|
|
|
# copy initial directory tree - dereference symlinks
|
2011-07-17 11:48:06 +00:00
|
|
|
echo "I: copy initial directory root tree $BOARD/root/ to $ROOTDIR/"
|
|
|
|
if [ -r "$BOARD/root" ]; then
|
|
|
|
cp --recursive --dereference $BOARD/root/* $ROOTDIR/
|
2011-06-22 08:38:04 +00:00
|
|
|
fi
|
2011-06-22 07:50:36 +00:00
|
|
|
|
|
|
|
# preseed debconf
|
2011-07-03 07:41:01 +00:00
|
|
|
echo "I: preseed debconf"
|
2011-07-17 11:48:06 +00:00
|
|
|
if [ -r "$BOARD/debconfseed.txt" ]; then
|
|
|
|
cp "$BOARD/debconfseed.txt" $ROOTDIR/tmp/
|
2014-06-21 13:18:34 +00:00
|
|
|
$CHROOTQEMUCMD $ROOTDIR debconf-set-selections /tmp/debconfseed.txt
|
2011-06-22 07:50:36 +00:00
|
|
|
rm $ROOTDIR/tmp/debconfseed.txt
|
|
|
|
fi
|
|
|
|
|
|
|
|
# run preinst scripts
|
|
|
|
for script in $ROOTDIR/var/lib/dpkg/info/*.preinst; do
|
2012-03-13 14:54:52 +00:00
|
|
|
[ "$script" = "$ROOTDIR/var/lib/dpkg/info/vpnc.preinst" ] && continue
|
2011-07-03 07:41:01 +00:00
|
|
|
echo "I: run preinst script ${script##$ROOTDIR}"
|
2012-03-13 14:54:52 +00:00
|
|
|
DPKG_MAINTSCRIPT_NAME=preinst \
|
|
|
|
DPKG_MAINTSCRIPT_PACKAGE="`basename $script .preinst`" \
|
2014-06-21 13:18:34 +00:00
|
|
|
$CHROOTQEMUCMD $ROOTDIR ${script##$ROOTDIR} install
|
2011-06-22 07:50:36 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
# run dpkg --configure -a twice because of errors during the first run
|
2011-07-03 07:41:01 +00:00
|
|
|
echo "I: configure packages"
|
2014-06-21 13:18:34 +00:00
|
|
|
$CHROOTQEMUCMD $ROOTDIR /usr/bin/dpkg --configure -a || $CHROOTCMD $ROOTDIR /usr/bin/dpkg --configure -a
|
2011-06-22 07:50:36 +00:00
|
|
|
|
|
|
|
# source hooks
|
2011-07-17 11:48:06 +00:00
|
|
|
if [ -r "$BOARD/hooks" ]; then
|
|
|
|
for f in $BOARD/hooks/*; do
|
2011-07-03 07:41:01 +00:00
|
|
|
echo "I: run hook $f"
|
2011-06-22 08:38:04 +00:00
|
|
|
. $f
|
|
|
|
done
|
|
|
|
fi
|
2011-06-22 07:50:36 +00:00
|
|
|
|
|
|
|
#cleanup
|
2011-07-03 07:41:01 +00:00
|
|
|
echo "I: cleanup"
|
2011-06-22 07:50:36 +00:00
|
|
|
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
|
2014-06-21 13:18:34 +00:00
|
|
|
#TARBALL=$(basename $ROOTDIR).tar
|
|
|
|
#echo "I: create tarball $TARBALL"
|
|
|
|
#$CHROOTCMD $ROOTDIR tar -cf $TARBALL -C / .
|
|
|
|
#mv $ROOTDIR/$TARBALL .
|