SUSE Build Tutorial/GConf scriptlets

From openSUSE


Contents

GConf scriptlets for dummies

A package that includes gconf schemas needs to update the gconf database upon installation. In the past, this was tedious for packagers. Today, we have RPM macros to automate much of the process, and it is much easier.

From openSUSE 10.3 onward, the macro is available "out of the box". It's provided by the gconf2 package, in the file /etc/rpm/macros.gconf2.


What follows are two examples: a simple example that most packages can copy directly, and a more complicated example.

Simple Example

Add the following line to the end of the spec file's preamble:

%gconf_schemas_prereq

This needs to be the last line in the preamble.

In the install section, use the following:

%install
%makeinstall
%find_gconf_schemas

Of course, this is a bare minimum, and install sections can be and often are more complicated.

Add preinstall, preuninstall, and posttransaction sections:

%pre -f %{name}.schemas_pre

%preun -f %{name}.schemas_preun

%posttrans -f %{name}.schemas_posttrans

Again, this is a bare minimum. These sections can also be more complicated, with each consisting of more than one line.

In the file list section, use the following:

%files -f %{name}.schemas_list

Complicated Example

When a package contains a number of subpackages, each of which installs its own gconf schemas, it is necessary to go through some contortions. The following spec file snippets come from gnome-panel.spec (as of 17 October 2007), edited slightly for clarity.

The spec file starts off just as simpler packages' spec files do, ending with %gconf_schemas_prereq.

Subpackages also use this macro:

%package extras
Summary:        Extra panel applets
Group:          System/GUI/GNOME
Requires:       %{name} = %{version} fortune
Obsoletes:      gnome-panel-nld-extras
%gconf_schemas_prereq

Not all subpackages use it, though. For instance, gnome-panel-doc does not use it.

Its install section is as follows:

%install
%makeinstall
...
%def_gconf_schemas %{name}
%add_gconf_schemas clock
%add_gconf_schemas panel-compatibility
%add_gconf_schemas panel-general
%add_gconf_schemas panel-global
%add_gconf_schemas panel-object
%add_gconf_schemas panel-toplevel
%add_gconf_schemas window-list
%add_gconf_schemas workspace-switcher

These are schemas installed in the main gnome-panel package. The spec file continues with:

%def_gconf_schemas %{name}-extras
%add_gconf_schemas fish

These schemas belong to the gnome-panel-extras package.

And the schemas part of the install section is ended thus:

%end_gconf_schemas

Later, we have the following:

%pre extras -f %{name}-extras.schemas_pre
%preun extras -f %{name}-extras.schemas_preun
%posttrans extras -f %{name}-extras.schemas_posttrans

The files section for the main gnome-panel package begins thus:

%files -f %{name}.schemas_list

And the files section for the -extras subpackage begins thus:

%files extras %{name}-extras.schemas_list

Combining the gconf macros with other macros

When we create more than one list of files, to ultimately be included in a files section, we use the following:

%install
...
%find_gconf_schemas
%find_lang %{name}
cat %{name}.schemas_list %{name}.lang >%{name}.lst

And, later in the spec file:

%files -f %{name}.lst

Keep in mind

In your spec file, you don't need to name any schema files explicitly; in particular, you don't need to know what their suffix is.

The file %{name}.schemas_list is created automatically, and you don't need to edit it by hand. This is important, because applications can crash when they're not properly installed.

If you're curious about the contents the schema list or any of the preinstall, preuninstall, and posttransaction scripts created, you can inspect them. They'll be viewable in /usr/src/packages/BUILD/%{name}-%{version}/ in your build chroot, with the suffixes .schemas_list, .schemas_pre, .schemas_preun, and .schemas_posttrans.

Older Distributions

When building packages for older distributions, the macro isn't directly available. To take advantage of the macro, you can use the following in your spec file:

%if %suse_version <= 1020
BuildRequires: gconf2-rpm-macros
%endif

These lines are typically placed after other BuildRequires: lines, but before the rest of the spec file. The gconf2-rpm-macros package is available in the GNOME:Community project/repository.

For more information