@@ -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,60 @@ 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 scriptlet is called: ${PKG_NAME} is getting installed."
138
+ # Add steps here for the fresh installed case for this scriptlet
139
+ elif [ $1 == 2 ];then
140
+ echo "pre scriptlet is called: ${PKG_NAME} is getting upgraded."
100
141
IS_FLEDGE_RUNNING= $(is_fledge_running)
101
142
if [ "$IS_FLEDGE_RUNNING" -eq "1" ]
102
143
then
103
- echo "*** ERROR. Fledge is currently running. Stop Fledge and try again. ***"
104
- exit 1
144
+ echo "${PKG_NAME} is currently running."
145
+ echo "Stop ${PKG_NAME} service."
146
+ stop_fledge_service
147
+ echo "Kill ${PKG_NAME}."
148
+ kill_fledge
105
149
fi
106
150
151
+ echo "Disable ${PKG_NAME} service."
152
+ disable_fledge_service
153
+ echo "Remove ${PKG_NAME} service script"
154
+ remove_fledge_service_file
155
+ echo "Reset systemctl"
156
+ reset_systemctl
157
+
107
158
# Persist current version in case of upgrade/downgrade
108
159
installed_version= `rpm -qi ${PKG_NAME} | grep Version |awk '{print $3}'`
109
160
if [ "${installed_version}" ]
110
161
then
111
- # Persist current Fledge version: it will be removed by postinstall script
162
+ # Persist current ${PKG_NAME} version: it will be removed by postinstall script
112
163
this_dir= `pwd`
113
164
cd /usr/local /fledge/
114
165
echo "${installed_version}" > .current_installed_version
@@ -118,22 +169,20 @@ then
118
169
# check schema version file, exit if schema change path does not exist
119
170
CURRENT_VERSION_FILE= $(get_current_version_file)
120
171
CURRENT_SCHEMA_VERSION= $(get_schema_version $CURRENT_VERSION_FILE)
121
- echo "Fledge currently has schema version $CURRENT_SCHEMA_VERSION"
172
+ echo "${PKG_NAME} currently has schema version $CURRENT_SCHEMA_VERSION"
122
173
EXISTS_SCHEMA_CHANGE_PATH= $(exists_schema_change_path)
123
174
if [ "$EXISTS_SCHEMA_CHANGE_PATH" -eq "0" ]
124
175
then
125
176
echo "*** ERROR. There is no schema change path from the installed version to the new version. ***"
126
177
exit 1
127
178
fi
128
-
129
179
fi
130
180
131
181
132
-
133
182
%preun
134
183
#!/usr/bin/env bash
135
184
136
- ##--------------------------------------------------------------------
185
+ ##--------------------------------------------------------------------------------
137
186
## Copyright (c) 2019 Dianomic Systems Inc.
138
187
##
139
188
## Licensed under the Apache License, Version 2.0 (the "License");
147
196
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
148
197
## See the License for the specific language governing permissions and
149
198
## limitations under the License.
150
- ##--------------------------------------------------------------------
199
+ ##--------------------------------------------------------------------------------
151
200
152
- ##--------------------------------------------------------------------
201
+ ##--------------------------------------------------------------------------------
153
202
##
154
- ## This script is used to execute before the removal of files associated with the package .
203
+ ## The %preun scriptlet executes just before the package is to be erased .
155
204
##
156
- ## Author: Ivan Zoratti, Ashwin Gopalakrishnan, Stefano Simonelli
205
+ ## Author: Ivan Zoratti, Ashwin Gopalakrishnan, Stefano Simonelli, Ashish Jabble
157
206
##
158
- ##----------------------------------------------------------------------------------------
207
+ ##--------------------------------------------------------------------------------
159
208
160
209
set -e
161
210
@@ -202,30 +251,33 @@ reset_systemctl () {
202
251
}
203
252
204
253
# main
254
+ if [ $1 == 1 ];then
255
+ echo "preun scriptlet is called: ${PKG_NAME} is getting upgraded."
256
+ elif [ $1 == 0 ];then
257
+ echo "preun scriptlet is called: ${PKG_NAME} is getting removed/uninstalled."
258
+ IS_FLEDGE_RUNNING= $(is_fledge_running)
259
+ if [ "$IS_FLEDGE_RUNNING" -eq "1" ]
260
+ then
261
+ echo "${PKG_NAME} is currently running."
262
+ echo "Stop ${PKG_NAME} service."
263
+ stop_fledge_service
264
+ echo "Kill ${PKG_NAME}."
265
+ kill_fledge
266
+ fi
205
267
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
268
+ echo "Disable ${PKG_NAME} service."
269
+ disable_fledge_service
270
+ echo "Remove ${PKG_NAME} service script"
271
+ remove_fledge_service_file
272
+ echo "Reset systemctl"
273
+ reset_systemctl
215
274
fi
216
275
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
276
225
277
%post
226
278
#!/usr/bin/env bash
227
279
228
- ##--------------------------------------------------------------------
280
+ ##----------------------------------------------------------------------------
229
281
## Copyright (c) 2019 Dianomic Systems Inc.
230
282
##
231
283
## Licensed under the Apache License, Version 2.0 (the "License");
@@ -239,15 +291,15 @@ reset_systemctl
239
291
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
240
292
## See the License for the specific language governing permissions and
241
293
## limitations under the License.
242
- ##--------------------------------------------------------------------
294
+ ##----------------------------------------------------------------------------
243
295
244
- ##--------------------------------------------------------------------
296
+ ##----------------------------------------------------------------------------
245
297
##
246
- ## This script is used to execute post installation tasks .
298
+ ## The %post scriptlet executes just after the package is to be installed .
247
299
##
248
- ## Author: Ivan Zoratti, Massimiliano Pinto, Stefano Simonelli
300
+ ## Author: Ivan Zoratti, Massimiliano Pinto, Stefano Simonelli, Ashish Jabble
249
301
##
250
- ##--------------------------------------------------------------------
302
+ ##----------------------------------------------------------------------------
251
303
252
304
set -e
253
305
@@ -274,7 +326,6 @@ copy_service_file() {
274
326
}
275
327
276
328
enable_fledge_service() {
277
-
278
329
/sbin/chkconfig fledge on
279
330
}
280
331
@@ -351,9 +402,10 @@ install_pip3_packages () {
351
402
fi
352
403
source scl_source enable rh-python36
353
404
354
- pip install -Ir /usr/local /fledge/python/requirements.txt
405
+ # TODO: we may need with --no-cache-dir
406
+ pip3 install -Ir /usr/local /fledge/python/requirements.txt
355
407
356
- sudo bash -c 'source scl_source enable rh-python36;pip install dbus-python'
408
+ sudo bash -c 'source scl_source enable rh-python36;pip3 install dbus-python'
357
409
set -e
358
410
}
359
411
@@ -378,7 +430,6 @@ call_package_update_script () {
378
430
379
431
380
432
# main
381
-
382
433
echo "Install python dependencies"
383
434
install_pip3_packages
384
435
@@ -418,7 +469,7 @@ start_fledge_service
418
469
%postun
419
470
#!/usr/bin/env bash
420
471
421
- ##--------------------------------------------------------------------
472
+ ##--------------------------------------------------------------------------
422
473
## Copyright (c) 2019 Dianomic Systems Inc.
423
474
##
424
475
## Licensed under the Apache License, Version 2.0 (the "License");
@@ -432,17 +483,18 @@ start_fledge_service
432
483
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
433
484
## See the License for the specific language governing permissions and
434
485
## limitations under the License.
435
- ##--------------------------------------------------------------------
486
+ ##--------------------------------------------------------------------------
436
487
437
- ##--------------------------------------------------------------------
488
+ ##--------------------------------------------------------------------------
438
489
##
439
- ## This script is used to modifies links or other files associated with fledge, and/or removes files created by the package .
490
+ ## The %postun scriptlet executes just after the package is to be erased .
440
491
##
441
492
## Author: Ashish Jabble
442
493
##
443
- ##--------------------------------------------------------------------
494
+ ##--------------------------------------------------------------------------
444
495
445
496
set -e
497
+ PKG_NAME= "fledge"
446
498
447
499
remove_unused_files () {
448
500
find /usr/local /fledge/ -maxdepth 1 -mindepth 1 -type d | egrep -v -w '(/usr/local /fledge/data)' | xargs rm -rf
@@ -452,11 +504,18 @@ remove_fledge_sudoer_file() {
452
504
rm -rf /etc/sudoers.d/fledge
453
505
}
454
506
455
- echo "Cleanup of files"
456
- remove_unused_files
507
+ # main
508
+ if [ $1 == 1 ];then
509
+ echo "postun scriptlet is called: ${PKG_NAME} is getting upgraded."
510
+ # Add steps here for the upgrade case for this scriptlet
511
+ elif [ $1 == 0 ];then
512
+ echo "postun scriptlet is called: ${PKG_NAME} is getting removed/uninstalled."
513
+ echo "Cleanup of files"
514
+ remove_unused_files
515
+ echo "Remove fledge sudoers file"
516
+ remove_fledge_sudoer_file
517
+ fi
457
518
458
- echo "Remove fledge sudoers file"
459
- remove_fledge_sudoer_file
460
519
461
520
%files
462
521
%{install_path }/*
0 commit comments