From 676b7f656372a42ace77bda806a5d01145784a77 Mon Sep 17 00:00:00 2001 From: Robin Candau Date: Wed, 25 Sep 2024 18:21:31 +0200 Subject: [PATCH 1/4] chore: Streamline option checking in arch-update.conf Streamline option checking in the `arch-update.conf` configuration file by optimizing the way each option are checked and the way the related variables are set. --- src/lib/common.sh | 7 +---- src/lib/config.sh | 67 ++++++++++++++--------------------------------- 2 files changed, 21 insertions(+), 53 deletions(-) diff --git a/src/lib/common.sh b/src/lib/common.sh index da68911..d6f9750 100755 --- a/src/lib/common.sh +++ b/src/lib/common.sh @@ -123,12 +123,7 @@ if [ -n "${diff_prog}" ]; then fi fi -# Definition of the tray icon style to use (default to "light" if it isn't set in the arch-update.conf configuration file) -if [ -z "${tray_icon_style}" ]; then - tray_icon_style="light" -fi - -# Definition of the icon_up-to-date function: Change icon to "up to date" +# Definition of the icon_up-to-date function: Change tray icon to "up to date" icon_up-to-date() { # shellcheck disable=SC2154 echo "${name}-${tray_icon_style}" > "${statedir}/tray_icon" diff --git a/src/lib/config.sh b/src/lib/config.sh index 175b6a5..f527940 100755 --- a/src/lib/config.sh +++ b/src/lib/config.sh @@ -46,68 +46,41 @@ fi config_file="${XDG_CONFIG_HOME:-${HOME}/.config}/${name}/${name}.conf" # Check the "NoColor" option in arch-update.conf -if grep -Eq '^[[:space:]]*NoColor[[:space:]]*$' "${config_file}" 2> /dev/null; then - # shellcheck disable=SC2034 - no_color="y" -fi +# shellcheck disable=SC2034 +no_color=$(grep -Eq '^[[:space:]]*NoColor[[:space:]]*$' "${config_file}" 2> /dev/null && echo "y") # Check the "NoVersion" option in arch-update.conf -if grep -Eq '^[[:space:]]*NoVersion[[:space:]]*$' "${config_file}" 2> /dev/null; then - # shellcheck disable=SC2034 - no_version="y" -fi +# shellcheck disable=SC2034 +no_version=$(grep -Eq '^[[:space:]]*NoVersion[[:space:]]*$' "${config_file}" 2> /dev/null && echo "y") # Check the "AlwaysShowNews" option in arch-update.conf -if grep -Eq '^[[:space:]]*AlwaysShowNews[[:space:]]*$' "${config_file}" 2> /dev/null; then - # shellcheck disable=SC2034 - show_news="y" -fi +# shellcheck disable=SC2034 +show_news=$(grep -Eq '^[[:space:]]*AlwaysShowNews[[:space:]]*$' "${config_file}" 2> /dev/null && echo "y") # Check the "NewsNum" option in arch-update.conf -if grep -Eq '^[[:space:]]*NewsNum[[:space:]]*=[[:space:]]*[1-9][0-9]*[[:space:]]*$' "${config_file}" 2> /dev/null; then - # shellcheck disable=SC2034 - 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 - # shellcheck disable=SC2034 - news_num="5" -fi +# shellcheck disable=SC2034 +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:]' || echo "5") # Check the "AURHelper" option in arch-update.conf -if grep -Eq '^[[:space:]]*AURHelper[[:space:]]*=[[:space:]]*(paru|yay)[[:space:]]*$' "${config_file}" 2> /dev/null; then - # shellcheck disable=SC2034 - aur_helper=$(grep -E '^[[:space:]]*AURHelper[[:space:]]*=[[:space:]]*(paru|yay)[[:space:]]*$' "${config_file}" 2> /dev/null | awk -F '=' '{print $2}' | tr -d '[:space:]') -fi +# shellcheck disable=SC2034 +aur_helper=$(grep -E '^[[:space:]]*AURHelper[[:space:]]*=[[:space:]]*(paru|yay)[[:space:]]*$' "${config_file}" 2> /dev/null | awk -F '=' '{print $2}' | tr -d '[:space:]') # Check the "PrivilegeElevationCommand" option in arch-update.conf -if grep -Eq '^[[:space:]]*PrivilegeElevationCommand[[:space:]]*=[[:space:]]*(sudo|doas|run0)[[:space:]]*$' "${config_file}" 2> /dev/null; then - # shellcheck disable=SC2034 - su_cmd=$(grep -E '^[[:space:]]*PrivilegeElevationCommand[[:space:]]*=[[:space:]]*(sudo|doas|run0)[[:space:]]*$' "${config_file}" 2> /dev/null | awk -F '=' '{print $2}' | tr -d '[:space:]') -fi +# shellcheck disable=SC2034 +su_cmd=$(grep -E '^[[:space:]]*PrivilegeElevationCommand[[:space:]]*=[[:space:]]*(sudo|doas|run0)[[:space:]]*$' "${config_file}" 2> /dev/null | awk -F '=' '{print $2}' | tr -d '[:space:]') # Check the "KeepOldPackages" option in arch-update.conf -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 - # shellcheck disable=SC2034 - old_packages_num="3" -fi +# shellcheck disable=SC2034 +old_packages_num=$(grep -E '^[[:space:]]*KeepOldPackages[[:space:]]*=[[:space:]]*[0-9]+[[:space:]]*$' "${config_file}" 2> /dev/null | awk -F '=' '{print $2}' | tr -d '[:space:]' || echo "3") # Check the "KeepUninstalledPackages" option in arch-update.conf -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 - # shellcheck disable=SC2034 - uninstalled_packages_num="0" -fi +# shellcheck disable=SC2034 +uninstalled_packages_num=$(grep -E '^[[:space:]]*KeepUninstalledPackages[[:space:]]*=[[:space:]]*[0-9]+[[:space:]]*$' "${config_file}" 2> /dev/null | awk -F '=' '{print $2}' | tr -d '[:space:]' || echo "0") # Check the "DiffProg" option in arch-update.conf -if grep -Eq '^[[:space:]]*DiffProg[[:space:]]*=[[:space:]]*[^[:space:]].*[[:space:]]*$' "${config_file}" 2> /dev/null; then - # shellcheck disable=SC2034 - diff_prog=$(grep -E '^[[:space:]]*DiffProg[[:space:]]*=[[:space:]]*[^[:space:]].*[[:space:]]*$' "${config_file}" 2> /dev/null | awk -F '=' '{print $2}' | tr -d '[:space:]') -fi +# shellcheck disable=SC2034 +diff_prog=$(grep -E '^[[:space:]]*DiffProg[[:space:]]*=[[:space:]]*[^[:space:]].*[[:space:]]*$' "${config_file}" 2> /dev/null | awk -F '=' '{print $2}' | tr -d '[:space:]') # Check the "TrayIconStyle" option in arch-update.conf -if grep -Eq '^[[:space:]]*TrayIconStyle[[:space:]]*=[[:space:]]*(light|dark|blue)[[:space:]]*$' "${config_file}" 2> /dev/null; then - # shellcheck disable=SC2034 - tray_icon_style=$(grep -E '^[[:space:]]*TrayIconStyle[[:space:]]*=[[:space:]]*(light|dark|blue)[[:space:]]*$' "${config_file}" 2> /dev/null | awk -F '=' '{print $2}' | tr -d '[:space:]') -fi +# shellcheck disable=SC2034 +tray_icon_style=$(grep -E '^[[:space:]]*TrayIconStyle[[:space:]]*=[[:space:]]*(light|dark|blue)[[:space:]]*$' "${config_file}" 2> /dev/null | awk -F '=' '{print $2}' | tr -d '[:space:]' || echo "light") From d9cf0eeec595868e0c42edcb8ffec782f4999885 Mon Sep 17 00:00:00 2001 From: Robin Candau Date: Wed, 25 Sep 2024 18:51:07 +0200 Subject: [PATCH 2/4] fix: Only check for options in arch-update.conf if it exists --- src/lib/config.sh | 81 ++++++++++++++++++++++++----------------------- 1 file changed, 42 insertions(+), 39 deletions(-) diff --git a/src/lib/config.sh b/src/lib/config.sh index f527940..9f4112b 100755 --- a/src/lib/config.sh +++ b/src/lib/config.sh @@ -45,42 +45,45 @@ fi # Define the path to the arch-update.conf configuration file config_file="${XDG_CONFIG_HOME:-${HOME}/.config}/${name}/${name}.conf" -# Check the "NoColor" option in arch-update.conf -# shellcheck disable=SC2034 -no_color=$(grep -Eq '^[[:space:]]*NoColor[[:space:]]*$' "${config_file}" 2> /dev/null && echo "y") - -# Check the "NoVersion" option in arch-update.conf -# shellcheck disable=SC2034 -no_version=$(grep -Eq '^[[:space:]]*NoVersion[[:space:]]*$' "${config_file}" 2> /dev/null && echo "y") - -# Check the "AlwaysShowNews" option in arch-update.conf -# shellcheck disable=SC2034 -show_news=$(grep -Eq '^[[:space:]]*AlwaysShowNews[[:space:]]*$' "${config_file}" 2> /dev/null && echo "y") - -# Check the "NewsNum" option in arch-update.conf -# shellcheck disable=SC2034 -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:]' || echo "5") - -# Check the "AURHelper" option in arch-update.conf -# shellcheck disable=SC2034 -aur_helper=$(grep -E '^[[:space:]]*AURHelper[[:space:]]*=[[:space:]]*(paru|yay)[[:space:]]*$' "${config_file}" 2> /dev/null | awk -F '=' '{print $2}' | tr -d '[:space:]') - -# Check the "PrivilegeElevationCommand" option in arch-update.conf -# shellcheck disable=SC2034 -su_cmd=$(grep -E '^[[:space:]]*PrivilegeElevationCommand[[:space:]]*=[[:space:]]*(sudo|doas|run0)[[:space:]]*$' "${config_file}" 2> /dev/null | awk -F '=' '{print $2}' | tr -d '[:space:]') - -# Check the "KeepOldPackages" option in arch-update.conf -# shellcheck disable=SC2034 -old_packages_num=$(grep -E '^[[:space:]]*KeepOldPackages[[:space:]]*=[[:space:]]*[0-9]+[[:space:]]*$' "${config_file}" 2> /dev/null | awk -F '=' '{print $2}' | tr -d '[:space:]' || echo "3") - -# Check the "KeepUninstalledPackages" option in arch-update.conf -# shellcheck disable=SC2034 -uninstalled_packages_num=$(grep -E '^[[:space:]]*KeepUninstalledPackages[[:space:]]*=[[:space:]]*[0-9]+[[:space:]]*$' "${config_file}" 2> /dev/null | awk -F '=' '{print $2}' | tr -d '[:space:]' || echo "0") - -# Check the "DiffProg" option in arch-update.conf -# shellcheck disable=SC2034 -diff_prog=$(grep -E '^[[:space:]]*DiffProg[[:space:]]*=[[:space:]]*[^[:space:]].*[[:space:]]*$' "${config_file}" 2> /dev/null | awk -F '=' '{print $2}' | tr -d '[:space:]') - -# Check the "TrayIconStyle" option in arch-update.conf -# shellcheck disable=SC2034 -tray_icon_style=$(grep -E '^[[:space:]]*TrayIconStyle[[:space:]]*=[[:space:]]*(light|dark|blue)[[:space:]]*$' "${config_file}" 2> /dev/null | awk -F '=' '{print $2}' | tr -d '[:space:]' || echo "light") +# Check options in the arch-update.conf configuration file if it exists +if [ -f "${config_file}" ]; then + # Check the "NoColor" option in arch-update.conf + # shellcheck disable=SC2034 + no_color=$(grep -Eq '^[[:space:]]*NoColor[[:space:]]*$' "${config_file}" 2> /dev/null && echo "y") + + # Check the "NoVersion" option in arch-update.conf + # shellcheck disable=SC2034 + no_version=$(grep -Eq '^[[:space:]]*NoVersion[[:space:]]*$' "${config_file}" 2> /dev/null && echo "y") + + # Check the "AlwaysShowNews" option in arch-update.conf + # shellcheck disable=SC2034 + show_news=$(grep -Eq '^[[:space:]]*AlwaysShowNews[[:space:]]*$' "${config_file}" 2> /dev/null && echo "y") + + # Check the "NewsNum" option in arch-update.conf + # shellcheck disable=SC2034 + 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:]' || echo "5") + + # Check the "AURHelper" option in arch-update.conf + # shellcheck disable=SC2034 + aur_helper=$(grep -E '^[[:space:]]*AURHelper[[:space:]]*=[[:space:]]*(paru|yay)[[:space:]]*$' "${config_file}" 2> /dev/null | awk -F '=' '{print $2}' | tr -d '[:space:]') + + # Check the "PrivilegeElevationCommand" option in arch-update.conf + # shellcheck disable=SC2034 + su_cmd=$(grep -E '^[[:space:]]*PrivilegeElevationCommand[[:space:]]*=[[:space:]]*(sudo|doas|run0)[[:space:]]*$' "${config_file}" 2> /dev/null | awk -F '=' '{print $2}' | tr -d '[:space:]') + + # Check the "KeepOldPackages" option in arch-update.conf + # shellcheck disable=SC2034 + old_packages_num=$(grep -E '^[[:space:]]*KeepOldPackages[[:space:]]*=[[:space:]]*[0-9]+[[:space:]]*$' "${config_file}" 2> /dev/null | awk -F '=' '{print $2}' | tr -d '[:space:]' || echo "3") + + # Check the "KeepUninstalledPackages" option in arch-update.conf + # shellcheck disable=SC2034 + uninstalled_packages_num=$(grep -E '^[[:space:]]*KeepUninstalledPackages[[:space:]]*=[[:space:]]*[0-9]+[[:space:]]*$' "${config_file}" 2> /dev/null | awk -F '=' '{print $2}' | tr -d '[:space:]' || echo "0") + + # Check the "DiffProg" option in arch-update.conf + # shellcheck disable=SC2034 + diff_prog=$(grep -E '^[[:space:]]*DiffProg[[:space:]]*=[[:space:]]*[^[:space:]].*[[:space:]]*$' "${config_file}" 2> /dev/null | awk -F '=' '{print $2}' | tr -d '[:space:]') + + # Check the "TrayIconStyle" option in arch-update.conf + # shellcheck disable=SC2034 + tray_icon_style=$(grep -E '^[[:space:]]*TrayIconStyle[[:space:]]*=[[:space:]]*(light|dark|blue)[[:space:]]*$' "${config_file}" 2> /dev/null | awk -F '=' '{print $2}' | tr -d '[:space:]' || echo "light") +fi From dba500e196c99c698b4237e51b996fa6d0b10005 Mon Sep 17 00:00:00 2001 From: Robin Candau Date: Wed, 25 Sep 2024 19:25:07 +0200 Subject: [PATCH 3/4] fix: dedicate config.sh to checking options in arch-update.conf + set default/fallback value for options that require it --- src/arch-update.sh | 4 ++-- src/lib/common.sh | 40 +++++++++++++++++++++++++++++++++- src/lib/config.sh | 54 ++++++++++------------------------------------ 3 files changed, 52 insertions(+), 46 deletions(-) diff --git a/src/arch-update.sh b/src/arch-update.sh index 0d9947c..77df6fc 100755 --- a/src/arch-update.sh +++ b/src/arch-update.sh @@ -28,11 +28,11 @@ else exit 14 fi -# Source the "config" library which contains every configuration parameters, pre-steps and pre-verifications required for Arch-Update to work properly +# Source the "config" library which checks options set in the arch-update.conf configuration file # shellcheck source=src/lib/config.sh source "${libdir}/config.sh" -# Source the "common" library which contains variables and functions commonly used across Arch-Update stages +# Source the "common" library which sets variables, functions and parameters commonly used across the various Arch-Update stages # shellcheck source=src/lib/common.sh source "${libdir}/common.sh" diff --git a/src/lib/common.sh b/src/lib/common.sh index d6f9750..3151516 100755 --- a/src/lib/common.sh +++ b/src/lib/common.sh @@ -1,9 +1,47 @@ #!/bin/bash -# common.sh: Set variables and functions commonly used across Arch-Update stages +# common.sh: Set variables, functions and parameters commonly used across the various Arch-Update stages # https://github.com/Antiz96/arch-update # SPDX-License-Identifier: GPL-3.0-or-later +# Display debug traces if the -D/--debug argument is passed +for arg in "${@}"; do + case "${arg}" in + -D|--debug) + set -x + ;; + esac +done + +# Reset the option var if it is equal to -D/--debug (to avoid false negative "invalid option" error) +# shellcheck disable=SC2154 +case "${option}" in + -D|--debug) + unset option + ;; +esac + +# Create state and tmp dirs if they don't exist +# shellcheck disable=SC2154 +statedir="${XDG_STATE_HOME:-${HOME}/.local/state}/${name}" +tmpdir="${TMPDIR:-/tmp}/${name}-${UID}" +mkdir -p "${statedir}" "${tmpdir}" + +# Declare necessary parameters for translations +# shellcheck disable=SC1091 +. gettext.sh +# shellcheck disable=SC2154 +export TEXTDOMAIN="${_name}" # Using "Arch-Update" as TEXTDOMAIN to avoid conflicting with the "arch-update" TEXTDOMAIN used by the arch-update Gnome extension (https://extensions.gnome.org/extension/1010/archlinux-updates-indicator/) +if [ -f "${XDG_DATA_HOME}/locale/fr/LC_MESSAGES/${_name}.mo" ]; then + export TEXTDOMAINDIR="${XDG_DATA_HOME}/locale" +elif [ -f "${HOME}/.local/share/locale/fr/LC_MESSAGES/${_name}.mo" ]; then + export TEXTDOMAINDIR="${HOME}/.local/share/locale" +elif [ -f "${XDG_DATA_DIRS}/locale/fr/LC_MESSAGES/${_name}.mo" ]; then + export TEXTDOMAINDIR="${XDG_DATA_DIRS}/locale" +elif [ -f "/usr/local/share/locale/fr/LC_MESSAGES/${_name}.mo" ]; then + export TEXTDOMAINDIR="/usr/local/share/locale" +fi + # Definition of the colors for the colorized output if [ -z "${no_color}" ]; then bold="\e[1m" diff --git a/src/lib/config.sh b/src/lib/config.sh index 9f4112b..a205fac 100755 --- a/src/lib/config.sh +++ b/src/lib/config.sh @@ -1,47 +1,9 @@ #!/bin/bash -# config.sh: Set configuration parameters, pre-steps and pre-verifications required for Arch-Update to work properly +# config.sh: Check options set in the arch-update.conf configuration file # https://github.com/Antiz96/arch-update # SPDX-License-Identifier: GPL-3.0-or-later -# Display debug traces if the -D/--debug argument is passed -for arg in "${@}"; do - case "${arg}" in - -D|--debug) - set -x - ;; - esac -done - -# Reset the option var if it is equal to -D/--debug (to avoid false negative "invalid option" error) -# shellcheck disable=SC2154 -case "${option}" in - -D|--debug) - unset option - ;; -esac - -# Create state and tmp dirs if they don't exist -# shellcheck disable=SC2154 -statedir="${XDG_STATE_HOME:-${HOME}/.local/state}/${name}" -tmpdir="${TMPDIR:-/tmp}/${name}-${UID}" -mkdir -p "${statedir}" "${tmpdir}" - -# Declare necessary parameters for translations -# shellcheck disable=SC1091 -. gettext.sh -# shellcheck disable=SC2154 -export TEXTDOMAIN="${_name}" # Using "Arch-Update" as TEXTDOMAIN to avoid conflicting with the "arch-update" TEXTDOMAIN used by the arch-update Gnome extension (https://extensions.gnome.org/extension/1010/archlinux-updates-indicator/) -if [ -f "${XDG_DATA_HOME}/locale/fr/LC_MESSAGES/${_name}.mo" ]; then - export TEXTDOMAINDIR="${XDG_DATA_HOME}/locale" -elif [ -f "${HOME}/.local/share/locale/fr/LC_MESSAGES/${_name}.mo" ]; then - export TEXTDOMAINDIR="${HOME}/.local/share/locale" -elif [ -f "${XDG_DATA_DIRS}/locale/fr/LC_MESSAGES/${_name}.mo" ]; then - export TEXTDOMAINDIR="${XDG_DATA_DIRS}/locale" -elif [ -f "/usr/local/share/locale/fr/LC_MESSAGES/${_name}.mo" ]; then - export TEXTDOMAINDIR="/usr/local/share/locale" -fi - # Define the path to the arch-update.conf configuration file config_file="${XDG_CONFIG_HOME:-${HOME}/.config}/${name}/${name}.conf" @@ -61,7 +23,7 @@ if [ -f "${config_file}" ]; then # Check the "NewsNum" option in arch-update.conf # shellcheck disable=SC2034 - 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:]' || echo "5") + 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:]') # Check the "AURHelper" option in arch-update.conf # shellcheck disable=SC2034 @@ -73,11 +35,11 @@ if [ -f "${config_file}" ]; then # Check the "KeepOldPackages" option in arch-update.conf # shellcheck disable=SC2034 - old_packages_num=$(grep -E '^[[:space:]]*KeepOldPackages[[:space:]]*=[[:space:]]*[0-9]+[[:space:]]*$' "${config_file}" 2> /dev/null | awk -F '=' '{print $2}' | tr -d '[:space:]' || echo "3") + old_packages_num=$(grep -E '^[[:space:]]*KeepOldPackages[[:space:]]*=[[:space:]]*[0-9]+[[:space:]]*$' "${config_file}" 2> /dev/null | awk -F '=' '{print $2}' | tr -d '[:space:]') # Check the "KeepUninstalledPackages" option in arch-update.conf # shellcheck disable=SC2034 - uninstalled_packages_num=$(grep -E '^[[:space:]]*KeepUninstalledPackages[[:space:]]*=[[:space:]]*[0-9]+[[:space:]]*$' "${config_file}" 2> /dev/null | awk -F '=' '{print $2}' | tr -d '[:space:]' || echo "0") + uninstalled_packages_num=$(grep -E '^[[:space:]]*KeepUninstalledPackages[[:space:]]*=[[:space:]]*[0-9]+[[:space:]]*$' "${config_file}" 2> /dev/null | awk -F '=' '{print $2}' | tr -d '[:space:]') # Check the "DiffProg" option in arch-update.conf # shellcheck disable=SC2034 @@ -85,5 +47,11 @@ if [ -f "${config_file}" ]; then # Check the "TrayIconStyle" option in arch-update.conf # shellcheck disable=SC2034 - tray_icon_style=$(grep -E '^[[:space:]]*TrayIconStyle[[:space:]]*=[[:space:]]*(light|dark|blue)[[:space:]]*$' "${config_file}" 2> /dev/null | awk -F '=' '{print $2}' | tr -d '[:space:]' || echo "light") + tray_icon_style=$(grep -E '^[[:space:]]*TrayIconStyle[[:space:]]*=[[:space:]]*(light|dark|blue)[[:space:]]*$' "${config_file}" 2> /dev/null | awk -F '=' '{print $2}' | tr -d '[:space:]') fi + +# Set the default/fallback value for options that require it (if the arch-update.conf configuration file doesn't exists, if the concerned option is commented or if the set value is invalid) +[ -z "${news_num}" ] && news_num="5" +[ -z "${old_packages_num}" ] && old_packages_num="3" +[ -z "${uninstalled_packages_num}" ] && uninstalled_packages_num="0" +[ -z "${tray_icon_style}" ] && tray_icon_style="light" From a92cf934a27f5ed0e0519a15e47bc58cb1a3ac48 Mon Sep 17 00:00:00 2001 From: Robin Candau Date: Wed, 25 Sep 2024 19:26:20 +0200 Subject: [PATCH 4/4] fix: disable shellcheck SC2154 --- src/lib/config.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/config.sh b/src/lib/config.sh index a205fac..956c176 100755 --- a/src/lib/config.sh +++ b/src/lib/config.sh @@ -5,6 +5,7 @@ # SPDX-License-Identifier: GPL-3.0-or-later # Define the path to the arch-update.conf configuration file +# shellcheck disable=SC2154 config_file="${XDG_CONFIG_HOME:-${HOME}/.config}/${name}/${name}.conf" # Check options in the arch-update.conf configuration file if it exists