aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/update-alternatives/update-alternatives-cworth/update-alternatives.use.last.patch
blob: 7bd5bd268ba5c9f60cfdb245749250a081169acd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
diff -uNr C.orig/update-alternatives C/update-alternatives
--- C.orig/update-alternatives	2003-03-28 17:39:45.000000000 +0100
+++ C/update-alternatives	2009-09-17 16:46:59.000000000 +0200
@@ -97,8 +97,8 @@
 
 ##	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 +107,19 @@
 		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 directory, than ln -sf $path $link, doesn't replace link to that directory, but 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