Skip to content

Commit

Permalink
bsp-cli/distro-agnostic: introduce KEEP_ORIGINAL_OS_RELEASE=yes so …
Browse files Browse the repository at this point in the history
…Debian/Ubuntu PRETTY_NAME is left unchanged in `/etc/os-release`

- useful when downstream software wants exact Debian OS
  • Loading branch information
rpardini committed Apr 15, 2023
1 parent c30a907 commit 0d276c9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 16 deletions.
17 changes: 9 additions & 8 deletions lib/functions/artifacts/artifact-armbian-bsp-cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ function artifact_armbian-bsp-cli_prepare_version() {
"${bootscript_info[bootenv_file_contents]}"
"${bootscript_info[has_bootscript]}"
"${bootscript_info[has_extlinux]}"
"${UBOOT_FW_ENV}" # not included in bootscript
"${BOARDFAMILY}" # /etc/armbian-release
"${LINUXFAMILY}" # /etc/armbian-release
"${IMAGE_TYPE}" # /etc/armbian-release
"${BOARD_TYPE}" # /etc/armbian-release
"${INITRD_ARCH}" # /etc/armbian-release
"${KERNEL_IMAGE_TYPE}" # /etc/armbian-release
"${VENDOR}" # /etc/armbian-release
"${UBOOT_FW_ENV}" # not included in bootscript
"${KEEP_ORIGINAL_OS_RELEASE:-"no"}" # /etc/os-release
"${BOARDFAMILY}" # /etc/armbian-release
"${LINUXFAMILY}" # /etc/armbian-release
"${IMAGE_TYPE}" # /etc/armbian-release
"${BOARD_TYPE}" # /etc/armbian-release
"${INITRD_ARCH}" # /etc/armbian-release
"${KERNEL_IMAGE_TYPE}" # /etc/armbian-release
"${VENDOR}" # /etc/armbian-release
)
declare hash_vars="undetermined"
hash_vars="$(echo "${vars_to_hash[@]}" | sha256sum | cut -d' ' -f1)"
Expand Down
23 changes: 21 additions & 2 deletions lib/functions/bsp/armbian-bsp-cli-deb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ function compile_armbian-bsp-cli() {
postinst_functions+=(board_side_bsp_cli_postinst_update_uboot_bootscript)
fi

if [[ "${KEEP_ORIGINAL_OS_RELEASE:-"no"}" != "yes" ]]; then
# add to postinst, to change PRETTY_NAME to Armbian's
postinst_functions+=(board_side_bsp_cli_postinst_os_release_armbian)
else
display_alert "bsp-cli: KEEP_ORIGINAL_OS_RELEASE" "Keeping original /etc/os-release's PRETTY_NAME as original" "info"
fi

# add configuration for setting uboot environment from userspace with: fw_setenv fw_printenv
if [[ -n $UBOOT_FW_ENV ]]; then
UBOOT_FW_ENV=($(tr ',' ' ' <<< "$UBOOT_FW_ENV"))
Expand Down Expand Up @@ -321,10 +328,11 @@ function board_side_bsp_cli_postinst_base() {
# Source the armbian-release information file
[ -f /etc/armbian-release ] && . /etc/armbian-release

# Read release value from lsb-release, so deploying a bsp-cli package on top of "X" makes it "Armbian X"
# Read release value from lsb-release and set it separately as ARMBIAN_PRETTY_NAME
# More is done, actually taking over PRETTY_NAME, in separate board_side_bsp_cli_postinst_os_release_armbian()
if [ -f /etc/lsb-release ]; then
ORIGINAL_DISTRO_RELEASE="$(cat /etc/lsb-release | grep CODENAME | cut -d"=" -f2 | sed 's/.*/\u&/')"
sed -i "s/^PRETTY_NAME=.*/PRETTY_NAME=\"${VENDOR} $REVISION ${ORIGINAL_DISTRO_RELEASE}\"/" /etc/os-release
echo "ARMBIAN_PRETTY_NAME=\"${VENDOR} ${REVISION} ${ORIGINAL_DISTRO_RELEASE}\"" >> /etc/os-release
echo -e "${VENDOR} ${REVISION} ${ORIGINAL_DISTRO_RELEASE} \\l \n" > /etc/issue
echo -e "${VENDOR} ${REVISION} ${ORIGINAL_DISTRO_RELEASE}" > /etc/issue.net
fi
Expand All @@ -345,6 +353,17 @@ function board_side_bsp_cli_postinst_base() {
fi
}

function board_side_bsp_cli_postinst_os_release_armbian() {
# Source the armbian-release information file
[ -f /etc/armbian-release ] && . /etc/armbian-release

# Read release value from lsb-release, so deploying a bsp-cli package on top of "X" makes it "Armbian X"
if [ -f /etc/lsb-release ]; then
ORIGINAL_DISTRO_RELEASE="$(cat /etc/lsb-release | grep CODENAME | cut -d"=" -f2 | sed 's/.*/\u&/')"
sed -i "s/^PRETTY_NAME=.*/PRETTY_NAME=\"${VENDOR} $REVISION ${ORIGINAL_DISTRO_RELEASE}\"/" /etc/os-release
fi
}

function board_side_bsp_cli_postinst_finish() {
[ ! -f "/etc/network/interfaces" ] && [ -f "/etc/network/interfaces.default" ] && cp /etc/network/interfaces.default /etc/network/interfaces
ln -sf /var/run/motd /etc/motd
Expand Down
18 changes: 12 additions & 6 deletions lib/functions/rootfs/distro-agnostic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,13 @@ function install_distribution_agnostic() {
# change console welcome text
echo -e "${VENDOR} ${IMAGE_VERSION:-"${REVISION}"} ${RELEASE^} \\l \n" > "${SDCARD}"/etc/issue
echo "${VENDOR} ${IMAGE_VERSION:-"${REVISION}"} ${RELEASE^}" > "${SDCARD}"/etc/issue.net
sed -i "s/^PRETTY_NAME=.*/PRETTY_NAME=\"${VENDOR} ${IMAGE_VERSION:-"${REVISION}"} ${RELEASE^}\"/" "${SDCARD}"/etc/os-release

# Keep, or change to Armbian's PRETTY_NAME in /etc/os-release (this is also done in the bsp-cli postinst)
if [[ "${KEEP_ORIGINAL_OS_RELEASE:-"no"}" != "yes" ]]; then
sed -i "s/^PRETTY_NAME=.*/PRETTY_NAME=\"${VENDOR} ${IMAGE_VERSION:-"${REVISION}"} ${RELEASE^}\"/" "${SDCARD}"/etc/os-release
else
display_alert "distro-agnostic: KEEP_ORIGINAL_OS_RELEASE" "Keeping original /etc/os-release's PRETTY_NAME as original" "warn"
fi

# enable few bash aliases enabled in Ubuntu by default to make it even
sed "s/#alias ll='ls -l'/alias ll='ls -l'/" -i "${SDCARD}"/etc/skel/.bashrc
Expand Down Expand Up @@ -400,11 +406,11 @@ function install_distribution_agnostic() {
if [[ "${BSPFREEZE:-"no"}" == yes ]]; then
display_alert "Freezing Armbian packages" "$BOARD" "info"
chroot_sdcard apt-mark hold "${image_artifacts_packages["armbian-plymouth-theme"]}" "${image_artifacts_packages["armbian-zsh"]}" \
"${image_artifacts_packages["armbian-config"]}" "${image_artifacts_packages["armbian-bsp-desktop"]}" \
"${image_artifacts_packages["armbian-desktop"]}" "${image_artifacts_packages["armbian-bsp-cli"]}" \
"${image_artifacts_packages["armbian-firmware"]}" "${image_artifacts_packages["armbian-firmware-full"]}" \
"${image_artifacts_packages["linux-headers"]}" "${image_artifacts_packages["linux-dtb"]}" \
"${image_artifacts_packages["linux-image"]}" "${image_artifacts_packages["uboot"]}" || true
"${image_artifacts_packages["armbian-config"]}" "${image_artifacts_packages["armbian-bsp-desktop"]}" \
"${image_artifacts_packages["armbian-desktop"]}" "${image_artifacts_packages["armbian-bsp-cli"]}" \
"${image_artifacts_packages["armbian-firmware"]}" "${image_artifacts_packages["armbian-firmware-full"]}" \
"${image_artifacts_packages["linux-headers"]}" "${image_artifacts_packages["linux-dtb"]}" \
"${image_artifacts_packages["linux-image"]}" "${image_artifacts_packages["uboot"]}" || true
fi

# remove deb files
Expand Down

0 comments on commit 0d276c9

Please sign in to comment.