File webyast-base.spec of Package webyast-base

# spec file for package webyast-base
# Copyright (c) 2013 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

Name:           webyast-base
Version:        0.3.45
Release:        0
Provides:       yast2-webservice = %{version}
Obsoletes:      yast2-webservice < %{version}
Provides:       webyast-language-ws = 0.1.0
Obsoletes:      webyast-language-ws <= 0.1.0

Obsoletes:      webyast-base-ui < %{version}
Obsoletes:      webyast-base-ws < %{version}
Obsoletes:      webyast-firstboot-ws < %{version}
Obsoletes:      yast2-webclient < %{version}
Obsoletes:      yast2-webservice < %{version}
Provides:       webyast-base-ui = %{version}
Provides:       webyast-base-ws = %{version}
Provides:       webyast-firstboot-ws = %{version}
Provides:       yast2-webclient = %{version}
Provides:       yast2-webservice = %{version}

%if 0%{?suse_version} == 0 || %suse_version > 1110
# 11.2 or newer

%if 0%{?suse_version} > 1120
# since 11.3, they are in a separate subpackage
Requires:       sysvinit-tools
# Require startproc respecting -p, bnc#559534#c44
Requires:       sysvinit > 2.86-215.2
Requires:       yast2-core >= 2.18.10
# 11.1 or SLES11
Requires:       sysvinit > 2.86-195.3.1
Requires:       yast2-core >=
%if 0%{?suse_version} == 1220
Requires:       rubygem-passenger-nginx >= 3.0.12
Requires:       rubygem-passenger-nginx >= 3.0.14
Requires:       check-create-certificate
Requires:       nginx >= 1.0.15
Requires:       rubygem-ruby-dbus
Requires:       syslog
Requires:       yast2-dbus-server

PreReq:         rubygem-webyast-rake-tasks >= 0.3.7
Requires:       webyast-base-branding
PreReq:         rubygem-bundler
# 634404
Recommends:     logrotate
%if 0%{?suse_version} == 0 || %suse_version > 1110
PreReq:         polkit, rubygem-polkit1 >= 0.1.0
PreReq:         rubygem-rake
# <11.1 or SLES11
PreReq:         PolicyKit, rubygem-polkit
PreReq:         rubygem-rake < 0.9
PreReq:         rubygem-sqlite3 >= 1.3.6
PreReq:         rubygem-rails-3_2 >= 3.2.3
PreReq:         rubygem-fast_gettext, rubygem-gettext_i18n_rails

# conflict with all old Webyast-1.2 plugins (to force upgrade)
Conflicts:      webyast-activedirectory-ui < 0.3.0
Conflicts:      webyast-firewall-ui < 0.3.0
Conflicts:      webyast-ldap-ui < 0.3.0
Conflicts:      webyast-licenses-ui < 0.3.0
Conflicts:      webyast-mail-ui < 0.3.0
Conflicts:      webyast-network-ui < 0.3.0
Conflicts:      webyast-reboot-ui < 0.3.0
Conflicts:      webyast-registration-ui < 0.3.0
Conflicts:      webyast-roles-ui < 0.3.0
Conflicts:      webyast-root-user-ui < 0.3.0
Conflicts:      webyast-services-ui < 0.3.0
Conflicts:      webyast-slms-ui < 0.3.0
Conflicts:      webyast-software-ui <= 0.3.20
Conflicts:      webyast-status-ui < 0.3.0
Conflicts:      webyast-time-ui < 0.3.0
Conflicts:      webyast-users-ui < 0.3.0

