1 # This hook generates XBPS pkg metadata INSTALL/REMOVE scripts.
4 local f
= found
= name
="$1"
6 for f
in ${triggers}; do
7 [ "$f" = "$name" ] && found
=1
9 [ -z "$found" ] && triggers
="$triggers $name"
12 process_metadata_scripts
() {
14 local action_file
="$2"
15 local tmpf
=$
(mktemp
) ||
exit 1
16 local fpattern
="s|${PKGDESTDIR}||g;s|^\./$||g;/^$/d"
17 local targets
= f
= _f
= info_files
= home
= shell
= descr
= groups
=
18 local found
= triggers_found
= _icondirs
= _schemas
= _mods
= _tmpfiles
=
30 # Generic INSTALL/REMOVE script. Arguments passed to this script:
32 # \$1 = ACTION [pre/post]
35 # \$4 = UPDATE [yes/no]
36 # \$5 = CONF_FILE (path to xbps.conf)
37 # \$6 = ARCH (uname -m)
39 # Note that paths must be relative to CWD, to avoid calling
40 # host commands if /bin/sh (dash) is not installed and it's
41 # not possible to chroot(2).
44 export PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
46 TRIGGERSDIR="./usr/libexec/xbps-triggers"
55 # The following code will run the triggers.
59 # Handle kernel hooks.
61 if [ -n "${kernel_hooks_version}" ]; then
62 _add_trigger kernel-hooks
63 echo "export kernel_hooks_version=\"${kernel_hooks_version}\"" >> $tmpf
66 # Handle DKMS modules.
68 if [ -n "${dkms_modules}" ]; then
70 echo "export dkms_modules=\"${dkms_modules}\"" >> $tmpf
73 # Handle system groups.
75 if [ -n "${system_groups}" ]; then
76 _add_trigger system-accounts
77 echo "export system_groups=\"${system_groups}\"" >> $tmpf
80 # Handle system accounts.
82 if [ -n "${system_accounts}" ]; then
83 _add_trigger system-accounts
84 echo "export system_accounts=\"${system_accounts}\"" >> $tmpf
85 for f
in ${system_accounts}; do
86 local _uname
="${f%:*}"
89 eval homedir
="\$${_uname}_homedir"
90 eval shell
="\$${_uname}_shell"
91 eval descr
="\$${_uname}_descr"
92 eval groups
="\$${_uname}_groups"
93 eval pgroup
="\$${_uname}_pgroup"
94 if [ -n "$homedir" ]; then
95 echo "export ${_uname}_homedir=\"$homedir\"" >> $tmpf
97 if [ -n "$shell" ]; then
98 echo "export ${_uname}_shell=\"$shell\"" >> $tmpf
100 if [ -n "$descr" ]; then
101 echo "export ${_uname}_descr=\"$descr\"" >> $tmpf
103 if [ -n "$groups" ]; then
104 echo "export ${_uname}_groups=\"${groups}\"" >> $tmpf
106 if [ -n "$pgroup" ]; then
107 echo "export ${_uname}_pgroup=\"${pgroup}\"" >> $tmpf
109 unset homedir shell descr groups pgroup
113 # Handle mkdirs trigger.
115 if [ -n "${make_dirs}" ]; then
117 echo "export make_dirs=\"${make_dirs}\"" >> $tmpf
120 # Handle binfmts trigger
122 if [ -n "${binfmts}" ] ||
[ -d "${PKGDESTDIR}/usr/share/binfmts" ]; then
125 if [ -n "${binfmts}" ]; then
126 echo "export binfmts=\"${binfmts}\"" >> $tmpf
128 if [ -d "${PKGDESTDIR}/usr/share/binfmts" ]; then
129 _import_binfmts
="$(find "${PKGDESTDIR}/usr
/share
/binfmts
" -type f -printf '%f\n')"
130 echo "export import_binfmts=\"${_import_binfmts}\"" >> $tmpf
133 # Handle GNU Info files.
135 if [ -d "${PKGDESTDIR}/usr/share/info" ]; then
137 for f
in $
(find ${PKGDESTDIR}/usr
/share
/info
-type f
); do
138 j
=$
(echo $f|
sed -e "$fpattern")
139 [ "$j" = "" ] && continue
140 [ "$j" = "/usr/share/info/dir" ] && continue
141 if [ -z "$info_files" ]; then
144 info_files
="$info_files $j"
147 if [ -n "${info_files}" ]; then
148 _add_trigger info-files
149 echo "export info_files=\"${info_files}\"" >> $tmpf
153 # Handle files in hwdb directory
155 if [ -d "${PKGDESTDIR}/usr/lib/udev/hwdb.d" ]; then
156 _add_trigger hwdb.d-dir
159 # Handle texmf database changes
161 if [ -d "${PKGDESTDIR}/usr/share/texmf-dist" ] ; then
162 _add_trigger texmf-dist
165 # (Un)Register a shell in /etc/shells.
167 if [ -n "${register_shell}" ]; then
168 _add_trigger register-shell
169 echo "export register_shell=\"${register_shell}\"" >> $tmpf
172 # Handle SGML/XML catalog entries via xmlcatmgr.
174 if [ -n "${sgml_catalogs}" ]; then
175 for catalog
in ${sgml_catalogs}; do
176 sgml_entries
="${sgml_entries} CATALOG ${catalog} --"
179 if [ -n "${sgml_entries}" ]; then
180 echo "export sgml_entries=\"${sgml_entries}\"" >> $tmpf
182 if [ -n "${xml_catalogs}" ]; then
183 for catalog
in ${xml_catalogs}; do
184 xml_entries
="${xml_entries} nextCatalog ${catalog} --"
187 if [ -n "${xml_entries}" ]; then
188 echo "export xml_entries=\"${xml_entries}\"" >> $tmpf
190 if [ -n "${sgml_entries}" -o -n "${xml_entries}" ]; then
191 _add_trigger xml-catalog
194 # Handle X11 font updates via mkfontdir/mkfontscale.
196 if [ -n "${font_dirs}" ]; then
197 _add_trigger x11-fonts
198 echo "export font_dirs=\"${font_dirs}\"" >> $tmpf
201 # Handle GTK+ Icon cache directories.
203 if [ -d ${PKGDESTDIR}/usr
/share
/icons
]; then
204 for f
in ${PKGDESTDIR}/usr
/share
/icons
/*; do
205 [ ! -d "${f}" ] && continue
206 _icondirs
="${_icondirs} ${f#${PKGDESTDIR}}"
208 if [ -n "${_icondirs}" ]; then
209 echo "export gtk_iconcache_dirs=\"${_icondirs}\"" >> $tmpf
210 _add_trigger gtk-icon-cache
214 # Handle .desktop files in /usr/share/applications with
215 # desktop-file-utils.
217 if [ -d ${PKGDESTDIR}/usr
/share
/applications
]; then
218 _add_trigger update-desktopdb
221 # Handle GConf schemas/entries files with gconf-schemas.
223 if [ -d ${PKGDESTDIR}/usr
/share
/gconf
/schemas
]; then
224 _add_trigger gconf-schemas
225 for f
in ${PKGDESTDIR}/usr
/share
/gconf
/schemas
/*.schemas
; do
226 _schemas
="${_schemas} ${f##*/}"
228 echo "export gconf_schemas=\"${_schemas}\"" >> $tmpf
231 # Handle gio-modules trigger.
233 if [ -d ${PKGDESTDIR}/usr
/lib
/gio
/modules
]; then
234 _add_trigger gio-modules
237 # Handle gtk immodules in /usr/lib/gtk-2.0/2.10.0/immodules with
240 if [ -d ${PKGDESTDIR}/usr
/lib
/gtk-2.0
/2.10.0/immodules
]; then
241 _add_trigger gtk-immodules
244 # Handle gtk3 immodules in /usr/lib/gtk-3.0/3.0.0/immodules with
247 if [ -d ${PKGDESTDIR}/usr
/lib
/gtk-3.0
/3.0.0/immodules
]; then
248 _add_trigger gtk3-immodules
251 # Handle gsettings schemas in /usr/share/glib-2.0/schemas with
254 if [ -d ${PKGDESTDIR}/usr
/share
/glib-2.0
/schemas
]; then
255 _add_trigger gsettings-schemas
258 # Handle gdk-pixbuf loadable modules in /usr/lib/gdk-pixbuf-2.0/2.10.0/loaders
259 # with gdk-pixbuf-loaders
261 if [ -d ${PKGDESTDIR}/usr
/lib
/gdk-pixbuf-2.0
/2.10.0/loaders
]; then
262 _add_trigger gdk-pixbuf-loaders
265 # Handle mime database in /usr/share/mime with update-mime-database.
267 if [ -d ${PKGDESTDIR}/usr
/share
/mime
]; then
271 # Handle python bytecode archives with pycompile trigger.
273 local pycompile_version
274 if [ -d ${PKGDESTDIR}/usr
/lib
/python
* ]; then
275 pycompile_version
="$(find ${PKGDESTDIR}/usr/lib/python* -prune -type d | grep -o '[[:digit:]]\.[[:digit:]]\+$')"
276 if [ -z "${pycompile_module}" ]; then
277 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 ')"
281 if [ -n "$python_version" ] && [ "$python_version" != ignore
]; then
282 pycompile_version
=${python_version}
285 if [ "$pycompile_version" = 3 ]; then
286 pycompile_version
=${py3_ver}
287 elif [ "$pycompile_version" = 2 ]; then
288 pycompile_version
=${py2_ver}
291 if [ -n "${pycompile_dirs}" -o -n "${pycompile_module}" ]; then
292 [ -n "$pycompile_version" ] || msg_error
"$pkgver: byte-compilation is required, but python_version is not set\n"
293 echo "export pycompile_version=\"${pycompile_version}\"" >>$tmpf
294 if [ -n "${pycompile_dirs}" ]; then
295 echo "export pycompile_dirs=\"${pycompile_dirs}\"" >>$tmpf
297 if [ -n "${pycompile_module}" ]; then
298 echo "export pycompile_module=\"${pycompile_module}\"" >>$tmpf
300 _add_trigger pycompile
303 # Handle appdata metadata with AppStream
305 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
306 if [ -f "${f}" ]; then
307 _add_trigger appstream-cache
312 # End of trigger var exports.
316 # Write the INSTALL/REMOVE package scripts.
318 if [ -n "$triggers" ]; then
320 echo "case \"\${ACTION}\" in" >> $tmpf
322 for f
in ${triggers}; do
323 if [ ! -f $XBPS_TRIGGERSDIR/$f ]; then
325 msg_error
"$pkgname: unknown trigger $f, aborting!\n"
327 echo " Added trigger '$f' for the '${action^^}' script."
329 for f
in ${triggers}; do
330 targets
=$
($XBPS_TRIGGERSDIR/$f targets
)
331 for j
in ${targets}; do
332 if ! [[ $j =~ pre-
${action} ]]; then
335 printf "\t\${TRIGGERSDIR}/$f run $j \${PKGNAME} \${VERSION} \${UPDATE} \${CONF_FILE}\n" >> $tmpf
336 printf "\t[ \$? -ne 0 ] && exit \$?\n" >> $tmpf
339 printf "\t;;\n" >> $tmpf
340 echo "post)" >> $tmpf
341 for f
in ${triggers}; do
342 targets
=$
($XBPS_TRIGGERSDIR/$f targets
)
343 for j
in ${targets}; do
344 if ! [[ $j =~ post-
${action} ]]; then
347 printf "\t\${TRIGGERSDIR}/$f run $j \${PKGNAME} \${VERSION} \${UPDATE} \${CONF_FILE}\n" >> $tmpf
348 printf "\t[ \$? -ne 0 ] && exit \$?\n" >> $tmpf
351 printf "\t;;\n" >> $tmpf
356 if [ -z "$triggers" -a ! -f "$action_file" ]; then
363 if [ -f ${action_file} ]; then
365 cat ${action_file} >> $tmpf
368 echo "exit 0" >> $tmpf
369 mv $tmpf ${PKGDESTDIR}/INSTALL
&& chmod 755 ${PKGDESTDIR}/INSTALL
373 if [ -f ${action_file} ]; then
375 cat ${action_file} >> $tmpf
378 echo "exit 0" >> $tmpf
379 mv $tmpf ${PKGDESTDIR}/REMOVE
&& chmod 755 ${PKGDESTDIR}/REMOVE
385 local meta_install meta_remove
387 if [ -n "${sourcepkg}" -a "${sourcepkg}" != "${pkgname}" ]; then
389 meta_install
=${XBPS_SRCPKGDIR}/${pkgname}/${pkgname}.INSTALL
390 msg_install
=${XBPS_SRCPKGDIR}/${pkgname}/${pkgname}.INSTALL.msg
391 meta_remove
=${XBPS_SRCPKGDIR}/${pkgname}/${pkgname}.REMOVE
392 msg_remove
=${XBPS_SRCPKGDIR}/${pkgname}/${pkgname}.REMOVE.msg
395 meta_install
=${XBPS_SRCPKGDIR}/${pkgname}/INSTALL
396 msg_install
=${XBPS_SRCPKGDIR}/${pkgname}/INSTALL.msg
397 meta_remove
=${XBPS_SRCPKGDIR}/${pkgname}/REMOVE
398 msg_remove
=${XBPS_SRCPKGDIR}/${pkgname}/REMOVE.msg
400 process_metadata_scripts
install ${meta_install} || \
401 msg_error
"$pkgver: failed to write INSTALL metadata file!\n"
403 process_metadata_scripts remove
${meta_remove} || \
404 msg_error
"$pkgver: failed to write REMOVE metadata file!\n"
406 if [ -s ${msg_install} ]; then
407 install -m644 ${msg_install} ${PKGDESTDIR}/INSTALL.msg
409 if [ -s ${msg_remove} ]; then
410 install -m644 ${msg_remove} ${PKGDESTDIR}/REMOVE.msg