Split out functions from /lib/configuration.sh

This commit is contained in:
hzy 2022-10-09 01:10:52 +08:00 committed by Igor Pečovnik
parent 037248761d
commit cda53306a6
4 changed files with 198 additions and 201 deletions

View File

@ -198,31 +198,6 @@ Since the family can override values from the user configuration and the board c
it is often used to in turn override those.
POST_FAMILY_CONFIG
# Myy : Menu configuration for choosing desktop configurations
show_menu() {
provided_title=$1
provided_backtitle=$2
provided_menuname=$3
# Myy : I don't know why there's a TTY_Y - 8...
#echo "Provided title : $provided_title"
#echo "Provided backtitle : $provided_backtitle"
#echo "Provided menuname : $provided_menuname"
#echo "Provided options : " "${@:4}"
#echo "TTY X: $TTY_X Y: $TTY_Y"
dialog --stdout --title "$provided_title" --backtitle "${provided_backtitle}" \
--menu "$provided_menuname" $TTY_Y $TTY_X $((TTY_Y - 8)) "${@:4}"
}
# Myy : FIXME Factorize
show_select_menu() {
provided_title=$1
provided_backtitle=$2
provided_menuname=$3
dialog --stdout --title "${provided_title}" --backtitle "${provided_backtitle}" \
--checklist "${provided_menuname}" $TTY_Y $TTY_X $((TTY_Y - 8)) "${@:4}"
}
# Myy : Once we got a list of selected groups, parse the PACKAGE_LIST inside configuration.sh
DESKTOP_ELEMENTS_DIR="${SRC}/config/desktop/${RELEASE}"
@ -230,55 +205,8 @@ DESKTOP_CONFIGS_DIR="${DESKTOP_ELEMENTS_DIR}/environments"
DESKTOP_CONFIG_PREFIX="config_"
DESKTOP_APPGROUPS_DIR="${DESKTOP_ELEMENTS_DIR}/appgroups"
desktop_element_available_for_arch() {
local desktop_element_path="${1}"
local targeted_arch="${2}"
local arch_limitation_file="${1}/only_for"
echo "Checking if ${desktop_element_path} is available for ${targeted_arch} in ${arch_limitation_file}" >> "${DEST}"/${LOG_SUBPATH}/output.log
if [[ -f "${arch_limitation_file}" ]]; then
grep -- "${targeted_arch}" "${arch_limitation_file}"
return $?
else
return 0
fi
}
desktop_element_supported() {
local desktop_element_path="${1}"
local support_level_filepath="${desktop_element_path}/support"
if [[ -f "${support_level_filepath}" ]]; then
local support_level="$(cat "${support_level_filepath}")"
if [[ "${support_level}" != "supported" && "${EXPERT}" != "yes" ]]; then
return 65
fi
desktop_element_available_for_arch "${desktop_element_path}" "${ARCH}"
if [[ $? -ne 0 ]]; then
return 66
fi
else
return 64
fi
return 0
}
if [[ $BUILD_DESKTOP == "yes" && -z $DESKTOP_ENVIRONMENT ]]; then
desktop_environments_prepare_menu() {
for desktop_env_dir in "${DESKTOP_CONFIGS_DIR}/"*; do
local desktop_env_name=$(basename ${desktop_env_dir})
local expert_infos=""
[[ "${EXPERT}" == "yes" ]] && expert_infos="[$(cat "${desktop_env_dir}/support" 2> /dev/null)]"
desktop_element_supported "${desktop_env_dir}" "${ARCH}" && options+=("${desktop_env_name}" "${desktop_env_name^} desktop environment ${expert_infos}")
done
}
options=()
desktop_environments_prepare_menu
@ -301,31 +229,6 @@ if [[ $BUILD_DESKTOP == "yes" ]]; then
# - options
# - ARCH
desktop_environment_check_if_valid() {
local error_msg=""
desktop_element_supported "${DESKTOP_ENVIRONMENT_DIRPATH}" "${ARCH}"
local retval=$?
if [[ ${retval} == 0 ]]; then
return
elif [[ ${retval} == 64 ]]; then
error_msg+="Either the desktop environment ${DESKTOP_ENVIRONMENT} does not exist "
error_msg+="or the file ${DESKTOP_ENVIRONMENT_DIRPATH}/support is missing"
elif [[ ${retval} == 65 ]]; then
error_msg+="Only experts can build an image with the desktop environment \"${DESKTOP_ENVIRONMENT}\", since the Armbian team won't offer any support for it (EXPERT=${EXPERT})"
elif [[ ${retval} == 66 ]]; then
error_msg+="The desktop environment \"${DESKTOP_ENVIRONMENT}\" has no packages for your targeted board architecture (BOARD=${BOARD} ARCH=${ARCH}). "
error_msg+="The supported boards architectures are : "
error_msg+="$(cat "${DESKTOP_ENVIRONMENT_DIRPATH}/only_for")"
fi
# supress error when cache is rebuilding
[[ -n "$ROOT_FS_CREATE_ONLY" ]] && exit 0
exit_with_error "${error_msg}"
}
DESKTOP_ENVIRONMENT_DIRPATH="${DESKTOP_CONFIGS_DIR}/${DESKTOP_ENVIRONMENT}"
desktop_environment_check_if_valid
@ -383,30 +286,6 @@ fi
#exit_with_error 'Testing'
# Expected variables
# - aggregated_content
# - potential_paths
# - separator
# Write to variables :
# - aggregated_content
aggregate_content() {
LOG_OUTPUT_FILE="$SRC/output/${LOG_SUBPATH}/potential-paths.log"
echo -e "Potential paths :" >> "${LOG_OUTPUT_FILE}"
show_checklist_variables potential_paths
for filepath in ${potential_paths}; do
if [[ -f "${filepath}" ]]; then
echo -e "${filepath/"$SRC"\//} yes" >> "${LOG_OUTPUT_FILE}"
aggregated_content+=$(cat "${filepath}")
aggregated_content+="${separator}"
# else
# echo -e "${filepath/"$SRC"\//} no\n" >> "${LOG_OUTPUT_FILE}"
fi
done
echo "" >> "${LOG_OUTPUT_FILE}"
unset LOG_OUTPUT_FILE
}
# set unique mounting directory
MOUNT_UUID=$(uuidgen)
SDCARD="${SRC}/.tmp/rootfs-${MOUNT_UUID}"
@ -480,86 +359,6 @@ desktop/${RELEASE}/appgroups
desktop/${RELEASE}/environments/${DESKTOP_ENVIRONMENT}/appgroups
"
get_all_potential_paths() {
local root_dirs="${AGGREGATION_SEARCH_ROOT_ABSOLUTE_DIRS}"
local rel_dirs="${1}"
local sub_dirs="${2}"
local looked_up_subpath="${3}"
for root_dir in ${root_dirs}; do
for rel_dir in ${rel_dirs}; do
for sub_dir in ${sub_dirs}; do
potential_paths+="${root_dir}/${rel_dir}/${sub_dir}/${looked_up_subpath} "
done
done
done
# for ppath in ${potential_paths}; do
# echo "Checking for ${ppath}"
# if [[ -f "${ppath}" ]]; then
# echo "OK !|"
# else
# echo "Nope|"
# fi
# done
}
# Environment variables expected :
# - aggregated_content
# Arguments :
# 1. File to look up in each directory
# 2. The separator to add between each concatenated file
# 3. Relative directories paths added to ${3}
# 4. Relative directories paths added to ${4}
#
# The function will basically generate a list of potential paths by
# generating all the potential paths combinations leading to the
# looked up file
# ${AGGREGATION_SEARCH_ROOT_ABSOLUTE_DIRS}/${3}/${4}/${1}
# Then it will concatenate the content of all the available files
# into ${aggregated_content}
#
# TODO :
# ${4} could be removed by just adding the appropriate paths to ${3}
# dynamically for each case
# (debootstrap, cli, desktop environments, desktop appgroups, ...)
aggregate_all_root_rel_sub() {
local separator="${2}"
local potential_paths=""
get_all_potential_paths "${3}" "${4}" "${1}"
aggregate_content
}
aggregate_all_debootstrap() {
local sub_dirs_to_check=". "
if [[ ! -z "${SELECTED_CONFIGURATION+x}" ]]; then
sub_dirs_to_check+="config_${SELECTED_CONFIGURATION}"
fi
aggregate_all_root_rel_sub "${1}" "${2}" "${DEBOOTSTRAP_SEARCH_RELATIVE_DIRS}" "${sub_dirs_to_check}"
}
aggregate_all_cli() {
local sub_dirs_to_check=". "
if [[ ! -z "${SELECTED_CONFIGURATION+x}" ]]; then
sub_dirs_to_check+="config_${SELECTED_CONFIGURATION}"
fi
aggregate_all_root_rel_sub "${1}" "${2}" "${CLI_SEARCH_RELATIVE_DIRS}" "${sub_dirs_to_check}"
}
aggregate_all_desktop() {
aggregate_all_root_rel_sub "${1}" "${2}" "${DESKTOP_ENVIRONMENTS_SEARCH_RELATIVE_DIRS}" "."
aggregate_all_root_rel_sub "${1}" "${2}" "${DESKTOP_APPGROUPS_SEARCH_RELATIVE_DIRS}" "${DESKTOP_APPGROUPS_SELECTED}"
}
one_line() {
local aggregate_func_name="${1}"
local aggregated_content=""
shift 1
$aggregate_func_name "${@}"
cleanup_list aggregated_content
}
DEBOOTSTRAP_LIST="$(one_line aggregate_all_debootstrap "packages" " ")"
DEBOOTSTRAP_COMPONENTS="$(one_line aggregate_all_debootstrap "components" " ")"
DEBOOTSTRAP_COMPONENTS="${DEBOOTSTRAP_COMPONENTS// /,}"

