2022-11-27 20:44:50 +00:00
#!/usr/bin/env bash
2023-03-09 17:30:40 +00:00
#
# SPDX-License-Identifier: GPL-2.0
#
# Copyright (c) 2013-2023 Igor Pecovnik, igor@armbian.com
#
# This file is a part of the Armbian Build Framework
# https://github.com/armbian/build/
2022-10-03 03:17:59 +00:00
2023-01-14 21:49:18 +00:00
function install_distribution_specific( ) {
display_alert "Applying distribution specific tweaks for" " ${ RELEASE :- } " "info"
2022-10-03 03:17:59 +00:00
2023-01-14 21:49:18 +00:00
# disable broken service, the problem is in default misconfiguration
2024-06-29 11:09:18 +00:00
disable_systemd_service_sdcard smartmontools.service smartd.service
2022-10-03 03:17:59 +00:00
2024-01-08 16:52:39 +00:00
if [ [ " ${ DISTRIBUTION } " = = "Ubuntu" ] ] ; then
2022-10-03 03:17:59 +00:00
2024-01-08 16:52:39 +00:00
# by using default lz4 initrd compression leads to corruption, go back to proven method
# @TODO: rpardini: this should be a config option (which is always set to zstd ;-D )
sed -i "s/^COMPRESS=.*/COMPRESS=gzip/" " ${ SDCARD } " /etc/initramfs-tools/initramfs.conf
2022-10-03 03:17:59 +00:00
2024-01-08 16:52:39 +00:00
run_host_command_logged 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}
2022-10-03 03:17:59 +00:00
2024-01-08 16:52:39 +00:00
# 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
2022-10-03 03:17:59 +00:00
2024-01-08 16:52:39 +00:00
# disable conflicting services
disable_systemd_service_sdcard ondemand.service
2023-03-19 12:44:09 +00:00
2024-01-08 16:52:39 +00:00
# Remove Ubuntu APT spamming
install_artifact_deb_chroot "fake-ubuntu-advantage-tools"
truncate --size= 0 " ${ SDCARD } " /etc/apt/apt.conf.d/20apt-esm-hook.conf
fi
2022-10-03 03:17:59 +00:00
2023-05-12 16:11:51 +00:00
# install our base-files package (this replaces the original from Debian/Ubuntu)
if [ [ " ${ KEEP_ORIGINAL_OS_RELEASE :- "no" } " != "yes" ] ] ; then
2024-08-22 08:43:45 +00:00
install_artifact_deb_chroot "armbian-base-files" "--allow-downgrades"
2023-05-12 16:11:51 +00:00
fi
2024-01-08 16:52:39 +00:00
# Set DNS server if systemd-resolved is in use
if [ [ -n " $NAMESERVER " && -f " ${ SDCARD } " /etc/systemd/resolved.conf ] ] ; then
2024-08-26 14:58:10 +00:00
display_alert "Using systemd-resolved" "for DNS management" "info"
# This used to set a default DNS entry from $NAMESERVER into "${SDCARD}"/etc/systemd/resolved.conf.d/00-armbian-default-dns.conf -- no longer; better left to DHCP.
2024-01-08 16:52:39 +00:00
fi
2022-10-03 03:17:59 +00:00
# cleanup motd services and related files
2023-01-14 21:49:18 +00:00
disable_systemd_service_sdcard motd-news.service motd-news.timer
2022-10-03 03:17:59 +00:00
# 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
2023-01-14 21:49:18 +00:00
display_alert "Use file list modules MODULES_INITRD" " ${ MODULES_INITRD } "
2022-10-03 03:17:59 +00:00
sed -i "s/^MODULES=.*/MODULES=list/" " ${ SDCARD } " /etc/initramfs-tools/initramfs.conf
cat " ${ SRC } " /config/modules/" ${ MODULES_INITRD } " >> " ${ SDCARD } " /etc/initramfs-tools/modules
fi
}
2023-05-13 09:00:28 +00:00
# create_sources_list_and_deploy_repo_key <when> <release> <basedir>
2022-10-03 02:52:43 +00:00
#
2023-05-13 09:00:28 +00:00
# <when>: rootfs|image
2024-05-11 08:27:38 +00:00
# <release>: bullseye|bookworm|sid|focal|jammy|noble|oracular
2022-10-03 02:52:43 +00:00
# <basedir>: path to root directory
#
2023-05-13 09:00:28 +00:00
function create_sources_list_and_deploy_repo_key( ) {
declare when = " ${ 1 } "
declare release = " ${ 2 } "
declare basedir = " ${ 3 } " # @TODO: rpardini: this is SDCARD in all practical senses. Why not just use SDCARD?
[ [ -z $basedir ] ] && exit_with_error "No basedir passed to create_sources_list_and_deploy_repo_key"
2022-10-03 02:52:43 +00:00
case $release in
2022-10-08 11:17:30 +00:00
buster)
cat <<- EOF > " ${ basedir } " /etc/apt/sources.list
deb http://${ DEBIAN_MIRROR } $release main contrib non-free
#deb-src http://${DEBIAN_MIRROR} $release main contrib non-free
deb http://${ DEBIAN_MIRROR } ${ release } -updates main contrib non-free
#deb-src http://${DEBIAN_MIRROR} ${release}-updates main contrib non-free
deb http://${ DEBIAN_SECURTY } ${ release } /updates main contrib non-free
#deb-src http://${DEBIAN_SECURTY} ${release}/updates main contrib non-free
EOF
; ;
2023-08-22 06:14:55 +00:00
bullseye)
2022-10-08 11:17:30 +00:00
cat <<- EOF > " ${ basedir } " /etc/apt/sources.list
deb http://${ DEBIAN_MIRROR } $release main contrib non-free
#deb-src http://${DEBIAN_MIRROR} $release main contrib non-free
deb http://${ DEBIAN_MIRROR } ${ release } -updates main contrib non-free
#deb-src http://${DEBIAN_MIRROR} ${release}-updates main contrib non-free
deb http://${ DEBIAN_MIRROR } ${ release } -backports main contrib non-free
#deb-src http://${DEBIAN_MIRROR} ${release}-backports main contrib non-free
deb http://${ DEBIAN_SECURTY } ${ release } -security main contrib non-free
#deb-src http://${DEBIAN_SECURTY} ${release}-security main contrib non-free
EOF
; ;
2023-08-22 06:14:55 +00:00
bookworm | trixie)
2023-02-03 12:01:02 +00:00
# non-free firmware in bookworm and later has moved from the non-free archive component to a new non-free-firmware component (alongside main/contrib/non-free). This was implemented on 2023-01-27, see also https://lists.debian.org/debian-boot/2023/01/msg00235.html
cat <<- EOF > " ${ basedir } " /etc/apt/sources.list
deb http://${ DEBIAN_MIRROR } $release main contrib non-free non-free-firmware
#deb-src http://${DEBIAN_MIRROR} $release main contrib non-free non-free-firmware
deb http://${ DEBIAN_MIRROR } ${ release } -updates main contrib non-free non-free-firmware
#deb-src http://${DEBIAN_MIRROR} ${release}-updates main contrib non-free non-free-firmware
deb http://${ DEBIAN_MIRROR } ${ release } -backports main contrib non-free non-free-firmware
#deb-src http://${DEBIAN_MIRROR} ${release}-backports main contrib non-free non-free-firmware
deb http://${ DEBIAN_SECURTY } ${ release } -security main contrib non-free non-free-firmware
#deb-src http://${DEBIAN_SECURTY} ${release}-security main contrib non-free non-free-firmware
EOF
; ;
2024-06-24 18:56:06 +00:00
sid | unstable) # sid is permanent unstable development and has no such thing as updates or security
2022-10-08 11:17:30 +00:00
cat <<- EOF > " ${ basedir } " /etc/apt/sources.list
2023-03-31 11:19:03 +00:00
deb http://${ DEBIAN_MIRROR } $release main contrib non-free non-free-firmware
#deb-src http://${DEBIAN_MIRROR} $release main contrib non-free non-free-firmware
2023-02-23 08:24:41 +00:00
2022-10-08 11:17:30 +00:00
EOF
2023-08-16 14:37:20 +00:00
2023-08-22 11:32:09 +00:00
# Exception: with riscv64 not everything was moved from ports
# https://lists.debian.org/debian-riscv/2023/07/msg00053.html
if [ [ " ${ ARCH } " = = riscv64 ] ] ; then
echo "deb http://deb.debian.org/debian-ports/ sid main " >> " ${ basedir } " /etc/apt/sources.list
fi
2022-10-08 11:17:30 +00:00
; ;
2024-05-11 08:27:38 +00:00
focal | jammy | noble | oracular)
2022-10-08 11:17:30 +00:00
cat <<- EOF > " ${ basedir } " /etc/apt/sources.list
deb http://${ UBUNTU_MIRROR } $release main restricted universe multiverse
#deb-src http://${UBUNTU_MIRROR} $release main restricted universe multiverse
deb http://${ UBUNTU_MIRROR } ${ release } -security main restricted universe multiverse
#deb-src http://${UBUNTU_MIRROR} ${release}-security main restricted universe multiverse
deb http://${ UBUNTU_MIRROR } ${ release } -updates main restricted universe multiverse
#deb-src http://${UBUNTU_MIRROR} ${release}-updates main restricted universe multiverse
deb http://${ UBUNTU_MIRROR } ${ release } -backports main restricted universe multiverse
#deb-src http://${UBUNTU_MIRROR} ${release}-backports main restricted universe multiverse
EOF
; ;
2022-10-03 02:52:43 +00:00
esac
2023-05-13 09:00:28 +00:00
display_alert "Adding Armbian repository and authentication key" " ${ when } :: /etc/apt/sources.list.d/armbian.list " "info"
2022-10-03 02:52:43 +00:00
# apt-key add is getting deprecated
APT_VERSION = $( chroot " ${ basedir } " /bin/bash -c "apt --version | cut -d\" \" -f2" )
if linux-version compare " ${ APT_VERSION } " ge 2.4.1; then
# add armbian key
mkdir -p " ${ basedir } " /usr/share/keyrings
# change to binary form
gpg --dearmor < " ${ SRC } " /config/armbian.key > " ${ basedir } " /usr/share/keyrings/armbian.gpg
SIGNED_BY = "[signed-by=/usr/share/keyrings/armbian.gpg] "
else
2023-01-14 21:49:18 +00:00
# use old method for compatibility reasons # @TODO: rpardini: not gonna fix this?
2022-10-03 02:52:43 +00:00
cp " ${ SRC } " /config/armbian.key " ${ basedir } "
2023-03-02 21:44:47 +00:00
chroot " ${ basedir } " /bin/bash -c "cat armbian.key | apt-key add -"
2022-10-03 02:52:43 +00:00
fi
2023-05-13 09:00:28 +00:00
declare -a components = ( )
2023-05-23 11:56:46 +00:00
if [ [ " ${ when } " = = "image" * ] ] ; then # only include the 'main' component when deploying to image (early or late)
2023-05-13 09:00:28 +00:00
components += ( "main" )
fi
components += ( " ${ RELEASE } -utils " ) # utils contains packages Igor picks from other repos
components += ( " ${ RELEASE } -desktop " ) # desktop contains packages Igor picks from other repos
2024-01-01 22:19:35 +00:00
# stage: add armbian repository and install key
if [ [ $DOWNLOAD_MIRROR = = "china" ] ] ; then
echo " deb ${ SIGNED_BY } https://mirrors.tuna.tsinghua.edu.cn/armbian $RELEASE ${ components [*] } " > " ${ basedir } " /etc/apt/sources.list.d/armbian.list
elif [ [ $DOWNLOAD_MIRROR = = "bfsu" ] ] ; then
echo " deb ${ SIGNED_BY } http://mirrors.bfsu.edu.cn/armbian $RELEASE ${ components [*] } " > " ${ basedir } " /etc/apt/sources.list.d/armbian.list
else
echo " deb ${ SIGNED_BY } http:// $( [ [ $BETA = = yes ] ] && echo "beta" || echo "apt" ) .armbian.com $RELEASE ${ components [*] } " > " ${ basedir } " /etc/apt/sources.list.d/armbian.list
fi
2022-10-03 02:52:43 +00:00
2024-01-01 22:19:35 +00:00
# replace local package server if defined. Suitable for development
[ [ -n $LOCAL_MIRROR ] ] && echo " deb ${ SIGNED_BY } http:// $LOCAL_MIRROR $RELEASE ${ components [*] } " > " ${ basedir } " /etc/apt/sources.list.d/armbian.list
2022-10-03 02:52:43 +00:00
2024-03-03 16:54:08 +00:00
# disable repo if DISTRIBUTION_STATUS==eos, or if SKIP_ARMBIAN_REPO==yes, or if when==image-early.
2024-06-24 18:56:06 +00:00
if [ [ " ${ when } " = = "image-early" ||
" $( cat " ${ SRC } /config/distributions/ ${ RELEASE } /support " ) " = = "eos" ||
2024-03-03 16:54:08 +00:00
" ${ SKIP_ARMBIAN_REPO } " = = "yes" ] ] ; then
2024-01-01 22:19:35 +00:00
display_alert "Disabling Armbian repo" " ${ ARCH } - ${ RELEASE } :: skip: ${ SKIP_ARMBIAN_REPO :- "no" } when: ${ when } " "info"
mv " ${ SDCARD } " /etc/apt/sources.list.d/armbian.list " ${ SDCARD } " /etc/apt/sources.list.d/armbian.list.disabled
2022-10-03 02:52:43 +00:00
fi
2023-05-13 09:00:28 +00:00
declare CUSTOM_REPO_WHEN = " ${ when } "
# Let user customize
call_extension_method "custom_apt_repo" <<- 'CUSTOM_APT_REPO'
*customize apt sources.list.d and/or deploy repo keys*
Called after core Armbian has finished setting up SDCARD' s sources.list and sources.list.d/armbian.list.
If SKIP_ARMBIAN_REPO = yes, armbian.list.disabled is present instead.
The global Armbian GPG key has been deployed to SDCARD' s /usr/share/keyrings/armbian.gpg, de-armored.
You can implement this hook to add, remove, or modify sources.list.d entries, and/or deploy additional GPG keys.
Important: honor $CUSTOM_REPO_WHEN ; if it's ==rootfs, don' t add repos/components that carry the .debs produced by armbian/build.
2023-05-23 11:56:46 +00:00
Ideally, also don' t add any possibly-conflicting repo if ` $CUSTOM_REPO_WHEN = = image-early` .
` $CUSTOM_APT_REPO = = image-late` is passed during the very final stages of image building, after all packages were installed/upgraded.
2023-05-13 09:00:28 +00:00
CUSTOM_APT_REPO
unset CUSTOM_REPO_WHEN
return 0
2022-10-03 02:52:43 +00:00
}