base-files: add update-alternatives call to default_{postinst,prerm}
authorYousong Zhou <yszhou4tech@gmail.com>
Sat, 4 Mar 2017 11:36:53 +0000 (19:36 +0800)
committerYousong Zhou <yszhou4tech@gmail.com>
Sun, 5 Mar 2017 09:23:47 +0000 (17:23 +0800)
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
package/base-files/Makefile
package/base-files/files/lib/functions.sh

index 99a10ffba678ae7a84e9c87c33651992e2019999..7dde9e19d9a6bbfeca44bb0e282b62ada840a06a 100644 (file)
@@ -11,7 +11,7 @@ include $(INCLUDE_DIR)/kernel.mk
 include $(INCLUDE_DIR)/version.mk
 
 PKG_NAME:=base-files
-PKG_RELEASE:=172
+PKG_RELEASE:=173
 PKG_FLAGS:=nonshared
 
 PKG_FILE_DEPENDS:=$(PLATFORM_DIR)/ $(GENERIC_PLATFORM_DIR)/base-files/
index de3fa96730393b76e39bd4d3ea5f41a104c16b69..42c4f6c08565999e8d5a1e58999eefa69d45a949 100755 (executable)
@@ -168,6 +168,7 @@ default_prerm() {
 
        name=$(basename ${1%.*})
        [ -f "$root/usr/lib/opkg/info/${name}.prerm-pkg" ] && . "$root/usr/lib/opkg/info/${name}.prerm-pkg"
+       check_update_alternatives remove "${name}"
 
        local shell="$(which bash)"
        for i in `cat "$root/usr/lib/opkg/info/${name}.list" | grep "^/etc/init.d/"`; do
@@ -217,12 +218,29 @@ add_group_and_user() {
        fi
 }
 
+check_update_alternatives() {
+       local cmd="$1"
+       local pkgname="$2"
+       local altspecs="$(sed -ne 's/^Alternatives: *//p' $root/usr/lib/opkg/info/${pkgname}.control 2>/dev/null)"
+       local spec
+       local oIFS
+       local shell="$(which bash)"
+
+       shell="${shell:-/bin/sh}"
+       oIFS="$IFS"; IFS=", "
+       for spec in $altspecs; do
+               $shell ${IPKG_INSTROOT}/usr/sbin/update-alternatives "$cmd" --spec "$spec"
+       done
+       IFS="$oIFS"
+}
+
 default_postinst() {
        local root="${IPKG_INSTROOT}"
        local pkgname="$(basename ${1%.*})"
        local ret=0
 
        add_group_and_user "${pkgname}"
+       check_update_alternatives update "${pkgname}"
 
        if [ -f "$root/usr/lib/opkg/info/${pkgname}.postinst-pkg" ]; then
                ( . "$root/usr/lib/opkg/info/${pkgname}.postinst-pkg" )