- local pkgname rusers
- pkgname=$(echo $(basename $1) | cut -d. -f1)
- rusers=$(grep "Require-User:" ${IPKG_INSTROOT}/usr/lib/opkg/info/${pkgname}.control)
- [ -n "$rusers" ] && {
- local user group uid gid
- for a in $(echo $rusers | sed "s/Require-User://g"); do
- user=""
- group=""
- for b in $(echo $a | sed "s/:/ /g"); do
- local ugname ugid
-
- ugname=$(echo $b | cut -d= -f1)
- ugid=$(echo $b | cut -d= -f2)
-
- [ -z "$user" ] && {
- user=$ugname
- uid=$ugid
- continue
- }
-
- gid=$ugid
- [ -n "$gid" ] && {
- group_exists $ugname || group_add $ugname $gid
- }
-
- [ -z "$gid" ] && {
- group_add_next $ugname
- gid=$?
- }
-
- [ -z "$group" ] && {
- user_exists $user || user_add $user "$uid" $gid
- group=$ugname
- continue
- }
-
- group_add_user $ugname $user
- done
+ local root="${IPKG_INSTROOT}"
+ local pkgname="$(basename ${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"
+ for tuple in $rusers; do
+ local uid gid uname gname
+
+ IFS=":"
+ set -- $tuple; uname="$1"; gname="$2"
+ IFS="="
+ set -- $uname; uname="$1"; uid="$2"
+ set -- $gname; gname="$1"; gid="$2"
+ IFS="$oIFS"
+
+ if [ -n "$gname" ] && [ -n "$gid" ]; then
+ group_exists "$gname" || group_add "$gname" "$gid"
+ elif [ -n "$gname" ]; then
+ group_add_next "$gname"; gid=$?
+ fi
+
+ if [ -n "$uname" ]; then
+ user_exists "$uname" || user_add "$uname" "$uid" "$gid"
+ fi
+
+ if [ -n "$uname" ] && [ -n "$gname" ]; then
+ group_add_user "$gname" "$uname"
+ fi
+
+ unset uid gid uname gname