-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrelease.bash
More file actions
executable file
·368 lines (335 loc) · 14.5 KB
/
Copy pathrelease.bash
File metadata and controls
executable file
·368 lines (335 loc) · 14.5 KB
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
#!/bin/bash -xe
root_command() {
if [ "${STRICT_ROOT_PERMISSION}" == 1 ]; then
COMMAND="${@}"
printf "Warning! This script will execute the following command *as root* if you enter a valid password:\n'%s'\nHit CTRL-C to abort.\n" "${COMMAND}"
sudo -k
sudo "${@}" || exit 1
else
if [ "${IGNORE_EXITCODE}" == 1 ]; then
sudo "${@}" || true
else
sudo "${@}" || exit 1
fi
fi
}
# Variables
if [ -z "${1}" ]; then
printf "You must provide the 'device' argument."
exit 1
elif [ -z "${2}" ]; then
printf "You must provide the 'private key path' argument.\n"
exit 1
elif [ -z "${3}" ]; then
printf "You must provide the 'public key path' argument.\n"
exit 1
elif [ -z "${4}" ]; then
printf "You must provide the 'kernel type' argument.\nAvailable options are: std, root"
exit 1
fi
PKEY="${2}"
PUBLICKEY="${3}"
KERNEL_TYPE="${4}"
GIT_BASE_URL="https://github.com/Quill-OS"
PKGS_BASE_URL="http://23.163.0.39"
MOUNT_BASEPATH="/tmp/inkbox-$(tr -dc A-Za-z0-9 < /dev/urandom | head -c 10)"
if [ "${AUTO_CLEANUP}" == 1 ]; then
# Cleaning up possible earlier unsuccessful attemps
IGNORE_EXITCODE=1 root_command umount -l -f /tmp/inkbox*/*
rm -rf out/
root_command qemu-nbd --disconnect /dev/nbd0
fi
# Setting current directory to this Git repository
cd "$(dirname '${0}')"
GITDIR="${PWD}"
mkdir -p out/release
build_base_sd_image() {
printf "==== Building base SD image ====\n"
IMAGE_FILE="release/inkbox-${DEVICE}.img"
pushd out/
# Load NBD module
# root_command modprobe nbd
# Manually, on the host :)
# Create image file (3.6 GiB)
qemu-img create -f qcow2 "${IMAGE_FILE}" 3865470976
root_command qemu-nbd --connect /dev/nbd0 "${IMAGE_FILE}"
# Partition image and write unpartitioned space
root_command dd if="${GITDIR}/sd/${DEVICE}.bin" of=/dev/nbd0 && sync
# Format partitions
root_command mkfs.ext4 /dev/nbd0p1 -O "^metadata_csum,^orphan_file,^64bit"
root_command mkfs.ext4 /dev/nbd0p2 -O "^metadata_csum,^orphan_file,^64bit"
root_command mkfs.ext4 /dev/nbd0p3 -O "^metadata_csum,^orphan_file,^64bit"
root_command mkfs.ext4 /dev/nbd0p4 -O "^metadata_csum,^orphan_file,^64bit"
# Label partitions
root_command e2label /dev/nbd0p1 "boot"
root_command e2label /dev/nbd0p2 "recoveryfs"
root_command e2label /dev/nbd0p3 "rootfs"
root_command e2label /dev/nbd0p4 "user"
popd
}
setup_kernel_repository() {
if [ -z "${KERNELDIR}" ]; then
pushd out/
[ ! -d "kernel" ] && git clone "${GIT_BASE_URL}/kernel"
pushd kernel/
else
pushd "${KERNELDIR}"
fi
}
setup_u_boot() {
printf "==== Setting up U-Boot bootloader ====\n"
setup_kernel_repository
# We don't modify U-Boot for Libra 2
if [ "${DEVICE}" != "n418" ]; then
if [ "${DEVICE}" == "n705" ] || [ "${DEVICE}" == "n905b" ] || [ "${DEVICE}" == "n905c" ] || [ "${DEVICE}" == "n613" ]; then
env TOOLCHAINDIR="${PWD}/toolchain/gcc-4.8" THREADS=$(($(nproc)*2)) TARGET=arm-linux-gnueabihf scripts/build_u-boot.sh "${DEVICE}"
elif [ "${DEVICE}" == "n236" ] || [ "${DEVICE}" == "n437" ] || [ "${DEVICE}" == "n306" ] || [ "${DEVICE}" == "n306c" ]; then
env TOOLCHAINDIR="${PWD}/toolchain/arm-nickel-linux-gnueabihf" THREADS=$(($(nproc)*2)) TARGET=arm-nickel-linux-gnueabihf scripts/build_u-boot.sh "${DEVICE}"
elif [ "${DEVICE}" == "n249" ]; then
env TOOLCHAINDIR="${PWD}/toolchain/arm-kobo-linux-gnueabihf" THREADS=$(($(nproc)*2)) TARGET=arm-kobo-linux-gnueabihf scripts/build_u-boot.sh "${DEVICE}"
fi
if [ "${DEVICE}" != "n306" ] && [ "${DEVICE}" != "n306c" ] && [ "${DEVICE}" != "n249" ]; then
cp -v "bootloader/out/u-boot_inkbox.${DEVICE}.bin" "${GITDIR}/out/release/u-boot_inkbox.bin"
sync
root_command dd if="${GITDIR}/out/release/u-boot_inkbox.bin" of=/dev/nbd0 bs=1K seek=1 skip=1
sync
else
cp -v "bootloader/out/u-boot_inkbox.${DEVICE}.imx" "${GITDIR}/out/release/u-boot_inkbox.bin"
sync
root_command dd if="${GITDIR}/out/release/u-boot_inkbox.bin" of=/dev/nbd0 bs=1K seek=1
sync
fi
fi
popd
}
mount_fs() {
printf "==== Mounting filesystems ====\n"
mkdir -p "${MOUNT_BASEPATH}/boot"
mkdir -p "${MOUNT_BASEPATH}/recoveryfs"
mkdir -p "${MOUNT_BASEPATH}/rootfs"
mkdir -p "${MOUNT_BASEPATH}/user"
root_command mount /dev/nbd0p1 "${MOUNT_BASEPATH}/boot"
root_command mount /dev/nbd0p2 "${MOUNT_BASEPATH}/recoveryfs"
root_command mount /dev/nbd0p3 "${MOUNT_BASEPATH}/rootfs"
root_command mount /dev/nbd0p4 "${MOUNT_BASEPATH}/user"
}
setup_kernel() {
printf "==== Setting up InkBox OS kernel ====\n"
setup_kernel_repository
if [ "${DEVICE}" == "n306" ] || [ "${DEVICE}" == "n306c" ] || [ "${DEVICE}" == "n249" ] || [ "${DEVICE}" == "n418" ]; then
KERNEL_FILE="zImage-${KERNEL_TYPE}"
if [ "${DEVICE}" == "n249" ]; then
DTB_FILE="DTB"
BOOTSCRIPT_FILE="boot.scr"
fi
else
KERNEL_FILE="uImage-${KERNEL_TYPE}"
fi
# Replace the public key in kernel
cd initrd/"${DEVICE}"/opt/
unsquashfs -f -no-xattrs -d key key.sqsh
rm -f key.sqsh
cd key/
rm -f public.pem
cp "${PUBLICKEY}" ./public.pem
mksquashfs . ../key.sqsh -b 1048576 -comp gzip -always-use-fragments -no-xattrs
cd ../
rm -rf key/
cd ../../../
if [ "${DEVICE}" == "n705" ] || [ "${DEVICE}" == "n905b" ] || [ "${DEVICE}" == "n905c" ] || [ "${DEVICE}" == "n613" ]; then
env GITDIR="${PWD}" TOOLCHAINDIR="${PWD}/toolchain/gcc-4.8" THREADS=$(($(nproc)*2)) TARGET=arm-linux-gnueabihf scripts/build_kernel.sh "${DEVICE}" std
env GITDIR="${PWD}" TOOLCHAINDIR="${PWD}/toolchain/gcc-4.8" THREADS=$(($(nproc)*2)) TARGET=arm-linux-gnueabihf scripts/build_kernel.sh "${DEVICE}" root
# Basic Diagnostics Kernel
if [ "${DEVICE}" == "n905b" ] || [ "${DEVICE}" == "n905c" ] || [ "${DEVICE}" == "n613" ]; then
env GITDIR="${PWD}" TOOLCHAINDIR="${PWD}/toolchain/gcc-4.8" THREADS=$(($(nproc)*2)) TARGET=arm-linux-gnueabihf scripts/build_kernel.sh "${DEVICE}" diags
cp -v "kernel/out/${DEVICE}/uImage-diags" "${GITDIR}/out/release/uImage-diags"
root_command dd if="kernel/out/${DEVICE}/uImage-diags" of=/dev/nbd0 bs=512 seek=19456
fi
elif [ "${DEVICE}" == "n236" ] || [ "${DEVICE}" == "n437" ] || [ "${DEVICE}" == "n306" ] || [ "${DEVICE}" == "n306c" ] || [ "${DEVICE}" == "n418" ]; then
env GITDIR="${PWD}" TOOLCHAINDIR="${PWD}/toolchain/arm-nickel-linux-gnueabihf" THREADS=$(($(nproc)*2)) TARGET=arm-nickel-linux-gnueabihf scripts/build_kernel.sh "${DEVICE}" std
env GITDIR="${PWD}" TOOLCHAINDIR="${PWD}/toolchain/arm-nickel-linux-gnueabihf" THREADS=$(($(nproc)*2)) TARGET=arm-nickel-linux-gnueabihf scripts/build_kernel.sh "${DEVICE}" root
elif [ "${DEVICE}" == "n249" ]; then
env GITDIR="${PWD}" TOOLCHAINDIR="${PWD}/toolchain/armv7l-linux-musleabihf-cross" THREADS=$(($(nproc)*2)) TARGET=armv7l-linux-musleabihf scripts/build_kernel.sh "${DEVICE}" std
env GITDIR="${PWD}" TOOLCHAINDIR="${PWD}/toolchain/armv7l-linux-musleabihf-cross" THREADS=$(($(nproc)*2)) TARGET=armv7l-linux-musleabihf scripts/build_kernel.sh "${DEVICE}" root
fi
if [ "${DEVICE}" == "n306" ] || [ "${DEVICE}" == "n306c" ] || [ "${DEVICE}" == "n249" ] || [ "${DEVICE}" == "n418" ]; then
cp -v "kernel/out/${DEVICE}/zImage-std" "${GITDIR}/out/release/zImage-std"
cp -v "kernel/out/${DEVICE}/zImage-root" "${GITDIR}/out/release/zImage-root"
else
cp -v "kernel/out/${DEVICE}/uImage-std" "${GITDIR}/out/release/uImage-std"
cp -v "kernel/out/${DEVICE}/uImage-root" "${GITDIR}/out/release/uImage-root"
fi
if [ "${DEVICE}" == "n249" ] || [ "${DEVICE}" == "n418" ]; then
root_command cp "kernel/out/${DEVICE}/${KERNEL_FILE}" "${MOUNT_BASEPATH}/boot/zImage"
if [ "${DEVICE}" == "n249" ]; then
root_command cp "kernel/out/${DEVICE}/${DTB_FILE}" "${MOUNT_BASEPATH}/boot"
if [ "${DEVICE}" == "n249" ]; then
root_command ln -s "${DTB_FILE}" "${MOUNT_BASEPATH}/boot/imx6sll-kobo-clarahd.dtb"
fi
root_command cp "kernel/out/${DEVICE}/${BOOTSCRIPT_FILE}" "${MOUNT_BASEPATH}/boot"
fi
else
root_command dd if="kernel/out/${DEVICE}/${KERNEL_FILE}" of=/dev/nbd0 bs=512 seek=81920
fi
if [ "${KERNEL_TYPE}" == "root" ]; then
printf "rooted" | root_command dd of=/dev/nbd0 bs=512 seek=79872
fi
popd
}
setup_boot() {
printf "==== Populating boot partition ====\n"
root_command mkdir -p "${MOUNT_BASEPATH}/boot/flags/"
printf "true\n" | root_command tee -a "${MOUNT_BASEPATH}/boot/flags/FIRST_BOOT"
printf "true\n" | root_command tee -a "${MOUNT_BASEPATH}/boot/flags/X11_START"
}
setup_rootfs() {
printf "==== Populating root filesystem partition ====\n"
pushd out/
git clone "${GIT_BASE_URL}/rootfs" && pushd rootfs/
env GITDIR="${PWD}" ./release.sh && popd
openssl dgst -sha256 -sign "${PKEY}" -out "${GITDIR}/sd/overlaymount-rootfs.squashfs.dgst" "${GITDIR}/sd/overlaymount-rootfs.squashfs"
root_command cp -v "${GITDIR}/sd/overlaymount-rootfs.squashfs" "${GITDIR}/sd/overlaymount-rootfs.squashfs.dgst" "${MOUNT_BASEPATH}/rootfs"
openssl dgst -sha256 -sign "${PKEY}" -out rootfs.squashfs.dgst rootfs.squashfs
root_command cp -v "rootfs.squashfs" "rootfs.squashfs.dgst" "${MOUNT_BASEPATH}/rootfs"
sync
pushd release/ && root_command tar -I 'xz -9 -T0' -cvf rootfs-partition.tar.xz -C "${MOUNT_BASEPATH}/rootfs" . && popd
sync
popd
}
setup_user() {
printf "==== Populating user data partition ====\n"
pushd out/
mkdir -p user/ && pushd user/
# cp /home/build/inkbox/emu/sd/user.sqsh.* .
wget "https://github.com/Quill-OS/emu/blob/main/sd/user.sqsh.a?raw=true" -O "user.sqsh.a"
wget "https://github.com/Quill-OS/emu/blob/main/sd/user.sqsh.b?raw=true" -O "user.sqsh.b"
wget "https://github.com/Quill-OS/emu/blob/main/sd/user.sqsh.c?raw=true" -O "user.sqsh.c"
wget "https://github.com/Quill-OS/emu/blob/main/sd/user.sqsh.d?raw=true" -O "user.sqsh.d"
cat user.sqsh.* > user.sqsh
sync
root_command unsquashfs -no-xattrs -f -d "${MOUNT_BASEPATH}/user" user.sqsh && sync && popd
root_command mkdir -p "${MOUNT_BASEPATH}/user/update"
# GUI rootfs base
git clone "${GIT_BASE_URL}/gui-rootfs" && pushd gui-rootfs/
env GITDIR="${PWD}" ./release.sh && popd
root_command cp -v "gui_rootfs.isa" "${MOUNT_BASEPATH}/user/gui_rootfs.isa"
root_command openssl dgst -sha256 -sign "${PKEY}" -out "${MOUNT_BASEPATH}/user/gui_rootfs.isa.dgst" "${MOUNT_BASEPATH}/user/gui_rootfs.isa"
# CURRENT_VERSION=$(wget -q -O - "${PKGS_BASE_URL}/bundles/inkbox/native/update/ota_current")
CURRENT_VERSION="2.0"
printf "%s\n" "${CURRENT_VERSION}" | root_command tee -a "${MOUNT_BASEPATH}/user/update/version"
if [ "${LOCAL_GUI_BUNDLE}" == "1" ]; then
pushd "${GITDIR}/../inkbox" && git pull && "${QMAKE}" && make clean && make -j$(($(nproc)*2)) && popd
pushd "${GITDIR}/../lockscreen" && git pull && "${QMAKE}" && make clean && make -j$(($(nproc)*2)) && popd
pushd "${GITDIR}/../oobe-inkbox" && git pull && "${QMAKE}" && make clean && make -j$(($(nproc)*2)) && popd
pushd "${GITDIR}/../gui-bundle" && env GITDIR="${PWD}" ./release.sh "${PKEY}" "${CURRENT_VERSION}" "${PWD}/.." && popd
root_command cp -v "${GITDIR}/../gui-bundle/out/update.isa" "${MOUNT_BASEPATH}/user/update/update.isa"
else
wget "${PKGS_BASE_URL}/bundles/inkbox/native/update/${CURRENT_VERSION}/${DEVICE}/inkbox-update-${CURRENT_VERSION}.upd.isa"
unsquashfs "inkbox-update-${CURRENT_VERSION}.upd.isa" -no-xattrs -extract-file update.isa
# Replace the keys in update.isa
cd squashfs-root/
unsquashfs -no-xattrs -d update_inkbox update.isa
rm -f update.isa
cd update_inkbox/
rm -f inkbox.isa.dgst
rm -f qt.isa.dgst
openssl dgst -sha256 -sign "${PKEY}" -out qt.isa.dgst qt.isa
openssl dgst -sha256 -sign "${PKEY}" -out inkbox.isa.dgst inkbox.isa
mksquashfs . ../update.isa -b 1048576 -comp gzip -always-use-fragments -no-xattrs
cd ../../
root_command cp -v squashfs-root/update.isa "${MOUNT_BASEPATH}/user/update/update.isa"
fi
sync
rm -rf squashfs-root/
root_command rm -rf "${MOUNT_BASEPATH}/user/config"
root_command mkdir -p "${MOUNT_BASEPATH}/user/config"
root_command tar -xvf "${GITDIR}/sd/config-${DEVICE}.tar.xz" -C "${MOUNT_BASEPATH}/user/config"
sync
pushd release/ && root_command tar -I 'xz -9 -T0' -cvf user-partition.tar.xz -C "${MOUNT_BASEPATH}/user" . && popd
sync
popd
}
setup_recoveryfs() {
printf "==== Populating recovery filesystem partition ====\n"
pushd out/
git clone "${GIT_BASE_URL}/recoveryfs" && pushd recoveryfs/
root_command cp -v "${GITDIR}/out/release/rootfs-partition.tar.xz" opt/recovery/restore/rootfs-part.tar.xz
root_command cp -v "${GITDIR}/out/release/user-partition.tar.xz" opt/recovery/restore/userstore.tar.xz
root_command cp -v "${GITDIR}/sd/config-${DEVICE}.tar.xz" opt/recovery/restore/config.tar.xz
if [ "${DEVICE}" != "n418" ]; then
root_command cp -v "${GITDIR}/out/release/u-boot_inkbox.bin" opt/recovery/restore/u-boot_inkbox.bin
fi
if [ "${DEVICE}" == "n306" ] || [ "${DEVICE}" == "n306c" ] || [ "${DEVICE}" == "n249" ] || [ "${DEVICE}" == "n418" ]; then
root_command cp -v "${GITDIR}/out/release/zImage-std" opt/recovery/restore/zImage-std
root_command cp -v "${GITDIR}/out/release/zImage-root" opt/recovery/restore/zImage-root
else
root_command cp -v "${GITDIR}/out/release/uImage-std" opt/recovery/restore/uImage-std
root_command cp -v "${GITDIR}/out/release/uImage-root" opt/recovery/restore/uImage-root
fi
[ -f "${GITDIR}/out/release/uImage-diags" ] && root_command cp -v "${GITDIR}/out/release/uImage-diags" opt/recovery/restore/uImage-diags
env GITDIR="${PWD}" ./release.sh && popd
openssl dgst -sha256 -sign "${PKEY}" -out "${GITDIR}/sd/overlaymount-rootfs.squashfs.dgst" "${GITDIR}/sd/overlaymount-rootfs.squashfs"
root_command cp -v "${GITDIR}/sd/overlaymount-rootfs.squashfs" "${GITDIR}/sd/overlaymount-rootfs.squashfs.dgst" "${MOUNT_BASEPATH}/recoveryfs"
openssl dgst -sha256 -sign "${PKEY}" -out recoveryfs.squashfs.dgst recoveryfs.squashfs
root_command cp -v "recoveryfs.squashfs" "recoveryfs.squashfs.dgst" "${MOUNT_BASEPATH}/recoveryfs"
sync
popd
}
pack_image() {
printf "==== Packing final image ====\n"
pushd out/release/
root_command dd if=/dev/nbd0 status=progress of="inkbox-${CURRENT_VERSION}-${DEVICE}.img"
sync
popd
}
cleanup() {
printf "==== Cleaning up ====\n"
root_command umount "${MOUNT_BASEPATH}/boot" "${MOUNT_BASEPATH}/recoveryfs" "${MOUNT_BASEPATH}/rootfs" "${MOUNT_BASEPATH}/user"
root_command qemu-nbd --disconnect /dev/nbd0
rm -rf "${MOUNT_BASEPATH}"
}
case "${1}" in
n705)
DEVICE="n705"
;;
n905b)
DEVICE="n905b"
;;
n905c)
DEVICE="n905c"
;;
n613)
DEVICE="n613"
;;
n236)
DEVICE="n236"
;;
n437)
DEVICE="n437"
;;
n306)
DEVICE="n306"
;;
n306c)
DEVICE="n306c"
;;
n249)
DEVICE="n249"
;;
n418)
DEVICE="n418"
;;
*)
printf "%s is not a valid device! Available options are: n705, n905b, n905c, n613, n236, n437, n306, n306c, n249, n418" "${1}" && exit 1
esac
build_base_sd_image
setup_u_boot
mount_fs
setup_kernel
setup_boot
setup_rootfs
setup_user
setup_recoveryfs
pack_image
cleanup
printf "==== All done! ====\n"