From 6d0c97d6ec0afe9eb55a48ee0d0b08e7f1b67eb2 Mon Sep 17 00:00:00 2001 From: hzy Date: Mon, 3 Oct 2022 11:22:11 +0800 Subject: [PATCH] Split `/lib/desktop.sh` --- .../bsp/bsp-desktop.sh} | 144 ------------------ lib/functions/rootfs/apt-sources.sh | 84 ++++++++++ lib/functions/rootfs/rootfs-desktop.sh | 21 +++ lib/main.sh | 2 - 4 files changed, 105 insertions(+), 146 deletions(-) rename lib/{desktop.sh => functions/bsp/bsp-desktop.sh} (50%) create mode 100644 lib/functions/rootfs/apt-sources.sh create mode 100644 lib/functions/rootfs/rootfs-desktop.sh diff --git a/lib/desktop.sh b/lib/functions/bsp/bsp-desktop.sh similarity index 50% rename from lib/desktop.sh rename to lib/functions/bsp/bsp-desktop.sh index c996e8e2d2..4bd8d29623 100644 --- a/lib/desktop.sh +++ b/lib/functions/bsp/bsp-desktop.sh @@ -1,25 +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: - -# create_desktop_package -# install_ppa_prerequisites -# add_apt_sources -# add_desktop_package_sources -# desktop_postinstall - - - - create_desktop_package () { @@ -105,9 +83,6 @@ create_desktop_package () } - - - create_bsp_desktop_package () { @@ -169,122 +144,3 @@ create_bsp_desktop_package () unset aggregated_content } - - - - -install_ppa_prerequisites() { - - # Myy : So... The whole idea is that, a good bunch of external sources - # are PPA. - # Adding PPA without add-apt-repository is poorly conveninent since - # you need to reconstruct the URL by hand, and find the GPG key yourself. - # add-apt-repository does that automatically, and in a way that allows you - # to remove it cleanly through the same tool. - - # Myy : TODO Try to find a way to install this package only when - # we encounter a PPA. - run_on_sdcard "DEBIAN_FRONTEND=noninteractive apt install -yqq software-properties-common" - -} - - - - -add_apt_sources() { - - local potential_paths="" - local sub_dirs_to_check=". " - if [[ ! -z "${SELECTED_CONFIGURATION+x}" ]]; then - sub_dirs_to_check+="config_${SELECTED_CONFIGURATION}" - fi - get_all_potential_paths "${DEBOOTSTRAP_SEARCH_RELATIVE_DIRS}" "${sub_dirs_to_check}" "sources/apt" - get_all_potential_paths "${CLI_SEARCH_RELATIVE_DIRS}" "${sub_dirs_to_check}" "sources/apt" - get_all_potential_paths "${DESKTOP_ENVIRONMENTS_SEARCH_RELATIVE_DIRS}" "." "sources/apt" - get_all_potential_paths "${DESKTOP_APPGROUPS_SEARCH_RELATIVE_DIRS}" "${DESKTOP_APPGROUPS_SELECTED}" "sources/apt" - - display_alert "Adding additional apt sources" - - for apt_sources_dirpath in ${potential_paths}; do - if [[ -d "${apt_sources_dirpath}" ]]; then - for apt_source_filepath in "${apt_sources_dirpath}/"*.source; do - apt_source_filepath=$(echo $apt_source_filepath | sed -re 's/(^.*[^/])\.[^./]*$/\1/') - local new_apt_source="$(cat "${apt_source_filepath}.source")" - local apt_source_gpg_filepath="${apt_source_filepath}.gpg" - - # extract filenames - local apt_source_gpg_filename="$(basename ${apt_source_gpg_filepath})" - local apt_source_filename="$(basename ${apt_source_filepath}).list" - - display_alert "Adding APT Source ${new_apt_source}" - - if [[ "${new_apt_source}" == ppa* ]] ; then - # ppa with software-common-properties - run_on_sdcard "add-apt-repository -y -n \"${new_apt_source}\"" - # add list with apt-add - # -y -> Assumes yes to all queries - # -n -> Do not update package cache after adding - if [[ -f "${apt_source_gpg_filepath}" ]]; then - display_alert "Adding GPG Key ${apt_source_gpg_filepath}" - cp "${apt_source_gpg_filepath}" "${SDCARD}/tmp/${apt_source_gpg_filename}" - run_on_sdcard "apt-key add \"/tmp/${apt_source_gpg_filename}\"" - echo "APT Key returned : $?" - fi - else - # installation without software-common-properties, sources.list + key.gpg - echo "${new_apt_source}" > "${SDCARD}/etc/apt/sources.list.d/${apt_source_filename}" - if [[ -f "${apt_source_gpg_filepath}" ]]; then - display_alert "Adding GPG Key ${apt_source_gpg_filepath}" -# local apt_source_gpg_filename="$(basename ${apt_source_gpg_filepath})" - mkdir -p "${SDCARD}"/usr/share/keyrings/ - cp "${apt_source_gpg_filepath}" "${SDCARD}"/usr/share/keyrings/ - fi - - fi - - done - fi - done - -} - - - - -add_desktop_package_sources() { - - # Myy : I see Snap and Flatpak coming up in the next releases - # so... let's prepare for that - - add_apt_sources - - ls -l "${SDCARD}/usr/share/keyrings" >> "${DEST}"/${LOG_SUBPATH}/install.log - ls -l "${SDCARD}/etc/apt/sources.list.d" >> "${DEST}"/${LOG_SUBPATH}/install.log - cat "${SDCARD}/etc/apt/sources.list" >> "${DEST}"/${LOG_SUBPATH}/install.log - -} - - - - -desktop_postinstall () -{ - - # disable display manager for the first run - run_on_sdcard "systemctl --no-reload disable lightdm.service >/dev/null 2>&1" - run_on_sdcard "systemctl --no-reload disable gdm3.service >/dev/null 2>&1" - - # update packages index - run_on_sdcard "DEBIAN_FRONTEND=noninteractive apt-get update >/dev/null 2>&1" - - # install per board packages - if [[ -n ${PACKAGE_LIST_DESKTOP_BOARD} ]]; then - run_on_sdcard "DEBIAN_FRONTEND=noninteractive apt-get -yqq --no-install-recommends install $PACKAGE_LIST_DESKTOP_BOARD" - fi - - # install per family packages - if [[ -n ${PACKAGE_LIST_DESKTOP_FAMILY} ]]; then - run_on_sdcard "DEBIAN_FRONTEND=noninteractive apt-get -yqq --no-install-recommends install $PACKAGE_LIST_DESKTOP_FAMILY" - fi - -} diff --git a/lib/functions/rootfs/apt-sources.sh b/lib/functions/rootfs/apt-sources.sh new file mode 100644 index 0000000000..490f069aa7 --- /dev/null +++ b/lib/functions/rootfs/apt-sources.sh @@ -0,0 +1,84 @@ +install_ppa_prerequisites() { + + # Myy : So... The whole idea is that, a good bunch of external sources + # are PPA. + # Adding PPA without add-apt-repository is poorly conveninent since + # you need to reconstruct the URL by hand, and find the GPG key yourself. + # add-apt-repository does that automatically, and in a way that allows you + # to remove it cleanly through the same tool. + + # Myy : TODO Try to find a way to install this package only when + # we encounter a PPA. + run_on_sdcard "DEBIAN_FRONTEND=noninteractive apt install -yqq software-properties-common" + +} + +add_apt_sources() { + + local potential_paths="" + local sub_dirs_to_check=". " + if [[ ! -z "${SELECTED_CONFIGURATION+x}" ]]; then + sub_dirs_to_check+="config_${SELECTED_CONFIGURATION}" + fi + get_all_potential_paths "${DEBOOTSTRAP_SEARCH_RELATIVE_DIRS}" "${sub_dirs_to_check}" "sources/apt" + get_all_potential_paths "${CLI_SEARCH_RELATIVE_DIRS}" "${sub_dirs_to_check}" "sources/apt" + get_all_potential_paths "${DESKTOP_ENVIRONMENTS_SEARCH_RELATIVE_DIRS}" "." "sources/apt" + get_all_potential_paths "${DESKTOP_APPGROUPS_SEARCH_RELATIVE_DIRS}" "${DESKTOP_APPGROUPS_SELECTED}" "sources/apt" + + display_alert "Adding additional apt sources" + + for apt_sources_dirpath in ${potential_paths}; do + if [[ -d "${apt_sources_dirpath}" ]]; then + for apt_source_filepath in "${apt_sources_dirpath}/"*.source; do + apt_source_filepath=$(echo $apt_source_filepath | sed -re 's/(^.*[^/])\.[^./]*$/\1/') + local new_apt_source="$(cat "${apt_source_filepath}.source")" + local apt_source_gpg_filepath="${apt_source_filepath}.gpg" + + # extract filenames + local apt_source_gpg_filename="$(basename ${apt_source_gpg_filepath})" + local apt_source_filename="$(basename ${apt_source_filepath}).list" + + display_alert "Adding APT Source ${new_apt_source}" + + if [[ "${new_apt_source}" == ppa* ]] ; then + # ppa with software-common-properties + run_on_sdcard "add-apt-repository -y -n \"${new_apt_source}\"" + # add list with apt-add + # -y -> Assumes yes to all queries + # -n -> Do not update package cache after adding + if [[ -f "${apt_source_gpg_filepath}" ]]; then + display_alert "Adding GPG Key ${apt_source_gpg_filepath}" + cp "${apt_source_gpg_filepath}" "${SDCARD}/tmp/${apt_source_gpg_filename}" + run_on_sdcard "apt-key add \"/tmp/${apt_source_gpg_filename}\"" + echo "APT Key returned : $?" + fi + else + # installation without software-common-properties, sources.list + key.gpg + echo "${new_apt_source}" > "${SDCARD}/etc/apt/sources.list.d/${apt_source_filename}" + if [[ -f "${apt_source_gpg_filepath}" ]]; then + display_alert "Adding GPG Key ${apt_source_gpg_filepath}" +# local apt_source_gpg_filename="$(basename ${apt_source_gpg_filepath})" + mkdir -p "${SDCARD}"/usr/share/keyrings/ + cp "${apt_source_gpg_filepath}" "${SDCARD}"/usr/share/keyrings/ + fi + + fi + + done + fi + done + +} + +add_desktop_package_sources() { + + # Myy : I see Snap and Flatpak coming up in the next releases + # so... let's prepare for that + + add_apt_sources + + ls -l "${SDCARD}/usr/share/keyrings" >> "${DEST}"/${LOG_SUBPATH}/install.log + ls -l "${SDCARD}/etc/apt/sources.list.d" >> "${DEST}"/${LOG_SUBPATH}/install.log + cat "${SDCARD}/etc/apt/sources.list" >> "${DEST}"/${LOG_SUBPATH}/install.log + +} diff --git a/lib/functions/rootfs/rootfs-desktop.sh b/lib/functions/rootfs/rootfs-desktop.sh new file mode 100644 index 0000000000..430c5833bf --- /dev/null +++ b/lib/functions/rootfs/rootfs-desktop.sh @@ -0,0 +1,21 @@ +desktop_postinstall () +{ + + # disable display manager for the first run + run_on_sdcard "systemctl --no-reload disable lightdm.service >/dev/null 2>&1" + run_on_sdcard "systemctl --no-reload disable gdm3.service >/dev/null 2>&1" + + # update packages index + run_on_sdcard "DEBIAN_FRONTEND=noninteractive apt-get update >/dev/null 2>&1" + + # install per board packages + if [[ -n ${PACKAGE_LIST_DESKTOP_BOARD} ]]; then + run_on_sdcard "DEBIAN_FRONTEND=noninteractive apt-get -yqq --no-install-recommends install $PACKAGE_LIST_DESKTOP_BOARD" + fi + + # install per family packages + if [[ -n ${PACKAGE_LIST_DESKTOP_FAMILY} ]]; then + run_on_sdcard "DEBIAN_FRONTEND=noninteractive apt-get -yqq --no-install-recommends install $PACKAGE_LIST_DESKTOP_FAMILY" + fi + +} diff --git a/lib/main.sh b/lib/main.sh index 0c59e3ddda..c9d97d8218 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=desktop.sh -source "${SRC}"/lib/desktop.sh # desktop specific install # shellcheck source=compilation.sh source "${SRC}"/lib/compilation.sh # patching and compilation of kernel, uboot, ATF # shellcheck source=compilation-prepare.sh