View File

@ -0,0 +1,103 @@
# Expected variables
# - aggregated_content
# - potential_paths
# - separator
# Write to variables :
# - aggregated_content
aggregate_content() {
LOG_OUTPUT_FILE="$SRC/output/${LOG_SUBPATH}/potential-paths.log"
echo -e "Potential paths :" >> "${LOG_OUTPUT_FILE}"
show_checklist_variables potential_paths
for filepath in ${potential_paths}; do
if [[ -f "${filepath}" ]]; then
echo -e "${filepath/"$SRC"\//} yes" >> "${LOG_OUTPUT_FILE}"
aggregated_content+=$(cat "${filepath}")
aggregated_content+="${separator}"
# else
# echo -e "${filepath/"$SRC"\//} no\n" >> "${LOG_OUTPUT_FILE}"
fi
done
echo "" >> "${LOG_OUTPUT_FILE}"
unset LOG_OUTPUT_FILE
}
get_all_potential_paths() {
local root_dirs="${AGGREGATION_SEARCH_ROOT_ABSOLUTE_DIRS}"
local rel_dirs="${1}"
local sub_dirs="${2}"
local looked_up_subpath="${3}"
for root_dir in ${root_dirs}; do
for rel_dir in ${rel_dirs}; do
for sub_dir in ${sub_dirs}; do
potential_paths+="${root_dir}/${rel_dir}/${sub_dir}/${looked_up_subpath} "
done
done
done
# for ppath in ${potential_paths}; do
# echo "Checking for ${ppath}"
# if [[ -f "${ppath}" ]]; then
# echo "OK !|"
# else
# echo "Nope|"
# fi
# done
}
# Environment variables expected :
# - aggregated_content
# Arguments :
# 1. File to look up in each directory
# 2. The separator to add between each concatenated file
# 3. Relative directories paths added to ${3}
# 4. Relative directories paths added to ${4}
#
# The function will basically generate a list of potential paths by
# generating all the potential paths combinations leading to the
# looked up file
# ${AGGREGATION_SEARCH_ROOT_ABSOLUTE_DIRS}/${3}/${4}/${1}
# Then it will concatenate the content of all the available files
# into ${aggregated_content}
#
# TODO :
# ${4} could be removed by just adding the appropriate paths to ${3}
# dynamically for each case
# (debootstrap, cli, desktop environments, desktop appgroups, ...)
aggregate_all_root_rel_sub() {
local separator="${2}"
local potential_paths=""
get_all_potential_paths "${3}" "${4}" "${1}"
aggregate_content
}
aggregate_all_debootstrap() {
local sub_dirs_to_check=". "
if [[ ! -z "${SELECTED_CONFIGURATION+x}" ]]; then
sub_dirs_to_check+="config_${SELECTED_CONFIGURATION}"
fi
aggregate_all_root_rel_sub "${1}" "${2}" "${DEBOOTSTRAP_SEARCH_RELATIVE_DIRS}" "${sub_dirs_to_check}"
}
aggregate_all_cli() {
local sub_dirs_to_check=". "
if [[ ! -z "${SELECTED_CONFIGURATION+x}" ]]; then
sub_dirs_to_check+="config_${SELECTED_CONFIGURATION}"
fi
aggregate_all_root_rel_sub "${1}" "${2}" "${CLI_SEARCH_RELATIVE_DIRS}" "${sub_dirs_to_check}"
}
aggregate_all_desktop() {
aggregate_all_root_rel_sub "${1}" "${2}" "${DESKTOP_ENVIRONMENTS_SEARCH_RELATIVE_DIRS}" "."
aggregate_all_root_rel_sub "${1}" "${2}" "${DESKTOP_APPGROUPS_SEARCH_RELATIVE_DIRS}" "${DESKTOP_APPGROUPS_SELECTED}"
}
one_line() {
local aggregate_func_name="${1}"
local aggregated_content=""
shift 1
$aggregate_func_name "${@}"
cleanup_list aggregated_content
}

