distributions.sh 46 KB

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