4 # Copyright (C) 2001 Carl D. Worth
6 # This program was inspired by the Debian update-alternatives program
7 # which is Copyright (C) 1995 Ian Jackson. This version of
8 # update-alternatives is command-line compatible with Debian's for a
9 # subset of the options, (only --install, --remove, and --help)
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2, or (at your option)
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
24 ad
="$OPKG_OFFLINE_ROOT/usr/lib/opkg/alternatives"
27 echo "update-alternatives: $*
29 Usage: update-alternatives --install <link> <name> <path> <priority>
30 update-alternatives --remove <name> <path>
31 update-alternatives --help
32 <link> is the link pointing to the provided path (ie. /usr/bin/foo).
33 <name> is the name in $ad/alternatives (ie. foo)
34 <path> is the name referred to (ie. /usr/bin/foo-extra-spiffy)
35 <priority> is an integer; options with higher numbers are chosen.
41 echo "update-alternatives: $*" >&2
46 [ $# -lt 2 ] && return 1
54 if [ -e "$ad/$name" ]; then
55 local olink
=`head -n 1 $ad/$name`
56 if [ "$link" != "$olink" ]; then
57 echo "update-alternatives: Error: cannot register alternative $name to $link since it is already registered to $olink" >&2
61 echo "$link" > "$ad/$name"
72 [ $# -lt 2 ] && return 1
76 [ ! -f $ad/$name ] && return 0
78 path
=`echo $path | protect_slashes`
79 sed -ne "/^$path\>.*/!p" $ad/$name > $ad/$name.new
80 mv $ad/$name.new
$ad/$name
84 [ $# -lt 3 ] && return 1
88 remove_alt
$name $path
89 echo "$path $priority" >> $ad/$name
93 [ $# -lt 1 ] && return 1
94 [ ! -f $ad/$name ] && return 0
96 link
=$OPKG_OFFLINE_ROOT/`head -n 1 $ad/$name`
98 ## path=`sed -ne "1!p" $ad/$name | sort -nr -k2 | head -1 | sed 's/ .*//'`
100 path
=`sed -ne "1!p" $ad/$name | sed -e "s/\(.*\) \(.*\)/\2 \1/g" | sort -nr | head -n 1 | sed 's/[^ ]* //'`
101 if [ -z "$path" ]; then
102 echo "update-alternatives: removing $link as no more alternatives exist for it"
104 if [ -L $link ]; then
110 if [ ! -e $link -o -L $link ]; then
111 local link_dir
=`dirname $link`
112 if [ ! -d $link_dir ]; then
116 echo "update-alternatives: Linking $link to $path"
118 echo "update-alternatives: Error: not linking $link to $path since $link exists and is not a link"
126 if [ $# -lt 4 ]; then
127 usage
"--install needs <link> <name> <path> <priority>"
134 path
=`echo $path | sed 's|/\+|/|g'`
136 # This is a bad hack, but I haven't thought of a cleaner solution yet...
137 [ -n "$OPKG_OFFLINE_ROOT" ] && path
=`echo $path | sed "s|^$OPKG_OFFLINE_ROOT/*|/|"`
139 register_alt
$name $link
140 add_alt
$name $path $priority
145 if [ $# -lt 2 ]; then
146 usage
"--remove needs <name> <path>"
151 path
=`echo $path | sed 's|/\+|/|g'`
153 # This is a bad hack, but I haven't thought of a cleaner solution yet...
154 [ -n "$OPKG_OFFLINE_ROOT" ] && path
=`echo $path | sed "s|^$OPKG_OFFLINE_ROOT/*|/|"`
156 remove_alt
$name $path
161 # update-alternatives "main"
164 while [ $# -gt 0 ]; do
182 usage
"unknown argument \`$arg'"
187 usage
"at least one of --install or --remove must appear"