fixes in generating job and cache IDs
[opensuse:yast-rest-service.git] / webservice / package / webyast-base-ws.spec
1 #
2 # spec file for package webyast-base-ws (Version 0.1.19)
3 #
4 # Copyright (c) 2008 SUSE LINUX Products GmbH, Nuernberg, Germany.
5 # This file and all modifications and additions to the pristine
6 # package are under the same license as the package itself.
7 #
8 # Please submit bugfixes or comments via http://bugs.opensuse.org/
9 #
10
11
12 Name:           webyast-base-ws
13 Provides:       yast2-webservice = %{version}
14 Obsoletes:      yast2-webservice < %{version}
15 Provides:       webyast-language-ws = 0.1.0
16 Obsoletes:      webyast-language-ws <= 0.1.0
17
18 %if 0%{?suse_version} == 0 || %suse_version > 1110
19 # 11.2 or newer
20
21 %if 0%{?suse_version} > 1120
22 # since 11.3, they are in a separate subpackage
23 Requires:       sysvinit-tools
24 %else
25 # Require startproc respecting -p, bnc#559534#c44
26 Requires:       sysvinit > 2.86-215.2
27 %endif
28 Requires:       yast2-core >= 2.18.10
29 %else
30 # 11.1 or SLES11
31 Requires:       yast2-core >= 2.17.30.1
32 Requires:       sysvinit > 2.86-195.3.1
33 %endif
34 Requires:       nginx, rubygem-passenger-nginx
35 Requires:       ruby-fcgi, sqlite, syslog-ng
36 %if 0%{?suse_version} == 0 || %suse_version <= 1130
37 Requires:       ruby-dbus
38 %else
39 Requires:       rubygem-ruby-dbus
40 %endif
41 Requires:       rubygem-webyast-rake-tasks, rubygem-http_accept_language
42 Requires:       rubygem-static_record_cache
43 Requires:       yast2-dbus-server
44 # 634404
45 Recommends:     logrotate
46 PreReq:         PolicyKit, PackageKit, rubygem-rake, rubygem-sqlite3
47 PreReq:         rubygem-rails-2_3 >= 2.3.8
48 PreReq:         rubygem-rpam, rubygem-polkit, rubygem-gettext_rails
49 PreReq:         yast2-runlevel
50 License:        LGPL v2.1 only
51 Group:          Productivity/Networking/Web/Utilities
52 URL:            http://en.opensuse.org/Portal:WebYaST
53 Autoreqprov:    on
54 Version:        0.2.16
55 Release:        0
56 Summary:        WebYaST - base components for rest service
57 Source:         www.tar.bz2
58 Source1:        webyastPermissionsService.rb
59 Source2:        webyast.permissions.conf
60 Source3:        webyast.permissions.service.service
61 Source4:        org.opensuse.yast.permissions.policy
62 Source5:        grantwebyastrights
63 Source6:        yast_user_roles
64 Source9:        yastws
65 Source10:       webyast
66 Source11:       webyast-ws.lr.conf
67 Source12:       nginx.conf
68
69 BuildRoot:      %{_tmppath}/%{name}-%{version}-build
70 BuildRequires:  ruby, pkg-config, rubygem-mocha, rubygem-static_record_cache
71 # if we run the tests during build, we need most of Requires here too,
72 # except for deployment specific stuff
73 BuildRequires:  rubygem-webyast-rake-tasks, rubygem-restility
74 BuildRequires:  yast2-core, yast2-dbus-server, sqlite, dbus-1
75 %if 0%{?suse_version} == 0 || %suse_version <= 1130
76 BuildRequires:  ruby-dbus
77 %else
78 BuildRequires:  rubygem-ruby-dbus
79 %endif
80 BuildRequires:  PolicyKit, PackageKit, rubygem-sqlite3
81 BuildRequires:  rubygem-rails-2_3 >= 2.3.8
82 BuildRequires:  rubygem-rpam, rubygem-polkit
83 # the testsuite is run during build
84 BuildRequires:  rubygem-test-unit rubygem-mocha
85 BuildRequires:  nginx, rubygem-passenger-nginx
86
87 # This is for Hudson (build service) to setup the build env correctly
88 %if 0
89 BuildRequires:  rubygem-test-unit
90 BuildRequires:  rubygem-rcov >= 0.9.3.2
91 %endif
92
93 # we do not necessarily need any UI in case of WebYaST
94 Provides:       yast2_ui
95 Provides:       yast2_ui_pkg
96
97 # rpmlint warns about file duplicates, this should take care but
98 # doesn't build (?!)
99 #%if 0%{?suse_version} > 1020
100 #BuildRequires:  fdupes
101 #%endif
102
103 BuildArch:      noarch
104
105 %package testsuite
106 Group:    Productivity/Networking/Web/Utilities
107 Requires: webyast-base-ws = %{version}
108 Summary:  Testsuite for webyast-base-ws package
109
110 #
111 %define pkg_home /var/lib/%{webyast_ws_user}
112 #
113
114
115 %description
116 WebYaST - Core components for REST based interface to system manipulation.
117 Authors:
118 --------
119     Duncan Mac-Vicar Prett <dmacvicar@suse.de>
120     Klaus Kaempf <kkaempf@suse.de>
121     Bjoern Geuken <bgeuken@suse.de>
122     Stefan Schubert <schubi@suse.de>
123
124 %description testsuite
125 Testsuite for core WebYaST webservice package.
126
127 %prep
128 %setup -q -n www
129
130 %build
131
132 %check
133 # run the testsuite
134 RAILS_ENV=test rake db:migrate
135 RAILS_ENV=test $RPM_BUILD_ROOT%{webyast_ws_dir}/test/dbus-launch-simple rake test
136
137 #---------------------------------------------------------------
138 %install
139
140 #
141 # Install all web and frontend parts.
142 #
143 mkdir -p $RPM_BUILD_ROOT%{webyast_ws_dir}/log/
144 cp -a * $RPM_BUILD_ROOT%{webyast_ws_dir}/
145 rm -f $RPM_BUILD_ROOT%{webyast_ws_dir}/log/*
146 rm -f $RPM_BUILD_ROOT%{webyast_ws_dir}/COPYING
147 touch $RPM_BUILD_ROOT%{webyast_ws_dir}/db/schema.rb
148
149 %{__install} -d -m 0755                            \
150     %{buildroot}%{pkg_home}/sockets/               \
151     %{buildroot}%{pkg_home}/cache/                 \
152     %{buildroot}%{_sbindir}                        \
153     %{buildroot}%{_var}/log/%{webyast_ws_user}
154 #
155 # init script
156 #
157 %{__install} -D -m 0755 %SOURCE9 \
158     %{buildroot}%{_sysconfdir}/init.d/%{webyast_ws_service}
159 %{__ln_s} -f %{_sysconfdir}/init.d/%{webyast_ws_service} %{buildroot}%{_sbindir}/rc%{webyast_ws_service}
160 #
161
162 # configure nginx web service
163 mkdir -p $RPM_BUILD_ROOT/etc/yastws/
164 install -m 0644 %SOURCE12 $RPM_BUILD_ROOT/etc/yastws/
165 # create symlinks to nginx config files
166 ln -s /etc/nginx/fastcgi.conf $RPM_BUILD_ROOT/etc/yastws
167 ln -s /etc/nginx/fastcgi_params $RPM_BUILD_ROOT/etc/yastws
168 ln -s /etc/nginx/koi-utf $RPM_BUILD_ROOT/etc/yastws
169 ln -s /etc/nginx/koi-win $RPM_BUILD_ROOT/etc/yastws
170 ln -s /etc/nginx/mime.types $RPM_BUILD_ROOT/etc/yastws
171 ln -s /etc/nginx/scgi_params $RPM_BUILD_ROOT/etc/yastws
172 ln -s /etc/nginx/uwsgi_params $RPM_BUILD_ROOT/etc/yastws
173 ln -s /etc/nginx/win-utf $RPM_BUILD_ROOT/etc/yastws
174
175 # Policies
176 mkdir -p $RPM_BUILD_ROOT/usr/share/PolicyKit/policy
177 install -m 0644 %SOURCE4 $RPM_BUILD_ROOT/usr/share/PolicyKit/policy/
178 install -m 0644 %SOURCE6 $RPM_BUILD_ROOT/etc/
179 install -m 0555 %SOURCE5 $RPM_BUILD_ROOT/usr/sbin/
180
181 # firewall service definition, bnc#545627
182 mkdir -p $RPM_BUILD_ROOT/etc/sysconfig/SuSEfirewall2.d/services
183 install -m 0644 %SOURCE10 $RPM_BUILD_ROOT/etc/sysconfig/SuSEfirewall2.d/services
184
185 # logrotate configuration bnc#634404
186 mkdir $RPM_BUILD_ROOT/etc/logrotate.d
187 install -m 0644 %SOURCE11 $RPM_BUILD_ROOT/etc/logrotate.d
188
189 #  create yastwsdirs (config, var and data)
190 mkdir -p $RPM_BUILD_ROOT/etc/webyast
191 mkdir -p $RPM_BUILD_ROOT/var/lib/yastws
192 mkdir -p $RPM_BUILD_ROOT/usr/share/yastws
193
194 #  create empty tmp directory
195 mkdir -p $RPM_BUILD_ROOT%{webyast_ws_dir}/tmp
196 mkdir -p $RPM_BUILD_ROOT%{webyast_ws_dir}/tmp/cache
197 mkdir -p $RPM_BUILD_ROOT%{webyast_ws_dir}/tmp/pids
198 mkdir -p $RPM_BUILD_ROOT%{webyast_ws_dir}/tmp/sessions
199 mkdir -p $RPM_BUILD_ROOT%{webyast_ws_dir}/tmp/sockets
200
201 # install permissions service
202 mkdir -p $RPM_BUILD_ROOT/usr/sbin/
203 install -m 0500 %SOURCE1 $RPM_BUILD_ROOT/usr/sbin/
204 mkdir -p $RPM_BUILD_ROOT/etc/dbus-1/system.d/
205 install -m 0644 %SOURCE2 $RPM_BUILD_ROOT/etc/dbus-1/system.d/
206 mkdir -p $RPM_BUILD_ROOT/usr/share/dbus-1/system-services/
207 install -m 0444 %SOURCE3 $RPM_BUILD_ROOT/usr/share/dbus-1/system-services/
208
209 #create dummy update-script
210 mkdir -p %buildroot/var/adm/update-scripts
211 touch %buildroot/var/adm/update-scripts/%name-%version-%release-1
212
213 #---------------------------------------------------------------
214 %clean
215 rm -rf $RPM_BUILD_ROOT
216
217 #---------------------------------------------------------------
218 %pre
219
220 #
221 # e.g. adding user
222 #
223 /usr/sbin/groupadd -r %{webyast_ws_user} &>/dev/null ||:
224 /usr/sbin/useradd  -g %{webyast_ws_user} -s /bin/false -r -c "User for YaST-Webservice" -d %{pkg_home} %{webyast_ws_user} &>/dev/null ||:
225
226 # services will not be restarted correctly if
227 # the package name will changed while the update
228 # So the service will be restarted by an update-script
229 # which will be called AFTER the installation
230 if /bin/rpm -q yast2-webservice > /dev/null ; then
231   echo "renaming yast2-webservice to webyast-base-ws"
232   if /sbin/yast runlevel summary service=yastws 2>&1|grep " 3 "|grep yastws >/dev/null ; then
233     echo "yastws is inserted into the runlevel"
234     echo "#!/bin/sh" > %name-%version-%release-1
235     echo "/sbin/yast runlevel add service=yastws" >> %name-%version-%release-1
236     echo "/usr/sbin/rcyastws restart" >> %name-%version-%release-1
237   else
238     if /usr/sbin/rcyastws status > /dev/null ; then
239       echo "yastws is running"
240       echo "#!/bin/sh" > %name-%version-%release-1
241       echo "/usr/sbin/rcyastws restart" >> %name-%version-%release-1
242     fi
243   fi
244   if [ -f %name-%version-%release-1 ] ; then
245     install -D -m 755 %name-%version-%release-1 /var/adm/update-scripts
246     rm %name-%version-%release-1
247     echo "Please check the service runlevels and restart WebYaST service with \"rcyastws restart\" if the update has not been called with zypper,yast or packagekit"
248   fi
249 fi
250 exit 0
251
252 #---------------------------------------------------------------
253 %post
254 %fillup_and_insserv %{webyast_ws_service}
255 #
256 #granting permissions for yastws
257 #
258 if [ `/usr/bin/polkit-auth --user %{webyast_ws_user} | grep -c "org.freedesktop.packagekit.system-update"` -eq 0 ]; then
259   # FIXME: remove ||: (don't hide errors), has to be correctly implemented for package update...
260   /usr/bin/polkit-auth --user %{webyast_ws_user} --grant org.freedesktop.packagekit.system-update > /dev/null ||:
261 fi
262 if [ `/usr/bin/polkit-auth --user %{webyast_ws_user} | grep -c "org.freedesktop.policykit.read"` -eq 0 ]; then
263   # FIXME: remove ||: (don't hide errors), has to be correctly implemented for package update...
264   /usr/bin/polkit-auth --user %{webyast_ws_user} --grant org.freedesktop.policykit.read > /dev/null ||:
265 fi
266 if [ `/usr/bin/polkit-auth --user %{webyast_ws_user} | grep -c "org.opensuse.yast.module-manager.import"` -eq 0 ]; then
267   # FIXME: remove ||: (don't hide errors), has to be correctly implemented for package update...
268   /usr/bin/polkit-auth --user %{webyast_ws_user} --grant org.opensuse.yast.module-manager.import > /dev/null ||:
269 fi
270 #
271 # granting all permissions for root 
272 #
273 /usr/sbin/grantwebyastrights --user root --action grant > /dev/null ||:
274 #
275 # create database 
276 #
277 cd %{webyast_ws_dir}
278 #migrate database
279 RAILS_ENV=production rake db:migrate
280 chown -R %{webyast_ws_user}: db
281 chown -R %{webyast_ws_user}: log
282 echo "Database is ready"
283 #
284 # patching nginx configuration
285 #
286 if [ -d /usr/lib64 ]; then
287   sed -i "s/passenger_root \/usr\/lib/passenger_root \/usr\/lib64/" /etc/yastws/nginx.conf
288 fi
289 #
290 # try-reload D-Bus config (bnc#635826)
291 #
292 dbus-send --print-reply --system --dest=org.freedesktop.DBus / org.freedesktop.DBus.ReloadConfig >/dev/null ||:
293
294 #---------------------------------------------------------------
295 %preun
296 %stop_on_removal %{webyast_ws_service}
297
298 #---------------------------------------------------------------
299 %postun
300 %restart_on_update %{webyast_ws_service}
301 %{insserv_cleanup}
302
303 #---------------------------------------------------------------
304 # restart yastws on nginx update (bnc#559534)
305 %triggerin -- nginx
306 %restart_on_update %{webyast_ws_service}
307
308 #---------------------------------------------------------------
309 %files 
310 %defattr(-,root,root)
311 #this /etc/yastws is for ligght conf for yastws
312 %dir /etc/yastws
313 %dir %{webyast_ws_dir}
314 %dir %{_datadir}/PolicyKit
315 %dir %{_datadir}/PolicyKit/policy
316 %attr(-,%{webyast_ws_user},%{webyast_ws_user}) %dir %{pkg_home}
317 %attr(-,%{webyast_ws_user},%{webyast_ws_user}) %dir %{pkg_home}/sockets
318 %attr(-,%{webyast_ws_user},%{webyast_ws_user}) %dir %{pkg_home}/cache
319 %attr(-,%{webyast_ws_user},%{webyast_ws_user}) %dir %{_var}/log/%{webyast_ws_user}
320
321 #logrotate configuration file
322 %config(noreplace) /etc/logrotate.d/webyast-ws.lr.conf
323
324 #this /etc/webyast is for webyast configuration files
325 %dir /etc/webyast/
326 %dir %{_datadir}/yastws
327 %dir %attr(-,%{webyast_ws_user},root) /var/lib/yastws
328 %dir %{webyast_ws_dir}/db
329 %{webyast_ws_dir}/app
330 %{webyast_ws_dir}/db/migrate
331 %ghost %{webyast_ws_dir}/db/schema.rb
332 %{webyast_ws_dir}/doc
333 %{webyast_ws_dir}/lib
334 %{webyast_ws_dir}/public
335 %{webyast_ws_dir}/Rakefile
336 %{webyast_ws_dir}/script
337 %{webyast_ws_dir}/vendor
338 %dir %{webyast_ws_dir}/config
339 %{webyast_ws_dir}/config/boot.rb
340 %{webyast_ws_dir}/config/database.yml
341 %{webyast_ws_dir}/config/environments
342 %{webyast_ws_dir}/config/initializers
343 %{webyast_ws_dir}/config/routes.rb
344 #also users can run granting script, as permissions is handled by policyKit right for granting permissions
345 %attr(555,root,root) /usr/sbin/grantwebyastrights
346 %attr(755,root,root) %{webyast_ws_dir}/start.sh
347 %attr(500,root,root) /usr/sbin/webyastPermissionsService.rb
348 %attr(444,root,root) /usr/share/dbus-1/system-services/webyast.permissions.service.service
349 %attr(644,root,root) %config /etc/dbus-1/system.d/webyast.permissions.conf
350 %doc %{webyast_ws_dir}/README
351 %attr(-,%{webyast_ws_user},%{webyast_ws_user}) %{webyast_ws_dir}/log
352 %attr(-,%{webyast_ws_user},%{webyast_ws_user}) %{webyast_ws_dir}/tmp
353 #nginx stuff
354 %config(noreplace) /etc/yastws/nginx.conf
355 %config /etc/yastws/fastcgi.conf
356 %config /etc/yastws/fastcgi_params
357 %config /etc/yastws/koi-utf
358 %config /etc/yastws/koi-win
359 %config /etc/yastws/mime.types
360 %config /etc/yastws/scgi_params
361 %config /etc/yastws/uwsgi_params
362 %config /etc/yastws/win-utf
363
364 %config /etc/sysconfig/SuSEfirewall2.d/services/webyast
365 %config /usr/share/PolicyKit/policy/org.opensuse.yast.permissions.policy
366 %config %{webyast_ws_dir}/config/environment.rb
367 %config(noreplace) /etc/yast_user_roles
368 %config %{_sysconfdir}/init.d/%{webyast_ws_service}
369 %{_sbindir}/rc%{webyast_ws_service}
370 %doc COPYING
371 %ghost %attr(755,root,root) /var/adm/update-scripts/%name-%version-%release-1
372
373 %files testsuite
374 %defattr(-,root,root)
375 %{webyast_ws_dir}/test
376
377 #---------------------------------------------------------------
378 %changelog