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
|
#!/bin/sh
# create files in the same directory as this script
cd "$(dirname "$0")"
# container image (initialized here, updated in makefile)
$CTR image exists "$CTR_IMG_TAG" 1> /dev/null 2> /dev/null
if [ $? -eq 0 ] ; then
! [ -e container_img ] && touch container_img
else
rm -f container_img
fi
# check if all the submodules are initialized
touch submodules
MODULES="$(git config \
--file "$(git rev-parse --show-toplevel)/.gitmodules" \
--name-only --get-regexp path |\
sed -e 's/^submodule\./modules\//' -e 's/\.path$/\/HEAD/')"
for git_module in $MODULES ; do
git rev-parse "$git_module" 1> /dev/null 2> /dev/null && continue
rm -f submodules
done
rm -f sdcard_part sdcard_fmt
# if no explicit SDCARD_DISK is set, guess which device is the sd card by
# checking if it is removable AND has a size of approx. 8GB
if [ -z "$SDCARD_DISK" ] ; then
SDCARD_DISK="$(lsblk --noheadings --bytes --list \
--output PATH,SIZE,TYPE,RM,NAME | awk '
$3 != "disk" { next }
$2 < 7900000000 { next }
$2 > 8000000000 { next }
($4 != 1) && (match($5, /^mmcblk/) == 0) { next }
{ print $1 }' | head -n1)"
fi
if [ -n "$SDCARD_DISK" ] ; then
# check if the sd card is partitioned correctly if no partition path
# variables are set
if [ -z "$SDCARD_PART_BOOT" ] || [ -z "$SDCARD_PART_ROOTFS" ] ; then
PARTS="$(lsblk "$SDCARD_DISK" --bytes --noheadings \
--output PATH,SIZE,TYPE,PTTYPE,FSTYPE,LABEL,PARTFLAGS \
2> /dev/null)"
# check if the disk is partitioned correctly
echo "$PARTS" | awk '
$3 == "part" { parts += 1 }
NR == 1 { if ($4 != "dos") exit(1) }
NR == 2 { if ($2 != 64 * 2^20) exit(1) }
END { if (parts != 2) exit(1) }' && touch sdcard_part
if [ $? -eq 0 ] ; then
SDCARD_PART_BOOT="$(echo "$PARTS" | awk 'NR == 2 { print $1 }')"
SDCARD_PART_ROOTFS="$(echo "$PARTS" | awk 'NR == 3 { print $1 }')"
# check if the disk is formatted correctly
echo "$PARTS" | awk '
NR == 2 {
if ($5 != "vfat") exit(1)
if ($6 != "BOOT") exit(1)
if ($7 != "0x80") exit(1)
}
NR == 3 {
if ($5 != "ext4") exit(1)
if ($6 != "ROOTFS") exit(1)
}' && touch sdcard_fmt
fi
fi
fi
cat << EOF
\$(eval SDCARD_DISK := $SDCARD_DISK)
\$(eval SDCARD_PART_BOOT := $SDCARD_PART_BOOT)
\$(eval SDCARD_PART_ROOTFS := $SDCARD_PART_ROOTFS)
\$(eval export)
EOF
|