View File

@ -0,0 +1,71 @@
desktop_element_available_for_arch() {
local desktop_element_path="${1}"
local targeted_arch="${2}"
local arch_limitation_file="${1}/only_for"
echo "Checking if ${desktop_element_path} is available for ${targeted_arch} in ${arch_limitation_file}" >> "${DEST}"/${LOG_SUBPATH}/output.log
if [[ -f "${arch_limitation_file}" ]]; then
grep -- "${targeted_arch}" "${arch_limitation_file}"
return $?
else
return 0
fi
}
desktop_element_supported() {
local desktop_element_path="${1}"
local support_level_filepath="${desktop_element_path}/support"
if [[ -f "${support_level_filepath}" ]]; then
local support_level="$(cat "${support_level_filepath}")"
if [[ "${support_level}" != "supported" && "${EXPERT}" != "yes" ]]; then
return 65
fi
desktop_element_available_for_arch "${desktop_element_path}" "${ARCH}"
if [[ $? -ne 0 ]]; then
return 66
fi
else
return 64
fi
return 0
}
desktop_environments_prepare_menu() {
for desktop_env_dir in "${DESKTOP_CONFIGS_DIR}/"*; do
local desktop_env_name=$(basename ${desktop_env_dir})
local expert_infos=""
[[ "${EXPERT}" == "yes" ]] && expert_infos="[$(cat "${desktop_env_dir}/support" 2> /dev/null)]"
desktop_element_supported "${desktop_env_dir}" "${ARCH}" && options+=("${desktop_env_name}" "${desktop_env_name^} desktop environment ${expert_infos}")
done
}
desktop_environment_check_if_valid() {
local error_msg=""
desktop_element_supported "${DESKTOP_ENVIRONMENT_DIRPATH}" "${ARCH}"
local retval=$?
if [[ ${retval} == 0 ]]; then
return
elif [[ ${retval} == 64 ]]; then
error_msg+="Either the desktop environment ${DESKTOP_ENVIRONMENT} does not exist "
error_msg+="or the file ${DESKTOP_ENVIRONMENT_DIRPATH}/support is missing"
elif [[ ${retval} == 65 ]]; then
error_msg+="Only experts can build an image with the desktop environment \"${DESKTOP_ENVIRONMENT}\", since the Armbian team won't offer any support for it (EXPERT=${EXPERT})"
elif [[ ${retval} == 66 ]]; then
error_msg+="The desktop environment \"${DESKTOP_ENVIRONMENT}\" has no packages for your targeted board architecture (BOARD=${BOARD} ARCH=${ARCH}). "
error_msg+="The supported boards architectures are : "
error_msg+="$(cat "${DESKTOP_ENVIRONMENT_DIRPATH}/only_for")"
fi
# supress error when cache is rebuilding
[[ -n "$ROOT_FS_CREATE_ONLY" ]] && exit 0
exit_with_error "${error_msg}"
}

View File

@ -1,3 +1,27 @@
# Myy : Menu configuration for choosing desktop configurations
show_menu() {
provided_title=$1
provided_backtitle=$2
provided_menuname=$3
# Myy : I don't know why there's a TTY_Y - 8...
#echo "Provided title : $provided_title"
#echo "Provided backtitle : $provided_backtitle"
#echo "Provided menuname : $provided_menuname"
#echo "Provided options : " "${@:4}"
#echo "TTY X: $TTY_X Y: $TTY_Y"
dialog --stdout --title "$provided_title" --backtitle "${provided_backtitle}" \
--menu "$provided_menuname" $TTY_Y $TTY_X $((TTY_Y - 8)) "${@:4}"
}
# Myy : FIXME Factorize
show_select_menu() {
provided_title=$1
provided_backtitle=$2
provided_menuname=$3
dialog --stdout --title "${provided_title}" --backtitle "${provided_backtitle}" \
--checklist "${provided_menuname}" $TTY_Y $TTY_X $((TTY_Y - 8)) "${@:4}"
}
function distro_menu() {
# create a select menu for choosing a distribution based EXPERT status