base-files: split user/group addition code into a function
authorJohn Crispin <blogic@openwrt.org>
Fri, 29 Apr 2016 01:13:40 +0000 (03:13 +0200)
committerJohn Crispin <blogic@openwrt.org>
Fri, 29 Apr 2016 02:15:34 +0000 (04:15 +0200)
Signed-off-by: John Crispin <john@phrozen.org>
package/base-files/files/lib/functions.sh

index dde1ac4f4707b66d6f096320cc8b587471a1f257..33b22d28426700784b185b5436b22002b1a68fbb 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" )