Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
orangepi-xunlong
GitHub Repository: orangepi-xunlong/orangepi-build
Path: blob/next/scripts/distributions.sh
22162 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
call_extension_method "post_family_tweaks" << 'FAMILY_TWEAKS'
464
*customize the tweaks made by $LINUXFAMILY-specific family_tweaks*
465
It is run after packages are installed in the rootfs, but before enabling additional services.
466
It allows implementors access to the rootfs (`${SDCARD}`) in its pristine state after packages are installed.
467
FAMILY_TWEAKS
468
469
# enable additional services
470
chroot "${SDCARD}" /bin/bash -c "systemctl --no-reload enable orangepi-firstrun.service >/dev/null 2>&1"
471
chroot "${SDCARD}" /bin/bash -c "systemctl --no-reload enable orangepi-firstrun-config.service >/dev/null 2>&1"
472
chroot "${SDCARD}" /bin/bash -c "systemctl --no-reload enable orangepi-zram-config.service >/dev/null 2>&1"
473
chroot "${SDCARD}" /bin/bash -c "systemctl --no-reload enable orangepi-hardware-optimize.service >/dev/null 2>&1"
474
chroot "${SDCARD}" /bin/bash -c "systemctl --no-reload enable orangepi-ramlog.service >/dev/null 2>&1"
475
chroot "${SDCARD}" /bin/bash -c "systemctl --no-reload enable orangepi-resize-filesystem.service >/dev/null 2>&1"
476
chroot "${SDCARD}" /bin/bash -c "systemctl --no-reload enable orangepi-hardware-monitor.service >/dev/null 2>&1"
477
478
# copy "first run automated config, optional user configured"
479
cp ${EXTER}/packages/bsp/orangepi_first_run.txt.template "${SDCARD}"/boot/orangepi_first_run.txt.template
480
481
## switch to beta repository at this stage if building nightly images
482
#[[ $IMAGE_TYPE == nightly ]] \
483
#&& echo "deb http://beta.orangepi.com $RELEASE main ${RELEASE}-utils ${RELEASE}-desktop" \
484
#> "${SDCARD}"/etc/apt/sources.list.d/orangepi.list
485
486
# Cosmetic fix [FAILED] Failed to start Set console font and keymap at first boot
487
[[ -f "${SDCARD}"/etc/console-setup/cached_setup_font.sh ]] \
488
&& sed -i "s/^printf '.*/printf '\\\033\%\%G'/g" "${SDCARD}"/etc/console-setup/cached_setup_font.sh
489
[[ -f "${SDCARD}"/etc/console-setup/cached_setup_terminal.sh ]] \
490
&& sed -i "s/^printf '.*/printf '\\\033\%\%G'/g" "${SDCARD}"/etc/console-setup/cached_setup_terminal.sh
491
[[ -f "${SDCARD}"/etc/console-setup/cached_setup_keyboard.sh ]] \
492
&& sed -i "s/-u/-x'/g" "${SDCARD}"/etc/console-setup/cached_setup_keyboard.sh
493
494
# fix for https://bugs.launchpad.net/ubuntu/+source/blueman/+bug/1542723
495
chroot "${SDCARD}" /bin/bash -c "chown root:messagebus /usr/lib/dbus-1.0/dbus-daemon-launch-helper"
496
chroot "${SDCARD}" /bin/bash -c "chmod u+s /usr/lib/dbus-1.0/dbus-daemon-launch-helper"
497
498
# disable samba NetBIOS over IP name service requests since it hangs when no network is present at boot
499
chroot "${SDCARD}" /bin/bash -c "systemctl --quiet disable nmbd 2> /dev/null"
500
501
# disable low-level kernel messages for non betas
502
if [[ -z $BETA ]]; then
503
sed -i "s/^#kernel.printk*/kernel.printk/" "${SDCARD}"/etc/sysctl.conf
504
fi
505
506
# disable repeated messages due to xconsole not being installed.
507
[[ -f "${SDCARD}"/etc/rsyslog.d/50-default.conf ]] && \
508
sed '/daemon\.\*\;mail.*/,/xconsole/ s/.*/#&/' -i "${SDCARD}"/etc/rsyslog.d/50-default.conf
509
510
# disable deprecated parameter
511
sed '/.*$KLogPermitNonKernelFacility.*/,// s/.*/#&/' -i "${SDCARD}"/etc/rsyslog.conf
512
513
# enable getty on multiple serial consoles
514
# and adjust the speed if it is defined and different than 115200
515
#
516
# example: SERIALCON="ttyS0:15000000,ttyGS1"
517
#
518
ifs=$IFS
519
for i in $(echo "${SERIALCON:-'ttyS0'}" | sed "s/,/ /g")
520
do
521
IFS=':' read -r -a array <<< "$i"
522
[[ "${array[0]}" == "tty1" ]] && continue # Don't enable tty1 as serial console.
523
display_alert "Enabling serial console" "${array[0]}" "info"
524
# add serial console to secure tty list
525
[ -z "$(grep -w '^${array[0]}' "${SDCARD}"/etc/securetty 2> /dev/null)" ] && \
526
echo "${array[0]}" >> "${SDCARD}"/etc/securetty
527
if [[ ${array[1]} != "115200" && -n ${array[1]} ]]; then
528
# make a copy, fix speed and enable
529
cp "${SDCARD}"/lib/systemd/system/[email protected] \
530
"${SDCARD}/lib/systemd/system/serial-getty@${array[0]}.service"
531
sed -i "s/--keep-baud 115200/--keep-baud ${array[1]},115200/" \
532
"${SDCARD}/lib/systemd/system/serial-getty@${array[0]}.service"
533
fi
534
chroot "${SDCARD}" /bin/bash -c "systemctl daemon-reload" >> "${DEST}"/${LOG_SUBPATH}/install.log 2>&1
535
chroot "${SDCARD}" /bin/bash -c "systemctl --no-reload enable serial-getty@${array[0]}.service" \
536
>> "${DEST}"/${LOG_SUBPATH}/install.log 2>&1
537
if [[ "${array[0]}" == "ttyGS0" && $LINUXFAMILY == sun8i && $BRANCH == legacy ]]; then
538
mkdir -p "${SDCARD}"/etc/systemd/system/[email protected]
539
cat <<-EOF > "${SDCARD}"/etc/systemd/system/[email protected]/10-switch-role.conf
540
[Service]
541
ExecStartPre=-/bin/sh -c "echo 2 > /sys/bus/platform/devices/sunxi_usb_udc/otg_role"
542
EOF
543
fi
544
done
545
IFS=$ifs
546
547
[[ $LINUXFAMILY == sun*i ]] && mkdir -p "${SDCARD}"/boot/overlay-user
548
549
# to prevent creating swap file on NFS (needs specific kernel options)
550
# and f2fs/btrfs (not recommended or needs specific kernel options)
551
[[ $ROOTFS_TYPE != ext4 ]] && touch "${SDCARD}"/var/swap
552
553
# install initial asound.state if defined
554
mkdir -p "${SDCARD}"/var/lib/alsa/
555
[[ -n $ASOUND_STATE ]] && cp "${EXTER}/packages/blobs/asound.state/${ASOUND_STATE}" "${SDCARD}"/var/lib/alsa/asound.state
556
557
# save initial orangepi-release state
558
cp "${SDCARD}"/etc/orangepi-release "${SDCARD}"/etc/orangepi-image-release
559
560
# DNS fix. package resolvconf is not available everywhere
561
if [ -d /etc/resolvconf/resolv.conf.d ] && [ -n "$NAMESERVER" ]; then
562
echo "nameserver $NAMESERVER" > "${SDCARD}"/etc/resolvconf/resolv.conf.d/head
563
fi
564
565
# permit root login via SSH for the first boot
566
sed -i 's/#\?PermitRootLogin .*/PermitRootLogin yes/' "${SDCARD}"/etc/ssh/sshd_config
567
568
# enable PubkeyAuthentication
569
sed -i 's/#\?PubkeyAuthentication .*/PubkeyAuthentication yes/' "${SDCARD}"/etc/ssh/sshd_config
570
571
if [ -f "${SDCARD}"/etc/NetworkManager/NetworkManager.conf ]; then
572
# configure network manager
573
sed "s/managed=\(.*\)/managed=true/g" -i "${SDCARD}"/etc/NetworkManager/NetworkManager.conf
574
575
# remove network manager defaults to handle eth by default
576
rm -f "${SDCARD}"/usr/lib/NetworkManager/conf.d/10-globally-managed-devices.conf
577
578
# most likely we don't need to wait for nm to get online
579
chroot "${SDCARD}" /bin/bash -c "systemctl disable NetworkManager-wait-online.service" >> "${DEST}"/${LOG_SUBPATH}/install.log 2>&1
580
581
# Just regular DNS and maintain /etc/resolv.conf as a file
582
sed "/dns/d" -i "${SDCARD}"/etc/NetworkManager/NetworkManager.conf
583
sed "s/\[main\]/\[main\]\ndns=default\nrc-manager=file/g" -i "${SDCARD}"/etc/NetworkManager/NetworkManager.conf
584
if [[ -n $NM_IGNORE_DEVICES ]]; then
585
mkdir -p "${SDCARD}"/etc/NetworkManager/conf.d/
586
cat <<-EOF > "${SDCARD}"/etc/NetworkManager/conf.d/10-ignore-interfaces.conf
587
[keyfile]
588
unmanaged-devices=$NM_IGNORE_DEVICES
589
EOF
590
fi
591
592
elif [ -d "${SDCARD}"/etc/systemd/network ]; then
593
# configure networkd
594
rm "${SDCARD}"/etc/resolv.conf
595
ln -s /run/systemd/resolve/resolv.conf "${SDCARD}"/etc/resolv.conf
596
597
# enable services
598
chroot "${SDCARD}" /bin/bash -c "systemctl enable systemd-networkd.service systemd-resolved.service" >> "${DEST}"/${LOG_SUBPATH}/install.log 2>&1
599
600
if [ -e /etc/systemd/timesyncd.conf ]; then
601
chroot "${SDCARD}" /bin/bash -c "systemctl enable systemd-timesyncd.service" >> "${DEST}"/${LOG_SUBPATH}/install.log 2>&1
602
fi
603
umask 022
604
cat > "${SDCARD}"/etc/systemd/network/eth0.network <<- __EOF__
605
[Match]
606
Name=eth0
607
608
[Network]
609
#MACAddress=
610
DHCP=ipv4
611
LinkLocalAddressing=ipv4
612
#Address=192.168.1.100/24
613
#Gateway=192.168.1.1
614
#DNS=192.168.1.1
615
#Domains=example.com
616
NTP=0.pool.ntp.org 1.pool.ntp.org
617
__EOF__
618
619
fi
620
621
# avahi daemon defaults if exists
622
[[ -f "${SDCARD}"/usr/share/doc/avahi-daemon/examples/sftp-ssh.service ]] && \
623
cp "${SDCARD}"/usr/share/doc/avahi-daemon/examples/sftp-ssh.service "${SDCARD}"/etc/avahi/services/
624
[[ -f "${SDCARD}"/usr/share/doc/avahi-daemon/examples/ssh.service ]] && \
625
cp "${SDCARD}"/usr/share/doc/avahi-daemon/examples/ssh.service "${SDCARD}"/etc/avahi/services/
626
627
# nsswitch settings for sane DNS behavior: remove resolve, assure libnss-myhostname support
628
sed "s/hosts\:.*/hosts: files mymachines dns myhostname/g" -i "${SDCARD}"/etc/nsswitch.conf
629
630
# build logo in any case
631
boot_logo
632
633
# disable MOTD for first boot - we want as clean 1st run as possible
634
chmod -x "${SDCARD}"/etc/update-motd.d/*
635
636
# execute $LINUXFAMILY-specific tweaks
637
[[ $(type -t family_tweaks) == function ]] && family_tweaks
638
}
639
640
install_rclocal()
641
{
642
643
if [[ $BURN_IMAGE == yes ]]; then
644
645
cat <<-EOF > "${SDCARD}"/etc/rc.local
646
#!/bin/sh -e
647
#
648
# rc.local
649
#
650
# This script is executed at the end of each multiuser runlevel.
651
# Make sure that the script will "exit 0" on success or any other
652
# value on error.
653
#
654
# In order to enable or disable this script just change the execution
655
# bits.
656
#
657
# By default this script does nothing.
658
659
burn_to_emmc
660
661
exit 0
662
EOF
663
664
else
665
666
cat <<-EOF > "${SDCARD}"/etc/rc.local
667
#!/bin/sh -e
668
#
669
# rc.local
670
#
671
# This script is executed at the end of each multiuser runlevel.
672
# Make sure that the script will "exit 0" on success or any other
673
# value on error.
674
#
675
# In order to enable or disable this script just change the execution
676
# bits.
677
#
678
# By default this script does nothing.
679
680
exit 0
681
EOF
682
683
fi
684
chmod +x "${SDCARD}"/etc/rc.local
685
686
}
687
688
install_distribution_specific()
689
{
690
691
display_alert "Applying distribution specific tweaks for" "$RELEASE" "info"
692
693
case $RELEASE in
694
695
xenial)
696
697
# remove legal info from Ubuntu
698
[[ -f "${SDCARD}"/etc/legal ]] && rm "${SDCARD}"/etc/legal
699
700
# ureadahead needs kernel tracing options that AFAIK are present only in mainline. disable
701
chroot "${SDCARD}" /bin/bash -c \
702
"systemctl --no-reload mask ondemand.service ureadahead.service >/dev/null 2>&1"
703
chroot "${SDCARD}" /bin/bash -c \
704
"systemctl --no-reload mask setserial.service etc-setserial.service >/dev/null 2>&1"
705
706
;;
707
708
stretch|buster|sid)
709
710
# remove doubled uname from motd
711
[[ -f "${SDCARD}"/etc/update-motd.d/10-uname ]] && rm "${SDCARD}"/etc/update-motd.d/10-uname
712
# rc.local is not existing but one might need it
713
install_rclocal
714
715
;;
716
717
bullseye)
718
719
# remove doubled uname from motd
720
[[ -f "${SDCARD}"/etc/update-motd.d/10-uname ]] && rm "${SDCARD}"/etc/update-motd.d/10-uname
721
# rc.local is not existing but one might need it
722
install_rclocal
723
# fix missing versioning
724
[[ $(grep -L "VERSION_ID=" "${SDCARD}"/etc/os-release) ]] && echo 'VERSION_ID="11"' >> "${SDCARD}"/etc/os-release
725
[[ $(grep -L "VERSION=" "${SDCARD}"/etc/os-release) ]] && echo 'VERSION="11 (bullseye)"' >> "${SDCARD}"/etc/os-release
726
727
728
;;
729
730
bookworm)
731
732
# remove doubled uname from motd
733
[[ -f "${SDCARD}"/etc/update-motd.d/10-uname ]] && rm "${SDCARD}"/etc/update-motd.d/10-uname
734
# rc.local is not existing but one might need it
735
install_rclocal
736
# fix missing versioning
737
[[ $(grep -L "VERSION_ID=" "${SDCARD}"/etc/os-release) ]] && echo 'VERSION_ID="12"' >> "${SDCARD}"/etc/os-release
738
[[ $(grep -L "VERSION=" "${SDCARD}"/etc/os-release) ]] && echo 'VERSION="11 (bookworm)"' >> "${SDCARD}"/etc/os-release
739
740
# remove security updates repository since it does not exists yet
741
sed '/security/ d' -i "${SDCARD}"/etc/apt/sources.list
742
743
;;
744
745
bionic|focal|hirsute|impish|jammy|noble)
746
747
# by using default lz4 initrd compression leads to corruption, go back to proven method
748
sed -i "s/^COMPRESS=.*/COMPRESS=gzip/" "${SDCARD}"/etc/initramfs-tools/initramfs.conf
749
echo -e "\n[Install]\nWantedBy=multi-user.target" >> "${SDCARD}"/lib/systemd/system/lightdm.service
750
751
# cleanup motd services and related files
752
chroot "${SDCARD}" /bin/bash -c "systemctl disable motd-news.service >/dev/null 2>&1"
753
chroot "${SDCARD}" /bin/bash -c "systemctl disable motd-news.timer >/dev/null 2>&1"
754
755
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}
756
757
# remove motd news from motd.ubuntu.com
758
[[ -f "${SDCARD}"/etc/default/motd-news ]] && sed -i "s/^ENABLED=.*/ENABLED=0/" "${SDCARD}"/etc/default/motd-news
759
760
# rc.local is not existing but one might need it
761
install_rclocal
762
763
if [ -d "${SDCARD}"/etc/NetworkManager ]; then
764
local RENDERER=NetworkManager
765
else
766
local RENDERER=networkd
767
fi
768
769
# Basic Netplan config. Let NetworkManager/networkd manage all devices on this system
770
[[ -d "${SDCARD}"/etc/netplan ]] && cat <<-EOF > "${SDCARD}"/etc/netplan/orangepi-default.yaml
771
network:
772
version: 2
773
renderer: $RENDERER
774
EOF
775
776
# DNS fix
777
if [ -n "$NAMESERVER" ]; then
778
sed -i "s/#DNS=.*/DNS=$NAMESERVER/g" "${SDCARD}"/etc/systemd/resolved.conf
779
fi
780
781
# Journal service adjustements
782
sed -i "s/#Storage=.*/Storage=volatile/g" "${SDCARD}"/etc/systemd/journald.conf
783
sed -i "s/#Compress=.*/Compress=yes/g" "${SDCARD}"/etc/systemd/journald.conf
784
sed -i "s/#RateLimitIntervalSec=.*/RateLimitIntervalSec=30s/g" "${SDCARD}"/etc/systemd/journald.conf
785
sed -i "s/#RateLimitBurst=.*/RateLimitBurst=10000/g" "${SDCARD}"/etc/systemd/journald.conf
786
787
# Chrony temporal fix https://bugs.launchpad.net/ubuntu/+source/chrony/+bug/1878005
788
sed -i '/DAEMON_OPTS=/s/"-F -1"/"-F 0"/' "${SDCARD}"/etc/default/chrony
789
790
# disable conflicting services
791
chroot "${SDCARD}" /bin/bash -c "systemctl --no-reload mask ondemand.service >/dev/null 2>&1"
792
793
;;
794
795
esac
796
797
# use list modules INITRAMFS
798
if [ -f "${EXTER}"/config/modules/"${MODULES_INITRD}" ]; then
799
display_alert "Use file list modules INITRAMFS" "${MODULES_INITRD}"
800
sed -i "s/^MODULES=.*/MODULES=list/" "${SDCARD}"/etc/initramfs-tools/initramfs.conf
801
cat "${EXTER}"/config/modules/"${MODULES_INITRD}" >> "${SDCARD}"/etc/initramfs-tools/modules
802
fi
803
}
804
805
806
807
808
post_debootstrap_tweaks()
809
{
810
811
# remove service start blockers and QEMU binary
812
rm -f "${SDCARD}"/sbin/initctl "${SDCARD}"/sbin/start-stop-daemon
813
chroot "${SDCARD}" /bin/bash -c "dpkg-divert --quiet --local --rename --remove /sbin/initctl"
814
chroot "${SDCARD}" /bin/bash -c "dpkg-divert --quiet --local --rename --remove /sbin/start-stop-daemon"
815
rm -f "${SDCARD}"/usr/sbin/policy-rc.d "${SDCARD}/usr/bin/${QEMU_BINARY}"
816
817
call_extension_method "post_post_debootstrap_tweaks" "config_post_debootstrap_tweaks" << 'POST_POST_DEBOOTSTRAP_TWEAKS'
818
*run after removing diversions and qemu with chroot unmounted*
819
Last chance to touch the `${SDCARD}` filesystem before it is copied to the final media.
820
It is too late to run any chrooted commands, since the supporting filesystems are already unmounted.
821
POST_POST_DEBOOTSTRAP_TWEAKS
822
823
}
824
825
on_chroot()
826
{
827
if [ "$SETFCAP" != "1" ]; then
828
export CAPSH_ARG="--drop=cap_setfcap"
829
fi
830
831
capsh $CAPSH_ARG "--chroot=${ROOTFS_DIR}/" -- -e "$@"
832
}
833
export -f on_chroot
834
835
# shellcheck disable=SC2119
836
run_sub_stage()
837
{
838
log "Begin ${SUB_STAGE_DIR}"
839
#pushd "${SUB_STAGE_DIR}" > /dev/null
840
cd ${SUB_STAGE_DIR}
841
842
for i in {00..99}; do
843
if [ -f "${SUB_STAGE_DIR}/${i}-debconf" ]; then
844
display_alert "Begin ${SUB_STAGE_DIR}/${i}-debconf" "" "info"
845
on_chroot << EOF
846
debconf-set-selections <<SELEOF
847
$(cat "${i}-debconf")
848
SELEOF
849
EOF
850
display_alert "End ${SUB_STAGE_DIR}/${i}-debconf" "" "info"
851
fi
852
if [ -f "${SUB_STAGE_DIR}/${i}-packages-nr" ]; then
853
display_alert "Begin ${SUB_STAGE_DIR}/${i}-packages-nr" "" "info"
854
PACKAGES="$(sed -f "${EXTER}/packages/raspi/scripts/remove-comments.sed" < "${SUB_STAGE_DIR}/${i}-packages-nr")"
855
if [ -n "$PACKAGES" ]; then
856
on_chroot << EOF
857
apt-get -o Acquire::Retries=3 install --no-install-recommends -y $PACKAGES
858
EOF
859
fi
860
display_alert "End ${SUB_STAGE_DIR}/${i}-packages-nr" "" "info"
861
fi
862
if [ -f "${SUB_STAGE_DIR}/${i}-packages" ]; then
863
display_alert "Begin ${SUB_STAGE_DIR}/${i}-packages" "" "info"
864
PACKAGES="$(sed -f "${EXTER}/packages/raspi/scripts/remove-comments.sed" < "${SUB_STAGE_DIR}/${i}-packages")"
865
if [ -n "$PACKAGES" ]; then
866
on_chroot << EOF
867
apt-get -o Acquire::Retries=3 install -y $PACKAGES
868
EOF
869
fi
870
display_alert "End ${SUB_STAGE_DIR}/${i}-packages" "" "info"
871
fi
872
# if [ -d "${SUB_STAGE_DIR}/${i}-patches" ]; then
873
# log "Begin ${SUB_STAGE_DIR}/${i}-patches"
874
# pushd "${STAGE_WORK_DIR}" > /dev/null
875
# #cd ${STAGE_WORK_DIR}
876
#
877
# QUILT_PATCHES="${SUB_STAGE_DIR}/${i}-patches"
878
# SUB_STAGE_QUILT_PATCH_DIR="$(basename "$SUB_STAGE_DIR")-pc"
879
# mkdir -p "$STAGE_WORK_DIR/$SUB_STAGE_QUILT_PATCH_DIR"
880
# ln -snf "$STAGE_WORK_DIR/$SUB_STAGE_QUILT_PATCH_DIR" .pc
881
# ln -snfv "${ROOTFS_DIR}" ${STAGE_WORK_DIR}/rootfs
882
# quilt upgrade
883
# if [ -e "${SUB_STAGE_DIR}/${i}-patches/EDIT" ]; then
884
# echo "Dropping into bash to edit patches..."
885
# bash
886
# fi
887
# RC=0
888
# quilt push -a || RC=$?
889
# case "$RC" in
890
# 0|2)
891
# ;;
892
# *)
893
# false
894
# ;;
895
# esac
896
# #popd > /dev/null
897
# cd -
898
# log "End ${SUB_STAGE_DIR}/${i}-patches"
899
# fi
900
if [ -x ${i}-run.sh ]; then
901
display_alert "Begin ${SUB_STAGE_DIR}/${i}-run.sh" "" "info"
902
./${i}-run.sh
903
display_alert "End ${SUB_STAGE_DIR}/${i}-run.sh" "" "info"
904
fi
905
if [ -f ${i}-run-chroot.sh ]; then
906
display_alert "Begin ${SUB_STAGE_DIR}/${i}-run-chroot.sh" "" "info"
907
on_chroot < ${i}-run-chroot.sh
908
display_alert "End ${SUB_STAGE_DIR}/${i}-run-chroot.sh" "" "info"
909
fi
910
done
911
#popd > /dev/null
912
log "End ${SUB_STAGE_DIR}"
913
}
914
915
run_stage(){
916
rm -rf "${SRC}"/output/raspi
917
[[ ! -d "${SRC}"/output/raspi ]] && mkdir -p "${SRC}"/output/raspi
918
919
STAGE_WORK_DIR="${SRC}/output/raspi"
920
921
if [ ! -f ${STAGE_DIR}/SKIP ]; then
922
if [ -x ${STAGE_DIR}/prerun.sh ]; then
923
display_alert "Begin ${STAGE_DIR}/prerun.sh" "" "info"
924
source ${STAGE_DIR}/prerun.sh
925
display_alert "End ${STAGE_DIR}/prerun.sh" "" "info"
926
fi
927
928
for SUB_STAGE_DIR in "${STAGE_DIR}"/*; do
929
if [ -d "${SUB_STAGE_DIR}" ] && [ ! -f "${SUB_STAGE_DIR}/SKIP" ]; then
930
run_sub_stage
931
fi
932
done
933
fi
934
}
935
936
log ()
937
{
938
date +"[%T] $*"
939
}
940
941
install_opi_specific()
942
{
943
cd $SRC
944
945
# install u-boot
946
UBOOT_VER=$(dpkg --info "${DEB_STORAGE}/u-boot/${CHOSEN_UBOOT}_${REVISION}_${ARCH}.deb" | grep Descr | awk '{print $(NF)}')
947
install_deb_chroot "${DEB_STORAGE}/u-boot/${CHOSEN_UBOOT}_${REVISION}_${ARCH}.deb"
948
949
# install kernel
950
VER=$(dpkg --info "${DEB_STORAGE}/${CHOSEN_KERNEL}_${REVISION}_${ARCH}.deb" | awk -F"-" '/Source:/{print $2}')
951
install_deb_chroot "${DEB_STORAGE}/${CHOSEN_KERNEL}_${REVISION}_${ARCH}.deb"
952
if [[ -f ${DEB_STORAGE}/${CHOSEN_KERNEL/image/dtb}_${REVISION}_${ARCH}.deb ]]; then
953
install_deb_chroot "${DEB_STORAGE}/${CHOSEN_KERNEL/image/dtb}_${REVISION}_${ARCH}.deb"
954
fi
955
if [[ $INSTALL_HEADERS == yes ]]; then
956
install_deb_chroot "${DEB_STORAGE}/${CHOSEN_KERNEL/image/headers}_${REVISION}_${ARCH}.deb"
957
else
958
cp "${DEB_STORAGE}/${CHOSEN_KERNEL/image/headers}_${REVISION}_${ARCH}.deb" "${SDCARD}"/opt/
959
fi
960
961
dpkg_install_deb_chroot "$EXTER/packages/raspi/orangepi/debs/raspi-config_20230214_all.deb"
962
963
case ${BOARDFAMILY} in
964
"rockchip-rk356x")
965
rk35xx_gpu_vpu_tweaks
966
esac
967
968
[[ ! -d "${SDCARD}/lib/firmware" ]] && mkdir -p "${SDCARD}/lib/firmware"
969
cp -rfa ${EXTER}/cache/sources/orangepi-firmware-git/* ${SDCARD}/lib/firmware/
970
971
# NOTE: this needs to be executed before family_tweaks
972
local bootscript_src=${BOOTSCRIPT%%:*}
973
local bootscript_dst=${BOOTSCRIPT##*:}
974
975
if [[ "${BOOTCONFIG}" != "none" ]]; then
976
if [ -f "${USERPATCHES_PATH}/bootscripts/${bootscript_src}" ]; then
977
cp "${USERPATCHES_PATH}/bootscripts/${bootscript_src}" "${SDCARD}/boot/${bootscript_dst}"
978
else
979
cp "${EXTER}/config/bootscripts/${bootscript_src}" "${SDCARD}/boot/${bootscript_dst}"
980
fi
981
fi
982
983
if [[ -n $BOOTENV_FILE ]]; then
984
if [[ -f $USERPATCHES_PATH/bootenv/$BOOTENV_FILE ]]; then
985
cp "$USERPATCHES_PATH/bootenv/${BOOTENV_FILE}" "${SDCARD}"/boot/orangepiEnv.txt
986
elif [[ -f $EXTER/config/bootenv/$BOOTENV_FILE ]]; then
987
cp "${EXTER}/config/bootenv/${BOOTENV_FILE}" "${SDCARD}"/boot/orangepiEnv.txt
988
fi
989
fi
990
991
[[ -n $OVERLAY_PREFIX && -f "${SDCARD}"/boot/orangepiEnv.txt && ($BRANCH =~ current|next || $BOARDFAMILY =~ "rockchip-rk3588"|"rockchip-rk356x") ]] && \
992
echo "overlay_prefix=$OVERLAY_PREFIX" >> "${SDCARD}"/boot/orangepiEnv.txt
993
994
[[ -n $DEFAULT_OVERLAYS && -f "${SDCARD}"/boot/orangepiEnv.txt && ($BRANCH =~ current|next || $BOARDFAMILY =~ "rockchip-rk3588"|"rockchip-rk356x") ]] && \
995
echo "overlays=${DEFAULT_OVERLAYS//,/ }" >> "${SDCARD}"/boot/orangepiEnv.txt
996
997
[[ -n $BOOT_FDT_FILE && -f "${SDCARD}"/boot/orangepiEnv.txt ]] && \
998
echo "fdtfile=${BOOT_FDT_FILE}" >> "${SDCARD}/boot/orangepiEnv.txt"
999
1000
# install initial asound.state if defined
1001
mkdir -p "${SDCARD}"/var/lib/alsa/
1002
[[ -n $ASOUND_STATE ]] && cp "${EXTER}/packages/blobs/asound.state/${ASOUND_STATE}" "${SDCARD}"/var/lib/alsa/asound.state
1003
1004
# create modules file
1005
local modules=MODULES_${BRANCH^^}
1006
if [[ -n "${!modules}" ]]; then
1007
tr ' ' '\n' <<< "${!modules}" > "${SDCARD}"/etc/modules
1008
elif [[ -n "${MODULES}" ]]; then
1009
tr ' ' '\n' <<< "${MODULES}" > "${SDCARD}"/etc/modules
1010
fi
1011
1012
# create blacklist files
1013
local blacklist=MODULES_BLACKLIST_${BRANCH^^}
1014
if [[ -n "${!blacklist}" ]]; then
1015
tr ' ' '\n' <<< "${!blacklist}" | sed -e 's/^/blacklist /' > "${SDCARD}/etc/modprobe.d/blacklist-${BOARD}.conf"
1016
elif [[ -n "${MODULES_BLACKLIST}" ]]; then
1017
tr ' ' '\n' <<< "${MODULES_BLACKLIST}" | sed -e 's/^/blacklist /' > "${SDCARD}/etc/modprobe.d/blacklist-${BOARD}.conf"
1018
fi
1019
1020
cat <<-EOF > "${SDCARD}"/etc/orangepi-release
1021
# PLEASE DO NOT EDIT THIS FILE
1022
BOARD=${BOARD}
1023
BOARD_NAME="$BOARD_NAME"
1024
BOARDFAMILY=${BOARDFAMILY}
1025
BUILD_REPOSITORY_URL=${BUILD_REPOSITORY_URL}
1026
BUILD_REPOSITORY_COMMIT=${BUILD_REPOSITORY_COMMIT}
1027
DISTRIBUTION_CODENAME=${RELEASE}
1028
DISTRIBUTION_STATUS=${DISTRIBUTION_STATUS}
1029
VERSION=${REVISION}
1030
LINUXFAMILY=${LINUXFAMILY}
1031
ARCH=${ARCHITECTURE}
1032
IMAGE_TYPE=$IMAGE_TYPE
1033
BOARD_TYPE=$BOARD_TYPE
1034
INITRD_ARCH=${INITRD_ARCH}
1035
KERNEL_IMAGE_TYPE=${KERNEL_IMAGE_TYPE}
1036
BRANCH=${BRANCH}
1037
EOF
1038
1039
install -d "${SDCARD}/etc/initramfs/post-update.d/"
1040
install -m 755 "${EXTER}/packages/bsp/common/etc/initramfs/post-update.d/99-uboot" "${SDCARD}/etc/initramfs/post-update.d/"
1041
1042
install -m 755 "${EXTER}/packages/raspi/orangepi/common/files/hciattach_opi" "${SDCARD}/usr/bin/"
1043
install -m 755 "${EXTER}/packages/raspi/orangepi/common/files/brcm_patchram_plus" "${SDCARD}/usr/bin/"
1044
1045
install -d "${SDCARD}/usr/lib/orangepi/"
1046
install -m 755 "${EXTER}/packages/raspi/orangepi/common/files/orangepi-hardware-optimization" "${SDCARD}/usr/lib/orangepi/"
1047
install -m 755 "${EXTER}/packages/raspi/orangepi/common/files/orangepi-hardware-optimize.service" "${SDCARD}/usr/lib/systemd/system/"
1048
chroot "${SDCARD}" /bin/bash -c "systemctl --no-reload enable orangepi-hardware-optimize.service >/dev/null 2>&1"
1049
1050
install_wiringop
1051
1052
rm $SDCARD/root/*.deb >/dev/null 2>&1
1053
}
1054
1055
install_raspi_specific()
1056
{
1057
export TARGET_HOSTNAME=${TARGET_HOSTNAME:-raspberrypi}
1058
export FIRST_USER_NAME=${FIRST_USER_NAME:-pi}
1059
export FIRST_USER_PASS
1060
export DISABLE_FIRST_BOOT_USER_RENAME=${DISABLE_FIRST_BOOT_USER_RENAME:-0}
1061
export WPA_ESSID
1062
export WPA_PASSWORD
1063
export WPA_COUNTRY
1064
export ENABLE_SSH="${ENABLE_SSH:-0}"
1065
export PUBKEY_ONLY_SSH="${PUBKEY_ONLY_SSH:-0}"
1066
1067
export LOCALE_DEFAULT="${LOCALE_DEFAULT:-en_GB.UTF-8}"
1068
1069
export KEYBOARD_KEYMAP="${KEYBOARD_KEYMAP:-gb}"
1070
export KEYBOARD_LAYOUT="${KEYBOARD_LAYOUT:-English (UK)}"
1071
1072
export TIMEZONE_DEFAULT="${TIMEZONE_DEFAULT:-Europe/London}"
1073
1074
export PUBKEY_SSH_FIRST_USER
1075
1076
export APT_PROXY
1077
1078
export STAGE
1079
export STAGE_DIR
1080
export STAGE_WORK_DIR
1081
export PREV_STAGE
1082
export PREV_STAGE_DIR
1083
export ROOTFS_DIR=${SDCARD}
1084
export PREV_ROOTFS_DIR
1085
export IMG_SUFFIX
1086
export NOOBS_NAME
1087
export NOOBS_DESCRIPTION
1088
export EXPORT_DIR
1089
export EXPORT_ROOTFS_DIR
1090
1091
export QUILT_PATCHES
1092
export QUILT_NO_DIFF_INDEX=1
1093
export QUILT_NO_DIFF_TIMESTAMPS=1
1094
export QUILT_REFRESH_ARGS="-p ab"
1095
1096
#check username is valid
1097
if [[ ! "$FIRST_USER_NAME" =~ ^[a-z][-a-z0-9_]*$ ]]; then
1098
echo "Invalid FIRST_USER_NAME: $FIRST_USER_NAME"
1099
exit 1
1100
fi
1101
1102
if [[ "$DISABLE_FIRST_BOOT_USER_RENAME" == "1" ]] && [ -z "${FIRST_USER_PASS}" ]; then
1103
echo "To disable user rename on first boot, FIRST_USER_PASS needs to be set"
1104
echo "Not setting FIRST_USER_PASS makes your system vulnerable and open to cyberattacks"
1105
exit 1
1106
fi
1107
1108
if [[ "$DISABLE_FIRST_BOOT_USER_RENAME" == "1" ]]; then
1109
echo "User rename on the first boot is disabled"
1110
echo "Be advised of the security risks linked to shipping a device with default username/password set."
1111
fi
1112
1113
if [[ -n "${APT_PROXY}" ]] && ! curl --silent "${APT_PROXY}" >/dev/null ; then
1114
echo "Could not reach APT_PROXY server: ${APT_PROXY}"
1115
exit 1
1116
fi
1117
1118
if [[ -n "${WPA_PASSWORD}" && ${#WPA_PASSWORD} -lt 8 || ${#WPA_PASSWORD} -gt 63 ]] ; then
1119
echo "WPA_PASSWORD" must be between 8 and 63 characters
1120
exit 1
1121
fi
1122
1123
if [[ "${PUBKEY_ONLY_SSH}" = "1" && -z "${PUBKEY_SSH_FIRST_USER}" ]]; then
1124
echo "Must set 'PUBKEY_SSH_FIRST_USER' to a valid SSH public key if using PUBKEY_ONLY_SSH"
1125
exit 1
1126
fi
1127
1128
RASPI_DIR="${EXTER}/packages/raspi"
1129
1130
if [[ ${BUILD_DESKTOP} == "yes" ]]; then
1131
rm -r ${RASPI_DIR}/stage3/SKIP ${RASPI_DIR}/stage4/SKIP ${RASPI_DIR}/stage5/SKIP 2>/dev/null
1132
touch ${RASPI_DIR}/stage5/SKIP
1133
else
1134
rm -r ${RASPI_DIR}/stage1/SKIP ${RASPI_DIR}/stage2/SKIP 2>/dev/null
1135
touch ${RASPI_DIR}/stage3/SKIP ${RASPI_DIR}/stage4/SKIP ${RASPI_DIR}/stage5/SKIP
1136
export FIRST_USER_PASS="pi"
1137
fi
1138
1139
STAGE_LIST=${RASPI_DIR}/stage*
1140
1141
for STAGE_DIR in $STAGE_LIST; do
1142
STAGE_DIR=$(realpath "${STAGE_DIR}")
1143
run_stage
1144
done
1145
1146
STAGE_DIR=${RASPI_DIR}/export-image
1147
run_stage
1148
1149
rm -rf ${SDCARD}/boot/*
1150
rm -rf ${SDCARD}/lib/firmware
1151
rm -rf ${SDCARD}/lib/modules/*
1152
}
1153
1154