Conflicts:      webyast-activedirectory-ws < 0.3.0
Conflicts:      webyast-firewall-ws < 0.3.0
Conflicts:      webyast-firstboot-ws < 0.3.0
Conflicts:      webyast-kerberos-ws < 0.3.0
Conflicts:      webyast-ldap-ws < 0.3.0
Conflicts:      webyast-licenses-ws < 0.3.0
Conflicts:      webyast-mail-ws < 0.3.0
Conflicts:      webyast-network-ws < 0.3.0
Conflicts:      webyast-ntp-ws < 0.3.0
Conflicts:      webyast-reboot-ws < 0.3.0
Conflicts:      webyast-registration-ws < 0.3.0
Conflicts:      webyast-roles-ws < 0.3.0
Conflicts:      webyast-root-user-ws < 0.3.0
Conflicts:      webyast-services-ws < 0.3.0
Conflicts:      webyast-slms-ws < 0.3.0
Conflicts:      webyast-software-ws <= 0.3.20
Conflicts:      webyast-status-ws < 0.3.0
Conflicts:      webyast-time-ws < 0.3.0
Conflicts:      webyast-users-ws < 0.3.0

Summary:        WebYaST - base components
License:        LGPL-2.1 and GPL-2.0 and Apache-2.0
Group:          Productivity/Networking/Web/Utilities
Source:         www.tar.bz2
Source1:        webyastPermissionsService.rb
Source2:        webyast.permissions.conf
Source3:        webyast.permissions.service.service
Source4:        org.opensuse.yast.permissions.policy
Source5:        grantwebyastrights
Source6:        yast_user_roles
Source9:        rcwebyast
Source10:       webyast
Source12:       nginx.conf
Source13:       control_panel.yml
Source14:       config.yml
Source16:       update_webyast_service
Source17:       40-default-webyast-base.rules

BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildRequires:  pkg-config
BuildRequires:  ruby
BuildRequires:  rubygem-mocha
# if we run the tests during build, we need most of Requires here too,
# except for deployment specific stuff
BuildRequires:  dbus-1
BuildRequires:  rubygem-rails-3_2
BuildRequires:  rubygem-ruby-dbus
BuildRequires:  rubygem-sqlite3 >= 1.3.6
BuildRequires:  rubygem-webyast-rake-tasks >= 0.3.7
%if 0%{?suse_version} == 0 || %suse_version > 1110
BuildRequires:  polkit
BuildRequires:  rubygem-polkit1
# <11.1 or SLES11
BuildRequires:  PolicyKit
BuildRequires:  rubygem-polkit
%if 0%{?suse_version} > 1220
BuildRequires:  polkit-default-privs
# the testsuite is run during build
BuildRequires:  nginx >= 1.0
BuildRequires:  rubygem-builder-3_0
BuildRequires:  rubygem-bundler
BuildRequires:  rubygem-cancan
BuildRequires:  rubygem-devise
BuildRequires:  rubygem-devise-i18n
BuildRequires:  rubygem-devise_unix2_chkpwd_authenticatable
BuildRequires:  rubygem-haml
BuildRequires:  rubygem-mocha
BuildRequires:  rubygem-test-unit

BuildRequires:  rubygem-gettext

BuildRequires:  rubygem-factory_girl
BuildRequires:  rubygem-factory_girl_rails
BuildRequires:  rubygem-mocha

Requires:       rubygem-builder-3_0
Requires:       rubygem-fast_gettext
Requires:       rubygem-gettext_i18n_rails
Requires:       rubygem-haml
Requires:       rubygem-rails-i18n
Requires:       rubygem-sqlite3

Requires:       rubygem-cancan
Requires:       rubygem-devise
Requires:       rubygem-devise-i18n
Requires:       rubygem-devise_unix2_chkpwd_authenticatable

# This is for Hudson (build service) to setup the build env correctly
%if 0
BuildRequires:  rubygem-rcov >=
BuildRequires:  rubygem-test-unit

# we do not necessarily need any UI in case of WebYaST
Provides:       yast2_ui
Provides:       yast2_ui_pkg

# rpmlint warns about file duplicates, this should take care but
# doesn't build (?!)
#%if 0%{?suse_version} > 1020
#BuildRequires:  fdupes

BuildArch:      noarch

%package testsuite
Requires:       webyast-base = %{version}
Summary:        Testsuite for webyast-base package
Group:          Productivity/Networking/Web/Utilities

%define pkg_home /var/lib/%{webyast_user}

Requires:       rubygem-factory_girl
Requires:       rubygem-factory_girl_rails
Requires:       rubygem-mocha
Requires:       tidy

