base-files: add update-alternatives call to default_{postinst,prerm}
[openwrt/staging/yousong.git] / package / base-files / files / lib / functions.sh
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" )