File opt_gnome-compat.spec of Package opt_gnome-compat

#
# spec file for package opt_gnome-compat (Version 0.1)
#
# Copyright (c) 2009 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#

# norootforbuild


Name:           opt_gnome-compat
BuildRequires:  shared-mime-info
License:        GPL-2.0+
Group:          System/Fhs
AutoReqProv:    on
Requires:       mktemp
PreReq:         coreutils grep sed
Summary:        Directory Layout for /opt/gnome Compatibility
Version:        0.1
Release:        131
# Verbatim copy from filesystem
Source:         languages
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
# gconftool hack conflicts with gconf in /opt/gnome.
Conflicts:      gconf2 <= 2.14.0-32
# Set Provides/Obsoletes, but see the hack in %%post.
Provides:       gnome-filesystem
Obsoletes:      gnome-filesystem
PreReq:         shared-mime-info

%description
This package provides as much compatibility as possible for packages
installed into the old /opt/gnome prefix. The package installs the
/opt/gnome directory structure and configures system and GNOME
components to support this prefix.

This package deletes itself, if it does not find any useful files in
/opt/gnome. If you want to install this package, you need to have at
least one useful file in /opt/gnome or create it just now.



Authors:
--------
    Stanislav Brabec <sbrabec@suse.cz>

%prep
%setup -c -T

%install
# Create skeleton
mkdir -p $RPM_BUILD_ROOT/etc/opt
mkdir -p $RPM_BUILD_ROOT/opt
mkdir -p $RPM_BUILD_ROOT/usr/share
mkdir -p $RPM_BUILD_ROOT/var/opt
# Create directories
rm -f opt_gnome-compat.lst
BIARCHDIR=
%if "%_lib" != "lib"
BIARCHDIR=/opt/gnome/lib
%endif
NEXT_ATTR=
for DIR in \
/etc/opt/gnome \
/etc/opt/gnome/sound \
/etc/opt/gnome/sound/events \
/opt/gnome \
/opt/gnome/%_lib \
/opt/gnome/%_lib/pkgconfig \
$BIARCHDIR \
/opt/gnome/lib/gnome-applets \
/opt/gnome/bin \
/opt/gnome/include \
/opt/gnome/sbin \
/opt/gnome/share \
/opt/gnome/share/aclocal \
/opt/gnome/share/application-registry \
/opt/gnome/share/applications \
/opt/gnome/share/backgrounds \
/opt/gnome/share/backgrounds/scalable \
/opt/gnome/share/control-center \
/opt/gnome/share/control-center/capplets \
/opt/gnome/share/devhelp \
/opt/gnome/share/devhelp/books \
/opt/gnome/share/gnome \
/opt/gnome/share/gnome-2.0 \
/opt/gnome/share/gnome-2.0/ui \
/opt/gnome/share/gnome/apps \
/opt/gnome/share/gnome/apps/Settings \
/opt/gnome/share/gnome/autostart \
/opt/gnome/share/gnome/help \
/opt/gnome/share/gnome/vfolders \
/opt/gnome/share/gnome/wm-properties \
/opt/gnome/share/gtk-doc \
/opt/gnome/share/gtk-doc/html \
/opt/gnome/share/icons \
/opt/gnome/share/icons/gnome \
/opt/gnome/share/icons/GnomeCrystal \
/opt/gnome/share/idl \
%doc /opt/gnome/share/info \
/opt/gnome/share/locale \
%doc /opt/gnome/share/man \
%doc /opt/gnome/share/man/man1 \
%doc /opt/gnome/share/man/man5 \
%doc /opt/gnome/share/man/man6 \
%doc /opt/gnome/share/man/man7 \
%doc /opt/gnome/share/man/man8 \
/opt/gnome/share/mime \
/opt/gnome/share/mime/application \
/opt/gnome/share/mime/audio \
/opt/gnome/share/mime/image \
/opt/gnome/share/mime/inode \
/opt/gnome/share/mime/message \
/opt/gnome/share/mime/model \
/opt/gnome/share/mime/multipart \
/opt/gnome/share/mime/packages \
/opt/gnome/share/mime/text \
/opt/gnome/share/mime/video \
/opt/gnome/share/mime-info \
/opt/gnome/share/oaf \
/opt/gnome/share/omf \
/opt/gnome/share/pixmaps \
/opt/gnome/share/pixmaps/nautilus \
/opt/gnome/share/pkgconfig \
/opt/gnome/share/sgml \
/opt/gnome/share/sounds \
/opt/gnome/share/themes \
/var/opt/gnome \
/var/opt/gnome/cache \
; do
if test $DIR = %doc ; then
NEXT_ATTR="%doc "
else
mkdir $RPM_BUILD_ROOT$DIR
echo "$NEXT_ATTR%%dir $DIR" >>opt_gnome-compat.lst
NEXT_ATTR=
fi
done
# Create locale directories
while read LNG ; do
  mkdir -p $RPM_BUILD_ROOT/opt/gnome/share/locale/$LNG/LC_MESSAGES
  echo "%%dir /opt/gnome/share/locale/$LNG" >>opt_gnome-compat.lst
  echo "%%dir /opt/gnome/share/locale/$LNG/LC_MESSAGES" >>opt_gnome-compat.lst