WebYaST - Core components for UI and REST based interface to system manipulation.
    Duncan Mac-Vicar Prett <>
    Klaus Kaempf <>
    Bjoern Geuken <>
    Stefan Schubert <>

%description testsuite
Testsuite for core WebYaST package.

%package branding-default
Provides:       webyast-base-branding = %{version}
PreReq:         %{name} = %{version}
Conflicts:      otherproviders(webyast-base-branding)
Supplements:    packageand(webyast-base:branding-default)

Provides:       webyast-base-ui-branding-default = %{version}
Obsoletes:      webyast-base-ui-branding-default < %{version}

Summary:        Branding package for webyast-base package
Group:          Productivity/Networking/Web/Utilities

%description branding-default
This package contains css, icons and images for webyast-base package.

%setup -q -n www

%if %suse_version <= 1110
# build *.mo files (redirect sterr to /dev/null as it contains tons of warnings about obsoleted (commented) msgids)
# if the task fails run it again and show the details of the failure for debugging
LANG=en rake gettext:pack 2> /dev/null || LANG=en rake -t gettext:pack
# gettext:pack for some reason creates empty db/development.sqlite3 file
rm -rf db/development.sqlite3

# precompile assets
rake assets:precompile

# split manifest file
rake assets:split_manifest
rm -rf public/assets/manifest.yml

# cleanup
rm -rf tmp
rm -rf log

# remove Gemfile.lock created by the above rake calls
rm Gemfile.lock


%if %suse_version <= 1110
# run the testsuite
RAILS_ENV=test rake db:migrate
rake tmp:create
RAILS_ENV=test $RPM_BUILD_ROOT%{webyast_dir}/test/dbus-launch-simple rake test


%if %suse_version <= 1110

# Install all web and frontend parts.
mkdir -p $RPM_BUILD_ROOT%{webyast_dir}
cp -a * $RPM_BUILD_ROOT%{webyast_dir}/
rm -f $RPM_BUILD_ROOT%{webyast_dir}/log
rm -rf $RPM_BUILD_ROOT/%{webyast_dir}/po
rm -f $RPM_BUILD_ROOT%{webyast_dir}/COPYING

# install production mode Gemfile
rake -s gemfile:production > $RPM_BUILD_ROOT%{webyast_dir}/Gemfile
# install test mode Gemfile
rake -s gemfile:test > $RPM_BUILD_ROOT%{webyast_dir}/Gemfile.test
# install assets mode Gemfile
rake -s gemfile:assets > $RPM_BUILD_ROOT%{webyast_dir}/Gemfile.assets

# remove .gitkeep files
find $RPM_BUILD_ROOT%{webyast_dir} -name .gitkeep -delete

# remove *.po files (compiled *.mo files are sufficient)
find $RPM_BUILD_ROOT%{webyast_dir}/locale -name '*.po' -delete

%{__install} -d -m 0755                            \
    %{buildroot}%{pkg_home}/sockets/               \
    %{buildroot}%{pkg_home}/cache/                 \
    %{buildroot}%{_sbindir}                        \
# init script
%{__install} -D -m 0755 -T %SOURCE9 \
%{__ln_s} -f %{_sysconfdir}/init.d/%{webyast_service} %{buildroot}%{_sbindir}/rc%{webyast_service}

# configure nginx web service
mkdir -p $RPM_BUILD_ROOT/etc/nginx/certs

# configure nginx web service
mkdir -p $RPM_BUILD_ROOT/etc/webyast/
install -m 0644 %SOURCE12 $RPM_BUILD_ROOT/etc/webyast/
# create symlinks to nginx config files
ln -s /etc/nginx/fastcgi.conf $RPM_BUILD_ROOT/etc/webyast
ln -s /etc/nginx/fastcgi_params $RPM_BUILD_ROOT/etc/webyast
ln -s /etc/nginx/koi-utf $RPM_BUILD_ROOT/etc/webyast
ln -s /etc/nginx/koi-win $RPM_BUILD_ROOT/etc/webyast
ln -s /etc/nginx/mime.types $RPM_BUILD_ROOT/etc/webyast
ln -s /etc/nginx/scgi_params $RPM_BUILD_ROOT/etc/webyast
ln -s /etc/nginx/uwsgi_params $RPM_BUILD_ROOT/etc/webyast
ln -s /etc/nginx/win-utf $RPM_BUILD_ROOT/etc/webyast

