This repository has been archived by the owner on Dec 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
/
build-initrd.sh
executable file
·98 lines (73 loc) · 3.31 KB
/
build-initrd.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/sh
set -ex
if [ -z "$FAKEROOTKEY" ]; then
exec fakeroot "$0" "$@"
fi
export FLASH_KERNEL_SKIP=1
export DEBIAN_FRONTEND=noninteractive
DEB_HOST_MULTIARCH=$(dpkg-architecture -qDEB_HOST_MULTIARCH)
# list all packages needed for a generic ubuntu touch initrd here
INCHROOTPKGS="initramfs-tools dctrl-tools lxc-android-config abootimg android-tools-adbd e2fsprogs"
MIRROR=$(grep "^deb " /etc/apt/sources.list|grep -v "ppa.launchpad.net"|head -1|cut -d' ' -f2)
RELEASE=$(lsb_release -cs)
ROOT=./build
# create a plain chroot to work in
rm -rf $ROOT
fakechroot -c fakechroot-config debootstrap --variant=fakechroot $RELEASE $ROOT $MIRROR || cat $ROOT/debootstrap/debootstrap.log
# TODO this can be dropped once all packages are in main
sed -i 's/main$/main universe/' $ROOT/etc/apt/sources.list
echo "deb $MIRROR $RELEASE-updates main restricted" >> $ROOT/etc/apt/sources.list
# for xenial/vivid builds we also need to make sure we use the overlay
cp ubports.list $ROOT/etc/apt/sources.list.d/
cp ubports.pref $ROOT/etc/apt/preferences.d/
# make sure we do not start daemons at install time
mv $ROOT/sbin/start-stop-daemon $ROOT/sbin/start-stop-daemon.REAL
cat > $ROOT/sbin/start-stop-daemon <<EOF
#!/bin/sh
echo 1>&2
echo 'Warning: Fake start-stop-daemon called, doing nothing.' 1>&2
exit 0
EOF
chmod a+rx $ROOT/sbin/start-stop-daemon
cat > $ROOT/usr/sbin/policy-rc.d <<EOF
#!/bin/sh
exit 101
EOF
chmod a+rx $ROOT/usr/sbin/policy-rc.d
# after teh switch to systemd we now need to install upstart explicitly
fakechroot chroot $ROOT apt-get -y update
fakechroot -c fakechroot-config chroot $ROOT apt-get -y --allow-unauthenticated install upstart
mv $ROOT/sbin/initctl $ROOT/sbin/initctl.REAL
cat > $ROOT/sbin/initctl <<EOF
#!/bin/sh
echo 1>&2
echo 'Warning: Fake initctl called, doing nothing.' 1>&2
exit 0
EOF
chmod a+rx $ROOT/sbin/initctl
# install all packages we need to roll the generic initrd
fakechroot -c fakechroot-config chroot $ROOT apt-get -y --allow-unauthenticated install $INCHROOTPKGS
cp -a conf/touch ${ROOT}/usr/share/initramfs-tools/conf.d
cp -a scripts/* ${ROOT}/usr/share/initramfs-tools/scripts
cp -a hooks/touch ${ROOT}/usr/share/initramfs-tools/hooks
sed -i -e "s/#DEB_HOST_MULTIARCH#/$DEB_HOST_MULTIARCH/g" ${ROOT}/usr/share/initramfs-tools/hooks/touch
# remove the plymouth hooks from the chroot
find $ROOT/usr/share/initramfs-tools -name plymouth -exec rm -f {} \;
VER="$(head -1 debian/changelog |sed -e 's/^.*(//' -e 's/).*$//')"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/lib/$DEB_HOST_MULTIARCH"
## Temporary HACK to work around FTBFS
mkdir -p $ROOT/usr/lib/$DEB_HOST_MULTIARCH/fakechroot
mkdir -p $ROOT/usr/lib/$DEB_HOST_MULTIARCH/libfakeroot
touch $ROOT/usr/lib/$DEB_HOST_MULTIARCH/fakechroot/libfakechroot.so
touch $ROOT/usr/lib/$DEB_HOST_MULTIARCH/libfakeroot/libfakeroot-sysv.so
# hack for arm64 builds where some binaries look for the ld libs in the wrong place
cd $ROOT
ln -s lib/ lib64
cd - >/dev/null 2>&1
fakechroot chroot $ROOT update-initramfs -c -ktouch-$VER -v
# make a more generically named link so external scripts can use the file without parsing the version
cd $ROOT/boot
ln -s initrd.img-touch-$VER initrd.img-touch
cd - >/dev/null 2>&1
# put a fake sha1sum file in place so update-initramfs -u works OOTB for developers
fakechroot chroot $ROOT sha1sum /boot/initrd.img-touch >$ROOT/var/lib/initramfs-tools/touch