done < %{SOURCE0}
# Provide /opt/gnome/bin/gconftool-2 for old gconf scriptlets.
echo -e '#! /bin/sh\nexec /usr/bin/gconftool-2 "$@"' >$RPM_BUILD_ROOT/opt/gnome/bin/gconftool-2
chmod +x $RPM_BUILD_ROOT/opt/gnome/bin/gconftool-2
# Define required variables.
mkdir $RPM_BUILD_ROOT/etc/profile.d
echo 'if test -z "$ACLOCAL_FLAGS" ; then
    export ACLOCAL_FLAGS="-I /opt/gnome/share/aclocal"
else
    export ACLOCAL_FLAGS="$ACLOCAL_FLAGS -I /opt/gnome/share/aclocal"
fi
if test -z "$PKG_CONFIG_PATH" ; then
    export PKG_CONFIG_PATH="/opt/gnome/%_lib/pkgconfig:/opt/gnome/share/pkgconfig"
else
    export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/opt/gnome/%_lib/pkgconfig:/opt/gnome/share/pkgconfig"
fi
if test -z "$INFOPATH" ; then
    export INFOPATH="/opt/gnome/share/info"
else
    export INFOPATH="$INFOPATH:/opt/gnome/share/info"
fi
if test -z "$GNOME2_PATH" ; then
    export GNOME2_PATH="/usr/local:/opt/gnome:/usr"
else
    export GNOME2_PATH="/usr/local:/opt/gnome:/usr:$GNOME2_PATH"
fi' > $RPM_BUILD_ROOT/etc/profile.d/opt_gnome-compat.sh
echo 'if ( ${?ACLOCAL_FLAGS} ) then
    setenv ACLOCAL_FLAGS "${ACLOCAL_FLAGS} -I /opt/gnome/share/aclocal"
else
    setenv ACLOCAL_FLAGS "-I /opt/gnome/share/aclocal"
endif
if ( ${?PKG_CONFIG_PATH} ) then
    setenv PKG_CONFIG_PATH ${PKG_CONFIG_PATH}:/opt/gnome/%_lib/pkgconfig:/opt/gnome/share/pkgconfig
else
    setenv PKG_CONFIG_PATH /opt/gnome/%_lib/pkgconfig:/opt/gnome/share/pkgconfig
endif
if ( ${?INFOPATH} ) then
    setenv INFOPATH ${INFOPATH}:/opt/gnome/share/info
else
    setenv INFOPATH /opt/gnome/share/info
endif
if ( ${?GNOME2_PATH} ) then
    setenv GNOME2_PATH /usr/local:/opt/gnome:/usr:${GNOME2_PATH}
else
    setenv GNOME2_PATH /usr/local:/opt/gnome:/usr