# Policies
mkdir -p $RPM_BUILD_ROOT/usr/share/%{webyast_polkit_dir}
install -m 0644 %SOURCE4 $RPM_BUILD_ROOT/usr/share/%{webyast_polkit_dir}
install -m 0644 %SOURCE6 $RPM_BUILD_ROOT/etc/
install -m 0555 %SOURCE5 $RPM_BUILD_ROOT/usr/sbin/
%if %suse_version >= 1230
mkdir -p $RPM_BUILD_ROOT/etc/polkit-1/rules.d/
install -m 0644 %SOURCE17 $RPM_BUILD_ROOT/etc/polkit-1/rules.d/

# firewall service definition, bnc#545627
mkdir -p $RPM_BUILD_ROOT/etc/sysconfig/SuSEfirewall2.d/services
install -m 0644 %SOURCE10 $RPM_BUILD_ROOT/etc/sysconfig/SuSEfirewall2.d/services

# logrotate configuration bnc#634404
mkdir $RPM_BUILD_ROOT/etc/logrotate.d
install -m 0644 %SOURCE11 $RPM_BUILD_ROOT/etc/logrotate.d

#  create webyast dirs (config, var and data)
mkdir -p $RPM_BUILD_ROOT/etc/webyast
mkdir -p $RPM_BUILD_ROOT/var/lib/webyast
mkdir -p $RPM_BUILD_ROOT/usr/share/webyast

#  create empty tmp directory
mkdir -p $RPM_BUILD_ROOT%{webyast_dir}/tmp
mkdir -p $RPM_BUILD_ROOT%{webyast_dir}/tmp/cache
mkdir -p $RPM_BUILD_ROOT%{webyast_dir}/tmp/pids
mkdir -p $RPM_BUILD_ROOT%{webyast_dir}/tmp/sessions
mkdir -p $RPM_BUILD_ROOT%{webyast_dir}/tmp/sockets

# install YAML config file
mkdir -p $RPM_BUILD_ROOT/etc/webyast/
cp %SOURCE13 $RPM_BUILD_ROOT/etc/webyast/

%if %suse_version <= 1110
cp %SOURCE14 $RPM_BUILD_ROOT/etc/webyast/
cp %SOURCE15 $RPM_BUILD_ROOT/etc/webyast/config.yml

# install permissions service
mkdir -p $RPM_BUILD_ROOT/usr/sbin/
install -m 0500 %SOURCE1 $RPM_BUILD_ROOT/usr/sbin/
mkdir -p $RPM_BUILD_ROOT/etc/dbus-1/system.d/
install -m 0644 %SOURCE2 $RPM_BUILD_ROOT/etc/dbus-1/system.d/
mkdir -p $RPM_BUILD_ROOT/usr/share/dbus-1/system-services/
install -m 0444 %SOURCE3 $RPM_BUILD_ROOT/usr/share/dbus-1/system-services/

#create dummy update-script
mkdir -p %buildroot/var/adm/update-scripts
touch %buildroot/var/adm/update-scripts/%name-%version-%release-1

# for basesystem setup (firstboot)
mkdir -p $RPM_BUILD_ROOT%{webyast_vardir}/basesystem

# install restart script
install -m 0755 %SOURCE16 $RPM_BUILD_ROOT/usr/sbin/

# restart Webyast at the end of the transaction

# create restart script for *-branding subpackage
ln -s /usr/sbin/update_webyast_service $RPM_BUILD_ROOT/var/adm/update-scripts/webyast-base-branding-default-%version-%release-update



