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