endif' > $RPM_BUILD_ROOT/etc/profile.d/opt_gnome-compat.csh
%if %suse_version > 1020
echo 'export PATH="$PATH:/opt/gnome/bin"
export MANPATH="$MANPATH:/opt/gnome/share/man"' >> $RPM_BUILD_ROOT/etc/profile.d/opt_gnome-compat.sh
echo 'setenv PATH ${PATH}:/opt/gnome/bin
setenv MANPATH ${MANPATH}:/opt/gnome/share/man' >> $RPM_BUILD_ROOT/etc/profile.d/opt_gnome-compat.csh
mkdir -p $RPM_BUILD_ROOT/etc/ld.so.conf.d
echo /opt/gnome/%{_lib} >$RPM_BUILD_ROOT/etc/ld.so.conf.d/opt_gnome-compat.conf
%endif
%if %suse_version <= 1020
# For older SuSE versions we need to define XDG environment.
# For >= 10.3 it is done automatically (Fate#301042)
# XDG_*_DIRS is in aaa_base on new products.
# Define them, only if xdg-enviroment.sh does not define it properly.
if test -f /etc/profile.d/xdg-enviroment.sh ; then
    . /etc/profile.d/xdg-enviroment.sh
fi
if ! echo $XDG_DATA_DIRS | grep -q /opt/gnome/share ; then
    echo 'if test -z "$XDG_DATA_DIRS" ; then
    export XDG_DATA_DIRS="/usr/local/share/:/usr/share/:/etc/opt/kde3/share/:/opt/kde3/share/:/opt/gnome/share/"
else
    export XDG_DATA_DIRS="$XDG_DATA_DIRS:/opt/gnome/share/"
fi' >> $RPM_BUILD_ROOT/etc/profile.d/opt_gnome-compat.sh
    echo 'if ( ${?XDG_DATA_DIRS} ) then
    setenv XDG_DATA_DIRS ${XDG_DATA_DIRS}:/opt/gnome/share/
else
    setenv XDG_DATA_DIRS /usr/local/share/:/usr/share/:/etc/opt/kde3/share/:/opt/kde3/share/:/opt/gnome/share/
endif' >> $RPM_BUILD_ROOT/etc/profile.d/opt_gnome-compat.csh
fi
if ! echo $XDG_CONFIG_DIRS | grep -q /etc/opt/gnome/xdg ; then
    echo 'if test -z "$XDG_CONFIG_DIRS" ; then
    export XDG_CONFIG_DIRS="/usr/local/etc/xdg/:/etc/xdg/:/etc/opt/gnome/xdg/"
else
    export XDG_CONFIG_DIRS="$XDG_CONFIG_DIRS:/etc/opt/gnome/xdg/"
fi' >> $RPM_BUILD_ROOT/etc/profile.d/opt_gnome-compat.sh
    echo 'if ( ${?XDG_CONFIG_DIRS} ) then
    setenv XDG_CONFIG_DIRS ${XDG_CONFIG_DIRS}:/etc/opt/gnome/xdg/
else
    setenv XDG_CONFIG_DIRS /usr/local/etc/xdg/:/etc/xdg/:/etc/opt/gnome/xdg/
endif' >> $RPM_BUILD_ROOT/etc/profile.d/opt_gnome-compat.csh
fi
%endif
%if %suse_version <= 1010
# Define search path for automake
# For >= 1020 it is done by trigger scriptlet
mkdir -p $RPM_BUILD_ROOT/usr/share/aclocal/dirlist.d
echo /opt/gnome/share/aclocal >$RPM_BUILD_ROOT/usr/share/aclocal/dirlist.d/opt_gnome-compat
%endif
mkdir -p $RPM_BUILD_ROOT/opt/gnome/share/info
touch $RPM_BUILD_ROOT/opt/gnome/share/info/dir
touch $RPM_BUILD_ROOT/opt/gnome/share/applications/mimeinfo.cache
cd $RPM_BUILD_ROOT/opt/gnome/share/mime
touch XMLnamespaces aliases generic-icons globs globs2 icons magic mime.cache subclasses treemagic types

%clean
rm -rf $RPM_BUILD_ROOT
%if %suse_version > 1010
# Define search path for automake
# For <= 1010 it is done by dirlist.d

%triggerin -- automake
if ! grep -q '^/opt/gnome/share/aclocal$' etc/aclocal_dirlist ; then
    echo /opt/gnome/share/aclocal >>etc/aclocal_dirlist
fi
%endif

