diff options
author | John Crispin <john@openwrt.org> | 2014-09-11 12:27:49 +0000 |
---|---|---|
committer | John Crispin <john@openwrt.org> | 2014-09-11 12:27:49 +0000 |
commit | d6dbc22bbcde78bbc378ca3f006771a2b074ff2e (patch) | |
tree | 0491fe2f49e0922ca3bad202ecfd9ee51dc5a1a5 /package | |
parent | 285012d8972b1891c78d9d77b8a2f7d4e81ae829 (diff) | |
download | mtk-20170518-d6dbc22bbcde78bbc378ca3f006771a2b074ff2e.zip mtk-20170518-d6dbc22bbcde78bbc378ca3f006771a2b074ff2e.tar.gz mtk-20170518-d6dbc22bbcde78bbc378ca3f006771a2b074ff2e.tar.bz2 |
ipkg: add a default postinst/prerm script
the postinst script enables/starts the init.d scripts upon package installation
and installs the users required by the package.
the prerm script stops and disables the init.d scripts.
Signed-off-by: John Crispin <blogic@openwrt.org>
SVN-Revision: 42470
Diffstat (limited to 'package')
-rw-r--r-- | package/Makefile | 3 | ||||
-rwxr-xr-x | package/base-files/files/lib/functions.sh | 77 |
2 files changed, 78 insertions, 2 deletions
diff --git a/package/Makefile b/package/Makefile index 0cba878..a42b4b0 100644 --- a/package/Makefile +++ b/package/Makefile @@ -116,7 +116,8 @@ $(curdir)/install: $(TMP_DIR)/.build @-find $(TARGET_DIR) -name CVS | $(XARGS) rm -rf @-find $(TARGET_DIR) -name .svn | $(XARGS) rm -rf @-find $(TARGET_DIR) -name '.#*' | $(XARGS) rm -f - rm -f $(TARGET_DIR)/usr/lib/opkg/info/*.postinst + rm -f $(TARGET_DIR)/usr/lib/opkg/info/*.postinst* + rm -f $(TARGET_DIR)/usr/lib/opkg/info/*.prerm* $(if $(CONFIG_CLEAN_IPKG),rm -rf $(TARGET_DIR)/usr/lib/opkg) $(call mklibs) diff --git a/package/base-files/files/lib/functions.sh b/package/base-files/files/lib/functions.sh index 0d4b2a3..67f4a04 100755 --- a/package/base-files/files/lib/functions.sh +++ b/package/base-files/files/lib/functions.sh @@ -160,6 +160,50 @@ insert_modules() { } } +default_prerm() { + 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 + 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 + for a in $(echo $rusers | sed "s/Require-User://g"); do + user="" + group="" + for b in $(echo $a | sed "s/:/ /g"); do + [ -z "$user" ] && { + user=$b + continue + } + [ -z "$group" ] && { + group=$b + group_add_next $b + gid=$? + user_exists $user || user_add $user "" $gid + continue + } + group_add_next $b + group_add_user $b $user + done + done + } + [ -n "${IPKG_INSTROOT}" -o "$PKG_UPGRADE" = "1" ] || for i in `cat /usr/lib/opkg/info/${name}.list | grep "^/etc/init.d/"`; do + $i enable + $i start + done + return 0 +} + include() { local file @@ -199,14 +243,45 @@ group_exists() { grep -qs "^${1}:" ${IPKG_INSTROOT}/etc/group } +group_add_next() { + local gid gids + gid=$(grep -s "^${1}:" ${IPKG_INSTROOT}/etc/group | cut -d: -f3) + [ -n "$gid" ] && return $gid + gids=$(cat ${IPKG_INSTROOT}/etc/group | cut -d: -f3) + gid=100 + while [ -n "$(echo $gids | grep $gid)" ] ; do + gid=$((gid + 1)) + done + group_add $1 $gid + return $gid +} + +group_add_user() { + local grp delim="," + grp=$(grep -s "^${1}:" ${IPKG_INSTROOT}/etc/group) + [ -z "$(echo $grp | cut -d: -f4 | grep $2)" ] || return + [ -n "$(echo $grp | grep ":$")" ] && delim="" + [ -n "$IPKG_INSTROOT" ] || lock /var/lock/passwd + sed -i "s/$grp/$grp$delim$2/g" ${IPKG_INSTROOT}/etc/group + [ -n "$IPKG_INSTROOT" ] || lock -u /var/lock/passwd +} + user_add() { local name="${1}" local uid="${2}" - local gid="${3:-$2}" + local gid="${3}" local desc="${4:-$1}" local home="${5:-/var/run/$1}" local shell="${6:-/bin/false}" local rc + [ -z "$uid" ] && { + uids=$(cat ${IPKG_INSTROOT}/etc/passwd | cut -d: -f3) + uid=100 + while [ -n "$(echo $uids | grep $uid)" ] ; do + uid=$((uid + 1)) + done + } + [ -z "$gid" ] && gid=$uid [ -f "${IPKG_INSTROOT}/etc/passwd" ] || return 1 [ -n "$IPKG_INSTROOT" ] || lock /var/lock/passwd echo "${name}:x:${uid}:${gid}:${desc}:${home}:${shell}" >> ${IPKG_INSTROOT}/etc/passwd |