-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmake-pi-image.sh
executable file
·71 lines (53 loc) · 1.71 KB
/
make-pi-image.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
#!/bin/bash
if [ $# -lt 3 ]; then
echo "USAGE: $0 <base> <sourcedir> <outputdir>"
echo "<base> := a Raspbian (lite) base"
echo "<sourcedir> := Full path to Alexandria source tree"
echo "<outputdir> := Full path to output directory"
exit 1
fi
BASEFILE=$1
SOURCEPATH=$2
OUTDIR=$3
if [ ! -d $SOURCEPATH ]; then
echo "FAIL: source directory doesn't exist."
exit 1
fi
if [ ! -d $OUTDIR ]; then
echo "FAIL: output directory doesn't exist."
exit 1
fi
if [ ! -f $BASEFILE ]; then
echo "FAIL: Base image does not exist."
exit 1
fi
TARGET=${OUTDIR}/alexandria-$(date -Iminutes).img
echo "INFO: copy ${BASEFILE} to ${TARGET}"
cp $BASEFILE $TARGET
echo "INFO: Hitch up ${TARGET} on loop7"
losetup -P /dev/loop7 $TARGET
echo "INFO: Mount /dev/loop7p2 as /mnt"
mount /dev/loop7p2 /mnt
echo "INFO: Mount /dev/loop7p1 as /mnt/boot"
mount /dev/loop7p1 /mnt/boot
echo "INFO: Copying source files from ${SOURCEPATH}"
cp -r $SOURCEPATH /mnt/opt/
# Clean up virtualenv stuff
if [ -d /mnt/opt/alexandria/venv ]; then
echo "WARN: CLeaning virtualenv files up from potential non-native Python installation."
rm /mnt/opt/alexandria/venv -rf
fi
echo "INFO: Starting systemd-nspawn in qemu-arm-static mode"
systemd-nspawn --bind /dev/fuse --bind `which qemu-arm-static` -D /mnt bin/bash /opt/alexandria/install.sh
echo "INFO: Unmounting /mnt/boot and /mnt"
umount /mnt/boot
umount /mnt/
echo "INFO: Disconnecting loopback devices in losetup"
losetup -D
if [ -f ${OUTDIR}/alexandria-latest.img ]; then
rm ${OUTDIR}/alexandria-latest.img
fi
echo "INFO: linking ${TARGET} to ${OUTDIR}/alexandria-latest.img"
ln -s $TARGET ${OUTDIR}/alexandria-latest.img
echo "INFO: zipping ${TARGET}"
zip ${TARGET}.zip ${TARGET}