From 1f65d9d8902d8711a5037169ea47de509d5799cc Mon Sep 17 00:00:00 2001 From: hzy Date: Mon, 3 Oct 2022 11:17:59 +0800 Subject: [PATCH] Split `/lib/distributions.sh` --- .../rootfs/distro-agnostic.sh} | 128 ------------------ lib/functions/rootfs/distro-specific.sh | 87 ++++++++++++ lib/functions/rootfs/post-tweaks.sh | 16 +++ lib/main.sh | 2 - 4 files changed, 103 insertions(+), 130 deletions(-) rename lib/{distributions.sh => functions/rootfs/distro-agnostic.sh} (85%) create mode 100644 lib/functions/rootfs/post-tweaks.sh diff --git a/lib/distributions.sh b/lib/functions/rootfs/distro-agnostic.sh similarity index 85% rename from lib/distributions.sh rename to lib/functions/rootfs/distro-agnostic.sh index 5b098a613..0e10d5058 100644 --- a/lib/distributions.sh +++ b/lib/functions/rootfs/distro-agnostic.sh @@ -1,24 +1,3 @@ -#!/bin/bash -# -# Copyright (c) 2013-2021 Igor Pecovnik, igor.pecovnik@gma**.com -# -# This file is licensed under the terms of the GNU General Public -# License version 2. This program is licensed "as is" without any -# warranty of any kind, whether express or implied. -# -# This file is a part of the Armbian build script -# https://github.com/armbian/build/ - -# Functions: - -# install_common -# install_rclocal -# install_distribution_specific -# post_debootstrap_tweaks - - - - install_common() { display_alert "Applying common tweaks" "" "info" @@ -640,110 +619,3 @@ install_rclocal() chmod +x "${SDCARD}"/etc/rc.local } - -install_distribution_specific() -{ - - display_alert "Applying distribution specific tweaks for" "$RELEASE" "info" - - case $RELEASE in - - sid) - - # (temporally) disable broken service - chroot "${SDCARD}" /bin/bash -c "systemctl --no-reload disable smartmontools.service >/dev/null 2>&1" - - ;; - - focal|jammy) - - # by using default lz4 initrd compression leads to corruption, go back to proven method - sed -i "s/^COMPRESS=.*/COMPRESS=gzip/" "${SDCARD}"/etc/initramfs-tools/initramfs.conf - - 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} - - if [ -d "${SDCARD}"/etc/NetworkManager ]; then - local RENDERER=NetworkManager - else - local RENDERER=networkd - fi - - # DNS fix - if [ -n "$NAMESERVER" ]; then - sed -i "s/#DNS=.*/DNS=$NAMESERVER/g" "${SDCARD}"/etc/systemd/resolved.conf - fi - - # Journal service adjustements - sed -i "s/#Storage=.*/Storage=volatile/g" "${SDCARD}"/etc/systemd/journald.conf - sed -i "s/#Compress=.*/Compress=yes/g" "${SDCARD}"/etc/systemd/journald.conf - sed -i "s/#RateLimitIntervalSec=.*/RateLimitIntervalSec=30s/g" "${SDCARD}"/etc/systemd/journald.conf - sed -i "s/#RateLimitBurst=.*/RateLimitBurst=10000/g" "${SDCARD}"/etc/systemd/journald.conf - - # Chrony temporal fix https://bugs.launchpad.net/ubuntu/+source/chrony/+bug/1878005 - sed -i '/DAEMON_OPTS=/s/"-F -1"/"-F 0"/' "${SDCARD}"/etc/default/chrony - - # disable conflicting services - chroot "${SDCARD}" /bin/bash -c "systemctl --no-reload mask ondemand.service >/dev/null 2>&1" - - ;; - - esac - - # configure language and locales - display_alert "Configuring locales" "$DEST_LANG" "info" - if [[ -f $SDCARD/etc/locale.gen ]]; then - [ -n "$DEST_LANG" ] && sed -i "s/^# $DEST_LANG/$DEST_LANG/" $SDCARD/etc/locale.gen - sed -i '/ C.UTF-8/s/^# //g' $SDCARD/etc/locale.gen - sed -i '/en_US.UTF-8/s/^# //g' $SDCARD/etc/locale.gen - fi - eval 'LC_ALL=C LANG=C chroot $SDCARD /bin/bash -c "locale-gen"' ${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'} - [ -n "$DEST_LANG" ] && eval 'LC_ALL=C LANG=C chroot $SDCARD /bin/bash -c \ - "update-locale --reset LANG=$DEST_LANG LANGUAGE=$DEST_LANG LC_ALL=$DEST_LANG"' ${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'} - - # Basic Netplan config. Let NetworkManager/networkd manage all devices on this system - [[ -d "${SDCARD}"/etc/netplan ]] && cat <<-EOF > "${SDCARD}"/etc/netplan/armbian-default.yaml - network: - version: 2 - renderer: $RENDERER - EOF - - # cleanup motd services and related files - chroot "${SDCARD}" /bin/bash -c "systemctl disable motd-news.service >/dev/null 2>&1" - chroot "${SDCARD}" /bin/bash -c "systemctl disable motd-news.timer >/dev/null 2>&1" - - # remove motd news from motd.ubuntu.com - [[ -f "${SDCARD}"/etc/default/motd-news ]] && sed -i "s/^ENABLED=.*/ENABLED=0/" "${SDCARD}"/etc/default/motd-news - - # remove doubled uname from motd - [[ -f "${SDCARD}"/etc/update-motd.d/10-uname ]] && rm "${SDCARD}"/etc/update-motd.d/10-uname - - # rc.local is not existing but one might need it - install_rclocal - - # use list modules INITRAMFS - if [ -f "${SRC}"/config/modules/"${MODULES_INITRD}" ]; then - display_alert "Use file list modules INITRAMFS" "${MODULES_INITRD}" - sed -i "s/^MODULES=.*/MODULES=list/" "${SDCARD}"/etc/initramfs-tools/initramfs.conf - cat "${SRC}"/config/modules/"${MODULES_INITRD}" >> "${SDCARD}"/etc/initramfs-tools/modules - fi -} - - - - -post_debootstrap_tweaks() -{ - - # remove service start blockers and QEMU binary - rm -f "${SDCARD}"/sbin/initctl "${SDCARD}"/sbin/start-stop-daemon - chroot "${SDCARD}" /bin/bash -c "dpkg-divert --quiet --local --rename --remove /sbin/initctl" - chroot "${SDCARD}" /bin/bash -c "dpkg-divert --quiet --local --rename --remove /sbin/start-stop-daemon" - rm -f "${SDCARD}"/usr/sbin/policy-rc.d "${SDCARD}/usr/bin/${QEMU_BINARY}" - - call_extension_method "post_post_debootstrap_tweaks" "config_post_debootstrap_tweaks" << 'POST_POST_DEBOOTSTRAP_TWEAKS' -*run after removing diversions and qemu with chroot unmounted* -Last chance to touch the `${SDCARD}` filesystem before it is copied to the final media. -It is too late to run any chrooted commands, since the supporting filesystems are already unmounted. -POST_POST_DEBOOTSTRAP_TWEAKS - -} diff --git a/lib/functions/rootfs/distro-specific.sh b/lib/functions/rootfs/distro-specific.sh index c26aea9f1..66d31bd8e 100644 --- a/lib/functions/rootfs/distro-specific.sh +++ b/lib/functions/rootfs/distro-specific.sh @@ -1,3 +1,90 @@ +install_distribution_specific() +{ + + display_alert "Applying distribution specific tweaks for" "$RELEASE" "info" + + case $RELEASE in + + sid) + + # (temporally) disable broken service + chroot "${SDCARD}" /bin/bash -c "systemctl --no-reload disable smartmontools.service >/dev/null 2>&1" + + ;; + + focal|jammy) + + # by using default lz4 initrd compression leads to corruption, go back to proven method + sed -i "s/^COMPRESS=.*/COMPRESS=gzip/" "${SDCARD}"/etc/initramfs-tools/initramfs.conf + + 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} + + if [ -d "${SDCARD}"/etc/NetworkManager ]; then + local RENDERER=NetworkManager + else + local RENDERER=networkd + fi + + # DNS fix + if [ -n "$NAMESERVER" ]; then + sed -i "s/#DNS=.*/DNS=$NAMESERVER/g" "${SDCARD}"/etc/systemd/resolved.conf + fi + + # Journal service adjustements + sed -i "s/#Storage=.*/Storage=volatile/g" "${SDCARD}"/etc/systemd/journald.conf + sed -i "s/#Compress=.*/Compress=yes/g" "${SDCARD}"/etc/systemd/journald.conf + sed -i "s/#RateLimitIntervalSec=.*/RateLimitIntervalSec=30s/g" "${SDCARD}"/etc/systemd/journald.conf + sed -i "s/#RateLimitBurst=.*/RateLimitBurst=10000/g" "${SDCARD}"/etc/systemd/journald.conf + + # Chrony temporal fix https://bugs.launchpad.net/ubuntu/+source/chrony/+bug/1878005 + sed -i '/DAEMON_OPTS=/s/"-F -1"/"-F 0"/' "${SDCARD}"/etc/default/chrony + + # disable conflicting services + chroot "${SDCARD}" /bin/bash -c "systemctl --no-reload mask ondemand.service >/dev/null 2>&1" + + ;; + + esac + + # configure language and locales + display_alert "Configuring locales" "$DEST_LANG" "info" + if [[ -f $SDCARD/etc/locale.gen ]]; then + [ -n "$DEST_LANG" ] && sed -i "s/^# $DEST_LANG/$DEST_LANG/" $SDCARD/etc/locale.gen + sed -i '/ C.UTF-8/s/^# //g' $SDCARD/etc/locale.gen + sed -i '/en_US.UTF-8/s/^# //g' $SDCARD/etc/locale.gen + fi + eval 'LC_ALL=C LANG=C chroot $SDCARD /bin/bash -c "locale-gen"' ${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'} + [ -n "$DEST_LANG" ] && eval 'LC_ALL=C LANG=C chroot $SDCARD /bin/bash -c \ + "update-locale --reset LANG=$DEST_LANG LANGUAGE=$DEST_LANG LC_ALL=$DEST_LANG"' ${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'} + + # Basic Netplan config. Let NetworkManager/networkd manage all devices on this system + [[ -d "${SDCARD}"/etc/netplan ]] && cat <<-EOF > "${SDCARD}"/etc/netplan/armbian-default.yaml + network: + version: 2 + renderer: $RENDERER + EOF + + # cleanup motd services and related files + chroot "${SDCARD}" /bin/bash -c "systemctl disable motd-news.service >/dev/null 2>&1" + chroot "${SDCARD}" /bin/bash -c "systemctl disable motd-news.timer >/dev/null 2>&1" + + # remove motd news from motd.ubuntu.com + [[ -f "${SDCARD}"/etc/default/motd-news ]] && sed -i "s/^ENABLED=.*/ENABLED=0/" "${SDCARD}"/etc/default/motd-news + + # remove doubled uname from motd + [[ -f "${SDCARD}"/etc/update-motd.d/10-uname ]] && rm "${SDCARD}"/etc/update-motd.d/10-uname + + # rc.local is not existing but one might need it + install_rclocal + + # use list modules INITRAMFS + if [ -f "${SRC}"/config/modules/"${MODULES_INITRD}" ]; then + display_alert "Use file list modules INITRAMFS" "${MODULES_INITRD}" + sed -i "s/^MODULES=.*/MODULES=list/" "${SDCARD}"/etc/initramfs-tools/initramfs.conf + cat "${SRC}"/config/modules/"${MODULES_INITRD}" >> "${SDCARD}"/etc/initramfs-tools/modules + fi +} + # create_sources_list # # : bullseye|focal|jammy|sid diff --git a/lib/functions/rootfs/post-tweaks.sh b/lib/functions/rootfs/post-tweaks.sh new file mode 100644 index 000000000..5699bd5b9 --- /dev/null +++ b/lib/functions/rootfs/post-tweaks.sh @@ -0,0 +1,16 @@ +post_debootstrap_tweaks() +{ + + # remove service start blockers and QEMU binary + rm -f "${SDCARD}"/sbin/initctl "${SDCARD}"/sbin/start-stop-daemon + chroot "${SDCARD}" /bin/bash -c "dpkg-divert --quiet --local --rename --remove /sbin/initctl" + chroot "${SDCARD}" /bin/bash -c "dpkg-divert --quiet --local --rename --remove /sbin/start-stop-daemon" + rm -f "${SDCARD}"/usr/sbin/policy-rc.d "${SDCARD}/usr/bin/${QEMU_BINARY}" + + call_extension_method "post_post_debootstrap_tweaks" "config_post_debootstrap_tweaks" << 'POST_POST_DEBOOTSTRAP_TWEAKS' +*run after removing diversions and qemu with chroot unmounted* +Last chance to touch the `${SDCARD}` filesystem before it is copied to the final media. +It is too late to run any chrooted commands, since the supporting filesystems are already unmounted. +POST_POST_DEBOOTSTRAP_TWEAKS + +} diff --git a/lib/main.sh b/lib/main.sh index af1619dba..0c59e3ddd 100644 --- a/lib/main.sh +++ b/lib/main.sh @@ -64,8 +64,6 @@ backtitle="Armbian building script, https://www.armbian.com | https://docs.armbi # shellcheck source=import-functions.sh source "${SRC}/lib/import-functions.sh" -# shellcheck source=distributions.sh -source "${SRC}"/lib/distributions.sh # system specific install # shellcheck source=desktop.sh source "${SRC}"/lib/desktop.sh # desktop specific install # shellcheck source=compilation.sh