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>

SVN-Revision: 46975
master
Jo-Philipp Wich 9 years ago
parent 94295b80ff
commit 33b3594332
  1. 101
      package/base-files/files/lib/functions.sh

@ -174,61 +174,60 @@ default_prerm() {
} }
default_postinst() { default_postinst() {
local pkgname rusers ret local root="${IPKG_INSTROOT}"
ret=0 local pkgname="$(basename ${1%.*})"
pkgname=$(basename ${1%.*}) local rusers="$(sed -ne 's/^Require-User: *//p' $root/usr/lib/opkg/info/${pkgname}.control 2>/dev/null)"
rusers=$(grep "Require-User:" ${IPKG_INSTROOT}/usr/lib/opkg/info/${pkgname}.control) local ret=0
[ -n "$rusers" ] && {
local user group uid gid if [ -n "$rusers" ]; then
for a in $(echo $rusers | sed "s/Require-User://g"); do local tuple oIFS="$IFS"
user="" for tuple in $rusers; do
group="" local uid gid uname gname
for b in $(echo $a | sed "s/:/ /g"); do
local ugname ugid IFS=":"
set -- $tuple; uname="$1"; gname="$2"
ugname=$(echo $b | cut -d= -f1) IFS="="
ugid=$(echo $b | cut -d= -f2) set -- $uname; uname="$1"; uid="$2"
set -- $gname; gname="$1"; gid="$2"
[ -z "$user" ] && { IFS="$oIFS"
user=$ugname
uid=$ugid if [ -n "$gname" ] && [ -n "$gid" ]; then
continue group_exists "$gname" || group_add "$gname" "$gid"
} elif [ -n "$gname" ]; then
group_add_next "$gname"; gid=$?
gid=$ugid fi
[ -n "$gid" ] && {
group_exists $ugname || group_add $ugname $gid if [ -n "$uname" ]; then
} user_exists "$uname" || user_add "$uname" "$uid" "$gid"
fi
[ -z "$gid" ] && {
group_add_next $ugname if [ -n "$uname" ] && [ -n "$gname" ]; then
gid=$? group_add_user "$gname" "$uname"
} fi
[ -z "$group" ] && { unset uid gid uname gname
user_exists $user || user_add $user "$uid" $gid
group=$ugname
continue
}
group_add_user $ugname $user
done
done done
} fi
if [ -f ${IPKG_INSTROOT}/usr/lib/opkg/info/${pkgname}.postinst-pkg ]; then if [ -f "$root/usr/lib/opkg/info/${pkgname}.postinst-pkg" ]; then
( . ${IPKG_INSTROOT}/usr/lib/opkg/info/${pkgname}.postinst-pkg ) ( . "$root/usr/lib/opkg/info/${pkgname}.postinst-pkg" )
ret=$? ret=$?
fi fi
[ -n "${IPKG_INSTROOT}" ] || rm -f /tmp/luci-indexcache 2>/dev/null
[ -n "$root" ] || 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; \ if [ "$PKG_UPGRADE" != "1" ]; then
[ -n "${IPKG_INSTROOT}" ] || { local shell="$(which bash)"
$i enable for i in $(grep -s "^/etc/init.d/" "$root/usr/lib/opkg/info/${pkgname}.list"); do
$i start if [ -n "$root" ]; then
} ${shell:-/bin/sh} "$root/etc/rc.common" "$root$i" enable
done else
"$i" enable
"$i" start
fi
done
fi
return $ret return $ret
} }

Loading…
Cancel
Save