Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
orangepi-xunlong
GitHub Repository: orangepi-xunlong/orangepi-build
Path: blob/next/scripts/distributions.sh
13066 views
1
#!/bin/bash
2
#
3
# Copyright (c) 2013-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
# Functions:
11
12
# install_common
13
# install_rclocal
14
# install_distribution_specific
15
# post_debootstrap_tweaks
16
17
18
19
20
install_common()
21
{
22
display_alert "Applying common tweaks" "" "info"
23
24
# install rootfs encryption related packages separate to not break packages cache
25
if [[ $CRYPTROOT_ENABLE == yes ]]; then
26
display_alert "Installing rootfs encryption related packages" "cryptsetup" "info"
27
chroot "${SDCARD}" /bin/bash -c "apt-get -y -qq --no-install-recommends install cryptsetup" \
28
>> "${DEST}"/${LOG_SUBPATH}/install.log 2>&1
29
if [[ $CRYPTROOT_SSH_UNLOCK == yes ]]; then
30
display_alert "Installing rootfs encryption related packages" "dropbear-initramfs" "info"
31
chroot "${SDCARD}" /bin/bash -c "apt-get -y -qq --no-install-recommends install dropbear-initramfs cryptsetup-initramfs" \
32
>> "${DEST}"/${LOG_SUBPATH}/install.log 2>&1
33
fi
34
35
fi
36
37
# add dummy fstab entry to make mkinitramfs happy
38
echo "/dev/mmcblk0p1 / $ROOTFS_TYPE defaults 0 1" >> "${SDCARD}"/etc/fstab
39
# required for initramfs-tools-core on Stretch since it ignores the / fstab entry
40
echo "/dev/mmcblk0p2 /usr $ROOTFS_TYPE defaults 0 2" >> "${SDCARD}"/etc/fstab
41
42
# adjust initramfs dropbear configuration
43
# needs to be done before kernel installation, else it won't be in the initrd image
44
if [[ $CRYPTROOT_ENABLE == yes && $CRYPTROOT_SSH_UNLOCK == yes ]]; then
45
# Set the port of the dropbear ssh daemon in the initramfs to a different one if configured
46
# this avoids the typical 'host key changed warning' - `WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!`
47
[[ -f "${SDCARD}"/etc/dropbear-initramfs/config ]] && \
48
sed -i 's/^#DROPBEAR_OPTIONS=/DROPBEAR_OPTIONS="-p '"${CRYPTROOT_SSH_UNLOCK_PORT}"'"/' \
49
"${SDCARD}"/etc/dropbear-initramfs/config
50
51
# setup dropbear authorized_keys, either provided by userpatches or generated
52
if [[ -f $USERPATCHES_PATH/dropbear_authorized_keys ]]; then
53
cp "$USERPATCHES_PATH"/dropbear_authorized_keys "${SDCARD}"/etc/dropbear-initramfs/authorized_keys
54
else
55
# generate a default ssh key for login on dropbear in initramfs
56
# this key should be changed by the user on first login
57
display_alert "Generating a new SSH key pair for dropbear (initramfs)" "" ""
58
ssh-keygen -t ecdsa -f "${SDCARD}"/etc/dropbear-initramfs/id_ecdsa \
59
-N '' -O force-command=cryptroot-unlock -C 'AUTOGENERATED_BY_ARMBIAN_BUILD' >> "${DEST}"/${LOG_SUBPATH}/install.log 2>&1
60
61
# /usr/share/initramfs-tools/hooks/dropbear will automatically add 'id_ecdsa.pub' to authorized_keys file
62
# during mkinitramfs of update-initramfs
63
#cat "${SDCARD}"/etc/dropbear-initramfs/id_ecdsa.pub > "${SDCARD}"/etc/dropbear-initramfs/authorized_keys
64
# The version of the Linux kernel
65
CRYPTROOT_SSH_UNLOCK_KEY_NAME="${BOARD^}_${REVISION}_${DISTRIBUTION,}_${RELEASE}_${SELECTED_CONFIGURATION}_linux"$(grab_version "$LINUXSOURCEDIR")"".key
66
# copy dropbear ssh key to image output dir for convenience
67
cp "${SDCARD}"/etc/dropbear-initramfs/id_ecdsa "${DEST}/images/${CRYPTROOT_SSH_UNLOCK_KEY_NAME}"
68
display_alert "SSH private key for dropbear (initramfs) has been copied to:" \
69
"$DEST/images/$CRYPTROOT_SSH_UNLOCK_KEY_NAME" "info"
70
fi
71
fi
72
73
# create modules file
74
local modules=MODULES_${BRANCH^^}
75
if [[ -n "${!modules}" ]]; then
76
tr ' ' '\n' <<< "${!modules}" > "${SDCARD}"/etc/modules
77
elif [[ -n "${MODULES}" ]]; then
78
tr ' ' '\n' <<< "${MODULES}" > "${SDCARD}"/etc/modules
79
fi
80
81
# create blacklist files
82
local blacklist=MODULES_BLACKLIST_${BRANCH^^}
83
if [[ -n "${!blacklist}" ]]; then
84
tr ' ' '\n' <<< "${!blacklist}" | sed -e 's/^/blacklist /' > "${SDCARD}/etc/modprobe.d/blacklist-${BOARD}.conf"
85
elif [[ -n "${MODULES_BLACKLIST}" ]]; then
86
tr ' ' '\n' <<< "${MODULES_BLACKLIST}" | sed -e 's/^/blacklist /' > "${SDCARD}/etc/modprobe.d/blacklist-${BOARD}.conf"
87
fi
88
89
# configure MIN / MAX speed for cpufrequtils
90
cat <<-EOF > "${SDCARD}"/etc/default/cpufrequtils
91
ENABLE=true
92
MIN_SPEED=$CPUMIN
93
MAX_SPEED=$CPUMAX
94
GOVERNOR=$GOVERNOR
95
EOF
96
97
# remove default interfaces file if present
98
# before installing board support package
99
rm -f "${SDCARD}"/etc/network/interfaces
100
101
# disable selinux by default
102
mkdir -p "${SDCARD}"/selinux
103
[[ -f "${SDCARD}"/etc/selinux/config ]] && sed "s/^SELINUX=.*/SELINUX=disabled/" -i "${SDCARD}"/etc/selinux/config
104
105
# remove Ubuntu's legal text
106
[[ -f "${SDCARD}"/etc/legal ]] && rm "${SDCARD}"/etc/legal
107
108
# Prevent loading paralel printer port drivers which we don't need here.
109
# Suppress boot error if kernel modules are absent
110
if [[ -f "${SDCARD}"/etc/modules-load.d/cups-filters.conf ]]; then
111
sed "s/^lp/#lp/" -i "${SDCARD}"/etc/modules-load.d/cups-filters.conf
112
sed "s/^ppdev/#ppdev/" -i "${SDCARD}"/etc/modules-load.d/cups-filters.conf
113
sed "s/^parport_pc/#parport_pc/" -i "${SDCARD}"/etc/modules-load.d/cups-filters.conf
114
fi
115
116
# console fix due to Debian bug
117
sed -e 's/CHARMAP=".*"/CHARMAP="'$CONSOLE_CHAR'"/g' -i "${SDCARD}"/etc/default/console-setup
118
119
# add the /dev/urandom path to the rng config file
120
echo "HRNGDEVICE=/dev/urandom" >> "${SDCARD}"/etc/default/rng-tools
121
122
# ping needs privileged action to be able to create raw network socket
123
# this is working properly but not with (at least) Debian Buster
124
chroot "${SDCARD}" /bin/bash -c "chmod u+s /bin/ping"
125
126
# change time zone data
127
echo "${TZDATA}" > "${SDCARD}"/etc/timezone
128
chroot "${SDCARD}" /bin/bash -c "dpkg-reconfigure -f noninteractive tzdata >/dev/null 2>&1"
129
130
# set root password
131
chroot "${SDCARD}" /bin/bash -c "(echo $ROOTPWD;echo $ROOTPWD;) | passwd root >/dev/null 2>&1"
132
133
# enable automated login to console(s)
134
#mkdir -p "${SDCARD}"/etc/systemd/system/[email protected]/
135
#mkdir -p "${SDCARD}"/etc/systemd/system/[email protected]/
136
#cat <<-EOF > "${SDCARD}"/etc/systemd/system/[email protected]/override.conf
137
#[Service]
138
#ExecStartPre=/bin/sh -c 'exec /bin/sleep 10'
139
#ExecStart=
140
#ExecStart=-/sbin/agetty --noissue --autologin root %I \$TERM
141
#Type=idle
142
#EOF
143
#cp "${SDCARD}"/etc/systemd/system/[email protected]/override.conf "${SDCARD}"/etc/systemd/system/[email protected]/override.conf
144
145
# force change root password at first login
146
#chroot "${SDCARD}" /bin/bash -c "chage -d 0 root"
147
148
# change console welcome text
149
echo -e "${VENDOR} ${REVISION} ${RELEASE^} \\l \n" > "${SDCARD}"/etc/issue
150
echo "${VENDOR} ${REVISION} ${RELEASE^}" > "${SDCARD}"/etc/issue.net
151
sed -i "s/^PRETTY_NAME=.*/PRETTY_NAME=\"${VENDOR} $REVISION "${RELEASE^}"\"/" "${SDCARD}"/etc/os-release
152
153
# enable few bash aliases enabled in Ubuntu by default to make it even
154
sed "s/#alias ll='ls -l'/alias ll='ls -l'/" -i "${SDCARD}"/etc/skel/.bashrc
155
sed "s/#alias la='ls -A'/alias la='ls -A'/" -i "${SDCARD}"/etc/skel/.bashrc
156
sed "s/#alias l='ls -CF'/alias l='ls -CF'/" -i "${SDCARD}"/etc/skel/.bashrc
157
# root user is already there. Copy bashrc there as well
158
cp "${SDCARD}"/etc/skel/.bashrc "${SDCARD}"/root
159
160
# display welcome message at first root login
161
touch "${SDCARD}"/root/.not_logged_in_yet
162
163
if [[ ${DESKTOP_AUTOLOGIN} != no ]]; then
164
# set desktop autologin
165
touch "${SDCARD}"/root/.desktop_autologin
166
fi
167
168
# NOTE: this needs to be executed before family_tweaks
169
local bootscript_src=${BOOTSCRIPT%%:*}
170
local bootscript_dst=${BOOTSCRIPT##*:}
171
local bootdir=$([[ "$BOOTFS_TYPE" == "fat" ]] || echo "/boot")
172
173
# create extlinux config file
174
if [[ $SRC_EXTLINUX == yes ]]; then
175
mkdir -p $SDCARD/boot/extlinux
176
cat <<-EOF > "$SDCARD/boot/extlinux/extlinux.conf"
177
label ${VENDOR}
178
kernel $bootdir/$NAME_KERNEL
179
initrd $bootdir/$NAME_INITRD
180
EOF
181
if [[ -n $BOOT_FDT_FILE ]]; then
182
if [[ $BOOT_FDT_FILE != "none" ]]; then
183
echo " fdt $bootdir/dtb/$BOOT_FDT_FILE" >> "$SDCARD/boot/extlinux/extlinux.conf"
184
fi
185
else
186
echo " fdtdir $bootdir/dtb/" >> "$SDCARD/boot/extlinux/extlinux.conf"
187
fi
188
else
189
190
if [[ "${BOOTCONFIG}" != "none" ]]; then
191
if [ -f "${USERPATCHES_PATH}/bootscripts/${bootscript_src}" ]; then
192
cp "${USERPATCHES_PATH}/bootscripts/${bootscript_src}" "${SDCARD}/boot/${bootscript_dst}"
193
else
194
cp "${EXTER}/config/bootscripts/${bootscript_src}" "${SDCARD}/boot/${bootscript_dst}"
195
fi
196
fi
197
198
if [[ -n $BOOTENV_FILE ]]; then
199
if [[ -f $USERPATCHES_PATH/bootenv/$BOOTENV_FILE ]]; then
200
cp "$USERPATCHES_PATH/bootenv/${BOOTENV_FILE}" "${SDCARD}"/boot/orangepiEnv.txt
201
elif [[ -f $EXTER/config/bootenv/$BOOTENV_FILE ]]; then
202
cp "${EXTER}/config/bootenv/${BOOTENV_FILE}" "${SDCARD}"/boot/orangepiEnv.txt
203
fi
204
fi
205
206
# TODO: modify $bootscript_dst or orangepiEnv.txt to make NFS boot universal
207
# instead of copying sunxi-specific template
208
if [[ $ROOTFS_TYPE == nfs ]]; then
209
display_alert "Copying NFS boot script template"
210
if [[ -f $USERPATCHES_PATH/nfs-boot.cmd ]]; then
211
cp "$USERPATCHES_PATH"/nfs-boot.cmd "${SDCARD}"/boot/boot.cmd
212
else
213
cp "${EXTER}"/config/templates/nfs-boot.cmd.template "${SDCARD}"/boot/boot.cmd
214
fi
215
fi
216
217
[[ -n $OVERLAY_PREFIX && -f "${SDCARD}"/boot/orangepiEnv.txt && ($BRANCH =~ current|next || $BOARDFAMILY =~ "rockchip-rk3588"|"rockchip-rk356x") ]] && \
218
echo "overlay_prefix=$OVERLAY_PREFIX" >> "${SDCARD}"/boot/orangepiEnv.txt
219
220
[[ -n $DEFAULT_OVERLAYS && -f "${SDCARD}"/boot/orangepiEnv.txt && ($BRANCH =~ current|next || $BOARDFAMILY =~ "rockchip-rk3588"|"rockchip-rk356x") ]] && \
221
echo "overlays=${DEFAULT_OVERLAYS//,/ }" >> "${SDCARD}"/boot/orangepiEnv.txt
222
223
[[ -n $BOOT_FDT_FILE && -f "${SDCARD}"/boot/orangepiEnv.txt ]] && \
224
echo "fdtfile=${BOOT_FDT_FILE}" >> "${SDCARD}/boot/orangepiEnv.txt"
225
226
fi
227
228
# initial date for fake-hwclock
229
date -u '+%Y-%m-%d %H:%M:%S' > "${SDCARD}"/etc/fake-hwclock.data
230
231
echo "${HOST}" > "${SDCARD}"/etc/hostname
232
233
# set hostname in hosts file
234
cat <<-EOF > "${SDCARD}"/etc/hosts
235
127.0.0.1 localhost
236
127.0.1.1 $HOST
237
::1 localhost $HOST ip6-localhost ip6-loopback
238
fe00::0 ip6-localnet
239
ff00::0 ip6-mcastprefix
240
ff02::1 ip6-allnodes
241
ff02::2 ip6-allrouters
242
EOF
243
244
cd $SRC
245
246
# Prepare and export caching-related params common to all apt calls below, to maximize apt-cacher-ng usage
247
export APT_EXTRA_DIST_PARAMS=""
248
[[ $NO_APT_CACHER != yes ]] && APT_EXTRA_DIST_PARAMS="-o Acquire::http::Proxy=\"http://${APT_PROXY_ADDR:-localhost:3142}\" -o Acquire::http::Proxy::localhost=\"DIRECT\""
249
250
display_alert "Cleaning" "package lists"
251
chroot "${SDCARD}" /bin/bash -c "apt-get clean"
252
253
display_alert "Updating" "package lists"
254
chroot "${SDCARD}" /bin/bash -c "apt-get ${APT_EXTRA_DIST_PARAMS} update" >> "${DEST}"/${LOG_SUBPATH}/install.log 2>&1
255
256
display_alert "Temporarily disabling" "initramfs-tools hook for kernel"
257
chroot "${SDCARD}" /bin/bash -c "chmod -v -x /etc/kernel/postinst.d/initramfs-tools" >> "${DEST}"/${LOG_SUBPATH}/install.log 2>&1
258
259
# install family packages
260
if [[ -n ${PACKAGE_LIST_FAMILY} ]]; then
261
display_alert "Installing PACKAGE_LIST_FAMILY packages" "${PACKAGE_LIST_FAMILY}"
262
chroot "${SDCARD}" /bin/bash -c "DEBIAN_FRONTEND=noninteractive apt-get ${APT_EXTRA_DIST_PARAMS} -yqq --no-install-recommends install $PACKAGE_LIST_FAMILY" >> "${DEST}"/${LOG_SUBPATH}/install.log
263
fi
264
265
# install board packages
266
if [[ -n ${PACKAGE_LIST_BOARD} ]]; then
267
display_alert "Installing PACKAGE_LIST_BOARD packages" "${PACKAGE_LIST_BOARD}"
268
chroot "${SDCARD}" /bin/bash -c "DEBIAN_FRONTEND=noninteractive apt-get ${APT_EXTRA_DIST_PARAMS} -yqq --no-install-recommends install $PACKAGE_LIST_BOARD" >> "${DEST}"/${LOG_SUBPATH}/install.log || { display_alert "Failed to install PACKAGE_LIST_BOARD" "${PACKAGE_LIST_BOARD}" "err"; exit 2; }
269
fi
270
271
# remove family packages
272
if [[ -n ${PACKAGE_LIST_FAMILY_REMOVE} ]]; then
273
display_alert "Removing PACKAGE_LIST_FAMILY_REMOVE packages" "${PACKAGE_LIST_FAMILY_REMOVE}"
274
chroot "${SDCARD}" /bin/bash -c "DEBIAN_FRONTEND=noninteractive apt-get ${APT_EXTRA_DIST_PARAMS} -yqq remove --auto-remove $PACKAGE_LIST_FAMILY_REMOVE" >> "${DEST}"/${LOG_SUBPATH}/install.log
275
fi
276
277
# remove board packages
278
if [[ -n ${PACKAGE_LIST_BOARD_REMOVE} ]]; then
279
display_alert "Removing PACKAGE_LIST_BOARD_REMOVE packages" "${PACKAGE_LIST_BOARD_REMOVE}"
280
for PKG_REMOVE in ${PACKAGE_LIST_BOARD_REMOVE}; do
281
chroot "${SDCARD}" /bin/bash -c "DEBIAN_FRONTEND=noninteractive apt-get ${APT_EXTRA_DIST_PARAMS} -yqq remove --auto-remove ${PKG_REMOVE}" >> "${DEST}"/${LOG_SUBPATH}/install.log
282
done
283
fi
284
285
# install u-boot
286
# @TODO: add install_bootloader() extension method, refactor into u-boot extension
287
[[ "${BOOTCONFIG}" != "none" ]] && {
288
if [[ "${REPOSITORY_INSTALL}" != *u-boot* ]]; then
289
UBOOT_VER=$(dpkg --info "${DEB_STORAGE}/u-boot/${CHOSEN_UBOOT}_${REVISION}_${ARCH}.deb" | grep Descr | awk '{print $(NF)}')
290
install_deb_chroot "${DEB_STORAGE}/u-boot/${CHOSEN_UBOOT}_${REVISION}_${ARCH}.deb"
291
else
292
UBOOT_VER=$(dpkg --info "${DEB_ORANGEPI}/u-boot/${CHOSEN_UBOOT}_${REVISION}_${ARCH}.deb" | grep Descr | awk '{print $(NF)}')
293
install_deb_chroot "${DEB_ORANGEPI}/u-boot/${CHOSEN_UBOOT}_${REVISION}_${ARCH}.deb" "orangepi"
294
fi
295
}
296
297
call_extension_method "pre_install_kernel_debs" << 'PRE_INSTALL_KERNEL_DEBS'
298
*called before installing the Armbian-built kernel deb packages*
299
It is not too late to `unset KERNELSOURCE` here and avoid kernel install.
300
PRE_INSTALL_KERNEL_DEBS
301
302
# install kernel
303
[[ -n $KERNELSOURCE ]] && {
304
if [[ "${REPOSITORY_INSTALL}" != *kernel* ]]; then
305
VER=$(dpkg --info "${DEB_STORAGE}/${CHOSEN_KERNEL}_${REVISION}_${ARCH}.deb" | awk -F"-" '/Source:/{print $2}')
306
307
install_deb_chroot "${DEB_STORAGE}/${CHOSEN_KERNEL}_${REVISION}_${ARCH}.deb"
308
if [[ -f ${DEB_STORAGE}/${CHOSEN_KERNEL/image/dtb}_${REVISION}_${ARCH}.deb ]]; then
309
install_deb_chroot "${DEB_STORAGE}/${CHOSEN_KERNEL/image/dtb}_${REVISION}_${ARCH}.deb"
310
fi
311
if [[ $INSTALL_HEADERS == yes ]]; then
312
install_deb_chroot "${DEB_STORAGE}/${CHOSEN_KERNEL/image/headers}_${REVISION}_${ARCH}.deb"
313
else
314
cp "${DEB_STORAGE}/${CHOSEN_KERNEL/image/headers}_${REVISION}_${ARCH}.deb" "${SDCARD}"/opt/
315
fi
316
else
317
VER=$(dpkg --info "${DEB_ORANGEPI}/${CHOSEN_KERNEL}_${REVISION}_${ARCH}.deb" | grep Descr | awk '{print $(NF)}')
318
VER="${VER/-$LINUXFAMILY/}"
319
320
install_deb_chroot "${DEB_ORANGEPI}/${CHOSEN_KERNEL}_${REVISION}_${ARCH}.deb" "orangepi"
321
322
if [[ -f ${DEB_ORANGEPI}/${CHOSEN_KERNEL/image/dtb}_${REVISION}_${ARCH}.deb ]]; then
323
install_deb_chroot "${DEB_ORANGEPI}/${CHOSEN_KERNEL/image/dtb}_${REVISION}_${ARCH}.deb" "orangepi"
324
fi
325
326
if [[ $INSTALL_HEADERS == yes ]]; then
327
install_deb_chroot "${DEB_ORANGEPI}/${CHOSEN_KERNEL/image/headers}_${REVISION}_${ARCH}.deb" "orangepi"
328
fi
329
fi
330
}
331
332
call_extension_method "post_install_kernel_debs" << 'POST_INSTALL_KERNEL_DEBS'
333
*allow config to do more with the installed kernel/headers*
334
Called after packages, u-boot, kernel and headers installed in the chroot, but before the BSP is installed.
335
If `KERNELSOURCE` is (still?) unset after this, Armbian-built firmware will not be installed.
336
POST_INSTALL_KERNEL_DEBS
337
338
# install board support packages
339
if [[ "${REPOSITORY_INSTALL}" != *bsp* ]]; then
340
install_deb_chroot "${DEB_STORAGE}/$RELEASE/${BSP_CLI_PACKAGE_FULLNAME}.deb"
341
else
342
install_deb_chroot "${DEB_ORANGEPI}/$RELEASE/${CHOSEN_ROOTFS}_${BSP_CLI_PACKAGE_FULLNAME}.deb" "orangepi"
343
fi
344
345
# install orangepi-desktop
346
if [[ "${REPOSITORY_INSTALL}" != *orangepi-desktop* ]]; then
347
if [[ $BUILD_DESKTOP == yes ]]; then
348
install_deb_chroot "${DEB_STORAGE}/${RELEASE}/${CHOSEN_DESKTOP}_${REVISION}_all.deb"
349
install_deb_chroot "${DEB_STORAGE}/${RELEASE}/${BSP_DESKTOP_PACKAGE_FULLNAME}.deb"
350
# install display manager and PACKAGE_LIST_DESKTOP_FULL packages if enabled per board
351
desktop_postinstall
352
fi
353
else
354
if [[ $BUILD_DESKTOP == yes ]]; then
355
install_deb_chroot "${CHOSEN_DESKTOP}" "orangepi"
356
# install display manager and PACKAGE_LIST_DESKTOP_FULL packages if enabled per board
357
desktop_postinstall
358
fi
359
fi
360
361
# install orangepi-firmware
362
if [[ "${REPOSITORY_INSTALL}" != *orangepi-firmware* ]]; then
363
if [[ -f ${DEB_STORAGE}/orangepi-firmware_${REVISION}_all.deb ]]; then
364
install_deb_chroot "${DEB_STORAGE}/orangepi-firmware_${REVISION}_all.deb"
365
fi
366
else
367
if [[ -f ${DEB_STORAGE}/orangepi-firmware_${REVISION}_all.deb ]]; then
368
install_deb_chroot "${DEB_ORANGEPI}/orangepi-firmware_${REVISION}_all.deb" "orangepi"
369
fi
370
fi
371
372
# install orangepi-config
373
if [[ "${PACKAGE_LIST_RM}" != *orangepi-config* ]]; then
374
if [[ "${REPOSITORY_INSTALL}" != *orangepi-config* ]]; then
375
if [[ $BUILD_MINIMAL != yes ]]; then
376
install_deb_chroot "${DEB_STORAGE}/orangepi-config_${REVISION}_all.deb"
377
fi
378
else
379
if [[ $BUILD_MINIMAL != yes ]]; then
380
install_deb_chroot "${DEB_ORANGEPI}/orangepi-config_${REVISION}_all.deb" "orangepi"
381
fi
382
fi
383
fi
384
385
# install orangepi-zsh
386
if [[ "${PACKAGE_LIST_RM}" != *orangepi-zsh* ]]; then
387
if [[ "${REPOSITORY_INSTALL}" != *orangepi-zsh* ]]; then
388
if [[ $BUILD_MINIMAL != yes ]]; then
389
install_deb_chroot "${DEB_STORAGE}/orangepi-zsh_${REVISION}_all.deb"
390
fi
391
else
392
if [[ $BUILD_MINIMAL != yes ]]; then
393
install_deb_chroot "orangepi-zsh" "remote"
394
fi
395
fi
396
fi
397
398
# install plymouth-theme-orangepi
399
if [[ $PLYMOUTH == yes && $BUILD_DESKTOP == yes && $RELEASE != buster ]]; then
400
if [[ "${REPOSITORY_INSTALL}" != *plymouth-theme-orangepi* ]]; then
401
install_deb_chroot "${DEB_STORAGE}/orangepi-plymouth-theme_${REVISION}_all.deb"
402
else
403
install_deb_chroot "orangepi-plymouth-theme" "remote"
404
fi
405
fi
406
407
# install kernel sources
408
if [[ -f ${DEB_STORAGE}/${CHOSEN_KSRC}_${REVISION}_all.deb && $INSTALL_KSRC == yes ]]; then
409
install_deb_chroot "${DEB_STORAGE}/${CHOSEN_KSRC}_${REVISION}_all.deb"
410
elif [[ $INSTALL_KSRC == yes ]]; then
411
display_alert "Please set BUILD_KSRC=yes to generate the kernel source package" "" "wrn"
412
fi
413
414
# install wireguard tools
415
if [[ $WIREGUARD == yes ]]; then
416
chroot "${SDCARD}" /bin/bash -c "apt-get -y -qq install wireguard-tools --no-install-recommends" >> "${DEST}"/debug/install.log 2>&1
417
fi
418
419
# freeze orangepi packages
420
if [[ $BSPFREEZE == yes ]]; then
421
display_alert "Freezing Orange Pi packages" "$BOARD" "info"
422
chroot "${SDCARD}" /bin/bash -c "apt-mark hold ${CHOSEN_KERNEL} ${CHOSEN_KERNEL/image/headers} \
423
linux-u-boot-${BOARD}-${BRANCH} ${CHOSEN_KERNEL/image/dtb}" >> "${DEST}"/${LOG_SUBPATH}/install.log 2>&1
424
fi
425
426
# add orangepi user
427
chroot "${SDCARD}" /bin/bash -c "adduser --quiet --disabled-password --shell /bin/bash --home /home/${OPI_USERNAME} --gecos ${OPI_USERNAME} ${OPI_USERNAME}"
428
chroot "${SDCARD}" /bin/bash -c "(echo ${OPI_PWD};echo ${OPI_PWD};) | passwd "${OPI_USERNAME}" >/dev/null 2>&1"
429
for additionalgroup in sudo netdev audio video disk tty users games dialout plugdev input bluetooth systemd-journal ssh docker; do
430
chroot "${SDCARD}" /bin/bash -c "usermod -aG ${additionalgroup} ${OPI_USERNAME} 2>/dev/null"
431
done
432
433
# fix for gksu in Xenial
434
touch ${SDCARD}/home/${OPI_USERNAME}/.Xauthority
435
chroot "${SDCARD}" /bin/bash -c "chown ${OPI_USERNAME}:${OPI_USERNAME} /home/${OPI_USERNAME}/.Xauthority"
436
# set up profile sync daemon on desktop systems
437
chroot "${SDCARD}" /bin/bash -c "which psd >/dev/null 2>&1"
438
if [ $? -eq 0 ]; then
439
echo -e "${OPI_USERNAME} ALL=(ALL) NOPASSWD: /usr/bin/psd-overlay-helper" >> ${SDCARD}/etc/sudoers
440
touch ${SDCARD}/home/${OPI_USERNAME}/.activate_psd
441
chroot "${SDCARD}" /bin/bash -c "chown $OPI_USERNAME:$OPI_USERNAME /home/${OPI_USERNAME}/.activate_psd"
442
fi
443
444
# remove deb files
445
rm -f "${SDCARD}"/root/*.deb
446
447
# copy boot splash images
448
cp "${EXTER}"/packages/blobs/splash/orangepi-u-boot.bmp "${SDCARD}"/boot/boot.bmp
449
cp "${EXTER}"/packages/blobs/splash/logo.bmp "${SDCARD}"/boot/logo.bmp
450
451
# copy audio.wav and mute.wav
452
cp "${EXTER}"/packages/blobs/audio_wav/audio.wav "${SDCARD}"/usr/share/sounds/alsa/
453
cp "${EXTER}"/packages/blobs/audio_wav/mute.wav "${SDCARD}"/usr/share/sounds/alsa/
454
455
cp "${EXTER}"/packages/blobs/test.mp4 "${SDCARD}"/usr/local/
456
457
# copy watchdog test programm
458
cp "${EXTER}"/packages/blobs/watchdog/watchdog_test_${ARCH} "${SDCARD}"/usr/local/bin/watchdog_test
459
460
[[ -f "${SDCARD}"/usr/bin/gnome-session ]] && sed -i "s/user-session.*/user-session=ubuntu-wayland/" ${SDCARD}/etc/lightdm/lightdm.conf.d/22-orangepi-autologin.conf > /dev/null 2>&1
461
[[ -f "${SDCARD}"/usr/bin/startplasma-x11 ]] && sed -i "s/user-session.*/user-session=plasma-x11/" ${SDCARD}/etc/lightdm/lightdm.conf.d/22-orangepi-autologin.conf
462
463
# execute $LINUXFAMILY-specific tweaks
464
[[ $(type -t family_tweaks) == function ]] && family_tweaks
465
466
call_extension_method "post_family_tweaks" << 'FAMILY_TWEAKS'
467
*customize the tweaks made by $LINUXFAMILY-specific family_tweaks*
468
It is run after packages are installed in the rootfs, but before enabling additional services.
469
It allows implementors access to the rootfs (`${SDCARD}`) in its pristine state after packages are installed.
470
FAMILY_TWEAKS
471
472
# enable additional services
473
chroot "${SDCARD}" /bin/bash -c "systemctl --no-reload enable orangepi-firstrun.service >/dev/null 2>&1"
474
chroot "${SDCARD}" /bin/bash -c "systemctl --no-reload enable orangepi-firstrun-config.service >/dev/null 2>&1"
475
chroot "${SDCARD}" /bin/bash -c "systemctl --no-reload enable orangepi-zram-config.service >/dev/null 2>&1"
476
chroot "${SDCARD}" /bin/bash -c "systemctl --no-reload enable orangepi-hardware-optimize.service >/dev/null 2>&1"
477
chroot "${SDCARD}" /bin/bash -c "systemctl --no-reload enable orangepi-ramlog.service >/dev/null 2>&1"
478
chroot "${SDCARD}" /bin/bash -c "systemctl --no-reload enable orangepi-resize-filesystem.service >/dev/null 2>&1"
479
chroot "${SDCARD}" /bin/bash -c "systemctl --no-reload enable orangepi-hardware-monitor.service >/dev/null 2>&1"
480
481
# copy "first run automated config, optional user configured"
482
cp ${EXTER}/packages/bsp/orangepi_first_run.txt.template "${SDCARD}"/boot/orangepi_first_run.txt.template
483
484
## switch to beta repository at this stage if building nightly images
485
#[[ $IMAGE_TYPE == nightly ]] \
486
#&& echo "deb http://beta.orangepi.com $RELEASE main ${RELEASE}-utils ${RELEASE}-desktop" \
487
#> "${SDCARD}"/etc/apt/sources.list.d/orangepi.list
488
489
# Cosmetic fix [FAILED] Failed to start Set console font and keymap at first boot
490
[[ -f "${SDCARD}"/etc/console-setup/cached_setup_font.sh ]] \
491
&& sed -i "s/^printf '.*/printf '\\\033\%\%G'/g" "${SDCARD}"/etc/console-setup/cached_setup_font.sh
492
[[ -f "${SDCARD}"/etc/console-setup/cached_setup_terminal.sh ]] \
493
&& sed -i "s/^printf '.*/printf '\\\033\%\%G'/g" "${SDCARD}"/etc/console-setup/cached_setup_terminal.sh
494
[[ -f "${SDCARD}"/etc/console-setup/cached_setup_keyboard.sh ]] \
495
&& sed -i "s/-u/-x'/g" "${SDCARD}"/etc/console-setup/cached_setup_keyboard.sh
496
497
# fix for https://bugs.launchpad.net/ubuntu/+source/blueman/+bug/1542723
498
chroot "${SDCARD}" /bin/bash -c "chown root:messagebus /usr/lib/dbus-1.0/dbus-daemon-launch-helper"
499
chroot "${SDCARD}" /bin/bash -c "chmod u+s /usr/lib/dbus-1.0/dbus-daemon-launch-helper"
500
501
# disable samba NetBIOS over IP name service requests since it hangs when no network is present at boot
502
chroot "${SDCARD}" /bin/bash -c "systemctl --quiet disable nmbd 2> /dev/null"
503
504
# disable low-level kernel messages for non betas
505
if [[ -z $BETA ]]; then
506
sed -i "s/^#kernel.printk*/kernel.printk/" "${SDCARD}"/etc/sysctl.conf
507
fi
508
509
# disable repeated messages due to xconsole not being installed.
510
[[ -f "${SDCARD}"/etc/rsyslog.d/50-default.conf ]] && \
511
sed '/daemon\.\*\;mail.*/,/xconsole/ s/.*/#&/' -i "${SDCARD}"/etc/rsyslog.d/50-default.conf
512
513
# disable deprecated parameter
514
sed '/.*$KLogPermitNonKernelFacility.*/,// s/.*/#&/' -i "${SDCARD}"/etc/rsyslog.conf
515
516
# enable getty on multiple serial consoles
517
# and adjust the speed if it is defined and different than 115200
518
#
519
# example: SERIALCON="ttyS0:15000000,ttyGS1"
520
#
521
ifs=$IFS
522
for i in $(echo "${SERIALCON:-'ttyS0'}" | sed "s/,/ /g")
523
do
524
IFS=':' read -r -a array <<< "$i"
525
[[ "${array[0]}" == "tty1" ]] && continue # Don't enable tty1 as serial console.
526
display_alert "Enabling serial console" "${array[0]}" "info"
527
# add serial console to secure tty list
528
[ -z "$(grep -w '^${array[0]}' "${SDCARD}"/etc/securetty 2> /dev/null)" ] && \
529
echo "${array[0]}" >> "${SDCARD}"/etc/securetty
530
if [[ ${array[1]} != "115200" && -n ${array[1]} ]]; then
531
# make a copy, fix speed and enable
532
cp "${SDCARD}"/lib/systemd/system/[email protected] \
533
"${SDCARD}/lib/systemd/system/serial-getty@${array[0]}.service"
534
sed -i "s/--keep-baud 115200/--keep-baud ${array[1]},115200/" \
535
"${SDCARD}/lib/systemd/system/serial-getty@${array[0]}.service"
536
fi
537
chroot "${SDCARD}" /bin/bash -c "systemctl daemon-reload" >> "${DEST}"/${LOG_SUBPATH}/install.log 2>&1
538
chroot "${SDCARD}" /bin/bash -c "systemctl --no-reload enable serial-getty@${array[0]}.service" \
539
>> "${DEST}"/${LOG_SUBPATH}/install.log 2>&1
540
if [[ "${array[0]}" == "ttyGS0" && $LINUXFAMILY == sun8i && $BRANCH == legacy ]]; then
541
mkdir -p "${SDCARD}"/etc/systemd/system/[email protected]
542
cat <<-EOF > "${SDCARD}"/etc/systemd/system/[email protected]/10-switch-role.conf
543
[Service]
544
ExecStartPre=-/bin/sh -c "echo 2 > /sys/bus/platform/devices/sunxi_usb_udc/otg_role"
545
EOF
546
fi
547
done
548
IFS=$ifs
549
550
[[ $LINUXFAMILY == sun*i ]] && mkdir -p "${SDCARD}"/boot/overlay-user
551
552
# to prevent creating swap file on NFS (needs specific kernel options)
553
# and f2fs/btrfs (not recommended or needs specific kernel options)
554
[[ $ROOTFS_TYPE != ext4 ]] && touch "${SDCARD}"/var/swap
555
556
# install initial asound.state if defined
557
mkdir -p "${SDCARD}"/var/lib/alsa/
558
[[ -n $ASOUND_STATE ]] && cp "${EXTER}/packages/blobs/asound.state/${ASOUND_STATE}" "${SDCARD}"/var/lib/alsa/asound.state
559
560
# save initial orangepi-release state
561
cp "${SDCARD}"/etc/orangepi-release "${SDCARD}"/etc/orangepi-image-release
562
563
# DNS fix. package resolvconf is not available everywhere
564
if [ -d /etc/resolvconf/resolv.conf.d ] && [ -n "$NAMESERVER" ]; then
565
echo "nameserver $NAMESERVER" > "${SDCARD}"/etc/resolvconf/resolv.conf.d/head
566
fi
567
568
# permit root login via SSH for the first boot
569
sed -i 's/#\?PermitRootLogin .*/PermitRootLogin yes/' "${SDCARD}"/etc/ssh/sshd_config
570
571
# enable PubkeyAuthentication
572
sed -i 's/#\?PubkeyAuthentication .*/PubkeyAuthentication yes/' "${SDCARD}"/etc/ssh/sshd_config
573
574
if [ -f "${SDCARD}"/etc/NetworkManager/NetworkManager.conf ]; then
575
# configure network manager
576
sed "s/managed=\(.*\)/managed=true/g" -i "${SDCARD}"/etc/NetworkManager/NetworkManager.conf
577
578
# remove network manager defaults to handle eth by default
579
rm -f "${SDCARD}"/usr/lib/NetworkManager/conf.d/10-globally-managed-devices.conf
580
581
# most likely we don't need to wait for nm to get online
582
chroot "${SDCARD}" /bin/bash -c "systemctl disable NetworkManager-wait-online.service" >> "${DEST}"/${LOG_SUBPATH}/install.log 2>&1
583
584
# Just regular DNS and maintain /etc/resolv.conf as a file
585
sed "/dns/d" -i "${SDCARD}"/etc/NetworkManager/NetworkManager.conf
586
sed "s/\[main\]/\[main\]\ndns=default\nrc-manager=file/g" -i "${SDCARD}"/etc/NetworkManager/NetworkManager.conf
587
if [[ -n $NM_IGNORE_DEVICES ]]; then
588
mkdir -p "${SDCARD}"/etc/NetworkManager/conf.d/
589
cat <<-EOF > "${SDCARD}"/etc/NetworkManager/conf.d/10-ignore-interfaces.conf
590
[keyfile]
591
unmanaged-devices=$NM_IGNORE_DEVICES
592
EOF
593
fi
594
595
elif [ -d "${SDCARD}"/etc/systemd/network ]; then
596
# configure networkd
597
rm "${SDCARD}"/etc/resolv.conf
598
ln -s /run/systemd/resolve/resolv.conf "${SDCARD}"/etc/resolv.conf
599
600
# enable services
601
chroot "${SDCARD}" /bin/bash -c "systemctl enable systemd-networkd.service systemd-resolved.service" >> "${DEST}"/${LOG_SUBPATH}/install.log 2>&1
602
603
if [ -e /etc/systemd/timesyncd.conf ]; then
604
chroot "${SDCARD}" /bin/bash -c "systemctl enable systemd-timesyncd.service" >> "${DEST}"/${LOG_SUBPATH}/install.log 2>&1
605
fi
606
umask 022
607
cat > "${SDCARD}"/etc/systemd/network/eth0.network <<- __EOF__
608
[Match]
609
Name=eth0
610
611
[Network]
612
#MACAddress=
613
DHCP=ipv4
614
LinkLocalAddressing=ipv4
615
#Address=192.168.1.100/24
616
#Gateway=192.168.1.1
617
#DNS=192.168.1.1
618
#Domains=example.com
619
NTP=0.pool.ntp.org 1.pool.ntp.org
620
__EOF__
621
622
fi
623
624
# avahi daemon defaults if exists
625
[[ -f "${SDCARD}"/usr/share/doc/avahi-daemon/examples/sftp-ssh.service ]] && \
626
cp "${SDCARD}"/usr/share/doc/avahi-daemon/examples/sftp-ssh.service "${SDCARD}"/etc/avahi/services/
627
[[ -f "${SDCARD}"/usr/share/doc/avahi-daemon/examples/ssh.service ]] && \
628
cp "${SDCARD}"/usr/share/doc/avahi-daemon/examples/ssh.service "${SDCARD}"/etc/avahi/services/
629
630
# nsswitch settings for sane DNS behavior: remove resolve, assure libnss-myhostname support
631
sed "s/hosts\:.*/hosts: files mymachines dns myhostname/g" -i "${SDCARD}"/etc/nsswitch.conf
632
633
# build logo in any case
634
boot_logo
635
636
# disable MOTD for first boot - we want as clean 1st run as possible
637
chmod -x "${SDCARD}"/etc/update-motd.d/*
638
639
}
640
641
install_rclocal()
642
{
643
644
if [[ $BURN_IMAGE == yes ]]; then
645
646
cat <<-EOF > "${SDCARD}"/etc/rc.local
647
#!/bin/sh -e
648
#
649
# rc.local
650
#
651
# This script is executed at the end of each multiuser runlevel.
652
# Make sure that the script will "exit 0" on success or any other
653
# value on error.
654
#
655
# In order to enable or disable this script just change the execution
656
# bits.
657
#
658
# By default this script does nothing.
659
660
burn_to_emmc
661
662
exit 0
663
EOF
664
665
else
666
667
cat <<-EOF > "${SDCARD}"/etc/rc.local
668
#!/bin/sh -e
669
#
670
# rc.local
671
#
672
# This script is executed at the end of each multiuser runlevel.
673
# Make sure that the script will "exit 0" on success or any other
674
# value on error.
675
#
676
# In order to enable or disable this script just change the execution
677
# bits.
678
#
679
# By default this script does nothing.
680
681
exit 0
682
EOF
683
684
fi
685
chmod +x "${SDCARD}"/etc/rc.local
686
687
}
688
689
install_distribution_specific()
690
{
691
692
display_alert "Applying distribution specific tweaks for" "$RELEASE" "info"
693
694
case $RELEASE in
695
696
xenial)
697
698
# remove legal info from Ubuntu
699
[[ -f "${SDCARD}"/etc/legal ]] && rm "${SDCARD}"/etc/legal
700
701
# ureadahead needs kernel tracing options that AFAIK are present only in mainline. disable
702
chroot "${SDCARD}" /bin/bash -c \
703
"systemctl --no-reload mask ondemand.service ureadahead.service >/dev/null 2>&1"
704
chroot "${SDCARD}" /bin/bash -c \
705
"systemctl --no-reload mask setserial.service etc-setserial.service >/dev/null 2>&1"
706
707
;;
708
709
stretch|buster|sid)
710
711
# remove doubled uname from motd
712
[[ -f "${SDCARD}"/etc/update-motd.d/10-uname ]] && rm "${SDCARD}"/etc/update-motd.d/10-uname
713
# rc.local is not existing but one might need it
714
install_rclocal
715
716
;;
717
718
bullseye)
719
720
# remove doubled uname from motd
721
[[ -f "${SDCARD}"/etc/update-motd.d/10-uname ]] && rm "${SDCARD}"/etc/update-motd.d/10-uname
722
# rc.local is not existing but one might need it
723
install_rclocal
724
# fix missing versioning
725
[[ $(grep -L "VERSION_ID=" "${SDCARD}"/etc/os-release) ]] && echo 'VERSION_ID="11"' >> "${SDCARD}"/etc/os-release
726
[[ $(grep -L "VERSION=" "${SDCARD}"/etc/os-release) ]] && echo 'VERSION="11 (bullseye)"' >> "${SDCARD}"/etc/os-release
727
728
729
;;
730
731
bookworm)
732
733
# remove doubled uname from motd
734
[[ -f "${SDCARD}"/etc/update-motd.d/10-uname ]] && rm "${SDCARD}"/etc/update-motd.d/10-uname
735
# rc.local is not existing but one might need it
736
install_rclocal
737
# fix missing versioning
738
[[ $(grep -L "VERSION_ID=" "${SDCARD}"/etc/os-release) ]] && echo 'VERSION_ID="12"' >> "${SDCARD}"/etc/os-release
739
[[ $(grep -L "VERSION=" "${SDCARD}"/etc/os-release) ]] && echo 'VERSION="11 (bookworm)"' >> "${SDCARD}"/etc/os-release
740
741
# remove security updates repository since it does not exists yet
742
sed '/security/ d' -i "${SDCARD}"/etc/apt/sources.list
743
744
;;
745
746
bionic|focal|hirsute|impish|jammy|noble)
747
748
# by using default lz4 initrd compression leads to corruption, go back to proven method
749
sed -i "s/^COMPRESS=.*/COMPRESS=gzip/" "${SDCARD}"/etc/initramfs-tools/initramfs.conf
750
echo -e "\n[Install]\nWantedBy=multi-user.target" >> "${SDCARD}"/lib/systemd/system/lightdm.service
751
752
# cleanup motd services and related files
753
chroot "${SDCARD}" /bin/bash -c "systemctl disable motd-news.service >/dev/null 2>&1"
754
chroot "${SDCARD}" /bin/bash -c "systemctl disable motd-news.timer >/dev/null 2>&1"
755
756
rm -f "${SDCARD}"/etc/update-motd.d/{10-uname,10-help-text,50-motd-news,80-esm,80-livepatch,90-updates-available,91-release-upgrade,95-hwe-eol}
757
758
# remove motd news from motd.ubuntu.com
759
[[ -f "${SDCARD}"/etc/default/motd-news ]] && sed -i "s/^ENABLED=.*/ENABLED=0/" "${SDCARD}"/etc/default/motd-news
760
761
# rc.local is not existing but one might need it
762
install_rclocal
763
764
if [ -d "${SDCARD}"/etc/NetworkManager ]; then
765
local RENDERER=NetworkManager
766
else
767
local RENDERER=networkd
768
fi
769
770
# Basic Netplan config. Let NetworkManager/networkd manage all devices on this system
771
[[ -d "${SDCARD}"/etc/netplan ]] && cat <<-EOF > "${SDCARD}"/etc/netplan/orangepi-default.yaml
772
network:
773
version: 2
774
renderer: $RENDERER
775
EOF
776
777
# DNS fix
778
if [ -n "$NAMESERVER" ]; then
779
sed -i "s/#DNS=.*/DNS=$NAMESERVER/g" "${SDCARD}"/etc/systemd/resolved.conf
780
fi
781
782
# Journal service adjustements
783
sed -i "s/#Storage=.*/Storage=volatile/g" "${SDCARD}"/etc/systemd/journald.conf
784
sed -i "s/#Compress=.*/Compress=yes/g" "${SDCARD}"/etc/systemd/journald.conf
785
sed -i "s/#RateLimitIntervalSec=.*/RateLimitIntervalSec=30s/g" "${SDCARD}"/etc/systemd/journald.conf
786
sed -i "s/#RateLimitBurst=.*/RateLimitBurst=10000/g" "${SDCARD}"/etc/systemd/journald.conf
787
788
# Chrony temporal fix https://bugs.launchpad.net/ubuntu/+source/chrony/+bug/1878005
789
sed -i '/DAEMON_OPTS=/s/"-F -1"/"-F 0"/' "${SDCARD}"/etc/default/chrony
790
791
# disable conflicting services
792
chroot "${SDCARD}" /bin/bash -c "systemctl --no-reload mask ondemand.service >/dev/null 2>&1"
793
794
;;
795
796
esac
797
798
# use list modules INITRAMFS
799
if [ -f "${EXTER}"/config/modules/"${MODULES_INITRD}" ]; then
800
display_alert "Use file list modules INITRAMFS" "${MODULES_INITRD}"
801
sed -i "s/^MODULES=.*/MODULES=list/" "${SDCARD}"/etc/initramfs-tools/initramfs.conf
802
cat "${EXTER}"/config/modules/"${MODULES_INITRD}" >> "${SDCARD}"/etc/initramfs-tools/modules
803
fi
804
}
805
806
807
808
809
post_debootstrap_tweaks()
810
{
811
812
# remove service start blockers and QEMU binary
813
rm -f "${SDCARD}"/sbin/initctl "${SDCARD}"/sbin/start-stop-daemon
814
chroot "${SDCARD}" /bin/bash -c "dpkg-divert --quiet --local --rename --remove /sbin/initctl"
815
chroot "${SDCARD}" /bin/bash -c "dpkg-divert --quiet --local --rename --remove /sbin/start-stop-daemon"
816
rm -f "${SDCARD}"/usr/sbin/policy-rc.d "${SDCARD}/usr/bin/${QEMU_BINARY}"
817
818
call_extension_method "post_post_debootstrap_tweaks" "config_post_debootstrap_tweaks" << 'POST_POST_DEBOOTSTRAP_TWEAKS'
819
*run after removing diversions and qemu with chroot unmounted*
820
Last chance to touch the `${SDCARD}` filesystem before it is copied to the final media.
821
It is too late to run any chrooted commands, since the supporting filesystems are already unmounted.
822
POST_POST_DEBOOTSTRAP_TWEAKS
823
824
}
825
826
on_chroot()
827
{
828
if [ "$SETFCAP" != "1" ]; then
829
export CAPSH_ARG="--drop=cap_setfcap"
830
fi
831
832
capsh $CAPSH_ARG "--chroot=${ROOTFS_DIR}/" -- -e "$@"
833
}
834
export -f on_chroot
835
836
# shellcheck disable=SC2119
837
run_sub_stage()
838
{
839
log "Begin ${SUB_STAGE_DIR}"
840
#pushd "${SUB_STAGE_DIR}" > /dev/null
841
cd ${SUB_STAGE_DIR}
842
843
for i in {00..99}; do
844
if [ -f "${SUB_STAGE_DIR}/${i}-debconf" ]; then
845
display_alert "Begin ${SUB_STAGE_DIR}/${i}-debconf" "" "info"
846
on_chroot << EOF
847
debconf-set-selections <<SELEOF
848
$(cat "${i}-debconf")
849
SELEOF
850
EOF
851
display_alert "End ${SUB_STAGE_DIR}/${i}-debconf" "" "info"
852
fi
853
if [ -f "${SUB_STAGE_DIR}/${i}-packages-nr" ]; then
854
display_alert "Begin ${SUB_STAGE_DIR}/${i}-packages-nr" "" "info"
855
PACKAGES="$(sed -f "${EXTER}/packages/raspi/scripts/remove-comments.sed" < "${SUB_STAGE_DIR}/${i}-packages-nr")"
856
if [ -n "$PACKAGES" ]; then
857
on_chroot << EOF
858
apt-get -o Acquire::Retries=3 install --no-install-recommends -y $PACKAGES
859
EOF
860
fi
861
display_alert "End ${SUB_STAGE_DIR}/${i}-packages-nr" "" "info"
862
fi
863
if [ -f "${SUB_STAGE_DIR}/${i}-packages" ]; then
864
display_alert "Begin ${SUB_STAGE_DIR}/${i}-packages" "" "info"
865
PACKAGES="$(sed -f "${EXTER}/packages/raspi/scripts/remove-comments.sed" < "${SUB_STAGE_DIR}/${i}-packages")"
866
if [ -n "$PACKAGES" ]; then
867
on_chroot << EOF
868
apt-get -o Acquire::Retries=3 install -y $PACKAGES
869
EOF
870
fi
871
display_alert "End ${SUB_STAGE_DIR}/${i}-packages" "" "info"
872
fi
873
# if [ -d "${SUB_STAGE_DIR}/${i}-patches" ]; then
874
# log "Begin ${SUB_STAGE_DIR}/${i}-patches"
875
# pushd "${STAGE_WORK_DIR}" > /dev/null
876
# #cd ${STAGE_WORK_DIR}
877
#
878
# QUILT_PATCHES="${SUB_STAGE_DIR}/${i}-patches"
879
# SUB_STAGE_QUILT_PATCH_DIR="$(basename "$SUB_STAGE_DIR")-pc"
880
# mkdir -p "$STAGE_WORK_DIR/$SUB_STAGE_QUILT_PATCH_DIR"
881
# ln -snf "$STAGE_WORK_DIR/$SUB_STAGE_QUILT_PATCH_DIR" .pc
882
# ln -snfv "${ROOTFS_DIR}" ${STAGE_WORK_DIR}/rootfs
883
# quilt upgrade
884
# if [ -e "${SUB_STAGE_DIR}/${i}-patches/EDIT" ]; then
885
# echo "Dropping into bash to edit patches..."
886
# bash
887
# fi
888
# RC=0
889
# quilt push -a || RC=$?
890
# case "$RC" in
891
# 0|2)
892
# ;;
893
# *)
894
# false
895
# ;;
896
# esac
897
# #popd > /dev/null
898
# cd -
899
# log "End ${SUB_STAGE_DIR}/${i}-patches"
900
# fi
901
if [ -x ${i}-run.sh ]; then
902
display_alert "Begin ${SUB_STAGE_DIR}/${i}-run.sh" "" "info"
903
./${i}-run.sh
904
display_alert "End ${SUB_STAGE_DIR}/${i}-run.sh" "" "info"
905
fi
906
if [ -f ${i}-run-chroot.sh ]; then
907
display_alert "Begin ${SUB_STAGE_DIR}/${i}-run-chroot.sh" "" "info"
908
on_chroot < ${i}-run-chroot.sh
909
display_alert "End ${SUB_STAGE_DIR}/${i}-run-chroot.sh" "" "info"
910
fi
911
done
912
#popd > /dev/null
913
log "End ${SUB_STAGE_DIR}"
914
}
915
916
run_stage(){
917
rm -rf "${SRC}"/output/raspi
918
[[ ! -d "${SRC}"/output/raspi ]] && mkdir -p "${SRC}"/output/raspi
919
920
STAGE_WORK_DIR="${SRC}/output/raspi"
921
922
if [ ! -f ${STAGE_DIR}/SKIP ]; then
923
if [ -x ${STAGE_DIR}/prerun.sh ]; then
924
display_alert "Begin ${STAGE_DIR}/prerun.sh" "" "info"
925
source ${STAGE_DIR}/prerun.sh
926
display_alert "End ${STAGE_DIR}/prerun.sh" "" "info"
927
fi
928
929
for SUB_STAGE_DIR in "${STAGE_DIR}"/*; do
930
if [ -d "${SUB_STAGE_DIR}" ] && [ ! -f "${SUB_STAGE_DIR}/SKIP" ]; then
931
run_sub_stage
932
fi
933
done
934
fi
935
}
936
937
log ()
938
{
939
date +"[%T] $*"
940
}
941
942
install_opi_specific()
943
{
944
cd $SRC
945
946
# install u-boot
947
UBOOT_VER=$(dpkg --info "${DEB_STORAGE}/u-boot/${CHOSEN_UBOOT}_${REVISION}_${ARCH}.deb" | grep Descr | awk '{print $(NF)}')
948
install_deb_chroot "${DEB_STORAGE}/u-boot/${CHOSEN_UBOOT}_${REVISION}_${ARCH}.deb"
949
950
# install kernel
951
VER=$(dpkg --info "${DEB_STORAGE}/${CHOSEN_KERNEL}_${REVISION}_${ARCH}.deb" | awk -F"-" '/Source:/{print $2}')
952
install_deb_chroot "${DEB_STORAGE}/${CHOSEN_KERNEL}_${REVISION}_${ARCH}.deb"
953
if [[ -f ${DEB_STORAGE}/${CHOSEN_KERNEL/image/dtb}_${REVISION}_${ARCH}.deb ]]; then
954
install_deb_chroot "${DEB_STORAGE}/${CHOSEN_KERNEL/image/dtb}_${REVISION}_${ARCH}.deb"
955
fi
956
if [[ $INSTALL_HEADERS == yes ]]; then
957
install_deb_chroot "${DEB_STORAGE}/${CHOSEN_KERNEL/image/headers}_${REVISION}_${ARCH}.deb"
958
else
959
cp "${DEB_STORAGE}/${CHOSEN_KERNEL/image/headers}_${REVISION}_${ARCH}.deb" "${SDCARD}"/opt/
960
fi
961
962
dpkg_install_deb_chroot "$EXTER/packages/raspi/orangepi/debs/raspi-config_20230214_all.deb"
963
964
case ${BOARDFAMILY} in
965
"rockchip-rk356x")
966
rk35xx_gpu_vpu_tweaks
967
esac
968
969
[[ ! -d "${SDCARD}/lib/firmware" ]] && mkdir -p "${SDCARD}/lib/firmware"
970
cp -rfa ${EXTER}/cache/sources/orangepi-firmware-git/* ${SDCARD}/lib/firmware/
971
972
# NOTE: this needs to be executed before family_tweaks
973
local bootscript_src=${BOOTSCRIPT%%:*}
974
local bootscript_dst=${BOOTSCRIPT##*:}
975
976
if [[ "${BOOTCONFIG}" != "none" ]]; then
977
if [ -f "${USERPATCHES_PATH}/bootscripts/${bootscript_src}" ]; then
978
cp "${USERPATCHES_PATH}/bootscripts/${bootscript_src}" "${SDCARD}/boot/${bootscript_dst}"
979
else
980
cp "${EXTER}/config/bootscripts/${bootscript_src}" "${SDCARD}/boot/${bootscript_dst}"
981
fi
982
fi
983
984
if [[ -n $BOOTENV_FILE ]]; then
985
if [[ -f $USERPATCHES_PATH/bootenv/$BOOTENV_FILE ]]; then
986
cp "$USERPATCHES_PATH/bootenv/${BOOTENV_FILE}" "${SDCARD}"/boot/orangepiEnv.txt
987
elif [[ -f $EXTER/config/bootenv/$BOOTENV_FILE ]]; then
988
cp "${EXTER}/config/bootenv/${BOOTENV_FILE}" "${SDCARD}"/boot/orangepiEnv.txt
989
fi
990
fi
991
992
[[ -n $OVERLAY_PREFIX && -f "${SDCARD}"/boot/orangepiEnv.txt && ($BRANCH =~ current|next || $BOARDFAMILY =~ "rockchip-rk3588"|"rockchip-rk356x") ]] && \
993
echo "overlay_prefix=$OVERLAY_PREFIX" >> "${SDCARD}"/boot/orangepiEnv.txt
994
995
[[ -n $DEFAULT_OVERLAYS && -f "${SDCARD}"/boot/orangepiEnv.txt && ($BRANCH =~ current|next || $BOARDFAMILY =~ "rockchip-rk3588"|"rockchip-rk356x") ]] && \
996
echo "overlays=${DEFAULT_OVERLAYS//,/ }" >> "${SDCARD}"/boot/orangepiEnv.txt
997
998
[[ -n $BOOT_FDT_FILE && -f "${SDCARD}"/boot/orangepiEnv.txt ]] && \
999
echo "fdtfile=${BOOT_FDT_FILE}" >> "${SDCARD}/boot/orangepiEnv.txt"
1000
1001
# install initial asound.state if defined
1002
mkdir -p "${SDCARD}"/var/lib/alsa/
1003
[[ -n $ASOUND_STATE ]] && cp "${EXTER}/packages/blobs/asound.state/${ASOUND_STATE}" "${SDCARD}"/var/lib/alsa/asound.state
1004
1005
# create modules file
1006
local modules=MODULES_${BRANCH^^}
1007
if [[ -n "${!modules}" ]]; then
1008
tr ' ' '\n' <<< "${!modules}" > "${SDCARD}"/etc/modules
1009
elif [[ -n "${MODULES}" ]]; then
1010
tr ' ' '\n' <<< "${MODULES}" > "${SDCARD}"/etc/modules
1011
fi
1012
1013
# create blacklist files
1014
local blacklist=MODULES_BLACKLIST_${BRANCH^^}
1015
if [[ -n "${!blacklist}" ]]; then
1016
tr ' ' '\n' <<< "${!blacklist}" | sed -e 's/^/blacklist /' > "${SDCARD}/etc/modprobe.d/blacklist-${BOARD}.conf"
1017
elif [[ -n "${MODULES_BLACKLIST}" ]]; then
1018
tr ' ' '\n' <<< "${MODULES_BLACKLIST}" | sed -e 's/^/blacklist /' > "${SDCARD}/etc/modprobe.d/blacklist-${BOARD}.conf"
1019
fi
1020
1021
cat <<-EOF > "${SDCARD}"/etc/orangepi-release
1022
# PLEASE DO NOT EDIT THIS FILE
1023
BOARD=${BOARD}
1024
BOARD_NAME="$BOARD_NAME"
1025
BOARDFAMILY=${BOARDFAMILY}
1026
BUILD_REPOSITORY_URL=${BUILD_REPOSITORY_URL}
1027
BUILD_REPOSITORY_COMMIT=${BUILD_REPOSITORY_COMMIT}
1028
DISTRIBUTION_CODENAME=${RELEASE}
1029
DISTRIBUTION_STATUS=${DISTRIBUTION_STATUS}
1030
VERSION=${REVISION}
1031
LINUXFAMILY=${LINUXFAMILY}
1032
ARCH=${ARCHITECTURE}
1033
IMAGE_TYPE=$IMAGE_TYPE
1034
BOARD_TYPE=$BOARD_TYPE
1035
INITRD_ARCH=${INITRD_ARCH}
1036
KERNEL_IMAGE_TYPE=${KERNEL_IMAGE_TYPE}
1037
BRANCH=${BRANCH}
1038
EOF
1039
1040
install -d "${SDCARD}/etc/initramfs/post-update.d/"
1041
install -m 755 "${EXTER}/packages/bsp/common/etc/initramfs/post-update.d/99-uboot" "${SDCARD}/etc/initramfs/post-update.d/"
1042
1043
install -m 755 "${EXTER}/packages/raspi/orangepi/common/files/hciattach_opi" "${SDCARD}/usr/bin/"
1044
install -m 755 "${EXTER}/packages/raspi/orangepi/common/files/brcm_patchram_plus" "${SDCARD}/usr/bin/"
1045
1046
install -d "${SDCARD}/usr/lib/orangepi/"
1047
install -m 755 "${EXTER}/packages/raspi/orangepi/common/files/orangepi-hardware-optimization" "${SDCARD}/usr/lib/orangepi/"
1048
install -m 755 "${EXTER}/packages/raspi/orangepi/common/files/orangepi-hardware-optimize.service" "${SDCARD}/usr/lib/systemd/system/"
1049
chroot "${SDCARD}" /bin/bash -c "systemctl --no-reload enable orangepi-hardware-optimize.service >/dev/null 2>&1"
1050
1051
install_wiringop
1052
1053
rm $SDCARD/root/*.deb >/dev/null 2>&1
1054
}
1055
1056
install_raspi_specific()
1057
{
1058
export TARGET_HOSTNAME=${TARGET_HOSTNAME:-raspberrypi}
1059
export FIRST_USER_NAME=${FIRST_USER_NAME:-pi}
1060
export FIRST_USER_PASS
1061
export DISABLE_FIRST_BOOT_USER_RENAME=${DISABLE_FIRST_BOOT_USER_RENAME:-0}
1062
export WPA_ESSID
1063
export WPA_PASSWORD
1064
export WPA_COUNTRY
1065
export ENABLE_SSH="${ENABLE_SSH:-0}"
1066
export PUBKEY_ONLY_SSH="${PUBKEY_ONLY_SSH:-0}"
1067
1068
export LOCALE_DEFAULT="${LOCALE_DEFAULT:-en_GB.UTF-8}"
1069
1070
export KEYBOARD_KEYMAP="${KEYBOARD_KEYMAP:-gb}"
1071
export KEYBOARD_LAYOUT="${KEYBOARD_LAYOUT:-English (UK)}"
1072
1073
export TIMEZONE_DEFAULT="${TIMEZONE_DEFAULT:-Europe/London}"
1074
1075
export PUBKEY_SSH_FIRST_USER
1076
1077
export APT_PROXY
1078
1079
export STAGE
1080
export STAGE_DIR
1081
export STAGE_WORK_DIR
1082
export PREV_STAGE
1083
export PREV_STAGE_DIR
1084
export ROOTFS_DIR=${SDCARD}
1085
export PREV_ROOTFS_DIR
1086
export IMG_SUFFIX
1087
export NOOBS_NAME
1088
export NOOBS_DESCRIPTION
1089
export EXPORT_DIR
1090
export EXPORT_ROOTFS_DIR
1091
1092
export QUILT_PATCHES
1093
export QUILT_NO_DIFF_INDEX=1
1094
export QUILT_NO_DIFF_TIMESTAMPS=1
1095
export QUILT_REFRESH_ARGS="-p ab"
1096
1097
#check username is valid
1098
if [[ ! "$FIRST_USER_NAME" =~ ^[a-z][-a-z0-9_]*$ ]]; then
1099
echo "Invalid FIRST_USER_NAME: $FIRST_USER_NAME"
1100
exit 1
1101
fi
1102
1103
if [[ "$DISABLE_FIRST_BOOT_USER_RENAME" == "1" ]] && [ -z "${FIRST_USER_PASS}" ]; then
1104
echo "To disable user rename on first boot, FIRST_USER_PASS needs to be set"
1105
echo "Not setting FIRST_USER_PASS makes your system vulnerable and open to cyberattacks"
1106
exit 1
1107
fi
1108
1109
if [[ "$DISABLE_FIRST_BOOT_USER_RENAME" == "1" ]]; then
1110
echo "User rename on the first boot is disabled"
1111
echo "Be advised of the security risks linked to shipping a device with default username/password set."
1112
fi
1113
1114
if [[ -n "${APT_PROXY}" ]] && ! curl --silent "${APT_PROXY}" >/dev/null ; then
1115
echo "Could not reach APT_PROXY server: ${APT_PROXY}"
1116
exit 1
1117
fi
1118
1119
if [[ -n "${WPA_PASSWORD}" && ${#WPA_PASSWORD} -lt 8 || ${#WPA_PASSWORD} -gt 63 ]] ; then
1120
echo "WPA_PASSWORD" must be between 8 and 63 characters
1121
exit 1
1122
fi
1123
1124
if [[ "${PUBKEY_ONLY_SSH}" = "1" && -z "${PUBKEY_SSH_FIRST_USER}" ]]; then
1125
echo "Must set 'PUBKEY_SSH_FIRST_USER' to a valid SSH public key if using PUBKEY_ONLY_SSH"
1126
exit 1
1127
fi
1128
1129
RASPI_DIR="${EXTER}/packages/raspi"
1130
1131
if [[ ${BUILD_DESKTOP} == "yes" ]]; then
1132
rm -r ${RASPI_DIR}/stage3/SKIP ${RASPI_DIR}/stage4/SKIP ${RASPI_DIR}/stage5/SKIP 2>/dev/null
1133
touch ${RASPI_DIR}/stage5/SKIP
1134
else
1135
rm -r ${RASPI_DIR}/stage1/SKIP ${RASPI_DIR}/stage2/SKIP 2>/dev/null
1136
touch ${RASPI_DIR}/stage3/SKIP ${RASPI_DIR}/stage4/SKIP ${RASPI_DIR}/stage5/SKIP
1137
export FIRST_USER_PASS="pi"
1138
fi
1139
1140
STAGE_LIST=${RASPI_DIR}/stage*
1141
1142
for STAGE_DIR in $STAGE_LIST; do
1143
STAGE_DIR=$(realpath "${STAGE_DIR}")
1144
run_stage
1145
done
1146
1147
STAGE_DIR=${RASPI_DIR}/export-image
1148
run_stage
1149
1150
rm -rf ${SDCARD}/boot/*
1151
rm -rf ${SDCARD}/lib/firmware
1152
rm -rf ${SDCARD}/lib/modules/*
1153
}
1154
1155