-
Notifications
You must be signed in to change notification settings - Fork 153
/
buildroot.sh
executable file
·58 lines (43 loc) · 1.05 KB
/
buildroot.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
#!/usr/bin/env bash
set -e
IMG=raspbian-ua-netinst-$(date +%Y%m%d)-git$(git rev-parse --short "@{0}").img
rm -f "$IMG"
rm -f "$IMG".bz2
rm -f "$IMG".xz
dd if=/dev/zero of="$IMG" bs=1M count=64
fdisk "$IMG" <<EOF
n
p
1
t
b
w
EOF
if ! losetup --version &> /dev/null ; then
losetup_lt_2_22=true
elif [ "$(echo "$(losetup --version | rev|cut -f1 -d' '|rev|cut -d'.' -f-2)"'<'2.22 | bc -l)" -ne 0 ]; then
losetup_lt_2_22=true
else
losetup_lt_2_22=false
fi
if [ "$losetup_lt_2_22" = "true" ] ; then
kpartx -as "$IMG"
mkfs.vfat /dev/mapper/loop0p1
mount /dev/mapper/loop0p1 /mnt
cp -r bootfs/* /mnt/
umount /mnt
kpartx -d "$IMG" || true
else
losetup --find --partscan "$IMG"
LOOP_DEV="$(losetup --associated "$IMG" | cut -f1 -d':')"
mkfs.vfat "${LOOP_DEV}"p1
mount "${LOOP_DEV}"p1 /mnt
cp -r bootfs/* /mnt/
umount /mnt
losetup --detach "${LOOP_DEV}"
fi
if ! xz -9 --keep "$IMG" ; then
# This happens e.g. on Raspberry Pi because xz runs out of memory.
echo "WARNING: Could not create '$IMG.xz' variant." >&2
fi
bzip2 -k -9 "$IMG"