# e.g. adding user
/usr/sbin/groupadd -r %{webyast_user} &>/dev/null ||:
/usr/sbin/useradd  -g %{webyast_user} -s /bin/false -r -c "User for WebYaST" -d %{pkg_home} %{webyast_user} &>/dev/null ||:

# services will not be restarted correctly if
# the package name will changed while the update
# So the service will be restarted by an update-script
# which will be called AFTER the installation
if /bin/rpm -q webyast-base-ui > /dev/null ; then
  echo "renaming webyast-base-ui to webyast-base"
  if /sbin/chkconfig -l yastwc 2> /dev/null | grep " 3:on " >/dev/null ; then
    echo "webyast is inserted into the runlevel"
    echo "#!/bin/sh" > %name-%version-%release-1
    echo "/sbin/chkconfig -a webyast" >> %name-%version-%release-1
    echo "/usr/sbin/rcwebyast restart" >> %name-%version-%release-1
    if /usr/sbin/rcyastwc status > /dev/null ; then
      echo "webyast is running"
      echo "#!/bin/sh" > %name-%version-%release-1
      echo "/usr/sbin/rcwebyast restart" >> %name-%version-%release-1

  # move the current SSL certificates to the new location
  if [ -f /etc/lighttpd/certs/webyast.pem ]; then
    mkdir -p /etc/nginx/certs
    mv /etc/lighttpd/certs/webyast* /etc/nginx/certs
#We are switching from lighttpd to nginx. So lighttpd has to be killed
#at first
if rpm -q --requires %{name}|grep lighttpd > /dev/null ; then
  if /usr/sbin/rcyastws status > /dev/null ; then
    echo "yastws is running under lighttpd -> switching to nginx"
    /usr/sbin/rcyastws stop > /dev/null

    # check if the restart file already exists
    if [ ! -f %name-%version-%release-1 ] ; then
      echo "#!/bin/sh" > %name-%version-%release-1
      echo "/usr/sbin/rcwebyast restart" >> %name-%version-%release-1
if [ -f %name-%version-%release-1 ] ; then
  install -D -m 755 %name-%version-%release-1 /var/adm/update-scripts
  rm %name-%version-%release-1
  echo "Please check the service runlevels and restart WebYaST service with \"rcwebyast restart\" if the update has not been called with zypper,yast or packagekit"
exit 0

%fillup_and_insserv %{webyast_service}

%if %suse_version < 1230
#granting permissions for webyast
/usr/sbin/grantwebyastrights --user %{webyast_user} --action grant --policy org.opensuse.yast.module-manager.import > /dev/null ||:

# granting all permissions for root
/usr/sbin/grantwebyastrights --user root --action grant > /dev/null ||:

# create database
cd %{webyast_dir}

# force refreshing the Gemfile.lock
rm -f Gemfile.lock

