CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
orangepi-xunlong

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: orangepi-xunlong/orangepi-build
Path: blob/next/scripts/makeboarddeb.sh
Views: 3960
1
#!/bin/bash
2
#
3
# Copyright (c) 2021 Igor Pecovnik, igor.pecovnik@gma**.com
4
#
5
# This file is licensed under the terms of the GNU General Public
6
# License version 2. This program is licensed "as is" without any
7
# warranty of any kind, whether express or implied.
8
9
10
#
11
# Functions:
12
# create_board_package
13
14
15
16
17
create_board_package()
18
{
19
display_alert "Creating board support package for CLI" "$CHOSEN_ROOTFS" "info"
20
21
bsptempdir=$(mktemp -d)
22
chmod 700 ${bsptempdir}
23
trap "rm -rf \"${bsptempdir}\" ; exit 0" 0 1 2 3 15
24
local destination=${bsptempdir}/${RELEASE}/${BSP_CLI_PACKAGE_FULLNAME}
25
mkdir -p "${destination}"/DEBIAN
26
cd $destination
27
28
# copy general overlay from packages/bsp-cli
29
copy_all_packages_files_for "bsp-cli"
30
31
# install copy of boot script & environment file
32
if [[ "${BOOTCONFIG}" != "none" ]]; then
33
# @TODO: add extension method bsp_prepare_bootloader(), refactor into u-boot extension
34
local bootscript_src=${BOOTSCRIPT%%:*}
35
local bootscript_dst=${BOOTSCRIPT##*:}
36
mkdir -p "${destination}"/usr/share/orangepi/
37
38
# create extlinux config file
39
if [[ $SRC_EXTLINUX != yes ]]; then
40
if [ -f "${USERPATCHES_PATH}/bootscripts/${bootscript_src}" ]; then
41
cp "${USERPATCHES_PATH}/bootscripts/${bootscript_src}" "${destination}/usr/share/orangepi/${bootscript_dst}"
42
else
43
cp "${EXTER}/config/bootscripts/${bootscript_src}" "${destination}/usr/share/orangepi/${bootscript_dst}"
44
fi
45
[[ -n $BOOTENV_FILE && -f $SRC/config/bootenv/$BOOTENV_FILE ]] && \
46
cp "${EXTER}/config/bootenv/${BOOTENV_FILE}" "${destination}"/usr/share/orangepi/orangepiEnv.txt
47
fi
48
49
# add configuration for setting uboot environment from userspace with: fw_setenv fw_printenv
50
if [[ -n $UBOOT_FW_ENV ]]; then
51
UBOOT_FW_ENV=($(tr ',' ' ' <<< "$UBOOT_FW_ENV"))
52
mkdir -p "${destination}"/etc
53
echo "# Device to access offset env size" > "${destination}"/etc/fw_env.config
54
echo "/dev/mmcblk0 ${UBOOT_FW_ENV[0]} ${UBOOT_FW_ENV[1]}" >> "${destination}"/etc/fw_env.config
55
fi
56
fi
57
58
# Replaces: base-files is needed to replace /etc/update-motd.d/ files on Xenial
59
# Replaces: unattended-upgrades may be needed to replace /etc/apt/apt.conf.d/50unattended-upgrades
60
# (distributions provide good defaults, so this is not needed currently)
61
# Depends: linux-base is needed for "linux-version" command in initrd cleanup script
62
# Depends: fping is needed for orangepimonitor to upload orangepi-hardware-monitor.log
63
cat <<-EOF > "${destination}"/DEBIAN/control
64
Package: ${BSP_CLI_PACKAGE_NAME}
65
Version: $REVISION
66
Architecture: $ARCH
67
Maintainer: $MAINTAINER <$MAINTAINERMAIL>
68
Installed-Size: 1
69
Section: kernel
70
Priority: optional
71
Depends: bash, linux-base, u-boot-tools, initramfs-tools, lsb-release, fping
72
Provides: linux-${RELEASE}-root-legacy-$BOARD, linux-${RELEASE}-root-current-$BOARD, linux-${RELEASE}-root-next-$BOARD
73
Suggests: orangepi-config
74
Replaces: zram-config, base-files, orangepi-tools-$RELEASE, linux-${RELEASE}-root-legacy-$BOARD (<< $REVISION~), linux-${RELEASE}-root-current-$BOARD (<< $REVISION~), linux-${RELEASE}-root-next-$BOARD (<< $REVISION~)
75
Breaks: linux-${RELEASE}-root-legacy-$BOARD (<< $REVISION~), linux-${RELEASE}-root-current-$BOARD (<< $REVISION~), linux-${RELEASE}-root-next-$BOARD (<< $REVISION~)
76
Recommends: bsdutils, parted, util-linux, toilet
77
Description: OrangePi board support files for $BOARD
78
EOF
79
80
# set up pre install script
81
cat <<-EOF > "${destination}"/DEBIAN/preinst
82
#!/bin/sh
83
84
# tell people to reboot at next login
85
[ "\$1" = "upgrade" ] && touch /var/run/.reboot_required
86
87
# convert link to file
88
if [ -L "/etc/network/interfaces" ]; then
89
90
cp /etc/network/interfaces /etc/network/interfaces.tmp
91
rm /etc/network/interfaces
92
mv /etc/network/interfaces.tmp /etc/network/interfaces
93
94
fi
95
96
# fixing ramdisk corruption when using lz4 compression method
97
sed -i "s/^COMPRESS=.*/COMPRESS=gzip/" /etc/initramfs-tools/initramfs.conf
98
99
# swap
100
grep -q vm.swappiness /etc/sysctl.conf
101
case \$? in
102
0)
103
sed -i 's/vm\.swappiness.*/vm.swappiness=100/' /etc/sysctl.conf
104
;;
105
*)
106
echo vm.swappiness=100 >>/etc/sysctl.conf
107
;;
108
esac
109
sysctl -p >/dev/null 2>&1
110
111
# disable deprecated services
112
[ -f "/etc/profile.d/activate_psd_user.sh" ] && rm /etc/profile.d/activate_psd_user.sh
113
[ -f "/etc/profile.d/check_first_login.sh" ] && rm /etc/profile.d/check_first_login.sh
114
[ -f "/etc/profile.d/check_first_login_reboot.sh" ] && rm /etc/profile.d/check_first_login_reboot.sh
115
[ -f "/etc/profile.d/ssh-title.sh" ] && rm /etc/profile.d/ssh-title.sh
116
[ -f "/etc/update-motd.d/10-header" ] && rm /etc/update-motd.d/10-header
117
[ -f "/etc/update-motd.d/30-sysinfo" ] && rm /etc/update-motd.d/30-sysinfo
118
[ -f "/etc/update-motd.d/35-tips" ] && rm /etc/update-motd.d/35-tips
119
[ -f "/etc/update-motd.d/40-updates" ] && rm /etc/update-motd.d/40-updates
120
[ -f "/etc/update-motd.d/98-autoreboot-warn" ] && rm /etc/update-motd.d/98-autoreboot-warn
121
[ -f "/etc/update-motd.d/99-point-to-faq" ] && rm /etc/update-motd.d/99-point-to-faq
122
[ -f "/etc/update-motd.d/80-esm" ] && rm /etc/update-motd.d/80-esm
123
[ -f "/etc/update-motd.d/80-livepatch" ] && rm /etc/update-motd.d/80-livepatch
124
[ -f "/etc/apt/apt.conf.d/02compress-indexes" ] && rm /etc/apt/apt.conf.d/02compress-indexes
125
[ -f "/etc/apt/apt.conf.d/02periodic" ] && rm /etc/apt/apt.conf.d/02periodic
126
[ -f "/etc/apt/apt.conf.d/no-languages" ] && rm /etc/apt/apt.conf.d/no-languages
127
[ -f "/etc/init.d/armhwinfo" ] && rm /etc/init.d/armhwinfo
128
[ -f "/etc/logrotate.d/armhwinfo" ] && rm /etc/logrotate.d/armhwinfo
129
[ -f "/etc/init.d/firstrun" ] && rm /etc/init.d/firstrun
130
[ -f "/etc/init.d/resize2fs" ] && rm /etc/init.d/resize2fs
131
[ -f "/lib/systemd/system/firstrun-config.service" ] && rm /lib/systemd/system/firstrun-config.service
132
[ -f "/lib/systemd/system/firstrun.service" ] && rm /lib/systemd/system/firstrun.service
133
[ -f "/lib/systemd/system/resize2fs.service" ] && rm /lib/systemd/system/resize2fs.service
134
[ -f "/usr/lib/orangepi/apt-updates" ] && rm /usr/lib/orangepi/apt-updates
135
[ -f "/usr/lib/orangepi/firstrun-config.sh" ] && rm /usr/lib/orangepi/firstrun-config.sh
136
# fix for https://bugs.launchpad.net/ubuntu/+source/lightdm-gtk-greeter/+bug/1897491
137
[ -d "/var/lib/lightdm" ] && (chown -R lightdm:lightdm /var/lib/lightdm ; chmod 0750 /var/lib/lightdm)
138
exit 0
139
EOF
140
141
chmod 755 "${destination}"/DEBIAN/preinst
142
143
# postrm script
144
cat <<-EOF > "${destination}"/DEBIAN/postrm
145
#!/bin/sh
146
if [ remove = "\$1" ] || [ abort-install = "\$1" ]; then
147
148
systemctl disable orangepi-hardware-monitor.service orangepi-hardware-optimize.service >/dev/null 2>&1
149
systemctl disable orangepi-zram-config.service orangepi-ramlog.service >/dev/null 2>&1
150
151
fi
152
exit 0
153
EOF
154
155
chmod 755 "${destination}"/DEBIAN/postrm
156
157
# set up post install script
158
cat <<-EOF > "${destination}"/DEBIAN/postinst
159
#!/bin/sh
160
#
161
# ${BOARD} BSP post installation script
162
#
163
164
[ -f /etc/lib/systemd/system/orangepi-ramlog.service ] && systemctl --no-reload enable orangepi-ramlog.service
165
166
# check if it was disabled in config and disable in new service
167
if [ -n "\$(grep -w '^ENABLED=false' /etc/default/log2ram 2> /dev/null)" ]; then
168
169
sed -i "s/^ENABLED=.*/ENABLED=false/" /etc/default/orangepi-ramlog
170
171
fi
172
173
# fix boot delay "waiting for suspend/resume device"
174
if [ -f "/etc/initramfs-tools/initramfs.conf" ]; then
175
176
if ! grep --quiet "RESUME=none" /etc/initramfs-tools/initramfs.conf; then
177
echo "RESUME=none" >> /etc/initramfs-tools/initramfs.conf
178
fi
179
180
fi
181
182
EOF
183
# install bootscripts if they are not present. Fix upgrades from old images
184
if [[ $FORCE_BOOTSCRIPT_UPDATE == yes ]]; then
185
cat <<-EOF >> "${destination}"/DEBIAN/postinst
186
if [ true ]; then
187
188
# this package recreate boot scripts
189
EOF
190
else
191
cat <<-EOF >> "${destination}"/DEBIAN/postinst
192
if [ ! -f /boot/$bootscript_dst ]; then
193
194
# if boot script does not exits its recreated
195
EOF
196
fi
197
cat <<-EOF >> "${destination}"/DEBIAN/postinst
198
# move bootscript to /usr/share/orangepi
199
# create a backup
200
[ -f /etc/orangepi-release ] && . /etc/orangepi-release
201
[ -z \${VERSION} ] && VERSION=$(echo \`date +%s\`)
202
if [ -f /boot/$bootscript_dst ]; then
203
cp /boot/$bootscript_dst /usr/share/orangepi/${bootscript_dst}-\${VERSION} >/dev/null 2>&1
204
echo "NOTE: You can find previous bootscript versions in /usr/share/orangepi !"
205
fi
206
207
# cleanup old bootscript backup
208
ls /usr/share/orangepi/boot.cmd-* >/dev/null 2>&1 | head -n -5 | xargs rm -f --
209
ls /usr/share/orangepi/boot.ini-* >/dev/null 2>&1 | head -n -5 | xargs rm -f --
210
211
echo "Recreating boot script"
212
cp /usr/share/orangepi/$bootscript_dst /boot >/dev/null 2>&1
213
rootdev=\$(sed -e 's/^.*root=//' -e 's/ .*\$//' < /proc/cmdline)
214
rootfstype=\$(sed -e 's/^.*rootfstype=//' -e 's/ .*$//' < /proc/cmdline)
215
216
# recreate orangepiEnv.txt if it and extlinux does not exists
217
if [ ! -f /boot/orangepiEnv.txt ] && [ ! -f /boot/extlinux/extlinux.conf ]; then
218
cp /usr/share/orangepi/orangepiEnv.txt /boot >/dev/null 2>&1
219
echo "rootdev="\$rootdev >> /boot/orangepiEnv.txt
220
echo "rootfstype="\$rootfstype >> /boot/orangepiEnv.txt
221
fi
222
223
[ -f /boot/boot.ini ] && sed -i "s/setenv rootdev.*/setenv rootdev \\"\$rootdev\\"/" /boot/boot.ini
224
[ -f /boot/boot.ini ] && sed -i "s/setenv rootfstype.*/setenv rootfstype \\"\$rootfstype\\"/" /boot/boot.ini
225
[ -f /boot/boot.cmd ] && mkimage -C none -A arm -T script -d /boot/boot.cmd /boot/boot.scr >/dev/null 2>&1
226
227
fi
228
229
[ ! -f "/etc/network/interfaces" ] && [ -f "/etc/network/interfaces.default" ] && cp /etc/network/interfaces.default /etc/network/interfaces
230
ln -sf /var/run/motd /etc/motd
231
rm -f /etc/update-motd.d/00-header /etc/update-motd.d/10-help-text
232
if [ -f "/boot/bin/$BOARD.bin" ] && [ ! -f "/boot/script.bin" ]; then ln -sf bin/$BOARD.bin /boot/script.bin >/dev/null 2>&1 || cp /boot/bin/$BOARD.bin /boot/script.bin; fi
233
if [ ! -f "/etc/default/orangepi-motd" ]; then
234
mv /etc/default/orangepi-motd.dpkg-dist /etc/default/orangepi-motd
235
fi
236
if [ ! -f "/etc/default/orangepi-ramlog" ] && [ -f /etc/default/orangepi-ramlog.dpkg-dist ]; then
237
mv /etc/default/orangepi-ramlog.dpkg-dist /etc/default/orangepi-ramlog
238
fi
239
if [ ! -f "/etc/default/orangepi-zram-config" ] && [ -f /etc/default/orangepi-zram-config.dpkg-dist ]; then
240
mv /etc/default/orangepi-zram-config.dpkg-dist /etc/default/orangepi-zram-config
241
fi
242
243
if [ -L "/usr/lib/chromium-browser/master_preferences.dpkg-dist" ]; then
244
mv /usr/lib/chromium-browser/master_preferences.dpkg-dist /usr/lib/chromium-browser/master_preferences
245
fi
246
247
# Read release value
248
if [ -f /etc/lsb-release ]; then
249
RELEASE=\$(cat /etc/lsb-release | grep CODENAME | cut -d"=" -f2 | sed 's/.*/\u&/')
250
sed -i "s/^PRETTY_NAME=.*/PRETTY_NAME=\"${VENDOR} $REVISION "\${RELEASE}"\"/" /etc/os-release
251
echo "${VENDOR} ${REVISION} \${RELEASE} \\l \n" > /etc/issue
252
echo "${VENDOR} ${REVISION} \${RELEASE}" > /etc/issue.net
253
fi
254
255
# Reload services
256
systemctl --no-reload enable orangepi-hardware-monitor.service orangepi-hardware-optimize.service orangepi-zram-config.service >/dev/null 2>&1
257
exit 0
258
EOF
259
260
chmod 755 "${destination}"/DEBIAN/postinst
261
262
# won't recreate files if they were removed by user
263
# TODO: Add proper handling for updated conffiles
264
#cat <<-EOF > "${destination}"/DEBIAN/conffiles
265
#EOF
266
267
# copy common files from a premade directory structure
268
rsync -a "${EXTER}"/packages/bsp/common/* ${destination}
269
270
# trigger uInitrd creation after installation, to apply
271
# /etc/initramfs/post-update.d/99-uboot
272
cat <<-EOF > "${destination}"/DEBIAN/triggers
273
activate update-initramfs
274
EOF
275
276
# copy distribution support status
277
local releases=($(find ${EXTER}/config/distributions -mindepth 1 -maxdepth 1 -type d))
278
for i in ${releases[@]}
279
do
280
echo "$(echo $i | sed 's/.*\///')=$(cat $i/support)" >> "${destination}"/etc/orangepi-distribution-status
281
done
282
283
# armhwinfo, firstrun, orangepimonitor, etc. config file
284
cat <<-EOF > "${destination}"/etc/orangepi-release
285
# PLEASE DO NOT EDIT THIS FILE
286
BOARD=${BOARD}
287
BOARD_NAME="$BOARD_NAME"
288
BOARDFAMILY=${BOARDFAMILY}
289
BUILD_REPOSITORY_URL=${BUILD_REPOSITORY_URL}
290
BUILD_REPOSITORY_COMMIT=${BUILD_REPOSITORY_COMMIT}
291
DISTRIBUTION_CODENAME=${RELEASE}
292
DISTRIBUTION_STATUS=${DISTRIBUTION_STATUS}
293
VERSION=${REVISION}
294
LINUXFAMILY=${LINUXFAMILY}
295
ARCH=${ARCHITECTURE}
296
IMAGE_TYPE=$IMAGE_TYPE
297
BOARD_TYPE=$BOARD_TYPE
298
INITRD_ARCH=${INITRD_ARCH}
299
KERNEL_IMAGE_TYPE=${KERNEL_IMAGE_TYPE}
300
BRANCH=${BRANCH}
301
EOF
302
303
# this is required for NFS boot to prevent deconfiguring the network on shutdown
304
sed -i 's/#no-auto-down/no-auto-down/g' "${destination}"/etc/network/interfaces.default
305
306
if [[ ( $LINUXFAMILY == sun8i ) && $BRANCH == legacy ]]; then
307
# add mpv config for vdpau_sunxi
308
mkdir -p "${destination}"/etc/mpv/
309
cp "${EXTER}"/packages/bsp/mpv/mpv_sunxi.conf "${destination}"/etc/mpv/mpv.conf
310
echo "export VDPAU_OSD=1" > "${destination}"/etc/profile.d/90-vdpau.sh
311
chmod 755 "${destination}"/etc/profile.d/90-vdpau.sh
312
fi
313
if [[ $LINUXFAMILY == sunxi* ]]; then
314
# add mpv config for x11 output - slow, but it works compared to no config at all
315
# TODO: Test which output driver is better with DRM
316
mkdir -p "${destination}"/etc/mpv/
317
cp "${EXTER}"/packages/bsp/mpv/mpv_mainline.conf "${destination}"/etc/mpv/mpv.conf
318
fi
319
320
case $RELEASE in
321
xenial)
322
if [[ $BRANCH == legacy && $LINUXFAMILY == sun8i ]]; then
323
# this is required only for old kernels
324
# not needed for Stretch since there will be no Stretch images with kernels < 4.4
325
mkdir -p "${destination}"/lib/systemd/system/haveged.service.d/
326
cp "${EXTER}"/packages/bsp/10-no-new-privileges.conf "${destination}"/lib/systemd/system/haveged.service.d/
327
fi
328
;;
329
esac
330
# execute $LINUXFAMILY-specific tweaks
331
[[ $(type -t family_tweaks_bsp) == function ]] && family_tweaks_bsp
332
333
call_extension_method "post_family_tweaks_bsp" << 'POST_FAMILY_TWEAKS_BSP'
334
*family_tweaks_bsp overrrides what is in the config, so give it a chance to override the family tweaks*
335
This should be implemented by the config to tweak the BSP, after the board or family has had the chance to.
336
POST_FAMILY_TWEAKS_BSP
337
338
# add some summary to the image
339
fingerprint_image "${destination}/etc/orangepi.txt"
340
341
# fixing permissions (basic), reference: dh_fixperms
342
find "${destination}" -print0 2>/dev/null | xargs -0r chown --no-dereference 0:0
343
find "${destination}" ! -type l -print0 2>/dev/null | xargs -0r chmod 'go=rX,u+rw,a-s'
344
345
# create board DEB file
346
fakeroot dpkg-deb -b -Z${DEB_COMPRESS} "${destination}" "${destination}.deb" >> "${DEST}"/${LOG_SUBPATH}/output.log 2>&1
347
mkdir -p "${DEB_STORAGE}/${RELEASE}/"
348
rsync --remove-source-files -rq "${destination}.deb" "${DEB_STORAGE}/${RELEASE}/"
349
350
# cleanup
351
rm -rf ${bsptempdir}
352
}
353
354