From: graham.gower Date: Fri, 20 Nov 2009 03:02:25 +0000 (+0000) Subject: Respect the --with-opkglibdir configure switch in update-alternatives. X-Git-Url: https://git.librecmc.org/?p=oweals%2Fopkg-lede.git;a=commitdiff_plain;h=7266416702d6d83cd1a2bc3a7b3e579d711c83df Respect the --with-opkglibdir configure switch in update-alternatives. From John L. Chmielewski . git-svn-id: http://opkg.googlecode.com/svn/trunk@342 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358 --- diff --git a/configure.ac b/configure.ac index c238e1b..f97a1c6 100644 --- a/configure.ac +++ b/configure.ac @@ -260,5 +260,6 @@ AC_OUTPUT( src/Makefile libbb/Makefile utils/Makefile + utils/update-alternatives libopkg.pc ) diff --git a/utils/update-alternatives b/utils/update-alternatives deleted file mode 100755 index 4983e19..0000000 --- a/utils/update-alternatives +++ /dev/null @@ -1,189 +0,0 @@ -#!/bin/sh -# update-alternatives -# -# Copyright (C) 2001 Carl D. Worth -# -# This program was inspired by the Debian update-alternatives program -# which is Copyright (C) 1995 Ian Jackson. This version of -# update-alternatives is command-line compatible with Debian's for a -# subset of the options, (only --install, --remove, and --help) -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -set -e - -# admin dir -ad="$OPKG_OFFLINE_ROOT/usr/lib/opkg/alternatives" - -usage() { - echo "update-alternatives: $* - -Usage: update-alternatives --install - update-alternatives --remove - update-alternatives --help - is the link pointing to the provided path (ie. /usr/bin/foo). - is the name in $ad/alternatives (ie. foo) - is the name referred to (ie. /usr/bin/foo-extra-spiffy) - is an integer; options with higher numbers are chosen. -" >&2 - exit 2 -} - -quit() { - echo "update-alternatives: $*" >&2 - exit 2 -} - -register_alt() { - [ $# -lt 2 ] && return 1 - local name="$1" - local link="$2" - - if [ ! -d $ad ]; then - mkdir -p $ad - fi - - if [ -e "$ad/$name" ]; then - local olink=`head -n 1 $ad/$name` - if [ "$link" != "$olink" ]; then - echo "update-alternatives: Error: cannot register alternative $name to $link since it is already registered to $olink" >&2 - return 1 - fi - else - echo "$link" > "$ad/$name" - fi - - return 0 -} - -protect_slashes() { - sed -e 's/\//\\\//g' -} - -remove_alt() { - [ $# -lt 2 ] && return 1 - local name="$1" - local path="$2" - - [ ! -f $ad/$name ] && return 0 - - path=`echo $path | protect_slashes` - sed -ne "/^$path\>.*/!p" $ad/$name > $ad/$name.new - mv $ad/$name.new $ad/$name -} - -add_alt() { - [ $# -lt 3 ] && return 1 - local name="$1" - local path="$2" - local priority="$3" - remove_alt $name $path - echo "$path $priority" >> $ad/$name -} - -find_best_alt() { - [ $# -lt 1 ] && return 1 - [ ! -f $ad/$name ] && return 0 - - 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 - echo "update-alternatives: removing $link as no more alternatives exist for it" - rm $ad/$name - if [ -L $link ]; then - rm $link - fi - return 0 - fi - - if [ ! -e $link -o -L $link ]; then - local link_dir=`dirname $link` - if [ ! -d $link_dir ]; then - mkdir -p $link_dir - fi - ln -sf $path $link - echo "update-alternatives: Linking $link to $path" - else - echo "update-alternatives: Error: not linking $link to $path since $link exists and is not a link" - return 1 - fi - - return 0 -} - -do_install() { - if [ $# -lt 4 ]; then - usage "--install needs " - fi - local link="$1" - local name="$2" - local path="$3" - local priority="$4" - - path=`echo $path | sed 's|/\+|/|g'` - - # This is a bad hack, but I haven't thought of a cleaner solution yet... - [ -n "$OPKG_OFFLINE_ROOT" ] && path=`echo $path | sed "s|^$OPKG_OFFLINE_ROOT/*|/|"` - - register_alt $name $link - add_alt $name $path $priority - find_best_alt $name -} - -do_remove() { - if [ $# -lt 2 ]; then - usage "--remove needs " - fi - local name="$1" - local path="$2" - - path=`echo $path | sed 's|/\+|/|g'` - - # This is a bad hack, but I haven't thought of a cleaner solution yet... - [ -n "$OPKG_OFFLINE_ROOT" ] && path=`echo $path | sed "s|^$OPKG_OFFLINE_ROOT/*|/|"` - - remove_alt $name $path - find_best_alt $name -} - -### -# update-alternatives "main" -### - -while [ $# -gt 0 ]; do - arg="$1" - shift - - case $arg in - --help) - usage "help:" - exit 0 - ;; - --install) - do_install $* - exit $? - ;; - --remove) - do_remove $* - exit $? - ;; - *) - usage "unknown argument \`$arg'" - ;; - esac -done - -usage "at least one of --install or --remove must appear" - -exit 0 diff --git a/utils/update-alternatives.in b/utils/update-alternatives.in new file mode 100644 index 0000000..a49cc09 --- /dev/null +++ b/utils/update-alternatives.in @@ -0,0 +1,189 @@ +#!/bin/sh +# update-alternatives +# +# Copyright (C) 2001 Carl D. Worth +# +# This program was inspired by the Debian update-alternatives program +# which is Copyright (C) 1995 Ian Jackson. This version of +# update-alternatives is command-line compatible with Debian's for a +# subset of the options, (only --install, --remove, and --help) +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +set -e + +# admin dir +ad="$OPKG_OFFLINE_ROOT@opkglibdir@/opkg/alternatives" + +usage() { + echo "update-alternatives: $* + +Usage: update-alternatives --install + update-alternatives --remove + update-alternatives --help + is the link pointing to the provided path (ie. /usr/bin/foo). + is the name in $ad/alternatives (ie. foo) + is the name referred to (ie. /usr/bin/foo-extra-spiffy) + is an integer; options with higher numbers are chosen. +" >&2 + exit 2 +} + +quit() { + echo "update-alternatives: $*" >&2 + exit 2 +} + +register_alt() { + [ $# -lt 2 ] && return 1 + local name="$1" + local link="$2" + + if [ ! -d $ad ]; then + mkdir -p $ad + fi + + if [ -e "$ad/$name" ]; then + local olink=`head -n 1 $ad/$name` + if [ "$link" != "$olink" ]; then + echo "update-alternatives: Error: cannot register alternative $name to $link since it is already registered to $olink" >&2 + return 1 + fi + else + echo "$link" > "$ad/$name" + fi + + return 0 +} + +protect_slashes() { + sed -e 's/\//\\\//g' +} + +remove_alt() { + [ $# -lt 2 ] && return 1 + local name="$1" + local path="$2" + + [ ! -f $ad/$name ] && return 0 + + path=`echo $path | protect_slashes` + sed -ne "/^$path\>.*/!p" $ad/$name > $ad/$name.new + mv $ad/$name.new $ad/$name +} + +add_alt() { + [ $# -lt 3 ] && return 1 + local name="$1" + local path="$2" + local priority="$3" + remove_alt $name $path + echo "$path $priority" >> $ad/$name +} + +find_best_alt() { + [ $# -lt 1 ] && return 1 + [ ! -f $ad/$name ] && return 0 + + 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 + echo "update-alternatives: removing $link as no more alternatives exist for it" + rm $ad/$name + if [ -L $link ]; then + rm $link + fi + return 0 + fi + + if [ ! -e $link -o -L $link ]; then + local link_dir=`dirname $link` + if [ ! -d $link_dir ]; then + mkdir -p $link_dir + fi + ln -sf $path $link + echo "update-alternatives: Linking $link to $path" + else + echo "update-alternatives: Error: not linking $link to $path since $link exists and is not a link" + return 1 + fi + + return 0 +} + +do_install() { + if [ $# -lt 4 ]; then + usage "--install needs " + fi + local link="$1" + local name="$2" + local path="$3" + local priority="$4" + + path=`echo $path | sed 's|/\+|/|g'` + + # This is a bad hack, but I haven't thought of a cleaner solution yet... + [ -n "$OPKG_OFFLINE_ROOT" ] && path=`echo $path | sed "s|^$OPKG_OFFLINE_ROOT/*|/|"` + + register_alt $name $link + add_alt $name $path $priority + find_best_alt $name +} + +do_remove() { + if [ $# -lt 2 ]; then + usage "--remove needs " + fi + local name="$1" + local path="$2" + + path=`echo $path | sed 's|/\+|/|g'` + + # This is a bad hack, but I haven't thought of a cleaner solution yet... + [ -n "$OPKG_OFFLINE_ROOT" ] && path=`echo $path | sed "s|^$OPKG_OFFLINE_ROOT/*|/|"` + + remove_alt $name $path + find_best_alt $name +} + +### +# update-alternatives "main" +### + +while [ $# -gt 0 ]; do + arg="$1" + shift + + case $arg in + --help) + usage "help:" + exit 0 + ;; + --install) + do_install $* + exit $? + ;; + --remove) + do_remove $* + exit $? + ;; + *) + usage "unknown argument \`$arg'" + ;; + esac +done + +usage "at least one of --install or --remove must appear" + +exit 0