2014-02-12 12:55:42 +01:00
# This hook generates XBPS pkg metadata INSTALL/REMOVE scripts.
_add_trigger( ) {
local f = found = name = " $1 "
for f in ${ triggers } ; do
[ " $f " = " $name " ] && found = 1
done
[ -z " $found " ] && triggers = " $triggers $name "
}
process_metadata_scripts( ) {
local action = " $1 "
local action_file = " $2 "
2019-06-17 17:38:07 +02:00
local tmpf = $( mktemp) || exit 1
2014-02-12 12:55:42 +01:00
local fpattern = " s| ${ PKGDESTDIR } ||g;s|^\./ $||g;/^ $/d "
local targets = f = _f = info_files = home = shell = descr = groups =
local found = triggers_found = _icondirs = _schemas = _mods = _tmpfiles =
case " $action " in
install) ; ;
remove) ; ;
*) return 1; ;
esac
cd ${ PKGDESTDIR }
cat >> $tmpf <<_EOF
#!/bin/sh
#
# Generic INSTALL/REMOVE script. Arguments passed to this script:
#
# \$1 = ACTION [pre/post]
# \$2 = PKGNAME
# \$3 = VERSION
# \$4 = UPDATE [yes/no]
# \$5 = CONF_FILE (path to xbps.conf)
2014-03-12 10:19:20 +01:00
# \$6 = ARCH (uname -m)
2014-02-12 12:55:42 +01:00
#
# Note that paths must be relative to CWD, to avoid calling
# host commands if /bin/sh (dash) is not installed and it's
2020-11-14 00:09:52 +01:00
# not possible to chroot(2).
2014-02-12 12:55:42 +01:00
#
export PATH = "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
TRIGGERSDIR = "./usr/libexec/xbps-triggers"
ACTION = "\$1"
PKGNAME = "\$2"
VERSION = "\$3"
UPDATE = "\$4"
CONF_FILE = "\$5"
2014-03-12 10:19:20 +01:00
ARCH = "\$6"
2014-02-12 12:55:42 +01:00
#
# The following code will run the triggers.
#
_EOF
#
# Handle kernel hooks.
#
if [ -n " ${ kernel_hooks_version } " ] ; then
_add_trigger kernel-hooks
echo " export kernel_hooks_version=\" ${ kernel_hooks_version } \" " >> $tmpf
fi
#
# Handle DKMS modules.
#
if [ -n " ${ dkms_modules } " ] ; then
_add_trigger dkms
echo " export dkms_modules=\" ${ dkms_modules } \" " >> $tmpf
fi
#
# Handle system groups.
#
if [ -n " ${ system_groups } " ] ; then
_add_trigger system-accounts
echo " export system_groups=\" ${ system_groups } \" " >> $tmpf
fi
#
# 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
2014-08-03 17:21:23 +02:00
local _uname = " ${ f % : * } "
local _uid = " ${ f #* : } "
2014-07-30 11:09:51 +02:00
2014-08-03 17:21:23 +02:00
eval homedir = " \$ ${ _uname } _homedir "
eval shell = " \$ ${ _uname } _shell "
eval descr = " \$ ${ _uname } _descr "
eval groups = " \$ ${ _uname } _groups "
2015-02-23 22:09:20 +01:00
eval pgroup = " \$ ${ _uname } _pgroup "
2014-02-12 12:55:42 +01:00
if [ -n " $homedir " ] ; then
2014-08-03 17:21:23 +02:00
echo " export ${ _uname } _homedir=\" $homedir \" " >> $tmpf
2014-02-12 12:55:42 +01:00
fi
if [ -n " $shell " ] ; then
2014-08-03 17:21:23 +02:00
echo " export ${ _uname } _shell=\" $shell \" " >> $tmpf
2014-02-12 12:55:42 +01:00
fi
if [ -n " $descr " ] ; then
2014-08-03 17:21:23 +02:00
echo " export ${ _uname } _descr=\" $descr \" " >> $tmpf
2014-02-12 12:55:42 +01:00
fi
if [ -n " $groups " ] ; then
2014-08-03 17:21:23 +02:00
echo " export ${ _uname } _groups=\" ${ groups } \" " >> $tmpf
2014-02-12 12:55:42 +01:00
fi
2015-02-23 22:09:20 +01:00
if [ -n " $pgroup " ] ; then
echo " export ${ _uname } _pgroup=\" ${ pgroup } \" " >> $tmpf
fi
unset homedir shell descr groups pgroup
2014-02-12 12:55:42 +01:00
done
fi
#
# Handle mkdirs trigger.
#
if [ -n " ${ make_dirs } " ] ; then
_add_trigger mkdirs
echo " export make_dirs=\" ${ make_dirs } \" " >> $tmpf
fi
#
2015-06-20 18:51:58 +02:00
# Handle binfmts trigger
#
2024-06-15 18:15:34 +02:00
if [ -n " ${ binfmts } " ] || [ -d " ${ PKGDESTDIR } /usr/share/binfmts " ] ; then
2015-06-20 18:51:58 +02:00
_add_trigger binfmts
2024-06-15 18:15:34 +02:00
fi
if [ -n " ${ binfmts } " ] ; then
2015-06-20 18:51:58 +02:00
echo " export binfmts=\" ${ binfmts } \" " >> $tmpf
fi
2024-06-15 18:15:34 +02:00
if [ -d " ${ PKGDESTDIR } /usr/share/binfmts " ] ; then
_import_binfmts = " $( find " ${ PKGDESTDIR } /usr/share/binfmts " -type f -printf '%f\n' ) "
echo " export import_binfmts=\" ${ _import_binfmts } \" " >> $tmpf
fi
2015-06-20 18:51:58 +02:00
#
2014-02-12 12:55:42 +01:00
# Handle GNU Info files.
#
if [ -d " ${ PKGDESTDIR } /usr/share/info " ] ; then
unset info_files
for f in $( find ${ PKGDESTDIR } /usr/share/info -type f) ; do
j = $( echo $f | sed -e " $fpattern " )
2018-01-15 14:32:42 +01:00
[ " $j " = "" ] && continue
2014-02-12 12:55:42 +01:00
[ " $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
2018-01-15 14:32:42 +01:00
fi
2017-12-08 02:55:30 +01:00
#
# Handle files in hwdb directory
#
if [ -d " ${ PKGDESTDIR } /usr/lib/udev/hwdb.d " ] ; then
_add_trigger hwdb.d-dir
2018-08-21 03:25:11 +02:00
fi
2014-02-12 12:55:42 +01:00
#
2020-07-05 03:39:30 +02:00
# Handle texmf database changes
#
if [ -d " ${ PKGDESTDIR } /usr/share/texmf-dist " ] ; then
_add_trigger texmf-dist
fi
#
2014-02-12 12:55:42 +01:00
# (Un)Register a shell in /etc/shells.
#
if [ -n " ${ register_shell } " ] ; then
_add_trigger register-shell
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
if [ -n " ${ sgml_entries } " -o -n " ${ xml_entries } " ] ; then
_add_trigger xml-catalog
fi
#
# Handle X11 font updates via mkfontdir/mkfontscale.
#
if [ -n " ${ font_dirs } " ] ; then
_add_trigger x11-fonts
echo " export font_dirs=\" ${ font_dirs } \" " >> $tmpf
fi
#
# Handle GTK+ Icon cache directories.
#
if [ -d ${ PKGDESTDIR } /usr/share/icons ] ; then
for f in ${ PKGDESTDIR } /usr/share/icons/*; do
[ ! -d " ${ f } " ] && continue
_icondirs = " ${ _icondirs } ${ f # ${ PKGDESTDIR } } "
done
if [ -n " ${ _icondirs } " ] ; then
echo " export gtk_iconcache_dirs=\" ${ _icondirs } \" " >> $tmpf
_add_trigger gtk-icon-cache
fi
fi
2018-01-15 14:32:42 +01:00
#
2014-02-12 12:55:42 +01:00
# Handle .desktop files in /usr/share/applications with
# desktop-file-utils.
#
if [ -d ${ PKGDESTDIR } /usr/share/applications ] ; then
_add_trigger update-desktopdb
fi
#
# Handle GConf schemas/entries files with gconf-schemas.
#
if [ -d ${ PKGDESTDIR } /usr/share/gconf/schemas ] ; then
_add_trigger gconf-schemas
for f in ${ PKGDESTDIR } /usr/share/gconf/schemas/*.schemas; do
2015-09-11 07:55:40 +02:00
_schemas = " ${ _schemas } ${ f ##*/ } "
2014-02-12 12:55:42 +01:00
done
echo " export gconf_schemas=\" ${ _schemas } \" " >> $tmpf
fi
#
# Handle gio-modules trigger.
#
if [ -d ${ PKGDESTDIR } /usr/lib/gio/modules ] ; then
_add_trigger gio-modules
fi
#
2018-08-19 02:11:27 +02:00
# Handle gtk immodules in /usr/lib/gtk-2.0/2.10.0/immodules with
# gtk-immodules
#
if [ -d ${ PKGDESTDIR } /usr/lib/gtk-2.0/2.10.0/immodules ] ; then
_add_trigger gtk-immodules
fi
#
# Handle gtk3 immodules in /usr/lib/gtk-3.0/3.0.0/immodules with
# gtk3-immodules
#
if [ -d ${ PKGDESTDIR } /usr/lib/gtk-3.0/3.0.0/immodules ] ; then
_add_trigger gtk3-immodules
fi
#
2014-02-12 12:55:42 +01:00
# Handle gsettings schemas in /usr/share/glib-2.0/schemas with
# gsettings-schemas.
#
if [ -d ${ PKGDESTDIR } /usr/share/glib-2.0/schemas ] ; then
_add_trigger gsettings-schemas
fi
#
2018-08-19 01:23:39 +02:00
# Handle gdk-pixbuf loadable modules in /usr/lib/gdk-pixbuf-2.0/2.10.0/loaders
# with gdk-pixbuf-loaders
#
if [ -d ${ PKGDESTDIR } /usr/lib/gdk-pixbuf-2.0/2.10.0/loaders ] ; then
_add_trigger gdk-pixbuf-loaders
fi
#
2014-02-12 12:55:42 +01:00
# Handle mime database in /usr/share/mime with update-mime-database.
#
if [ -d ${ PKGDESTDIR } /usr/share/mime ] ; then
_add_trigger mimedb
fi
#
# Handle python bytecode archives with pycompile trigger.
#
2020-04-20 19:22:10 +02:00
local pycompile_version
2016-10-16 16:46:46 +02:00
if [ -d ${ PKGDESTDIR } /usr/lib/python* ] ; then
2021-09-25 03:58:45 +02:00
pycompile_version = " $( find ${ PKGDESTDIR } /usr/lib/python* -prune -type d | grep -o '[[:digit:]]\.[[:digit:]]\+$' ) "
2019-12-02 20:40:19 +01:00
if [ -z " ${ pycompile_module } " ] ; then
pycompile_module = " $( find ${ PKGDESTDIR } /usr/lib/python*/site-packages -mindepth 1 -maxdepth 1 '!' -name '*.egg-info' '!' -name '*.dist-info' '!' -name '*.so' '!' -name '*.pth' -printf '%f ' ) "
fi
2016-10-16 16:46:46 +02:00
fi
2024-04-18 03:51:01 +02:00
if [ -n " $python_version " ] && [ " $python_version " != ignore ] ; then
2020-04-20 19:22:10 +02:00
pycompile_version = ${ python_version }
fi
if [ " $pycompile_version " = 3 ] ; then
pycompile_version = ${ py3_ver }
2020-04-25 02:09:40 +02:00
elif [ " $pycompile_version " = 2 ] ; then
pycompile_version = ${ py2_ver }
2020-04-20 19:22:10 +02:00
fi
2014-02-12 12:55:42 +01:00
if [ -n " ${ pycompile_dirs } " -o -n " ${ pycompile_module } " ] ; then
2020-04-20 19:22:10 +02:00
[ -n " $pycompile_version " ] || msg_error " $pkgver : byte-compilation is required, but python_version is not set\n "
echo " export pycompile_version=\" ${ pycompile_version } \" " >>$tmpf
2014-02-12 12:55:42 +01:00
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
2018-08-21 23:06:08 +02:00
#
# Handle appdata metadata with AppStream
#
for f in ${ PKGDESTDIR } /usr/share/appdata/*.xml ${ PKGDESTDIR } /usr/share/app-info/*.xml ${ PKGDESTDIR } /var/lib/app-info/*.xml ${ PKGDESTDIR } /var/cache/app-info/*.xml; do
if [ -f " ${ f } " ] ; then
_add_trigger appstream-cache
break
fi
done
2014-02-12 12:55:42 +01:00
# End of trigger var exports.
echo >> $tmpf
#
# Write the INSTALL/REMOVE package scripts.
#
if [ -n " $triggers " ] ; then
triggers_found = 1
echo "case \"\${ACTION}\" in" >> $tmpf
echo "pre)" >> $tmpf
for f in ${ triggers } ; do
if [ ! -f $XBPS_TRIGGERSDIR /$f ] ; then
rm -f $tmpf
msg_error " $pkgname : unknown trigger $f , aborting!\n "
fi
2015-02-21 13:03:51 +01:00
echo " Added trigger ' $f ' for the ' ${ action ^^ } ' script. "
2014-02-12 12:55:42 +01:00
done
for f in ${ triggers } ; do
targets = $( $XBPS_TRIGGERSDIR /$f targets)
for j in ${ targets } ; do
2019-04-14 07:12:51 +02:00
if ! [ [ $j = ~ pre-${ action } ] ] ; then
2014-02-12 12:55:42 +01:00
continue
fi
printf " \t\${TRIGGERSDIR}/ $f run $j \${PKGNAME} \${VERSION} \${UPDATE} \${CONF_FILE}\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
2019-04-14 07:12:51 +02:00
if ! [ [ $j = ~ post-${ action } ] ] ; then
2014-02-12 12:55:42 +01:00
continue
fi
printf " \t\${TRIGGERSDIR}/ $f run $j \${PKGNAME} \${VERSION} \${UPDATE} \${CONF_FILE}\n " >> $tmpf
printf "\t[ \$? -ne 0 ] && exit \$?\n" >> $tmpf
done
done
printf "\t;;\n" >> $tmpf
echo "esac" >> $tmpf
echo >> $tmpf
fi
if [ -z " $triggers " -a ! -f " $action_file " ] ; then
rm -f $tmpf
return 0
fi
case " $action " in
install)
if [ -f ${ action_file } ] ; then
found = 1
cat ${ action_file } >> $tmpf
fi
2014-04-14 10:41:06 +02:00
echo >> $tmpf
2014-02-12 12:55:42 +01:00
echo "exit 0" >> $tmpf
mv $tmpf ${ PKGDESTDIR } /INSTALL && chmod 755 ${ PKGDESTDIR } /INSTALL
; ;
remove)
unset found
if [ -f ${ action_file } ] ; then
found = 1
cat ${ action_file } >> $tmpf
fi
2014-04-14 10:41:06 +02:00
echo >> $tmpf
2014-02-12 12:55:42 +01:00
echo "exit 0" >> $tmpf
mv $tmpf ${ PKGDESTDIR } /REMOVE && chmod 755 ${ PKGDESTDIR } /REMOVE
; ;
esac
}
hook( ) {
local meta_install meta_remove
if [ -n " ${ sourcepkg } " -a " ${ sourcepkg } " != " ${ pkgname } " ] ; then
# subpkg
meta_install = ${ XBPS_SRCPKGDIR } /${ pkgname } /${ pkgname } .INSTALL
2014-09-15 16:18:46 +02:00
msg_install = ${ XBPS_SRCPKGDIR } /${ pkgname } /${ pkgname } .INSTALL.msg
2014-02-12 12:55:42 +01:00
meta_remove = ${ XBPS_SRCPKGDIR } /${ pkgname } /${ pkgname } .REMOVE
2014-09-15 16:18:46 +02:00
msg_remove = ${ XBPS_SRCPKGDIR } /${ pkgname } /${ pkgname } .REMOVE.msg
2014-02-12 12:55:42 +01:00
else
# sourcepkg
meta_install = ${ XBPS_SRCPKGDIR } /${ pkgname } /INSTALL
2014-09-15 16:18:46 +02:00
msg_install = ${ XBPS_SRCPKGDIR } /${ pkgname } /INSTALL.msg
2014-02-12 12:55:42 +01:00
meta_remove = ${ XBPS_SRCPKGDIR } /${ pkgname } /REMOVE
2014-09-15 16:18:46 +02:00
msg_remove = ${ XBPS_SRCPKGDIR } /${ pkgname } /REMOVE.msg
2014-02-12 12:55:42 +01:00
fi
process_metadata_scripts install ${ meta_install } || \
msg_error " $pkgver : failed to write INSTALL metadata file!\n "
process_metadata_scripts remove ${ meta_remove } || \
msg_error " $pkgver : failed to write REMOVE metadata file!\n "
2014-09-15 16:18:46 +02:00
if [ -s ${ msg_install } ] ; then
2015-04-01 15:08:28 +02:00
install -m644 ${ msg_install } ${ PKGDESTDIR } /INSTALL.msg
2014-09-15 16:18:46 +02:00
fi
if [ -s ${ msg_remove } ] ; then
2015-04-01 15:08:28 +02:00
install -m644 ${ msg_remove } ${ PKGDESTDIR } /REMOVE.msg
2014-09-15 16:18:46 +02:00
fi
2014-02-12 12:55:42 +01:00
}