2009-10-18 09:17:26 +00:00
|
|
|
#-
|
2011-07-01 14:15:59 +00:00
|
|
|
# Copyright (c) 2009-2011 Juan Romero Pardines.
|
2009-10-18 09:17:26 +00:00
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
#-
|
|
|
|
|
2009-12-02 00:55:51 +00:00
|
|
|
_add_trigger()
|
|
|
|
{
|
|
|
|
local f found name="$1"
|
|
|
|
|
|
|
|
for f in ${triggers}; do
|
|
|
|
[ "$f" = "$name" ] && found=1
|
|
|
|
done
|
|
|
|
[ -z "$found" ] && triggers="$triggers $name"
|
|
|
|
}
|
|
|
|
|
2009-10-18 09:17:26 +00:00
|
|
|
xbps_write_metadata_scripts_pkg()
|
|
|
|
{
|
|
|
|
local action="$1"
|
2011-10-28 09:56:39 +00:00
|
|
|
local action_file="$2"
|
2009-10-18 09:17:26 +00:00
|
|
|
local tmpf=$(mktemp -t xbps-install.XXXXXXXXXX) || exit 1
|
|
|
|
local fpattern="s|${DESTDIR}||g;s|^\./$||g;/^$/d"
|
2009-12-11 11:03:21 +00:00
|
|
|
local targets f info_files home shell descr groups
|
2010-01-17 21:22:12 +00:00
|
|
|
local found triggers_found
|
2009-10-18 09:17:26 +00:00
|
|
|
|
|
|
|
case "$action" in
|
|
|
|
install) ;;
|
|
|
|
remove) ;;
|
|
|
|
*) return 1;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
cd ${DESTDIR}
|
|
|
|
cat >> $tmpf <<_EOF
|
|
|
|
#!/bin/sh -e
|
|
|
|
#
|
|
|
|
# Generic INSTALL/REMOVE script. Arguments passed to this script:
|
|
|
|
#
|
|
|
|
# \$1 = ACTION [pre/post]
|
|
|
|
# \$2 = PKGNAME
|
|
|
|
# \$3 = VERSION
|
|
|
|
# \$4 = UPDATE [yes/no]
|
|
|
|
#
|
|
|
|
# Note that paths must be relative to CWD, to avoid calling
|
|
|
|
# host commands if /bin/sh (dash) is not installed and it's
|
|
|
|
# not possible to chroot(3).
|
|
|
|
#
|
|
|
|
|
2011-07-01 14:15:59 +00:00
|
|
|
export PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
|
2009-10-18 09:17:26 +00:00
|
|
|
|
|
|
|
TRIGGERSDIR="./var/db/xbps/triggers"
|
|
|
|
ACTION="\$1"
|
|
|
|
PKGNAME="\$2"
|
|
|
|
VERSION="\$3"
|
|
|
|
UPDATE="\$4"
|
|
|
|
|
|
|
|
#
|
|
|
|
# The following code will run the triggers.
|
|
|
|
#
|
|
|
|
_EOF
|
2011-07-09 21:07:50 +00:00
|
|
|
#
|
|
|
|
# Handle kernel hooks.
|
|
|
|
#
|
|
|
|
if [ -n "${kernel_hooks_version}" ]; then
|
2011-07-09 22:40:02 +00:00
|
|
|
_add_trigger kernel-hooks
|
2011-07-09 21:07:50 +00:00
|
|
|
echo "export kernel_hooks_version=\"${kernel_hooks_version}\"" >> $tmpf
|
|
|
|
fi
|
2009-10-18 09:17:26 +00:00
|
|
|
#
|
2010-12-23 13:29:38 +00:00
|
|
|
# Handle DKMS modules.
|
2009-10-18 09:17:26 +00:00
|
|
|
#
|
2010-12-23 13:29:38 +00:00
|
|
|
if [ -n "${dkms_modules}" ]; then
|
|
|
|
_add_trigger dkms
|
|
|
|
echo "export dkms_modules=\"${dkms_modules}\"" >> $tmpf
|
|
|
|
fi
|
2010-12-28 10:23:33 +00:00
|
|
|
#
|
|
|
|
# Handle system groups.
|
|
|
|
#
|
|
|
|
if [ -n "${system_groups}" ]; then
|
|
|
|
_add_trigger system-accounts
|
|
|
|
echo "export system_groups=\"${system_groups}\"" >> $tmpf
|
|
|
|
fi
|
2009-12-11 11:03:21 +00:00
|
|
|
#
|
|
|
|
# Handle system accounts.
|
|
|
|
#
|
|
|
|
if [ -n "${system_accounts}" ]; then
|
|
|
|
_add_trigger system-accounts
|
|
|
|
echo "export system_accounts=\"${system_accounts}\"" >> $tmpf
|
|
|
|
for f in ${system_accounts}; do
|
|
|
|
eval homedir="\$${f}_homedir"
|
|
|
|
eval shell="\$${f}_shell"
|
|
|
|
eval descr="\$${f}_descr"
|
|
|
|
eval groups="\$${f}_groups"
|
|
|
|
if [ -n "$homedir" ]; then
|
|
|
|
echo "export ${f}_homedir=\"$homedir\"" >> $tmpf
|
|
|
|
fi
|
|
|
|
if [ -n "$shell" ]; then
|
|
|
|
echo "export ${f}_shell=\"$shell\"" >> $tmpf
|
|
|
|
fi
|
|
|
|
if [ -n "$descr" ]; then
|
|
|
|
echo "export ${f}_descr=\"$descr\"" >> $tmpf
|
|
|
|
fi
|
|
|
|
if [ -n "$groups" ]; then
|
|
|
|
echo "export ${f}_groups=\"${groups}\"" >> $tmpf
|
|
|
|
fi
|
|
|
|
unset homedir shell descr groups
|
|
|
|
done
|
2009-10-18 09:17:26 +00:00
|
|
|
fi
|
2010-12-23 13:29:38 +00:00
|
|
|
#
|
2011-11-09 14:18:39 +00:00
|
|
|
# Handle mkdirs trigger.
|
|
|
|
#
|
|
|
|
if [ -n "${make_dirs}" ]; then
|
|
|
|
_add_trigger mkdirs
|
|
|
|
echo "export make_dirs=\"${make_dirs}\"" >> $tmpf
|
|
|
|
fi
|
|
|
|
#
|
|
|
|
# Handle systemd services.
|
|
|
|
#
|
|
|
|
if [ -n "${systemd_services}" ]; then
|
|
|
|
_add_trigger systemd-service
|
|
|
|
echo "export systemd_services=\"${systemd_services}\"" >> $tmpf
|
|
|
|
fi
|
|
|
|
#
|
2010-12-23 13:29:38 +00:00
|
|
|
# Handle GNU Info files.
|
|
|
|
#
|
|
|
|
if [ -d "${DESTDIR}/usr/share/info" ]; then
|
|
|
|
unset info_files
|
|
|
|
for f in $(find ${DESTDIR}/usr/share/info -type f); do
|
|
|
|
j=$(echo $f|sed -e "$fpattern")
|
|
|
|
[ "$j" = "" ] && continue
|
|
|
|
[ "$j" = "/usr/share/info/dir" ] && continue
|
|
|
|
if [ -z "$info_files" ]; then
|
|
|
|
info_files="$j"
|
|
|
|
else
|
|
|
|
info_files="$info_files $j"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ -n "${info_files}" ]; then
|
|
|
|
_add_trigger info-files
|
|
|
|
echo "export info_files=\"${info_files}\"" >> $tmpf
|
|
|
|
fi
|
|
|
|
fi
|
2009-10-18 09:17:26 +00:00
|
|
|
#
|
|
|
|
# (Un)Register a shell in /etc/shells.
|
|
|
|
#
|
|
|
|
if [ -n "${register_shell}" ]; then
|
2009-12-02 00:55:51 +00:00
|
|
|
_add_trigger register-shell
|
2009-10-18 09:17:26 +00:00
|
|
|
echo "export register_shell=\"${register_shell}\"" >> $tmpf
|
|
|
|
fi
|
|
|
|
#
|
|
|
|
# Handle SGML/XML catalog entries via xmlcatmgr.
|
|
|
|
#
|
|
|
|
if [ -n "${sgml_catalogs}" ]; then
|
|
|
|
for catalog in ${sgml_catalogs}; do
|
|
|
|
sgml_entries="${sgml_entries} CATALOG ${catalog} --"
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
if [ -n "${sgml_entries}" ]; then
|
|
|
|
echo "export sgml_entries=\"${sgml_entries}\"" >> $tmpf
|
|
|
|
fi
|
|
|
|
if [ -n "${xml_catalogs}" ]; then
|
|
|
|
for catalog in ${xml_catalogs}; do
|
|
|
|
xml_entries="${xml_entries} nextCatalog ${catalog} --"
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
if [ -n "${xml_entries}" ]; then
|
|
|
|
echo "export xml_entries=\"${xml_entries}\"" >> $tmpf
|
|
|
|
fi
|
2009-12-02 00:55:51 +00:00
|
|
|
if [ -n "${sgml_entries}" -o -n "${xml_entries}" ]; then
|
|
|
|
_add_trigger xml-catalog
|
|
|
|
fi
|
2009-10-18 09:17:26 +00:00
|
|
|
#
|
|
|
|
# Handle X11 font updates via mkfontdir/mkfontscale.
|
|
|
|
#
|
|
|
|
if [ -n "${font_dirs}" ]; then
|
2009-12-02 00:55:51 +00:00
|
|
|
_add_trigger x11-fonts
|
2009-10-18 09:17:26 +00:00
|
|
|
echo "export font_dirs=\"${font_dirs}\"" >> $tmpf
|
|
|
|
fi
|
|
|
|
#
|
|
|
|
# Handle GTK+ Icon cache directories.
|
|
|
|
#
|
|
|
|
if [ -n "${gtk_iconcache_dirs}" ]; then
|
2009-12-02 00:55:51 +00:00
|
|
|
_add_trigger gtk-icon-cache
|
2009-10-18 09:17:26 +00:00
|
|
|
echo "export gtk_iconcache_dirs=\"${gtk_iconcache_dirs}\"" \
|
|
|
|
>> $tmpf
|
|
|
|
fi
|
2009-12-02 00:55:51 +00:00
|
|
|
#
|
|
|
|
# Handle .desktop files in /usr/share/applications with
|
|
|
|
# desktop-file-utils.
|
|
|
|
#
|
|
|
|
if [ -d ${DESTDIR}/usr/share/applications ]; then
|
|
|
|
if find . -type f -name \*.desktop 2>&1 >/dev/null; then
|
|
|
|
_add_trigger update-desktopdb
|
|
|
|
fi
|
|
|
|
fi
|
2010-04-11 10:50:35 +00:00
|
|
|
#
|
|
|
|
# Handle GConf schemas/entries files with gconf-schemas.
|
|
|
|
#
|
|
|
|
if [ -n "${gconf_entries}" -o -n "${gconf_schemas}" ]; then
|
|
|
|
if find . -type f -name \*.schemas \
|
|
|
|
-o -name \*.entries 2>&1 >/dev/null; then
|
|
|
|
_add_trigger gconf-schemas
|
|
|
|
fi
|
|
|
|
if [ -n "${gconf_entries}" ]; then
|
|
|
|
echo "export gconf_entries=\"${gconf_entries}\"" \
|
|
|
|
>> $tmpf
|
|
|
|
fi
|
|
|
|
if [ -n "${gconf_schemas}" ]; then
|
|
|
|
echo "export gconf_schemas=\"${gconf_schemas}\"" \
|
|
|
|
>> $tmpf
|
|
|
|
fi
|
|
|
|
fi
|
2011-10-05 09:00:03 +00:00
|
|
|
#
|
|
|
|
# Handle gio-modules trigger.
|
|
|
|
#
|
|
|
|
if [ -d ${DESTDIR}/usr/lib/gio/modules ]; then
|
|
|
|
if find ${DESTDIR}/usr/lib/gio/modules -type f -name \*.so 2>&1 >/dev/null; then
|
|
|
|
_add_trigger gio-modules
|
|
|
|
fi
|
|
|
|
fi
|
2011-10-05 07:34:48 +00:00
|
|
|
#
|
|
|
|
# Handle gsettings schemas in /usr/share/glib-2.0/schemas with
|
|
|
|
# gsettings-schemas.
|
|
|
|
#
|
|
|
|
if [ -d ${DESTDIR}/usr/share/glib-2.0/schemas ]; then
|
|
|
|
if find ${DESTDIR}/usr/share/glib-2.0/schemas -type f -name \*.xml 2>&1 >/dev/null; then
|
|
|
|
_add_trigger gsettings-schemas
|
|
|
|
fi
|
|
|
|
fi
|
2011-10-05 08:29:57 +00:00
|
|
|
#
|
|
|
|
# Handle mime database in /usr/share/mime with update-mime-database.
|
|
|
|
#
|
|
|
|
if [ -d ${DESTDIR}/usr/share/mime ]; then
|
|
|
|
if find ${DESTDIR}/usr/share/mime -type f -name \*.xml 2>&1 >/dev/null; then
|
|
|
|
_add_trigger mimedb
|
|
|
|
fi
|
|
|
|
fi
|
2011-10-05 12:26:54 +00:00
|
|
|
#
|
|
|
|
# Handle python bytecode archives with pycompile trigger.
|
|
|
|
#
|
|
|
|
if [ -n "${pycompile_dirs}" -o -n "${pycompile_module}" ]; then
|
|
|
|
if [ -n "${pycompile_dirs}" ]; then
|
|
|
|
echo "export pycompile_dirs=\"${pycompile_dirs}\"" >>$tmpf
|
|
|
|
fi
|
|
|
|
if [ -n "${pycompile_module}" ]; then
|
|
|
|
echo "export pycompile_module=\"${pycompile_module}\"" >>$tmpf
|
|
|
|
fi
|
|
|
|
_add_trigger pycompile
|
|
|
|
fi
|
|
|
|
|
2010-12-23 13:29:38 +00:00
|
|
|
# End of trigger var exports.
|
|
|
|
echo >> $tmpf
|
|
|
|
|
2009-12-02 00:55:51 +00:00
|
|
|
#
|
|
|
|
# Write the INSTALL/REMOVE package scripts.
|
|
|
|
#
|
2009-10-18 09:17:26 +00:00
|
|
|
if [ -n "$triggers" ]; then
|
2010-01-17 21:22:12 +00:00
|
|
|
triggers_found=1
|
2009-10-18 09:17:26 +00:00
|
|
|
echo "case \"\${ACTION}\" in" >> $tmpf
|
|
|
|
echo "pre)" >> $tmpf
|
|
|
|
for f in ${triggers}; do
|
|
|
|
if [ ! -f $XBPS_TRIGGERSDIR/$f ]; then
|
|
|
|
rm -f $tmpf
|
2010-12-19 23:22:12 +00:00
|
|
|
msg_error "$pkgname: unknown trigger $f, aborting!\n"
|
2009-10-18 09:17:26 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
for f in ${triggers}; do
|
|
|
|
targets=$($XBPS_TRIGGERSDIR/$f targets)
|
|
|
|
for j in ${targets}; do
|
|
|
|
if ! $(echo $j|grep -q pre-${action}); then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
printf "\t\${TRIGGERSDIR}/$f run $j \${PKGNAME} \${VERSION} \${UPDATE}\n" >> $tmpf
|
|
|
|
printf "\t[ \$? -ne 0 ] && exit \$?\n" >> $tmpf
|
|
|
|
done
|
|
|
|
done
|
|
|
|
printf "\t;;\n" >> $tmpf
|
|
|
|
echo "post)" >> $tmpf
|
|
|
|
for f in ${triggers}; do
|
|
|
|
targets=$($XBPS_TRIGGERSDIR/$f targets)
|
|
|
|
for j in ${targets}; do
|
|
|
|
if ! $(echo $j|grep -q post-${action}); then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
printf "\t\${TRIGGERSDIR}/$f run $j \${PKGNAME} \${VERSION} \${UPDATE}\n" >> $tmpf
|
|
|
|
printf "\t[ \$? -ne 0 ] && exit \$?\n" >> $tmpf
|
|
|
|
done
|
|
|
|
done
|
|
|
|
printf "\t;;\n" >> $tmpf
|
|
|
|
echo "esac" >> $tmpf
|
|
|
|
echo >> $tmpf
|
|
|
|
fi
|
|
|
|
|
|
|
|
case "$action" in
|
|
|
|
install)
|
2011-10-28 09:56:39 +00:00
|
|
|
if [ -f ${action_file} ]; then
|
2009-10-18 09:17:26 +00:00
|
|
|
found=1
|
2011-10-28 09:56:39 +00:00
|
|
|
cat ${action_file} >> $tmpf
|
2009-10-18 09:17:26 +00:00
|
|
|
fi
|
|
|
|
echo "exit 0" >> $tmpf
|
|
|
|
mv $tmpf ${DESTDIR}/INSTALL && chmod 755 ${DESTDIR}/INSTALL
|
|
|
|
;;
|
|
|
|
remove)
|
2010-01-16 05:13:12 +00:00
|
|
|
unset found
|
2011-10-28 09:56:39 +00:00
|
|
|
if [ -f ${action_file} ]; then
|
2009-10-18 09:17:26 +00:00
|
|
|
found=1
|
2011-10-28 09:56:39 +00:00
|
|
|
cat ${action_file} >> $tmpf
|
2009-10-18 09:17:26 +00:00
|
|
|
fi
|
|
|
|
echo "exit 0" >> $tmpf
|
|
|
|
mv $tmpf ${DESTDIR}/REMOVE && chmod 755 ${DESTDIR}/REMOVE
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|