diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2015-09-16 08:43:58 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2015-09-16 08:43:58 +0000 |
commit | 59e9bad641228deaae52a2485fbf766a04f1fa30 (patch) | |
tree | 4aec142eb6d92cd6cc135a0d69a50fda5ca9ea16 /package | |
parent | 3d9bd69700a9e6278bd0a6ab0e4d669c05fa045a (diff) | |
download | master-187ad058-59e9bad641228deaae52a2485fbf766a04f1fa30.tar.gz master-187ad058-59e9bad641228deaae52a2485fbf766a04f1fa30.tar.bz2 master-187ad058-59e9bad641228deaae52a2485fbf766a04f1fa30.zip |
base-files: refactor default_postinst()
- Simplify user spec parsing code
- Alias IPKG_INSTROOT to shorten code
- Quote variables where appropriate
- Remove a useless-use-of-cat instance
- Suppress errors in case control or list files are missing
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@46975 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'package')
-rwxr-xr-x | package/base-files/files/lib/functions.sh | 101 |
1 files changed, 50 insertions, 51 deletions
diff --git a/package/base-files/files/lib/functions.sh b/package/base-files/files/lib/functions.sh index 2f78d67025..dde1ac4f47 100755 --- a/package/base-files/files/lib/functions.sh +++ b/package/base-files/files/lib/functions.sh @@ -174,61 +174,60 @@ default_prerm() { } default_postinst() { - local pkgname rusers ret - ret=0 - pkgname=$(basename ${1%.*}) - 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 done - } + fi - if [ -f ${IPKG_INSTROOT}/usr/lib/opkg/info/${pkgname}.postinst-pkg ]; then - ( . ${IPKG_INSTROOT}/usr/lib/opkg/info/${pkgname}.postinst-pkg ) + if [ -f "$root/usr/lib/opkg/info/${pkgname}.postinst-pkg" ]; then + ( . "$root/usr/lib/opkg/info/${pkgname}.postinst-pkg" ) ret=$? fi - [ -n "${IPKG_INSTROOT}" ] || rm -f /tmp/luci-indexcache 2>/dev/null - - [ "$PKG_UPGRADE" = "1" ] || for i in `cat ${IPKG_INSTROOT}/usr/lib/opkg/info/${pkgname}.list | grep "^/etc/init.d/"`; do - [ -n "${IPKG_INSTROOT}" ] && $(which bash) ${IPKG_INSTROOT}/etc/rc.common ${IPKG_INSTROOT}$i enable; \ - [ -n "${IPKG_INSTROOT}" ] || { - $i enable - $i start - } - done + + [ -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 + "$i" enable + "$i" start + fi + done + fi + return $ret } |