base-files: split user/group addition code into a function
authorblogic <blogic@3c298f89-4303-0410-b956-a3cf2f4a3e73>
Sat, 30 Apr 2016 16:53:21 +0000 (16:53 +0000)
committerblogic <blogic@3c298f89-4303-0410-b956-a3cf2f4a3e73>
Sat, 30 Apr 2016 16:53:21 +0000 (16:53 +0000)
Signed-off-by: John Crispin <blogic@openwrt.org>
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@49275 3c298f89-4303-0410-b956-a3cf2f4a3e73

package/base-files/files/lib/functions.sh

index 8582605..4ec0cac 100755 (executable)
@@ -173,11 +173,9 @@ default_prerm() {
        done
 }
 
-default_postinst() {
-       local root="${IPKG_INSTROOT}"
-       local pkgname="$(basename ${1%.*})"
+add_group_and_user() {
+       local pkgname="$1"
        local rusers="$(sed -ne 's/^Require-User: *//p' $root/usr/lib/opkg/info/${pkgname}.control 2>/dev/null)"
-       local ret=0
 
        if [ -n "$rusers" ]; then
                local tuple oIFS="$IFS"
@@ -208,6 +206,14 @@ default_postinst() {
                        unset uid gid uname gname
                done
        fi
+}
+
+default_postinst() {
+       local root="${IPKG_INSTROOT}"
+       local pkgname="$(basename ${1%.*})"
+       local ret=0
+
+       add_group_and_user "${pkgname}"
 
        if [ -f "$root/usr/lib/opkg/info/${pkgname}.postinst-pkg" ]; then
                ( . "$root/usr/lib/opkg/info/${pkgname}.postinst-pkg" )