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