%triggerin -- libbonobo
if ! grep -q '<item>/opt/gnome/%{_lib}/bonobo/servers</item>$' etc/bonobo-activation/bonobo-activation-config.xml ; then
    sed -i "/<!-- Examples: -->/i\    <item>/opt/gnome/%{_lib}/bonobo/servers</item>" etc/bonobo-activation/bonobo-activation-config.xml
fi

%triggerin -- scrollkeeper
if ! grep -q '/opt/gnome/share/omf' etc/scrollkeeper.conf ; then
    sed -i "s%%[^ ]*%%&:/opt/gnome/share/omf%%" etc/scrollkeeper.conf
fi

%pre
# Remove obsolete files kept by purge script of gnome-filesystem package.
# See gnome-filesystem.spec from openSUSE 10.2 for details.
# This script should be kept for next releases up to end of SLED 10/SLES 10
# upgrade protection cycle.
rm -rf var/adm/backup/GNOME
rm -rf var/log/YaST2/gnome-preinstall.log var/log/YaST2/gnome-postinstall.log
# Is it an update from older distribution using /opt/gnome and package
# gnome-filesystem? (<= openSUSE 10.2)
# If /opt/gnome already exists and this is the first package installation,
# then it's most probably upgrade from old product and we need cleanup.
if test "$1" = "1" -a -d opt/gnome ; then
    cat >sbin/conf.d/SuSEconfig.zzzopt_gnome-compat <<EOF
#! /bin/sh
# FIXME: If it is an installation from CD, this script must not be
# started after installation of first CD, but only after final
# installation. While installing from DVD or Build Service, this should
# be called at the end of installation.
#
#
# Search for any installed binaries, libraries or themes:
if ! find 2>/dev/null \$r/opt/gnome -type f |
	grep -v \$r/opt/gnome/bin/gconftool-2 |
	grep -v \$r/opt/gnome/share/mime |
	grep -v \$r/opt/gnome/share/applications/mimeinfo.cache |
	grep -q -v \$r/opt/gnome/share/info ; then
    # There is nothing interesting in /opt/gnome. Remove this package silently.
    rpm -r /\$r -e opt_gnome-compat
fi
#
# Remove all empty unowned directories.
# Do it 6 times to remove the deepest system directory.
# In /etc/opt/gnome, twice is sufficient.
# Do it after optional removal of opt_gnome-compat - it runs faster.
find 2>/dev/null \$r/opt/gnome -mindepth 5 -maxdepth 5 -empty -type d -exec sh -c "f={} ; if ! rpm -r /\$r --quiet -qf \\\${f#\$r} ; then rmdir {} ; fi" \;
find 2>/dev/null \$r/opt/gnome -mindepth 4 -maxdepth 4 -empty -type d -exec sh -c "f={} ; if ! rpm -r /\$r --quiet -qf \\\${f#\$r} ; then rmdir {} ; fi" \;
find 2>/dev/null \$r/opt/gnome -mindepth 3 -maxdepth 3 -empty -type d -exec sh -c "f={} ; if ! rpm -r /\$r --quiet -qf \\\${f#\$r} ; then rmdir {} ; fi" \;
find 2>/dev/null \$r/opt/gnome \$r/etc/opt/gnome -mindepth 2 -maxdepth 2 -empty -type d -exec sh -c "f={} ; if ! rpm -r /\$r --quiet -qf \\\${f#\$r} ; then rmdir {} ; fi" \;
find 2>/dev/null \$r/opt/gnome \$r/etc/opt/gnome -mindepth 1 -maxdepth 1 -empty -type d -exec sh -c "f={} ; if ! rpm -r /\$r --quiet -qf \\\${f#\$r} ; then rmdir {} ; fi" \;
find 2>/dev/null \$r/opt/gnome \$r/etc/opt/gnome -mindepth 0 -maxdepth 0 -empty -type d -exec sh -c "f={} ; if ! rpm -r /\$r --quiet -qf \\\${f#\$r} ; then rmdir {} ; fi" \;
#
# This SuSEconfig will be never more needed.
rm -f \$r/sbin/conf.d/SuSEconfig.zzzopt_gnome-compat
EOF
    chmod +x sbin/conf.d/SuSEconfig.zzzopt_gnome-compat
fi

