From f9ea695b5b2413d16b9601007305a2932f4267a7 Mon Sep 17 00:00:00 2001 From: Robin Candau Date: Thu, 20 Jun 2024 17:51:05 +0200 Subject: [PATCH] Move the check of options in arch-update.conf lower in the script so I can make use of the error_msg function in it --- src/script/arch-update.sh | 82 +++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/src/script/arch-update.sh b/src/script/arch-update.sh index 0a00a84..8d27b41 100755 --- a/src/script/arch-update.sh +++ b/src/script/arch-update.sh @@ -40,47 +40,6 @@ elif [ -f "/usr/local/share/locale/fr/LC_MESSAGES/${_name}.mo" ]; then export TEXTDOMAINDIR="/usr/local/share/locale" fi -# Checking options in arch-update.conf -config_file="${XDG_CONFIG_HOME:-${HOME}/.config}/${name}/${name}.conf" - -if grep -Eq '^[[:space:]]*NoColor[[:space:]]*$' "${config_file}" 2> /dev/null; then - no_color="y" -fi - -if grep -Eq '^[[:space:]]*NoVersion[[:space:]]*$' "${config_file}" 2> /dev/null; then - no_version="y" -fi - -if grep -Eq '^[[:space:]]*AlwaysShowNews[[:space:]]*$' "${config_file}" 2> /dev/null; then - show_news="y" -fi - -if grep -Eq '^[[:space:]]*NewsNum[[:space:]]*=[[:space:]]*[1-9][0-9]*[[:space:]]*$' "${config_file}" 2> /dev/null; then - news_num=$(grep -E '^[[:space:]]*NewsNum[[:space:]]*=[[:space:]]*[1-9][0-9]*[[:space:]]*$' "${config_file}" 2> /dev/null | awk -F '=' '{print $2}' | tr -d '[:space:]') -else - news_num="5" -fi - -if grep -Eq '^[[:space:]]*KeepOldPackages[[:space:]]*=[[:space:]]*[0-9]+[[:space:]]*$' "${config_file}" 2> /dev/null; then - old_packages_num=$(grep -E '^[[:space:]]*KeepOldPackages[[:space:]]*=[[:space:]]*[0-9]+[[:space:]]*$' "${config_file}" 2> /dev/null | awk -F '=' '{print $2}' | tr -d '[:space:]') -else - old_packages_num="3" -fi - -if grep -Eq '^[[:space:]]*KeepUninstalledPackages[[:space:]]*=[[:space:]]*[0-9]+[[:space:]]*$' "${config_file}" 2> /dev/null; then - uninstalled_packages_num=$(grep -E '^[[:space:]]*KeepUninstalledPackages[[:space:]]*=[[:space:]]*[0-9]+[[:space:]]*$' "${config_file}" 2> /dev/null | awk -F '=' '{print $2}' | tr -d '[:space:]') -else - uninstalled_packages_num="0" -fi - -if grep -Eq '^[[:space:]]*PrivilegeElevationCommand[[:space:]]*=[[:space:]]*(sudo|doas|run0)[[:space:]]*$' "${config_file}" 2> /dev/null; then - su_cmd=$(grep -E '^[[:space:]]*PrivilegeElevationCommand[[:space:]]*=[[:space:]]*(sudo|doas|run0)[[:space:]]*$' "${config_file}" 2> /dev/null | awk -F '=' '{print $2}' | tr -d '[:space:]') - if ! command -v "${su_cmd}" > /dev/null; then - error_msg "$(eval_gettext "The \${su_cmd} command set for privilege escalation in the arch-update.conf configuration file is not found\n")" && quit_msg - exit 2 - fi -fi - # Definition of the colors for the colorized output if [ -z "${no_color}" ]; then bold="\e[1m" @@ -142,6 +101,47 @@ quit_msg() { read -n 1 -r -s -p $"$(info_msg "${msg}")" && echo } +# Checking options in arch-update.conf +config_file="${XDG_CONFIG_HOME:-${HOME}/.config}/${name}/${name}.conf" + +if grep -Eq '^[[:space:]]*NoColor[[:space:]]*$' "${config_file}" 2> /dev/null; then + no_color="y" +fi + +if grep -Eq '^[[:space:]]*NoVersion[[:space:]]*$' "${config_file}" 2> /dev/null; then + no_version="y" +fi + +if grep -Eq '^[[:space:]]*AlwaysShowNews[[:space:]]*$' "${config_file}" 2> /dev/null; then + show_news="y" +fi + +if grep -Eq '^[[:space:]]*NewsNum[[:space:]]*=[[:space:]]*[1-9][0-9]*[[:space:]]*$' "${config_file}" 2> /dev/null; then + news_num=$(grep -E '^[[:space:]]*NewsNum[[:space:]]*=[[:space:]]*[1-9][0-9]*[[:space:]]*$' "${config_file}" 2> /dev/null | awk -F '=' '{print $2}' | tr -d '[:space:]') +else + news_num="5" +fi + +if grep -Eq '^[[:space:]]*KeepOldPackages[[:space:]]*=[[:space:]]*[0-9]+[[:space:]]*$' "${config_file}" 2> /dev/null; then + old_packages_num=$(grep -E '^[[:space:]]*KeepOldPackages[[:space:]]*=[[:space:]]*[0-9]+[[:space:]]*$' "${config_file}" 2> /dev/null | awk -F '=' '{print $2}' | tr -d '[:space:]') +else + old_packages_num="3" +fi + +if grep -Eq '^[[:space:]]*KeepUninstalledPackages[[:space:]]*=[[:space:]]*[0-9]+[[:space:]]*$' "${config_file}" 2> /dev/null; then + uninstalled_packages_num=$(grep -E '^[[:space:]]*KeepUninstalledPackages[[:space:]]*=[[:space:]]*[0-9]+[[:space:]]*$' "${config_file}" 2> /dev/null | awk -F '=' '{print $2}' | tr -d '[:space:]') +else + uninstalled_packages_num="0" +fi + +if grep -Eq '^[[:space:]]*PrivilegeElevationCommand[[:space:]]*=[[:space:]]*(sudo|doas|run0)[[:space:]]*$' "${config_file}" 2> /dev/null; then + su_cmd=$(grep -E '^[[:space:]]*PrivilegeElevationCommand[[:space:]]*=[[:space:]]*(sudo|doas|run0)[[:space:]]*$' "${config_file}" 2> /dev/null | awk -F '=' '{print $2}' | tr -d '[:space:]') + if ! command -v "${su_cmd}" > /dev/null; then + error_msg "$(eval_gettext "The \${su_cmd} command set for privilege escalation in the arch-update.conf configuration file is not found\n")" && quit_msg + exit 2 + fi +fi + # Definition of the elevation command to use (depending on which one is installed on the system and if it's not already defined in arch-update.conf) if [ -z "${su_cmd}" ]; then if command -v sudo > /dev/null; then