base-files: fix prerm return value, align with postinst code
[openwrt/staging/chunkeey.git] / package / base-files / files / lib / functions.sh
index c69feb33b8f73d3002d21a5e0f7b4d93fc936aef..51ca8d5a0c80873b285feccc44319b5958140ba4 100755 (executable)
@@ -165,22 +165,27 @@ insert_modules() {
 
 default_prerm() {
        local root="${IPKG_INSTROOT}"
-       local name
+       local pkgname="$(basename ${1%.*})"
+       local ret=0
 
-       name=$(basename ${1%.*})
-       [ -f "$root/usr/lib/opkg/info/${name}.prerm-pkg" ] && . "$root/usr/lib/opkg/info/${name}.prerm-pkg"
+       if [ -f "$root/usr/lib/opkg/info/${pkgname}.prerm-pkg" ]; then
+               ( . "$root/usr/lib/opkg/info/${pkgname}.prerm-pkg" )
+               ret=$?
+       fi
 
        local shell="$(which bash)"
-       for i in `cat "$root/usr/lib/opkg/info/${name}.list" | grep "^/etc/init.d/"`; do
+       for i in $(grep -s "^/etc/init.d/" "$root/usr/lib/opkg/info/${pkgname}.list"); do
                if [ -n "$root" ]; then
                        ${shell:-/bin/sh} "$root/etc/rc.common" "$root$i" disable
                else
                        if [ "$PKG_UPGRADE" != "1" ]; then
                                "$i" disable
                        fi
-                       "$i" stop || /bin/true
+                       "$i" stop
                fi
        done
+
+       return $ret
 }
 
 add_group_and_user() {