diff options
author | graham.gower <graham.gower@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358> | 2009-12-02 23:11:26 (EST) |
---|---|---|
committer | graham.gower <graham.gower@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358> | 2009-12-02 23:11:26 (EST) |
commit | a19597b2beb95ac615b515607dc56490586e6222 (patch) | |
tree | c05b46aefae9ab37f550b872479f1eff5b7c6812 | |
parent | b65cb493330307f8028e7e8ae88f312cb47842b3 (diff) |
Two fixes from Martin Jansa <martin.jansa@gmail.com>.
* if there are more alternatives with highest priority, use the one last
in alternatives file (latest installed)
* if target exists and is a directory, remove link, otherwise new
alternative link is created inside that direstory
git-svn-id: http://opkg.googlecode.com/svn/trunk@439 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358
-rw-r--r-- | utils/update-alternatives.in | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/utils/update-alternatives.in b/utils/update-alternatives.in index a49cc09..34d89f1 100644 --- a/utils/update-alternatives.in +++ b/utils/update-alternatives.in @@ -95,10 +95,8 @@ find_best_alt() { link=$OPKG_OFFLINE_ROOT/`head -n 1 $ad/$name` -## path=`sed -ne "1!p" $ad/$name | sort -nr -k2 | head -1 | sed 's/ .*//'` -## busybox safe: - path=`sed -ne "1!p" $ad/$name | sed -e "s/\(.*\) \(.*\)/\2 \1/g" | sort -nr | head -n 1 | sed 's/[^ ]* //'` - if [ -z "$path" ]; then + prio=`sed -ne "1!p" $ad/$name | sed -e "s/\(.*\) \(.*\)/\2 \1/g" | sort -nr | head -n 1 | sed 's/ [^ ]*$//'` + if [ -z "$prio" ]; then echo "update-alternatives: removing $link as no more alternatives exist for it" rm $ad/$name if [ -L $link ]; then @@ -107,11 +105,21 @@ find_best_alt() { return 0 fi + ## Find last line with highest priority. + path=`grep "${prio}$" $ad/$name | tail -n 1 | sed 's/ [^ ]*$//'` + if [ ! -e $link -o -L $link ]; then local link_dir=`dirname $link` if [ ! -d $link_dir ]; then mkdir -p $link_dir fi + if [ -h $link -a -d $link ]; then + # If $link exists and the target is a directory, + # 'ln -sf $path $link' doesn't replace the link to + # that directory, it creates new link inside. + echo "update-alternatives: Removing $link". + rm -f $link + fi ln -sf $path $link echo "update-alternatives: Linking $link to $path" else |