Fall back to reading config from XDG_DATA_DIRS
If there is no configuration file in “$XDG_CONFIG_HOME/update-mirrors”, try looking through directories specified in XDG_CONFIG_DIRS. If XDG_CONFIG_DIRS is not specified, use “/etc/xdg”. Now config files are searched for in this order: - “$XDG_CONFIG_HOME/update-mirrors/config.sh”, or “$HOME/.config/update-mirrors/config.sh” if XDG_CONFIG_DIR is not defined. - For each DIR in XDG_CONFIG_DIRS “$DIR/update-mirrors/config.sh” is tried, or “/etc/xdg/update-mirrors/config.sh” if XDG_CONFIG_DIRS is not defined.
This commit is contained in:
parent
a5d3cbbe2c
commit
6093fddfff
1 changed files with 22 additions and 2 deletions
|
@ -36,9 +36,29 @@ function make-url ()
|
||||||
echo "${url}/?${countryparams}&${protocolparams}&${ipparams}&${statusparams}"
|
echo "${url}/?${countryparams}&${protocolparams}&${ipparams}&${statusparams}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function load-global-config ()
|
||||||
|
{
|
||||||
|
local IFS=":"
|
||||||
|
|
||||||
|
for dir in $1; do
|
||||||
|
local cfgfile="${dir}${2}"
|
||||||
|
if [[ -x $cfgfile ]]; then
|
||||||
|
source $cfgfile
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
# Load config file
|
# Load config file
|
||||||
cfgfile=${XDG_CONFIG_HOME:-"${HOME}/.config"}/update-mirrors/config.sh
|
etcbases=${XDG_CONFIG_DIRS:-"/etc/xdg"}
|
||||||
[ -x $cfgfile ] && source $cfgfile
|
cfgbase=${XDG_CONFIG_HOME:-"${HOME}/.config"}
|
||||||
|
cfgfile="/update-mirrors/config.sh"
|
||||||
|
|
||||||
|
if [[ -x $cfgfile ]]; then
|
||||||
|
source "${cfgbase}${cfgfile}"
|
||||||
|
else
|
||||||
|
load-global-config $etcbases $cfgfile
|
||||||
|
fi
|
||||||
|
|
||||||
# Check destination
|
# Check destination
|
||||||
if [[ ! -e "$dest" ]] && [[ ! -w "$(dirname "$dest")" ]]; then
|
if [[ ! -e "$dest" ]] && [[ ! -w "$(dirname "$dest")" ]]; then
|
||||||
|
|
Loading…
Reference in a new issue