forked from debian-pi/raspbian-ua-netinst
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildroot.sh
executable file
·59 lines (43 loc) · 984 Bytes
/
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
59
#!/bin/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=32
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 -D
losetup -P /dev/loop0 $IMG
mkfs.vfat /dev/loop0p1
mount /dev/loop0p1 /mnt
cp -r bootfs/* /mnt/
umount /mnt
losetup -D || true
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
cat $IMG | bzip2 -9 > $IMG.bz2