@@ -19,10 +19,30 @@ AutoReqProv: no
19
19
%description
20
20
Fledge, the open source platform for the Internet of Things
21
21
22
+
23
+ ## -------------------------------------------------------------------------------------------------
24
+ ## Scriptlet values which we must use in our scripts
25
+
26
+ ## scriptlet install upgrade uninstall
27
+ ## %pre $1 == 1 $1 == 2 (N/A)
28
+ ## %post $1 == 1 $1 == 2 (N/A)
29
+ ## %preun (N/A) $1 == 1 $1 == 0
30
+ ## %postun (N/A) $1 == 1 $1 == 0
31
+
32
+
33
+ ## On upgrade, the scripts are run in the following order:
34
+
35
+ ## %pre of new package
36
+ ## %post of new package
37
+ ## %preun of old package
38
+ ## %postun of old package
39
+
40
+ ## --------------------------------------------------------------------------------------------------
41
+
22
42
%pre
23
43
#!/usr/bin/env bash
24
44
25
- ##--------------------------------------------------------------------
45
+ ##---------------------------------------------------------------------------------------------------
26
46
## Copyright (c) 2019 Dianomic Systems Inc.
27
47
##
28
48
## Licensed under the Apache License, Version 2.0 (the "License");
@@ -36,23 +56,23 @@ Fledge, the open source platform for the Internet of Things
36
56
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
37
57
## See the License for the specific language governing permissions and
38
58
## limitations under the License.
39
- ##--------------------------------------------------------------------
59
+ ##---------------------------------------------------------------------------------------------------
40
60
41
- ##--------------------------------------------------------------------
61
+ ##---------------------------------------------------------------------------------------------------
42
62
##
43
- ## This script is used to execute pre installation tasks .
63
+ ## The %pre scriptlet executes just before the package is to be installed .
44
64
##
45
- ## Author: Ivan Zoratti, Ashwin Gopalakrishnan, Massimiliano Pinto, Stefano Simonelli
65
+ ## Author: Ivan Zoratti, Ashwin Gopalakrishnan, Massimiliano Pinto, Stefano Simonelli, Ashish Jabble
46
66
##
47
- ##--------------------------------------------------------------------
67
+ ##---------------------------------------------------------------------------------------------------
48
68
49
69
set -e
50
70
51
71
PKG_NAME= "fledge"
52
72
53
73
is_fledge_installed () {
54
74
set +e
55
- rc= ` rpm -qa 2 > /dev/null | grep -Fx ${PKG_NAME}`
75
+ rc= $( rpm -ql ${PKG_NAME} | grep 'fledge/bin/fledge$')
56
76
echo $rc
57
77
set -e
58
78
}
@@ -86,29 +106,59 @@ exists_schema_change_path () {
86
106
echo 1
87
107
}
88
108
89
- # main
109
+ stop_fledge_service () {
110
+ systemctl stop fledge
111
+ }
90
112
91
- # check if fledge is installed
92
- IS_FLEDGE_INSTALLED= $(is_fledge_installed)
113
+ kill_fledge () {
114
+ set +e
115
+ fledge_script= $(get_fledge_script)
116
+ fledge_status_output= $($fledge_script kill 2> &1)
117
+ set -e
118
+ }
93
119
94
- # if fledge is installed...
95
- if [ "$IS_FLEDGE_INSTALLED" -eq "1" ]
96
- then
97
- echo "Fledge is already installed: this is an upgrade/downgrade."
120
+ disable_fledge_service () {
121
+ set +e
122
+ /sbin/chkconfig fledge off
123
+ set -e
124
+ }
98
125
99
- # exit if fledge is running
126
+ remove_fledge_service_file () {
127
+ rm -rf /etc/init.d/fledge
128
+ }
129
+
130
+ reset_systemctl () {
131
+ systemctl daemon-reload
132
+ systemctl reset-failed
133
+ }
134
+
135
+ # main
136
+ if [ $1 == 1 ];then
137
+ echo "pre step: ${PKG_NAME} is getting installed."
138
+ elif [ $1 == 2 ];then
139
+ echo "preun step: ${PKG_NAME} is getting upgraded"
100
140
IS_FLEDGE_RUNNING= $(is_fledge_running)
101
141
if [ "$IS_FLEDGE_RUNNING" -eq "1" ]
102
142
then
103
- echo "*** ERROR. Fledge is currently running. Stop Fledge and try again. ***"
104
- exit 1
143
+ echo "${PKG_NAME} is currently running."
144
+ echo "Stop ${PKG_NAME} service."
145
+ stop_fledge_service
146
+ echo "Kill ${PKG_NAME}."
147
+ kill_fledge
105
148
fi
106
149
150
+ echo "Disable ${PKG_NAME} service."
151
+ disable_fledge_service
152
+ echo "Remove ${PKG_NAME} service script"
153
+ remove_fledge_service_file
154
+ echo "Reset systemctl"
155
+ reset_systemctl
156
+
107
157
# Persist current version in case of upgrade/downgrade
108
158
installed_version= `rpm -qi ${PKG_NAME} | grep Version |awk '{print $3}'`
109
159
if [ "${installed_version}" ]
110
160
then
111
- # Persist current Fledge version: it will be removed by postinstall script
161
+ # Persist current ${PKG_NAME} version: it will be removed by postinstall script
112
162
this_dir= `pwd`
113
163
cd /usr/local /fledge/
114
164
echo "${installed_version}" > .current_installed_version
@@ -118,22 +168,20 @@ then
118
168
# check schema version file, exit if schema change path does not exist
119
169
CURRENT_VERSION_FILE= $(get_current_version_file)
120
170
CURRENT_SCHEMA_VERSION= $(get_schema_version $CURRENT_VERSION_FILE)
121
- echo "Fledge currently has schema version $CURRENT_SCHEMA_VERSION"
171
+ echo "${PKG_NAME} currently has schema version $CURRENT_SCHEMA_VERSION"
122
172
EXISTS_SCHEMA_CHANGE_PATH= $(exists_schema_change_path)
123
173
if [ "$EXISTS_SCHEMA_CHANGE_PATH" -eq "0" ]
124
174
then
125
175
echo "*** ERROR. There is no schema change path from the installed version to the new version. ***"
126
176
exit 1
127
177
fi
128
-
129
178
fi
130
179
131
180
132
-
133
181
%preun
134
182
#!/usr/bin/env bash
135
183
136
- ##--------------------------------------------------------------------
184
+ ##--------------------------------------------------------------------------------
137
185
## Copyright (c) 2019 Dianomic Systems Inc.
138
186
##
139
187
## Licensed under the Apache License, Version 2.0 (the "License");
147
195
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
148
196
## See the License for the specific language governing permissions and
149
197
## limitations under the License.
150
- ##--------------------------------------------------------------------
198
+ ##--------------------------------------------------------------------------------
151
199
152
- ##--------------------------------------------------------------------
200
+ ##--------------------------------------------------------------------------------
153
201
##
154
- ## This script is used to execute before the removal of files associated with the package .
202
+ ## The %preun scriptlet executes just before the package is to be erased .
155
203
##
156
- ## Author: Ivan Zoratti, Ashwin Gopalakrishnan, Stefano Simonelli
204
+ ## Author: Ivan Zoratti, Ashwin Gopalakrishnan, Stefano Simonelli, Ashish Jabble
157
205
##
158
- ##----------------------------------------------------------------------------------------
206
+ ##--------------------------------------------------------------------------------
159
207
160
208
set -e
161
209
@@ -202,30 +250,33 @@ reset_systemctl () {
202
250
}
203
251
204
252
# main
253
+ if [ $1 == 1 ];then
254
+ echo "preun step: ${PKG_NAME} is getting upgraded. But Nothing to upgrade."
255
+ elif [ $1 == 0 ];then
256
+ echo "preun step: ${PKG_NAME} is getting removed/uninstalled"
257
+ IS_FLEDGE_RUNNING= $(is_fledge_running)
258
+ if [ "$IS_FLEDGE_RUNNING" -eq "1" ]
259
+ then
260
+ echo "${PKG_NAME} is currently running."
261
+ echo "Stop ${PKG_NAME} service."
262
+ stop_fledge_service
263
+ echo "Kill ${PKG_NAME}."
264
+ kill_fledge
265
+ fi
205
266
206
- IS_FLEDGE_RUNNING= $(is_fledge_running)
207
-
208
- if [ "$IS_FLEDGE_RUNNING" -eq "1" ]
209
- then
210
- echo "Fledge is currently running."
211
- echo "Stop Fledge service."
212
- stop_fledge_service
213
- echo "Kill Fledge."
214
- kill_fledge
267
+ echo "Disable ${PKG_NAME} service."
268
+ disable_fledge_service
269
+ echo "Remove ${PKG_NAME} service script"
270
+ remove_fledge_service_file
271
+ echo "Reset systemctl"
272
+ reset_systemctl
215
273
fi
216
274
217
- echo "Disable Fledge service."
218
- disable_fledge_service
219
- echo "Remove Fledge service script"
220
- remove_fledge_service_file
221
- echo "Reset systemctl"
222
- reset_systemctl
223
-
224
275
225
276
%post
226
277
#!/usr/bin/env bash
227
278
228
- ##--------------------------------------------------------------------
279
+ ##----------------------------------------------------------------------------
229
280
## Copyright (c) 2019 Dianomic Systems Inc.
230
281
##
231
282
## Licensed under the Apache License, Version 2.0 (the "License");
@@ -239,15 +290,15 @@ reset_systemctl
239
290
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
240
291
## See the License for the specific language governing permissions and
241
292
## limitations under the License.
242
- ##--------------------------------------------------------------------
293
+ ##----------------------------------------------------------------------------
243
294
244
- ##--------------------------------------------------------------------
295
+ ##----------------------------------------------------------------------------
245
296
##
246
- ## This script is used to execute post installation tasks .
297
+ ## The %post scriptlet executes just after the package is to be installed .
247
298
##
248
- ## Author: Ivan Zoratti, Massimiliano Pinto, Stefano Simonelli
299
+ ## Author: Ivan Zoratti, Massimiliano Pinto, Stefano Simonelli, Ashish Jabble
249
300
##
250
- ##--------------------------------------------------------------------
301
+ ##----------------------------------------------------------------------------
251
302
252
303
set -e
253
304
@@ -274,7 +325,6 @@ copy_service_file() {
274
325
}
275
326
276
327
enable_fledge_service() {
277
-
278
328
/sbin/chkconfig fledge on
279
329
}
280
330
@@ -351,9 +401,10 @@ install_pip3_packages () {
351
401
fi
352
402
source scl_source enable rh-python36
353
403
354
- pip install -Ir /usr/local /fledge/python/requirements.txt
404
+ # TODO: we may need with --no-cache-dir
405
+ pip3 install -Ir /usr/local /fledge/python/requirements.txt
355
406
356
- sudo bash -c 'source scl_source enable rh-python36;pip install dbus-python'
407
+ sudo bash -c 'source scl_source enable rh-python36;pip3 install dbus-python'
357
408
set -e
358
409
}
359
410
@@ -378,7 +429,6 @@ call_package_update_script () {
378
429
379
430
380
431
# main
381
-
382
432
echo "Install python dependencies"
383
433
install_pip3_packages
384
434
@@ -418,7 +468,7 @@ start_fledge_service
418
468
%postun
419
469
#!/usr/bin/env bash
420
470
421
- ##--------------------------------------------------------------------
471
+ ##--------------------------------------------------------------------------
422
472
## Copyright (c) 2019 Dianomic Systems Inc.
423
473
##
424
474
## Licensed under the Apache License, Version 2.0 (the "License");
@@ -432,17 +482,18 @@ start_fledge_service
432
482
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
433
483
## See the License for the specific language governing permissions and
434
484
## limitations under the License.
435
- ##--------------------------------------------------------------------
485
+ ##--------------------------------------------------------------------------
436
486
437
- ##--------------------------------------------------------------------
487
+ ##--------------------------------------------------------------------------
438
488
##
439
- ## This script is used to modifies links or other files associated with fledge, and/or removes files created by the package .
489
+ ## The %postun scriptlet executes just after the package is to be erased .
440
490
##
441
491
## Author: Ashish Jabble
442
492
##
443
- ##--------------------------------------------------------------------
493
+ ##--------------------------------------------------------------------------
444
494
445
495
set -e
496
+ PKG_NAME= "fledge"
446
497
447
498
remove_unused_files () {
448
499
find /usr/local /fledge/ -maxdepth 1 -mindepth 1 -type d | egrep -v -w '(/usr/local /fledge/data)' | xargs rm -rf
@@ -452,11 +503,17 @@ remove_fledge_sudoer_file() {
452
503
rm -rf /etc/sudoers.d/fledge
453
504
}
454
505
455
- echo "Cleanup of files"
456
- remove_unused_files
506
+ # main
507
+ if [ $1 == 1 ];then
508
+ echo "postun step: ${PKG_NAME} is getting upgraded. But nothing to upgrade."
509
+ elif [ $1 == 0 ];then
510
+ echo "postun step: ${PKG_NAME} is getting removed/uninstalled"
511
+ echo "Cleanup of files"
512
+ remove_unused_files
513
+ echo "Remove fledge sudoers file"
514
+ remove_fledge_sudoer_file
515
+ fi
457
516
458
- echo "Remove fledge sudoers file"
459
- remove_fledge_sudoer_file
460
517
461
518
%files
462
519
%{install_path }/*
0 commit comments