X-Git-Url: http://git.openwrt.org/?a=blobdiff_plain;f=package%2Fbase-files%2Ffiles%2Flib%2Ffunctions.sh;h=bea5f0f96be1a2bc97899f50f2bca7cc19f9a9f3;hb=f173464f13102e6901c60de417b50b44d93bcbde;hp=3a5a65dcc7ee1dc9d490d58bca517c6650d55ba7;hpb=d099a349806f2f6a4945c382ab8b7ed47228bac4;p=openwrt%2Fopenwrt.git diff --git a/package/base-files/files/lib/functions.sh b/package/base-files/files/lib/functions.sh index 3a5a65dcc7..bea5f0f96b 100755 --- a/package/base-files/files/lib/functions.sh +++ b/package/base-files/files/lib/functions.sh @@ -1,5 +1,5 @@ #!/bin/sh -# Copyright (C) 2006-2013 OpenWrt.org +# Copyright (C) 2006-2014 OpenWrt.org # Copyright (C) 2006 Fokus Fraunhofer # Copyright (C) 2010 Vertical Communications @@ -154,70 +154,112 @@ config_list_foreach() { } insert_modules() { - [ -d /etc/modules.d ] && { - cd /etc/modules.d - sed 's/^[^#]/insmod &/' $* | ash 2>&- || : - } + for m in $*; do + if [ -f /etc/modules.d/$m ]; then + sed 's/^[^#]/insmod &/' /etc/modules.d/$m | ash 2>&- || : + else + modprobe $m + fi + done } default_prerm() { + local root="${IPKG_INSTROOT}" local name - name=$(echo $(basename $1) | cut -d. -f1) - [ -f /usr/lib/opkg/info/${name}.prerm-pkg ] && . /usr/lib/opkg/info/${name}.prerm-pkg - for i in `cat /usr/lib/opkg/info/${name}.list | grep "^/etc/init.d/"`; do - $i disable - $i stop + + name=$(basename ${1%.*}) + [ -f "$root/usr/lib/opkg/info/${name}.prerm-pkg" ] && . "$root/usr/lib/opkg/info/${name}.prerm-pkg" + + local shell="$(which bash)" + for i in `cat "$root/usr/lib/opkg/info/${name}.list" | grep "^/etc/init.d/"`; do + if [ -n "$root" ]; then + ${shell:-/bin/sh} "$root/etc/rc.common" "$root$i" disable + else + if [ "$PKG_UPGRADE" != "1" ]; then + "$i" disable + fi + "$i" stop || /bin/true + fi done } -default_postinst() { - local name rusers - name=$(echo $(basename $1) | cut -d. -f1) - [ -f ${IPKG_INSTROOT}/usr/lib/opkg/info/${name}.postinst-pkg ] && ( . ${IPKG_INSTROOT}/usr/lib/opkg/info/${name}.postinst-pkg ) - rusers=$(grep "Require-User:" ${IPKG_INSTROOT}/usr/lib/opkg/info/${name}.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 name id - - name=$(echo $b | cut -d= -f1) - id=$(echo $b | cut -d= -f2) - - [ -z "$user" ] && { - user=$name - uid=$id - continue - } - - gid=$id - [ -n "$gid" ] && group_exists $name || group_add $name $gid - [ -z "$gid" ] && { - group_add_next $name - gid=$? - } - - [ -z "$group" ] && { - user_exists $user || user_add $user "$uid" $gid - group=$name - continue - } - - group_add_user $name $user - done +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)" + + 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 - } - [ "$PKG_UPGRADE" = "1" ] || for i in `cat ${IPKG_INSTROOT}/usr/lib/opkg/info/${name}.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 - } + 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" ) + ret=$? + fi + + if [ -d "$root/rootfs-overlay" ]; then + cp -R $root/rootfs-overlay/. $root/ + rm -fR $root/rootfs-overlay/ + fi + + if [ -z "$root" ] && grep -q -s "^/etc/uci-defaults/" "/usr/lib/opkg/info/${pkgname}.list"; then + . /lib/functions/system.sh + [ -d /tmp/.uci ] || mkdir -p /tmp/.uci + for i in $(sed -ne 's!^/etc/uci-defaults/!!p' "/usr/lib/opkg/info/${pkgname}.list"); do ( + cd /etc/uci-defaults + [ -f "$i" ] && . ./"$i" && rm -f "$i" + ) done + uci commit + fi + + [ -n "$root" ] || rm -f /tmp/luci-indexcache 2>/dev/null + + 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 + if [ "$PKG_UPGRADE" != "1" ]; then + "$i" enable + fi + "$i" start + fi done - [ -n "${IPKG_INSTROOT}" ] || rm -f /tmp/luci-indexcache 2>/dev/null - return 0 + + return $ret } include() { @@ -311,4 +353,8 @@ user_exists() { grep -qs "^${1}:" ${IPKG_INSTROOT}/etc/passwd } +board_name() { + [ -e /tmp/sysinfo/board_name ] && cat /tmp/sysinfo/board_name || echo "generic" +} + [ -z "$IPKG_INSTROOT" -a -f /lib/config/uci.sh ] && . /lib/config/uci.sh