forked from ubports/initramfs-tools-ubuntu-touch
-
Notifications
You must be signed in to change notification settings - Fork 25
/
build-initrd.sh
executable file
·120 lines (95 loc) · 3.17 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/sh
set -e
export FLASH_KERNEL_SKIP=1
export DEBIAN_FRONTEND=noninteractive
DEFAULTMIRROR="https://deb.debian.org/debian"
APT_COMMAND="apt -y"
usage() {
echo "Usage:
-a|--arch Architecture to create initrd for. Default armhf
-m|--mirror Custom mirror URL to use. Must serve your arch.
"
}
echob() {
echo "Builder: $@"
}
while [ $# -gt 0 ]; do
case "$1" in
-h | --help)
usage
exit 0
;;
-a | --arch)
[ -n "$2" ] && ARCH=$2 shift || usage
;;
-m | --mirror)
[ -n "$2" ] && MIRROR=$2 shift || usage
;;
esac
shift
done
# Defaults for all arguments, so they can be set by the environment
[ -z $ARCH ] && ARCH="armhf"
[ -z $MIRROR ] && MIRROR=$DEFAULTMIRROR
[ -z $RELEASE ] && RELEASE="stretch"
[ -z $ROOT ] && ROOT=./build/$ARCH
[ -z $OUT ] && OUT=./out
# list all packages needed for halium's initrd here
[ -z $INCHROOTPKGS ] && INCHROOTPKGS="initramfs-tools dctrl-tools e2fsprogs libc6-dev zlib1g-dev libssl-dev busybox-static"
BOOTSTRAP_BIN="qemu-debootstrap --arch $ARCH --variant=minbase"
umount_chroot() {
chroot $ROOT umount /sys >/dev/null 2>&1 || true
chroot $ROOT umount /proc >/dev/null 2>&1 || true
echo
}
do_chroot() {
trap umount_chroot INT EXIT
ROOT="$1"
CMD="$2"
echob "Executing \"$2\" in chroot"
chroot $ROOT mount -t proc proc /proc
chroot $ROOT mount -t sysfs sys /sys
chroot $ROOT $CMD
umount_chroot
trap - INT EXIT
}
if [ ! -e $ROOT/.min-done ]; then
[ -d $ROOT ] && rm -r $ROOT
# create a plain chroot to work in
echob "Creating chroot with arch $ARCH in $ROOT"
mkdir -p "$ROOT"
$BOOTSTRAP_BIN $RELEASE $ROOT $MIRROR || cat $ROOT/debootstrap/debootstrap.log
#sed -i 's/main$/main universe/' $ROOT/etc/apt/sources.list
sed -i 's,'"$DEFAULTMIRROR"','"$MIRROR"',' $ROOT/etc/apt/sources.list
# make sure we do not start daemons at install time
mv $ROOT/sbin/start-stop-daemon $ROOT/sbin/start-stop-daemon.REAL
echo $START_STOP_DAEMON >$ROOT/sbin/start-stop-daemon
chmod a+rx $ROOT/sbin/start-stop-daemon
echo $POLICY_RC_D >$ROOT/usr/sbin/policy-rc.d
# after the switch to systemd we now need to install upstart explicitly
echo "nameserver 8.8.8.8" >$ROOT/etc/resolv.conf
do_chroot $ROOT "$APT_COMMAND update"
# We also need to install dpkg-dev in order to use dpkg-architecture.
do_chroot $ROOT "$APT_COMMAND install dpkg-dev --no-install-recommends"
touch $ROOT/.min-done
else
echob "Build environment for $ARCH found, reusing."
fi
# install all packages we need to roll the generic initrd
do_chroot $ROOT "$APT_COMMAND update"
do_chroot $ROOT "$APT_COMMAND dist-upgrade"
do_chroot $ROOT "$APT_COMMAND install $INCHROOTPKGS --no-install-recommends"
DEB_HOST_MULTIARCH=$(chroot $ROOT dpkg-architecture -q DEB_HOST_MULTIARCH)
cp -a conf/halium ${ROOT}/usr/share/initramfs-tools/conf.d
cp -a scripts/* ${ROOT}/usr/share/initramfs-tools/scripts
cp -a hooks/* ${ROOT}/usr/share/initramfs-tools/hooks
VER="$ARCH"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/lib/$DEB_HOST_MULTIARCH"
do_chroot $ROOT "update-initramfs -tc -ktouch-$VER -v"
mkdir "$OUT" >/dev/null 2>&1 || true
FILENAME=initrd.img-touch-$VER
cp "$ROOT/boot/${FILENAME}" "$OUT"
cd "$OUT"
sha256sum "${FILENAME}" > "${FILENAME}.sha256"
date -R > "${FILENAME}.timestamp"
cd - >/dev/null 2>&1