File macros.openstack-suse of Package openstack-macros

# Macros for building OpenStack RPMs.
#
# Copyright: (c) 2015 SUSE Linux GmbH

# python specific macros to be compatible with other distros to share OpenStack
# upstream packaging
%__python2 /usr/bin/python2
%python2_sitelib %(%{__python2} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")
%python2_sitearch %(%{__python2} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))")
# Make %license work like %doc for now - discussion started with openSUSE
%_defaultlicensedir %_defaultdocdir

%py_req_cleanup true

# Create given user with given group (to be used as %pre scriptlet for
# openstack related daemons). Also migrates away from openstack- prefixed
# users/group if it exists
# Optional:
#   -u userid to pick
#   -g groupid to pick
#   -s shell to pick
# Example: openstack_pre_user_group_create keystone keystone
%openstack_pre_user_group_create(u:g:s:) \
    # Migrate away from old openstack- prefix \
    oldu=$(getent passwd openstack-%1 |cut -d: -f3) || : \
    [ -n "$oldu" ] && { \
        oldu="-o -u $oldu"   \
        userdel openstack-%1  \
    } \
    getent group %2 >/dev/null || { \
        # Migrate away from old openstack- prefix \
        oldg=$(getent group openstack-%2 |cut -d: -f3) || : \
        [ -n "$oldg" ] && oldg="-o -g $oldg" \
        [ -n "$oldg" ] && groupdel openstack-%2 || : \
        [ -z "$oldg" ] && oldg="%{-g:-g %{-g*}}" \
        groupadd -r %2 $oldg \
    } \
    [ -z "$oldu" ] && oldu="%{-u:-u %{-u*}}" \
    getent passwd %1 >/dev/null || { \
        useradd -r -g %2 $oldu -d %{_localstatedir}/lib/%1 %{-s:-s %{-s*}}%{!-s: -s /sbin/nologin} -c "OpenStack %1 Daemon" %1 \
    } \
%nil

# Create a fake tempest plugin entry point which will
# resides under %{python2_sitelib}/%{service}_tests.egg-info.
# The prefix is %py2_entrypoint %{modulename} %{service}
# where service is the name of the openstack-service or the modulename
# It should used under %install section
# the generated %{python2_sitelib}/%{service}_tests.egg-info
# will go under %files section of tempest plugin subpackage
# Example: %py2_entrypoint %{modulename} %{service}
# In most of the cases %{service} is same as %{modulename}
# but in case of neutron plugins it is different
# like servicename is neutron-lbaas and modulename is neutron_lbass
%py2_entrypoint() \
egg_path=%{buildroot}%{python2_sitelib}/%{1}-*.egg-info \
tempest_egg_path=%{buildroot}%{python2_sitelib}/%{1}_tests.egg-info \
mkdir $tempest_egg_path \
echo %{1} >$tempest_egg_path/top_level.txt \
grep "tempest\\|Tempest" %{1}.egg-info/entry_points.txt >$tempest_egg_path/entry_points.txt \
sed -i "/tempest\\|Tempest/d" $egg_path/entry_points.txt \
cp -r $egg_path/PKG-INFO $tempest_egg_path \
sed -i "s/%{2}/%{1}_tests/g" $tempest_egg_path/PKG-INFO \
%nil

#
# Apache related macros
#
%apache_name apache2
%apache_site_dir %{_sysconfdir}/%{apache_name}/vhosts.d/
%apache_conf_dir %{_sysconfdir}/%{apache_name}/conf.d/
%apache_user wwwrun
%apache_group www
openSUSE Build Service is sponsored by