%post
# Update MIME database to be sure that there are no orphan files.
usr/bin/update-mime-database /opt/gnome/share/mime >/dev/null 2>&1
%if %suse_version > 1010
# Define search path for automake
# For <= 1010 it is done by dirlist.d
if test -f etc/aclocal_dirlist ; then
    if ! grep -q '^/opt/gnome/share/aclocal$' etc/aclocal_dirlist ; then
	echo /opt/gnome/share/aclocal >>etc/aclocal_dirlist
    fi
fi
%endif
if test -f etc/bonobo-activation/bonobo-activation-config.xml ; then
    if ! grep -q '<item>/opt/gnome/%{_lib}/bonobo/servers</item>$' etc/bonobo-activation/bonobo-activation-config.xml ; then
	sed -i "/<!-- Examples: -->/i\    <item>/opt/gnome/%{_lib}/bonobo/servers</item>" etc/bonobo-activation/bonobo-activation-config.xml
    fi
fi
if test -f etc/scrollkeeper.conf ; then
    if ! grep -q '/opt/gnome/share/omf' etc/scrollkeeper.conf ; then
	sed -i "s%%[^ ]*%%&:/opt/gnome/share/omf%%" etc/scrollkeeper.conf
    fi
fi

%preun
# Update MIME database to be sure that there are no orphan files.
usr/bin/update-mime-database /opt/gnome/share/mime >/dev/null 2>&1

%postun
if ! test -f opt/gnome/bin/gconftool-2 ; then
# Do it only if it is a package removal
%if %suse_version > 1010
    if test -f etc/aclocal_dirlist ; then
	sed -i '\:^/opt/gnome/share/aclocal$:d' etc/aclocal_dirlist
    fi
%endif
    if test -f etc/bonobo-activation/bonobo-activation-config.xml ; then
	sed -i '\:<item>/opt/gnome/%{_lib}/bonobo/servers</item>:d' etc/bonobo-activation/bonobo-activation-config.xml
    fi
    if test -f etc/scrollkeeper.conf ; then
	sed -i 's%%:/opt/gnome/share/omf%%%%' etc/scrollkeeper.conf
    fi
fi
# This SuSEconfig will be never more needed.
# Do it unconditionally here (if it is an upgrade, it should not be created.
rm -f sbin/conf.d/SuSEconfig.zzzopt_gnome-compat

%files -f opt_gnome-compat.lst
%defattr(-,root,root)
%if %suse_version > 1020
/etc/ld.so.conf.d/opt_gnome-compat.conf
%endif
/etc/profile.d/opt_gnome-compat.*
/opt/gnome/bin/gconftool-2
%if %suse_version <= 1010
/usr/share/aclocal
%endif
%ghost /opt/gnome/share/applications/mimeinfo.cache
%ghost /opt/gnome/share/info/dir
%ghost /opt/gnome/share/mime/XMLnamespaces
%ghost /opt/gnome/share/mime/aliases
%ghost /opt/gnome/share/mime/generic-icons
%ghost /opt/gnome/share/mime/globs
%ghost /opt/gnome/share/mime/globs2
%ghost /opt/gnome/share/mime/icons
%ghost /opt/gnome/share/mime/magic
%ghost /opt/gnome/share/mime/mime.cache
%ghost /opt/gnome/share/mime/subclasses
%ghost /opt/gnome/share/mime/treemagic
%ghost /opt/gnome/share/mime/types

%changelog
* Mon Jan 19 2009 sbrabec@suse.cz
- Clean-up mime directory completely on removal (bnc#462466).
- Send expected update-mime-database complains to /dev/null.
* Tue Mar 11 2008 sbrabec@suse.cz
- Clean-up also /etc/opt/gnome (prevents keeping orphan
  /etc/opt/gnome/gconf/schemas).
* Thu Feb 22 2007 sbrabec@suse.cz
- Remove obsolete files kept by gnome-filesystem package.
- Fixed cleanup and removal scriptlets.
* Fri Feb 09 2007 sbrabec@suse.cz
- Removed /opt/gnome/share/autostart (#243027).
* Tue Feb 06 2007 sbrabec@suse.cz
- Use correct filename for ld.so.conf.d entry (James Ogley,
  [#242563]).
* Wed Jan 31 2007 sbrabec@suse.cz
- Created new package, based on its predecessor - gnome-filesystem.