-
Notifications
You must be signed in to change notification settings - Fork 102
/
raspberryimage.sh
executable file
·183 lines (140 loc) · 4.74 KB
/
raspberryimage.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/bin/sh
while getopts ":v:p:" opt; do
case $opt in
v)
VERSION=$OPTARG
;;
p)
PATCH=$OPTARG
;;
esac
done
BUILDDATE=$(date -I)
IMG_FILE="Volumio${VERSION}-${BUILDDATE}-pi.img"
echo "Creating Image Bed"
echo "Image file: ${IMG_FILE}"
dd if=/dev/zero of=${IMG_FILE} bs=1M count=2800
LOOP_DEV=`sudo losetup -f --show ${IMG_FILE}`
sudo parted -s "${LOOP_DEV}" mklabel msdos
sudo parted -s "${LOOP_DEV}" mkpart primary fat32 0 64
sudo parted -s "${LOOP_DEV}" mkpart primary ext3 64 2500
sudo parted -s "${LOOP_DEV}" mkpart primary ext3 2500 2800
sudo parted -s "${LOOP_DEV}" set 1 boot on
sudo parted -s "${LOOP_DEV}" print
sudo partprobe "${LOOP_DEV}"
sudo kpartx -a "${LOOP_DEV}" -s
BOOT_PART=`echo /dev/mapper/"$( echo $LOOP_DEV | sed -e 's/.*\/\(\w*\)/\1/' )"p1`
IMG_PART=`echo /dev/mapper/"$( echo $LOOP_DEV | sed -e 's/.*\/\(\w*\)/\1/' )"p2`
DATA_PART=`echo /dev/mapper/"$( echo $LOOP_DEV | sed -e 's/.*\/\(\w*\)/\1/' )"p3`
if [ ! -b "$BOOT_PART" ]
then
echo "$BOOT_PART doesn't exist"
exit 1
fi
echo "Creating filesystems"
#sudo mkfs.vfat "${BOOT_PART}" -n boot
# Using mkdosfs because pi seems to be picky with first partition block size
mkdosfs -n boot -F 32 -v "${BOOT_PART}"
sudo mkfs.ext4 -E stride=2,stripe-width=1024 -b 4096 "${IMG_PART}" -L volumio
sudo mkfs.ext4 -E stride=2,stripe-width=1024 -b 4096 "${DATA_PART}" -L volumio_data
sync
echo "Copying Volumio RootFs"
if [ -d /mnt ]; then
echo "/mnt/folder exist"
else
sudo mkdir /mnt
fi
if [ -d /mnt/volumio ]; then
echo "Volumio Temp Directory Exists - Cleaning it"
rm -rf /mnt/volumio/*
else
echo "Creating Volumio Temp Directory"
sudo mkdir /mnt/volumio
fi
#Create mount point for the images partition
sudo mkdir /mnt/volumio/images
sudo mount -t ext4 "${IMG_PART}" /mnt/volumio/images
sudo mkdir /mnt/volumio/rootfs
sudo cp -pdR build/arm/root/* /mnt/volumio/rootfs
#sudo mkdir /mnt/volumio/boot
sudo mount -t vfat "${BOOT_PART}" /mnt/volumio/rootfs/boot
sync
echo "Entering Chroot Environment"
cp scripts/raspberryconfig.sh /mnt/volumio/rootfs
cp scripts/initramfs/init /mnt/volumio/rootfs/root
cp scripts/initramfs/mkinitramfs-custom.sh /mnt/volumio/rootfs/usr/local/sbin
mount /dev /mnt/volumio/rootfs/dev -o bind
mount /proc /mnt/volumio/rootfs/proc -t proc
mount /sys /mnt/volumio/rootfs/sys -t sysfs
echo "Custom dtoverlay pre and post"
mkdir -p /mnt/volumio/rootfs/opt/vc/bin/
cp -rp volumio/opt/vc/bin/* /mnt/volumio/rootfs/opt/vc/bin/
echo $PATCH > /mnt/volumio/rootfs/patch
if [ -f "/mnt/volumio/rootfs/$PATCH/patch.sh" ] && [ -f "config.js" ]; then
if [ -f "UIVARIANT" ] && [ -f "variant.js" ]; then
UIVARIANT=$(cat "UIVARIANT")
echo "Configuring variant $UIVARIANT"
echo "Starting config.js for variant $UIVARIANT"
node config.js $PATCH $UIVARIANT
echo $UIVARIANT > /mnt/volumio/rootfs/UIVARIANT
else
echo "Starting config.js"
node config.js $PATCH
fi
fi
chroot /mnt/volumio/rootfs /bin/bash -x <<'EOF'
su -
/raspberryconfig.sh -p
EOF
UIVARIANT_FILE=/mnt/volumio/rootfs/UIVARIANT
if [ -f "${UIVARIANT_FILE}" ]; then
echo "Starting variant.js"
node variant.js
rm $UIVARIANT_FILE
fi
echo "Base System Installed"
rm /mnt/volumio/rootfs/raspberryconfig.sh /mnt/volumio/rootfs/root/init
echo "Unmounting Temp devices"
umount -l /mnt/volumio/rootfs/dev
umount -l /mnt/volumio/rootfs/proc
umount -l /mnt/volumio/rootfs/sys
echo "Copying Firmwares"
sync
echo "Finalizing Rootfs creation"
sh scripts/finalize.sh
echo "Creating RootFS Base for SquashFS"
if [ -d /mnt/squash ]; then
echo "Volumio SquashFS Temp Directory Exists - Cleaning it"
rm -rf /mnt/squash/*
else
echo "Creating Volumio SquashFS Temp Directory"
sudo mkdir /mnt/squash
fi
echo "Copying Volumio ROOTFS to Temp DIR"
cp -rp /mnt/volumio/rootfs/* /mnt/squash/
if [ -e /mnt/kernel_current.tar ]; then
echo "Volumio Kernel Partition Archive exists - Cleaning it"
rm -rf /mnt/kernel_current.tar
fi
echo "Creating Kernel Partition Archive"
tar cf /mnt/kernel_current.tar --exclude='resize-volumio-datapart' -C /mnt/squash/boot/ .
echo "Removing the Kernel"
rm -rf /mnt/squash/boot/*
echo "Creating SquashFS, removing any previous one"
if [ -e Volumio.sqsh ]; then
echo "Volumio Kernel Partition Archive exists - Cleaning it"
rm -r Volumio.sqsh
fi
echo "Creating SquashFS"
mksquashfs /mnt/squash/* Volumio.sqsh
echo "Squash file system created"
echo "Cleaning squash environment"
rm -rf /mnt/squash
#copy the squash image inside the images partition
cp Volumio.sqsh /mnt/volumio/images/volumio_current.sqsh
echo "Unmounting Temp Devices"
sudo umount -l /mnt/volumio/images
sudo umount -l /mnt/volumio/rootfs/boot
dmsetup remove_all
sudo losetup -d ${LOOP_DEV}
md5sum "$IMG_FILE" > "${IMG_FILE}.md5"