From fcb26339000021eb9bb711aa264247aebcfdd4ae Mon Sep 17 00:00:00 2001 From: Alejandro del Castillo Date: Tue, 23 Jan 2018 12:00:22 -0600 Subject: [PATCH] update-alternatives: add support for link renames During package upgrades, the link location might change. For example: Package A: 'update-alternatives --install /bin/app app /some/real/path 100' Package B: 'update-alternatives --install /sbin/app app /some/other/path 100' Opkg disallows a link change and throws an error. Debian does allow the operation, changing the link to the new location. Add support to follow the debian update-alternatives behavior. bugzilla #8344 Signed-off-by: Alejandro del Castillo --- update-alternatives | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/update-alternatives b/update-alternatives index ce7d66c..89a440b 100644 --- a/update-alternatives +++ b/update-alternatives @@ -54,8 +54,11 @@ register_alt() { 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 + echo "update-alternatives: renaming $name link from $olink to $link" + local link_str=`echo $link | protect_slashes` + sed -e "1s/.*/$link_str/" $ad/$name > $ad/$name.new + mv $ad/$name.new $ad/$name + mv $olink $link fi else echo "$link" > "$ad/$name"