aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Bo ├śrsted Andresen <zlin@exherbo.org> 2008-10-29 02:02:42 +0100
committerAvatar Bo ├śrsted Andresen <zlin@exherbo.org> 2008-10-29 02:18:38 +0100
commit295420f9e483b127b56b57deeecf0e731d3cfb2a (patch)
treee938d15695063586347f0960b41311014d59d3c2
parentd4fc10828a77720fd5b71e701e16a4c0969a6771 (diff)
downloadeclectic-295420f9.tar.gz
eclectic-295420f9.tar.xz
Tweak do_update.
- If the existing provider was updated, reselect that since it might have changed - Otherwise verify and if necessary reselect existing provider - Otherwise select newly available provider - If the above fails to select a valid provider, select first available provider, sorted according to importance, that doesn't fail - If all providers fail yet something was selected clean up
-rw-r--r--libs/alternatives.bash.in32
1 files changed, 19 insertions, 13 deletions
diff --git a/libs/alternatives.bash.in b/libs/alternatives.bash.in
index 42396fb..2b78f0d 100644
--- a/libs/alternatives.bash.in
+++ b/libs/alternatives.bash.in
@@ -124,30 +124,36 @@ describe_update_options() {
do_update() {
[[ -z "${ALTERNATIVE}" ]] && die "Need to set ALTERNATIVE in the eclectic module"
- if [[ -f "${ROOT}${ALTERNATIVESDIR}/${ALTERNATIVE}_set" ]] ; then
- local p= bad=0
+ local p cur=$(get_current_provider) providers=( $(get_providers) )
+
+ if [[ ${cur} == ${1} ]]; then
+ # if current provider was just updated, reselect it since it could have changed
+ do_set "${cur}" && return 0
+ elif [[ -f "${ROOT}${ALTERNATIVESDIR}/${ALTERNATIVE}_set" ]] ; then
# verify existing provider's symlinks
+ local p= bad=0
while read p ; do
[[ -L "${ROOT}${p}" && -e "${ROOT}${p}" ]] || (( bad++ ))
done < "${ROOT}${ALTERNATIVESDIR}/${ALTERNATIVE}_set"
[[ "${bad}" -eq 0 ]] && return 0
# fix existing provider if possible
- local cur="$(get_current_provider)"
- has "${cur}" $(get_providers) && do_set "${cur}" && return 0
+ has "${cur}" "${providers[@]}" && do_set "${cur}" && return 0
+ elif has "${1}" "${providers[@]}"; then
+ # switch to new provider if none was set before or it can't be fixed
+ do_set "${1}" && return 0
fi
- local providers=( $(get_providers) )
+ # if no valid provider has been selected switch to first available, valid
+ # provider, sorted according to importance
+ for p in "${providers[@]}"; do
+ do_set "${p}" && return 0
+ done
- # switch to new provider if none was set before or it can't be fixed
- if has "${1}" "${providers[@]}"; then
- do_set "${1}"
- # otherwise switch to first available provider, sorted according to importance
- elif has "${providers[0]}" "${providers[@]}"; then
- do_set "${providers[0]}"
- # if a was set but no providers are available anymore cleanup
- elif [[ -n ${cur} ]]; then
+ # if a provider is set but no providers are available anymore cleanup
+ cur=$(get_current_provider)
+ if [[ -n ${cur} ]]; then
do_unset "${cur}"
fi
}