base-files: allocate uid/gid starting from 65536
[openwrt/openwrt.git] / package / base-files / files / lib / functions.sh
index e6c6822cec5d3eb16b529776d59ad691f43c56e8..81ef84b8ef8fc44ae8731b80766c222094408010 100755 (executable)
@@ -164,12 +164,22 @@ insert_modules() {
 }
 
 default_prerm() {
+       local root="${IPKG_INSTROOT}"
        local name
+
        name=$(basename ${1%.*})
-       [ -f /usr/lib/opkg/info/${name}.prerm-pkg ] && . /usr/lib/opkg/info/${name}.prerm-pkg
-       for i in `cat /usr/lib/opkg/info/${name}.list | grep "^/etc/init.d/"`; do
-               $i disable
-               $i stop
+       [ -f "$root/usr/lib/opkg/info/${name}.prerm-pkg" ] && . "$root/usr/lib/opkg/info/${name}.prerm-pkg"
+
+       local shell="$(which bash)"
+       for i in `cat "$root/usr/lib/opkg/info/${name}.list" | grep "^/etc/init.d/"`; 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
+               fi
        done
 }
 
@@ -220,6 +230,11 @@ default_postinst() {
                ret=$?
        fi
 
+       if [ -d "$root/rootfs-overlay" ]; then
+               cp -R $root/rootfs-overlay/. $root/
+               rm -fR $root/rootfs-overlay/
+       fi
+
        if [ -z "$root" ] && grep -q -s "^/etc/uci-defaults/" "/usr/lib/opkg/info/${pkgname}.list"; then
                . /lib/functions/system.sh
                [ -d /tmp/.uci ] || mkdir -p /tmp/.uci
@@ -232,17 +247,17 @@ default_postinst() {
 
        [ -n "$root" ] || rm -f /tmp/luci-indexcache 2>/dev/null
 
-       if [ "$PKG_UPGRADE" != "1" ]; then
-               local shell="$(which bash)"
-               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" enable
-                       else
+       local shell="$(which bash)"
+       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" enable
+               else
+                       if [ "$PKG_UPGRADE" != "1" ]; then
                                "$i" enable
-                               "$i" start
                        fi
-               done
-       fi
+                       "$i" start
+               fi
+       done
 
        return $ret
 }
@@ -291,8 +306,8 @@ group_add_next() {
        gid=$(grep -s "^${1}:" ${IPKG_INSTROOT}/etc/group | cut -d: -f3)
        [ -n "$gid" ] && return $gid
        gids=$(cat ${IPKG_INSTROOT}/etc/group | cut -d: -f3)
-       gid=100
-       while [ -n "$(echo $gids | grep $gid)" ] ; do
+       gid=65536
+       while [ -n "$(echo "$gids" | grep "^$gid$")" ] ; do
                gid=$((gid + 1))
        done
        group_add $1 $gid
@@ -319,8 +334,8 @@ user_add() {
        local rc
        [ -z "$uid" ] && {
                uids=$(cat ${IPKG_INSTROOT}/etc/passwd | cut -d: -f3)
-               uid=100
-               while [ -n "$(echo $uids | grep $uid)" ] ; do
+               uid=65536
+               while [ -n "$(echo "$uids" | grep "^$uid$")" ] ; do
                        uid=$((uid + 1))
                done
        }
@@ -338,4 +353,8 @@ user_exists() {
        grep -qs "^${1}:" ${IPKG_INSTROOT}/etc/passwd
 }
 
+board_name() {
+       [ -e /tmp/sysinfo/board_name ] && cat /tmp/sysinfo/board_name || echo "generic"
+}
+
 [ -z "$IPKG_INSTROOT" -a -f /lib/config/uci.sh ] && . /lib/config/uci.sh