1#
2# This file is part of the LibreOffice project.
3#
4# This Source Code Form is subject to the terms of the Mozilla Public
5# License, v. 2.0. If a copy of the MPL was not distributed with this
6# file, You can obtain one at http://mozilla.org/MPL/2.0/.
7#
8# This file incorporates work covered by the following license notice:
9#
10#   Licensed to the Apache Software Foundation (ASF) under one or more
11#   contributor license agreements. See the NOTICE file distributed
12#   with this work for additional information regarding copyright
13#   ownership. The ASF licenses this file to you under the Apache
14#   License, Version 2.0 (the "License"); you may not use this file
15#   except in compliance with the License. You may obtain a copy of
16#   the License at http://www.apache.org/licenses/LICENSE-2.0 .
17#
18# version and release passed by command-line
19Version: %version
20Release: %release
21Summary: %productname desktop integration
22Name: %pkgprefix-freedesktop-menus
23#BuildRequires: sed
24#BuildRequires: perl
25Group: Office
26License: LGPLv3 with MPLv2, ALv2 and others
27Provides: libreoffice-desktop-integration
28Conflicts: %pkgprefix-suse-menus
29Conflicts: %pkgprefix-debian-menus
30Conflicts: %pkgprefix-redhat-menus
31Conflicts: %pkgprefix-mandriva-menus
32BuildArch: noarch
33AutoReqProv: no
34%define _binary_filedigest_algorithm 1
35%define _binary_payload w9.gzdio
36
37%define gnome_dir /usr
38%define gnome_mime_theme hicolor
39
40# only symlinks in the package that at the time of building point to non-existing files
41%global dont_check_desktop_files 1
42
43%description
44%productname desktop integration for desktop-environments that implement
45the menu- and mime-related specifications from http://www.freedesktop.org
46These specifications are implemented by all current distributions.
47
48%install
49rm -rf $RPM_BUILD_ROOT
50
51# hack/workaround to make SuSE's brp-symlink-script happy. It wants the targets of all links
52# to be present on the build-system/the buildroot. But the point is that we generate stale
53# links intentionally (until we find a better solution) #46226
54export NO_BRP_STALE_LINK_ERROR=yes
55
56mkdir -p $RPM_BUILD_ROOT
57
58# set parameters for the create_tree script
59export DESTDIR=$RPM_BUILD_ROOT
60export KDEMAINDIR=/usr
61export PREFIXDIR=/usr
62export BINDIR=/usr/bin
63export GNOMEDIR=%{gnome_dir}
64
65./create_tree.sh
66
67cd $RPM_BUILD_ROOT
68
69# freedesktop-based desktop-environments don't need/use this.
70rm -rf usr/share/application-registry
71rm -rf usr/share/applications.flag
72rm -rf usr/share/mime-info
73rm -rf usr/share/applnk-redhat
74#find usr/share/icons -name '*.png' -exec chmod g+w {} \;
75
76%clean
77rm -rf $RPM_BUILD_ROOT
78
79%triggerin -- %pkgprefix, %pkgprefix-writer, %pkgprefix-calc, %pkgprefix-draw, %pkgprefix-impress, %pkgprefix-math
80# this is run when one of the above packages is already installed and the menu
81# package gets installed OR when the menu-package is already installed and one
82# of the above listed packages gets installed
83
84# Due to a bug in rpm it is not possible to check why the script is triggered...
85# This is how it should be: 1st arg: number of this package, 2nd arg: number of
86# package that triggers - the bug is that rpm reports the same number for both
87# (the value of the 2nd one), so just run this always...
88# http://rhn.redhat.com/errata/RHBA-2004-098.html
89# https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=100509
90
91if [ -x /opt/gnome/bin/update-desktop-database ]; then
92    /opt/gnome/bin/update-desktop-database -q
93elif (which update-desktop-database); then
94  update-desktop-database -q /usr/share/applications
95fi
96
97%triggerun -- %pkgprefix, %pkgprefix-writer, %pkgprefix-calc, %pkgprefix-draw, %pkgprefix-impress, %pkgprefix-math
98if [ "$1" = "0" ] ; then
99  # the menu-package gets uninstalled/updated - postun will run the command
100  exit 0
101fi
102if [ "$2" = "0" ] ; then
103  # the triggering package gets removed
104  if [ -x /opt/gnome/bin/update-desktop-database ]; then
105      /opt/gnome/bin/update-desktop-database -q
106  elif (which update-desktop-database); then
107    update-desktop-database -q /usr/share/applications
108  fi
109fi
110
111%post
112# no need to run it when updating, since %postun of the old package is run
113# afterwards
114
115if [ "$1" = "1" ] ; then  # first install
116  if [ -x /opt/gnome/bin/update-desktop-database ]; then
117    /opt/gnome/bin/update-desktop-database -q
118  elif (which update-desktop-database); then
119    update-desktop-database -q /usr/share/applications
120  fi
121
122  if (which update-mime-database); then
123    update-mime-database /usr/share/mime
124  fi
125fi
126
127# add symlinks so that nautilus can identify the mime-icons
128# not strictly freedesktop-stuff but there is no common naming scheme yet.
129# One proposal is "mime-application:vnd.oasis.opendocument.spreadsheet.png"
130# for e.g. application/vnd.oasis.opendocument.spreadsheet
131link_target_root="%{gnome_dir}/share/icons/%{gnome_mime_theme}"
132
133if [ ! -d "${link_target_root}" ]
134then
135  link_target_root="%{gnome_dir}/share/icons/gnome"
136fi
137
138for subdir in `cd ${link_target_root}; ls -d *`
139do
140  link_dir="%{gnome_dir}/share/icons/%{gnome_mime_theme}/$subdir/mimetypes"
141  link_target_dir="../../../gnome/$subdir/mimetypes/"
142
143  test -d "${link_dir}" || mkdir -p "${link_dir}"
144  test -d ${link_dir}/${link_target_dir} || continue
145
146  icon=${link_target_dir}%iconprefix-drawing.png;                     test -f ${link_dir}/$icon && ln -sf ${icon} ${link_dir}/gnome-mime-application-vnd.sun.xml.draw.png
147  icon=${link_target_dir}%iconprefix-drawing-template.png;            test -f ${link_dir}/$icon && ln -sf ${icon} ${link_dir}/gnome-mime-application-vnd.sun.xml.draw.template.png
148  icon=${link_target_dir}%iconprefix-formula.png;                     test -f ${link_dir}/$icon && ln -sf ${icon} ${link_dir}/gnome-mime-application-vnd.sun.xml.math.png
149  icon=${link_target_dir}%iconprefix-master-document.png;             test -f ${link_dir}/$icon && ln -sf ${icon} ${link_dir}/gnome-mime-application-vnd.sun.xml.writer.global.png
150  icon=${link_target_dir}%iconprefix-oasis-database.png;              test -f ${link_dir}/$icon && ln -sf ${icon} ${link_dir}/gnome-mime-application-vnd.sun.xml.base.png
151  icon=${link_target_dir}%iconprefix-oasis-database.png;              test -f ${link_dir}/$icon && ln -sf ${icon} ${link_dir}/gnome-mime-application-vnd.oasis.opendocument.database.png
152  icon=${link_target_dir}%iconprefix-oasis-drawing.png;               test -f ${link_dir}/$icon && ln -sf ${icon} ${link_dir}/gnome-mime-application-vnd.oasis.opendocument.graphics.png
153  icon=${link_target_dir}%iconprefix-oasis-drawing-template.png;      test -f ${link_dir}/$icon && ln -sf ${icon} ${link_dir}/gnome-mime-application-vnd.oasis.opendocument.graphics-template.png
154  icon=${link_target_dir}%iconprefix-oasis-formula.png;               test -f ${link_dir}/$icon && ln -sf ${icon} ${link_dir}/gnome-mime-application-vnd.oasis.opendocument.formula.png
155  icon=${link_target_dir}%iconprefix-oasis-master-document.png;       test -f ${link_dir}/$icon && ln -sf ${icon} ${link_dir}/gnome-mime-application-vnd.oasis.opendocument.text-master.png
156  icon=${link_target_dir}%iconprefix-oasis-master-document-template.png;       test -f ${link_dir}/$icon && ln -sf ${icon} ${link_dir}/gnome-mime-application-vnd.oasis.opendocument.text-master-template.png
157  icon=${link_target_dir}%iconprefix-oasis-presentation.png;          test -f ${link_dir}/$icon && ln -sf ${icon} ${link_dir}/gnome-mime-application-vnd.oasis.opendocument.presentation.png
158  icon=${link_target_dir}%iconprefix-oasis-presentation-template.png; test -f ${link_dir}/$icon && ln -sf ${icon} ${link_dir}/gnome-mime-application-vnd.oasis.opendocument.presentation-template.png
159  icon=${link_target_dir}%iconprefix-oasis-spreadsheet.png;           test -f ${link_dir}/$icon && ln -sf ${icon} ${link_dir}/gnome-mime-application-vnd.oasis.opendocument.spreadsheet.png
160  icon=${link_target_dir}%iconprefix-oasis-spreadsheet-template.png;  test -f ${link_dir}/$icon && ln -sf ${icon} ${link_dir}/gnome-mime-application-vnd.oasis.opendocument.spreadsheet-template.png
161  icon=${link_target_dir}%iconprefix-oasis-text.png;                  test -f ${link_dir}/$icon && ln -sf ${icon} ${link_dir}/gnome-mime-application-vnd.oasis.opendocument.text.png
162  icon=${link_target_dir}%iconprefix-oasis-text-template.png;         test -f ${link_dir}/$icon && ln -sf ${icon} ${link_dir}/gnome-mime-application-vnd.oasis.opendocument.text-template.png
163  icon=${link_target_dir}%iconprefix-oasis-web-template.png;          test -f ${link_dir}/$icon && ln -sf ${icon} ${link_dir}/gnome-mime-application-vnd.oasis.opendocument.text-web.png
164  icon=${link_target_dir}%iconprefix-presentation.png;                test -f ${link_dir}/$icon && ln -sf ${icon} ${link_dir}/gnome-mime-application-vnd.sun.xml.impress.png
165  icon=${link_target_dir}%iconprefix-presentation-template.png;       test -f ${link_dir}/$icon && ln -sf ${icon} ${link_dir}/gnome-mime-application-vnd.sun.xml.impress.template.png
166  icon=${link_target_dir}%iconprefix-spreadsheet.png;                 test -f ${link_dir}/$icon && ln -sf ${icon} ${link_dir}/gnome-mime-application-vnd.sun.xml.calc.png
167  icon=${link_target_dir}%iconprefix-spreadsheet-template.png;        test -f ${link_dir}/$icon && ln -sf ${icon} ${link_dir}/gnome-mime-application-vnd.sun.xml.calc.template.png
168  icon=${link_target_dir}%iconprefix-text.png;                        test -f ${link_dir}/$icon && ln -sf ${icon} ${link_dir}/gnome-mime-application-vnd.sun.xml.writer.png
169  icon=${link_target_dir}%iconprefix-text-template.png;               test -f ${link_dir}/$icon && ln -sf ${icon} ${link_dir}/gnome-mime-application-vnd.sun.xml.writer.template.png
170  icon=${link_target_dir}%iconprefix-extension.png;                   test -f ${link_dir}/$icon && ln -sf ${icon} ${link_dir}/gnome-mime-application-vnd.openofficeorg.extension.png
171done
172
173#run always
174for theme in gnome hicolor locolor; do
175    if [ -e /usr/share/icons/$theme/icon-theme.cache ] ; then
176        # touch it, just in case we cannot find the binary...
177        touch /usr/share/icons/$theme
178        if [ -x /opt/gnome/bin/gtk-update-icon-cache ]; then
179            /opt/gnome/bin/gtk-update-icon-cache -q /usr/share/icons/$theme
180        elif (which gtk-update-icon-cache); then
181            gtk-update-icon-cache -q /usr/share/icons/$theme
182        fi
183        # ignore errors (e.g. when there is a cache, but no index.theme)
184        true
185    fi
186done
187
188
189# update /etc/mime.types
190# backing out existing entries to avoid duplicates
191sed '
192/application\/vnd\.oasis\.opendocument/d
193/application\/vnd\.sun/d
194/application\/vnd\.stardivision/d
195/application\/vnd\.openofficeorg/d
196' /etc/mime.types 2>/dev/null >> /etc/mime.types.tmp$$
197
198# now append our stuff to the temporary file
199cat >> /etc/mime.types.tmp$$ << END
200application/vnd.oasis.opendocument.text	odt
201application/vnd.oasis.opendocument.text-flat-xml fodt
202application/vnd.oasis.opendocument.text-template ott
203application/vnd.oasis.opendocument.text-web oth
204application/vnd.oasis.opendocument.text-master odm
205application/vnd.oasis.opendocument.graphics odg
206application/vnd.oasis.opendocument.graphics-flat-xml fodg
207application/vnd.oasis.opendocument.graphics-template otg
208application/vnd.oasis.opendocument.presentation odp
209application/vnd.oasis.opendocument.presentation-flat-xml fodp
210application/vnd.oasis.opendocument.presentation-template otp
211application/vnd.oasis.opendocument.spreadsheet ods
212application/vnd.oasis.opendocument.spreadsheet-flat-xml fods
213application/vnd.oasis.opendocument.spreadsheet-template ots
214application/vnd.oasis.opendocument.chart odc
215application/vnd.oasis.opendocument.formula odf
216application/vnd.oasis.opendocument.image odi
217application/vnd.sun.xml.writer sxw
218application/vnd.sun.xml.writer.template stw
219application/vnd.sun.xml.writer.global sxg
220application/vnd.stardivision.writer sdw vor
221application/vnd.stardivision.writer-global sgl
222application/vnd.sun.xml.calc sxc
223application/vnd.sun.xml.calc.template stc
224application/vnd.stardivision.calc sdc
225application/vnd.stardivision.chart sds
226application/vnd.sun.xml.impress sxi
227application/vnd.sun.xml.impress.template sti
228application/vnd.stardivision.impress sdd sdp
229application/vnd.sun.xml.draw sxd
230application/vnd.sun.xml.draw.template std
231application/vnd.stardivision.draw sda
232application/vnd.sun.xml.math sxm
233application/vnd.sun.xml.base odb
234application/vnd.stardivision.math smf
235application/vnd.openofficeorg.extension oxt
236application/vnd.openxmlformats-officedocument.wordprocessingml.document docx
237application/vnd.ms-word.document.macroEnabled.12 docm
238application/vnd.openxmlformats-officedocument.wordprocessingml.template dotx
239application/vnd.ms-word.template.macroEnabled.12 dotm
240application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx
241application/vnd.ms-excel.sheet.macroEnabled.12 xlsm
242application/vnd.openxmlformats-officedocument.spreadsheetml.template xltx
243application/vnd.ms-excel.template.macroEnabled.12 xltm
244application/vnd.openxmlformats-officedocument.presentationml.presentation pptx
245application/vnd.ms-powerpoint.presentation.macroEnabled.12 pptm
246application/vnd.openxmlformats-officedocument.presentationml.template potx
247application/vnd.ms-powerpoint.template.macroEnabled.12 potm
248END
249
250# and replace the original file
251mv -f /etc/mime.types.tmp$$ /etc/mime.types 2>/dev/null
252
253# update /etc/mailcap only at initial install
254if [ "$1" = 1 ]
255then
256  # backing out existing entries to avoid duplicates
257  sed '
258/^# LibreOffice/d
259/^application\/vnd\.oasis\.opendocument/d
260/^application\/vnd\.openofficeorg/d
261/^application\/vnd\.sun/d
262/^application\/vnd\.stardivision/d
263/^application\/vnd\.ms-word/d
264/^application\/vnd\.ms-excel/d
265/^application\/vnd\.ms-powerpoint/d
266/^application\/x-star/d
267/excel/d
268/ms[-]*word/d
269/powerpoint/d
270' /etc/mailcap 2>/dev/null >> /etc/mailcap.tmp$$
271
272  # now append our stuff to the temporary file
273  cat >> /etc/mailcap.tmp$$ << END
274# LibreOffice
275application/vnd.oasis.opendocument.text; %unixfilename -view %s
276application/vnd.oasis.opendocument.text-flat-xml; %unixfilename -view %s
277application/vnd.oasis.opendocument.text-template; %unixfilename -view %s
278application/vnd.oasis.opendocument.text-web; %unixfilename -view %s
279application/vnd.oasis.opendocument.text-master; %unixfilename -view %s
280application/vnd.sun.xml.writer; %unixfilename -view %s
281application/vnd.sun.xml.writer.template; %unixfilename -view %s
282application/vnd.sun.xml.writer.global; %unixfilename -view %s
283application/vnd.stardivision.writer; %unixfilename -view %s
284application/vnd.stardivision.writer-global; %unixfilename -view %s
285application/x-starwriter; %unixfilename -view %s
286application/vnd.oasis.opendocument.formula; %unixfilename -view %s
287application/vnd.sun.xml.math; %unixfilename -view %s
288application/vnd.stardivision.math; %unixfilename -view %s
289application/x-starmath; %unixfilename -view %s
290application/msword; %unixfilename -view %s
291application/vnd.oasis.opendocument.spreadsheet; %unixfilename -view %s
292application/vnd.oasis.opendocument.spreadsheet-flat-xml; %unixfilename -view %s
293application/vnd.oasis.opendocument.spreadsheet-template; %unixfilename -view %s
294application/vnd.sun.xml.calc; %unixfilename -view %s
295application/vnd.sun.xml.calc.template; %unixfilename -view %s
296application/vnd.stardivision.calc; %unixfilename -view %s
297application/x-starcalc; %unixfilename -view %s
298application/vnd.stardivision.chart; %unixfilename -view %s
299application/x-starchart; %unixfilename -view %s
300application/excel; %unixfilename -view %s
301application/msexcel; %unixfilename -view %s
302application/vnd.ms-excel; %unixfilename -view %s
303application/x-msexcel; %unixfilename -view %s
304application/vnd.oasis.opendocument.presentation; %unixfilename -view %s
305application/vnd.oasis.opendocument.presentation-flat-xml; %unixfilename -view %s
306application/vnd.oasis.opendocument.presentation-template; %unixfilename -view %s
307application/vnd.sun.xml.impress; %unixfilename -view %s
308application/vnd.sun.xml.impress.template; %unixfilename -view %s
309application/vnd.stardivision.impress; %unixfilename -view %s
310application/x-starimpress; %unixfilename -view %s
311application/powerpoint; %unixfilename -view %s
312application/mspowerpoint; %unixfilename -view %s
313application/vnd.ms-powerpoint; %unixfilename -view %s
314application/x-mspowerpoint; %unixfilename -view %s
315application/vnd.oasis.opendocument.graphics; %unixfilename -view %s
316application/vnd.oasis.opendocument.graphics-flat-xml; %unixfilename -view %s
317application/vnd.oasis.opendocument.graphics-template; %unixfilename -view %s
318application/vnd.sun.xml.draw; %unixfilename -view %s
319application/vnd.sun.xml.draw.template; %unixfilename -view %s
320application/vnd.stardivision.draw; %unixfilename -view %s
321application/x-stardraw; %unixfilename -view %s
322application/vnd.oasis.opendocument.database; %unixfilename -view %s
323application/vnd.sun.xml.base; %unixfilename -view %s
324application/vnd.openofficeorg.extension; %unixfilename %s
325application/vnd.openxmlformats-officedocument.wordprocessingml.document; %unixfilename -view %s
326application/vnd.ms-word.document.macroEnabled.12;%unixfilename -view %s
327application/vnd.openxmlformats-officedocument.wordprocessingml.template; %unixfilename -view %s
328application/vnd.ms-word.template.macroEnabled.12; %unixfilename -view %s
329application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; %unixfilename -view %s
330application/vnd.ms-excel.sheet.macroEnabled.12; %unixfilename -view %s
331application/vnd.openxmlformats-officedocument.spreadsheetml.template; %unixfilename -view %s
332application/vnd.ms-excel.template.macroEnabled.12; %unixfilename -view %s
333application/vnd.openxmlformats-officedocument.presentationml.presentation; %unixfilename -view %s
334application/vnd.ms-powerpoint.presentation.macroEnabled.12; %unixfilename -view %s
335application/vnd.openxmlformats-officedocument.presentationml.template; %unixfilename -view %s
336application/vnd.ms-powerpoint.template.macroEnabled.12; %unixfilename -view %s
337END
338
339  # and replace the original file
340  mv -f /etc/mailcap.tmp$$ /etc/mailcap
341fi
342
343if [ -x /opt/gnome/bin/update-desktop-database ]; then
344    /opt/gnome/bin/update-desktop-database -q
345elif (which update-desktop-database); then
346  update-desktop-database -q /usr/share/applications
347fi
348
349%preun
350# remove from /etc/mailcap only on de-install
351if [ "$1" = 0 ]
352then
353  # backing all entries pointing to our binary
354  sed '/%unixfilename/d' /etc/mailcap 2>/dev/null >> /etc/mailcap.tmp$$
355
356  # and replace the original file
357  mv -f /etc/mailcap.tmp$$ /etc/mailcap
358fi
359
360%postun
361if [ "$1" = 0 ] ; then # only run when erasing the package - other cases handled by the triggers
362  if [ -x /opt/gnome/bin/update-desktop-database ]; then
363    /opt/gnome/bin/update-desktop-database -q
364  elif (which update-desktop-database); then
365    update-desktop-database -q
366  fi
367# run always - both when upgrading as well as when erasing the package
368  if (which update-mime-database); then
369    update-mime-database /usr/share/mime
370  fi
371fi
372
373#run always
374for theme in gnome hicolor locolor; do
375  if [ -e /usr/share/icons/$theme/icon-theme.cache ] ; then
376   # touch it, just in case we cannot find the binary...
377    touch /usr/share/icons/$theme
378    if [ -x /opt/gnome/bin/gtk-update-icon-cache ]; then
379      /opt/gnome/bin/gtk-update-icon-cache -q /usr/share/icons/$theme
380    elif (which gtk-update-icon-cache); then
381      gtk-update-icon-cache -q /usr/share/icons/$theme
382    fi
383    # ignore errors (e.g. when there is a cache, but no index.theme)
384    true
385  fi
386done
387
388%files
389# specify stale symlinks verbatim, not as glob - a change in recent versions of
390# glibc breaks rpm unless rpm is build with internal glob-matching (issue 49374)
391# https://bugzilla.redhat.com/beta/show_bug.cgi?id=134362
392%defattr(-, root, root)
393%if "%unixfilename" != "libreoffice%productversion" && "%unixfilename" != "libreofficedev%productversion"
394# compat symlinks
395%attr(0755,root,root) /opt/%unixfilename
396%endif
397/usr/bin/*
398/usr/share/applications/%unixfilename-base.desktop
399/usr/share/applications/%unixfilename-calc.desktop
400/usr/share/applications/%unixfilename-draw.desktop
401/usr/share/applications/%unixfilename-impress.desktop
402/usr/share/applications/%unixfilename-math.desktop
403/usr/share/applications/%unixfilename-writer.desktop
404/usr/share/applications/%unixfilename-startcenter.desktop
405/usr/share/applications/%unixfilename-xsltfilter.desktop
406/usr/share/icons/gnome/*/apps/*png
407/usr/share/icons/gnome/*/apps/*svg
408/usr/share/icons/gnome/*/mimetypes/*png
409/usr/share/icons/gnome/*/mimetypes/*svg
410/usr/share/icons/hicolor/*/apps/*png
411/usr/share/icons/hicolor/*/apps/*svg
412/usr/share/icons/hicolor/*/mimetypes/*png
413/usr/share/icons/hicolor/*/mimetypes/*svg
414/usr/share/icons/locolor/*/apps/*png
415/usr/share/icons/locolor/*/apps/*svg
416/usr/share/icons/locolor/*/mimetypes/*png
417/usr/share/icons/locolor/*/mimetypes/*svg
418/usr/share/mime/packages/*
419/usr/share/appdata/*
420