#migrate database
%if %suse_version <= 1110
(umask 0077; RAILS_ENV=production rake db:migrate)
chown %{webyast_user}: db/*.sqlite3
chmod o-r db/production.sqlite3
chown -R %{webyast_user}: /var/log/webyast
chmod -R o-r /var/log/webyast
echo "Database is ready"

# try-reload D-Bus config (bnc#635826)
# check if the system bus socket is present to avoid errors/hangs during RPM build (bnc#767066)
if [ -S /var/run/dbus/system_bus_socket ]; then
  echo "Reloading DBus configuration..."
  dbus-send --print-reply --system --dest=org.freedesktop.DBus / org.freedesktop.DBus.ReloadConfig >/dev/null ||:

# update firewall config
if [ -f /etc/sysconfig/SuSEfirewall2 ]; then
  if grep -q webyast-ui /etc/sysconfig/SuSEfirewall2; then
    echo "Updating firewall config..."
    sed -i "s/\(^[ \t]*FW_CONFIGURATIONS_.*[ \t]*=[ \t]*\".*[ \t]*\)webyast-ui\(.*$\)/\1webyast\2/" /etc/sysconfig/SuSEfirewall2

    # reload the changes
    echo "Restarting firewall..."
    /sbin/rcSuSEfirewall2 try-restart

# move the base system status to avoid running it after update
if [ -f /var/lib/yastws/basesystem/finish ]; then
    mv /var/lib/yastws/basesystem/finish /var/lib/webyast/basesystem/


%stop_on_removal %{webyast_service}

%restart_on_update %{webyast_service}

# restart webyast on nginx update (bnc#559534)
%triggerin -- nginx
%restart_on_update %{webyast_service}

%post branding-default
# make sure the directory exists
mkdir -p /var/lib/webyast

%postun branding-default

#this /etc/webyast is for nginx conf for webyast
%dir /etc/webyast
%dir %{webyast_dir}
%attr(-,root,root) %{_datadir}/%{webyast_polkit_dir}
%attr(-,%{webyast_user},%{webyast_user}) %dir %{pkg_home}
%attr(-,%{webyast_user},%{webyast_user}) %dir %{pkg_home}/sockets
%attr(-,%{webyast_user},%{webyast_user}) %dir %{pkg_home}/cache
%attr(-,%{webyast_user},%{webyast_user}) %dir %{_var}/log/%{webyast_user}

# include the restart script
%attr(755,root,root) /usr/sbin/update_webyast_service

#logrotate configuration file
%config(noreplace) /etc/logrotate.d/

%dir %{_datadir}/webyast
%dir %attr(-,root,root) /var/lib/webyast
%attr(-,%{webyast_user},%{webyast_user}) %dir %{webyast_dir}/db
%ghost %{webyast_dir}/db/schema.rb
%dir %{webyast_dir}/public
%dir %{webyast_dir}/config
#also users can run granting script, as permissions is handled by polkit right for granting permissions
%attr(555,root,root) /usr/sbin/grantwebyastrights
%attr(755,root,root) %{webyast_dir}/
%attr(500,root,root) /usr/sbin/webyastPermissionsService.rb
%attr(444,root,root) /usr/share/dbus-1/system-services/webyast.permissions.service.service
%attr(644,root,root) %config /etc/dbus-1/system.d/webyast.permissions.conf
%doc %{webyast_dir}/README
%attr(-,%{webyast_user},%{webyast_user}) %{webyast_dir}/tmp
%dir %{webyast_vardir}
%attr(-,%{webyast_user},%{webyast_user}) %dir %{webyast_vardir}/basesystem

%dir /etc/nginx/certs
#this /etc/webyast is for webyast configuration files
%dir /etc/webyast/
%config /etc/webyast/control_panel.yml
%config /etc/webyast/config.yml
#nginx stuff
%config /etc/webyast/nginx.conf
%config /etc/webyast/fastcgi.conf
%config /etc/webyast/fastcgi_params
%config /etc/webyast/koi-utf
%config /etc/webyast/koi-win
%config /etc/webyast/mime.types
%config /etc/webyast/scgi_params
%config /etc/webyast/uwsgi_params
%config /etc/webyast/win-utf

%config /etc/sysconfig/SuSEfirewall2.d/services/webyast
%config /usr/share/%{webyast_polkit_dir}/org.opensuse.yast.permissions.policy
%if %suse_version >= 1230
%config %{webyast_dir}/config/initializers/secret_token.rb
%config %{webyast_dir}/config/environment.rb
%config(noreplace) /etc/yast_user_roles
%config %{_sysconfdir}/init.d/%{webyast_service}

### include JS assets
%exclude %{webyast_dir}/app/assets/icons
%exclude %{webyast_dir}/app/assets/images
%exclude %{webyast_dir}/app/assets/stylesheets

%exclude %{webyast_dir}/test

%ghost %attr(755,root,root) /var/adm/update-scripts/%name-%version-%release-1

%files testsuite

%files branding-default
### include css, icons and images 
# exclude files belonging to the base
%exclude %{webyast_dir}/app/assets/javascripts/*
%exclude %{webyast_dir}/public/assets/*.js
%exclude %{webyast_dir}/public/assets/*.js.gz
%exclude %{webyast_dir}/public/assets/manifest.yml.base
# restart script


openSUSE Build Service is sponsored by