completion_50_configscript.sh 1.79 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#!/bin/sh
#
# completion_50_configscript.sh
# Copyright 2015 Jonas Smedegaard <dr@jones.dk>
# License: GNU Public License version 3 or newer
#
# multistrap completion hook supporting alien arch with fakeroot
#
# Recommends: fakeroot proot qemu-user
# Enhances: multistrap
#
# TODO: avoid need for libfakeroot installed into target system

set -e

fs="$1"
# TODO: replace with multiarch-safe method
arch=$(grep -Pom1 '(?<=Architecture: )(?!all)(.*)' "$fs/var/lib/dpkg/available") #'
arch_host=$(dpkg --print-architecture)

21 22 23
# libssl needs either HOME or RANDFILE defined
export RANDFILE=/root/.rnd.installer

24
# TODO: check for incompatible (not just different) arch
25
if [ -n "$FAKEROOTKEY" ] && [ "$FAKECHROOT" != "true" ] && [ "$arch" != "$arch_host" ]; then
26 27 28 29 30 31 32 33
	# Favor dpkg-dev tools (most reliable but pulls many packages)
	if which dpkg-architecture; then
		multiarch=$(dpkg-architecture -a"$arch" -qDEB_TARGET_MULTIARCH)
		cpu=$(dpkg-architecture -a"$arch" -qDEB_TARGET_GNU_CPU)
	else
		multiarch=$(basename "$(dirname "$(find "$fs/usr/lib" -type d -name libfakeroot)")")
		cpu=$(echo "multiarch" | cut -d- -f1)
	fi
34
	PATH=/usr/sbin:/usr/bin:/sbin:/bin \
35
		LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/lib/$multiarch/libfakeroot" \
36
		QEMU_LD_PREFIX="$fs" \
37
		proot -r "$fs" -b /proc -b /sys -b /dev -q "qemu-$cpu" -w / /multistrap-configure.sh
38
elif [ -n "$FAKEROOTKEY" ] && [ "$FAKECHROOT" != "true" ]; then
39 40 41
	PATH=/usr/sbin:/usr/bin:/sbin:/bin \
		proot -r "$fs" -b /proc -b /sys -b /dev -w / /multistrap-configure.sh
else
42 43 44 45 46 47 48 49 50 51 52
	sudo=sudo
	if [ "$(whoami)" = "root" ]; then
		sudo=
	fi
	$sudo mount proc -t proc "$fs/proc"
	$sudo mount sysfs -t sysfs "$fs/sysfs"
	$sudo mount --bind /dev "$fs/dev"
	$sudo chroot "$fs" /multistrap-configure.sh
	$sudo umount "$fs/proc"
	$sudo umount "$fs/sys"
	$sudo umount "$fs/dev"
53
fi
54 55

rm -f "$fs/$RANDFILE"