-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtoolkit-entrypoint.sh
executable file
·59 lines (49 loc) · 1.33 KB
/
toolkit-entrypoint.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
#!/bin/sh
set -euo pipefail
usage() {
cat >&2 <<EOF
Usage:
$0 DISTRIBUTION KERNEL_PACKAGE OUTPUT_DIR
EOF
exit 1
}
unpack_coreos_kernel()
{
KERNEL_PACKAGE="$1"
OUTPUT_DIR="$2"
bzcat "$KERNEL_PACKAGE" > /tmp/container.img
# mount developer container is a very stateful part of this script
# the section between mount/unmounting should be kept very small
# otherwise if something fails there are many inconsistencies that can happen
OFFSET=$(sfdisk -J /tmp/container.img | jq '.partitiontable.sectorsize * .partitiontable.partitions[0].start')
mount -o ro,loop,offset="$OFFSET" /tmp/container.img /mnt
# Copy kernel headers
cp -r /mnt/lib/modules "$OUTPUT_DIR"
# Copy kernel config
rm -f $OUTPUT_DIR/config*
cp /mnt/usr/boot/config* $OUTPUT_DIR/
# umount the developer container
umount /mnt
}
unpack_rpm()
{
KERNEL_PACKAGE="$1"
OUTPUT_DIR="$2"
# This "rpm2cpio | cpio pipeline" seems to fail under obscure circumstances
# rpm2cpio "$KERNEL_PACKAGE" | (cd "$OUTPUT_DIR" && cpio -idm)
# since alpine ships a bsdtar which seems perfectly capable (in and of itself)
# of extracting the files we need from an .rpm file, use that instead
bsdtar xf "$KERNEL_PACKAGE" -C "$OUTPUT_DIR"
}
case "$1" in
coreos)
unpack_coreos_kernel "$2" "$3"
;;
rpm)
unpack_rpm "$2" "$3"
;;
*)
echo "Unsupported distribution $1"
exit 1
;;
esac