Skip to content

Commit f020c7a

Browse files
author
Ivan Zoratti
authored
Merge pull request #4 from foglamp/FOGL-1220
FOGL-1220 improve debian package
2 parents ba58091 + 7ef955e commit f020c7a

File tree

6 files changed

+291
-9
lines changed

6 files changed

+291
-9
lines changed

make_deb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,25 @@ mkdir "${package_name}"
119119

120120
# Populate the package directory with Debian files
121121
# First with files common to all pla
122-
echo -n "Populating the package..."
122+
echo -n "Populating the package and updating version in control file..."
123123
cd "${package_name}"
124124
cp -R ${GIT_ROOT}/packages/Debian/common/* .
125125
cp -R ${GIT_ROOT}/packages/Debian/${architecture}/* .
126-
126+
sed -i "s/Version: 0.0/Version: $version/g" DEBIAN/control
127127
mkdir -p usr/local/foglamp
128128
cd usr/local/foglamp
129129
cp -R ${FOGLAMP_ROOT}/* .
130130
echo "Done."
131131

132+
# Prepare new data directory
133+
echo "Prepare data directory"
134+
mv data data.new
135+
cd data.new
136+
rm -rf core.err
137+
rm -rf etc/certs/*
138+
rm -rf foglamp.db
139+
rm -rf var
140+
132141
# Add customised files
133142
#echo -n "Adding FogLAMP customization..."
134143

packages/Debian/armhf/DEBIAN/control

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Package: foglamp
2-
Version: 1.2
2+
Version: 0.0
33
Section: devel
44
Priority: optional
55
Architecture: armhf
6-
Depends:
6+
Depends: postgresql,postgresql-server-dev-9.6,libpq-dev,autoconf,libtool,jq,libboost-dev,libboost-system-dev,libboost-thread-dev,sqlite3,python-setuptools,python3.5-dev,python3-dbus,python3-pip
77
Conflicts:
88
Maintainer: Dianomic Systems, Inc. <[email protected]>
99
Homepage: http://www.dianomic.com

packages/Debian/common/DEBIAN/postinst

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,62 @@
2727

2828
set -e
2929

30-
# Set FogLAMP to run as a service
31-
cp /usr/local/foglamp/extras/scripts/foglamp.service /etc/init.d/foglamp
30+
# certificate generation defaults
31+
SSL_NAME="foglamp"
32+
SSL_DAYS="365"
3233

33-
systemctl enable foglamp
34-
systemctl start foglamp
34+
copy_service_file() {
35+
cp /usr/local/foglamp/extras/scripts/foglamp.service /etc/init.d/foglamp
36+
}
37+
38+
enable_foglamp_service() {
39+
systemctl enable foglamp
40+
}
41+
42+
start_foglamp_service() {
43+
systemctl start foglamp
44+
}
45+
46+
set_files_ownership () {
47+
chown root:root /etc/init.d/foglamp
48+
chown -R root:root /usr/local/foglamp
49+
chown -R ${SUDO_USER}:${SUDO_USER} /usr/local/foglamp/data
50+
}
51+
52+
generate_certs () {
53+
if [ ! -f /usr/local/foglamp/data/etc/certs/foglamp.cert ]; then
54+
echo "Certificate files do not exist. Generating new certificate files."
55+
cd /usr/local/foglamp
56+
./scripts/certificates ${SSL_NAME} ${SSL_DAYS}
57+
else
58+
echo "Certificate files already exist. Skipping generating new certificate files."
59+
fi
60+
}
61+
62+
copy_new_data () {
63+
if [ ! -d /usr/local/foglamp/data ]; then
64+
echo "Data directory does not exist. Using new data directory"
65+
mv /usr/local/foglamp/data.new /usr/local/foglamp/data
66+
else
67+
echo "Data directory already exists. Updating data/extras/fogbench/fogbench_sensor_coap.template.json only."
68+
cp /usr/local/foglamp/data.new/extras/fogbench/fogbench_sensor_coap.template.json /usr/local/foglamp/data/extras/fogbench/fogbench_sensor_coap.template.json
69+
rm -rf /usr/local/foglamp/data.new
70+
fi
71+
}
72+
73+
# main
74+
75+
echo "Resolving data directory"
76+
copy_new_data
77+
echo "Installing service script"
78+
copy_service_file
79+
echo "Generating certificate files"
80+
generate_certs
81+
echo "Setting ownership of FogLAMP files"
82+
set_files_ownership
83+
echo "Enabling FogLAMP service"
84+
enable_foglamp_service
85+
echo "Starting FogLAMP service"
86+
start_foglamp_service
3587

3688

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#!/bin/sh
2+
3+
##--------------------------------------------------------------------
4+
## Copyright (c) 2018 OSIsoft, LLC
5+
##
6+
## Licensed under the Apache License, Version 2.0 (the "License");
7+
## you may not use this file except in compliance with the License.
8+
## You may obtain a copy of the License at
9+
##
10+
## http://www.apache.org/licenses/LICENSE-2.0
11+
##
12+
## Unless required by applicable law or agreed to in writing, software
13+
## distributed under the License is distributed on an "AS IS" BASIS,
14+
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
## See the License for the specific language governing permissions and
16+
## limitations under the License.
17+
##--------------------------------------------------------------------
18+
19+
##--------------------------------------------------------------------
20+
##
21+
## @preinst DEBIAN/preinst
22+
## This script is used to execute pre installation tasks.
23+
##
24+
## Author: Ivan Zoratti, Ashwin Gopalakrishnan
25+
##
26+
##--------------------------------------------------------------------
27+
28+
set -e
29+
30+
PKG_NAME="foglamp"
31+
32+
is_foglamp_installed () {
33+
set +e
34+
current_files_all=$(dpkg -L $PKG_NAME | grep 'foglamp/bin/foglamp$')
35+
rc=$((!$?))
36+
echo $rc
37+
set -e
38+
}
39+
40+
get_foglamp_script () {
41+
foglamp_script=$(dpkg -L $PKG_NAME | grep 'foglamp/bin/foglamp$')
42+
echo $foglamp_script
43+
}
44+
45+
is_foglamp_running () {
46+
set +e
47+
foglamp_script=$(get_foglamp_script)
48+
foglamp_status_output=$($foglamp_script status 2>&1 | grep 'FogLAMP Uptime')
49+
rc=$((!$?))
50+
echo $rc
51+
set -e
52+
}
53+
54+
get_current_version_file () {
55+
current_version_file=$(dpkg -L $PKG_NAME | grep VERSION)
56+
echo $current_version_file
57+
}
58+
59+
get_schema_version () {
60+
version_file=$1
61+
schema_version=$(grep foglamp_schema $version_file | awk -F = '{print $2}')
62+
echo $schema_version
63+
}
64+
65+
exists_schema_change_path () {
66+
echo 1
67+
}
68+
69+
install_pip3_packages() {
70+
71+
sudo pip3 install --upgrade pip
72+
sudo pip3 install psycopg2
73+
sudo pip3 install aiohttp
74+
sudo pip3 install aiohttp_cors
75+
sudo pip3 install chardet
76+
sudo pip3 install requests
77+
sudo pip3 install pyjwt
78+
sudo pip3 install pyparsing
79+
sudo pip3 install aiocoap
80+
sudo pip3 install cbor2
81+
sudo pip3 install pexpect
82+
sudo pip3 install pyjq
83+
84+
}
85+
86+
# main
87+
88+
# check if foglamp is installed
89+
IS_FOGLAMP_INSTALLED=$(is_foglamp_installed)
90+
91+
# if foglamp is installed...
92+
if [ "$IS_FOGLAMP_INSTALLED" -eq "1" ]
93+
then
94+
echo "FogLAMP is already installed: this is an upgrade/downgrade."
95+
96+
# exit if foglamp is running
97+
IS_FOGLAMP_RUNNING=$(is_foglamp_running)
98+
if [ "$IS_FOGLAMP_RUNNING" -eq "1" ]
99+
then
100+
echo "*** ERROR. FogLAMP is currently running. Stop FogLAMP and try again. ***"
101+
exit 1
102+
fi
103+
104+
# check schema version file, exit if schema change path does not exist
105+
CURRENT_VERSION_FILE=$(get_current_version_file)
106+
CURRENT_SCHEMA_VERSION=$(get_schema_version $CURRENT_VERSION_FILE)
107+
echo "FogLAMP currently has schema version $CURRENT_SCHEMA_VERSION"
108+
EXISTS_SCHEMA_CHANGE_PATH=$(exists_schema_change_path)
109+
if [ "$EXISTS_SCHEMA_CHANGE_PATH" -eq "0" ]
110+
then
111+
echo "*** ERROR. There is no schema change path from the installed version to the new version. ***"
112+
exit 1
113+
fi
114+
115+
fi
116+
117+
install_pip3_packages
118+
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#!/bin/sh
2+
3+
##--------------------------------------------------------------------
4+
## Copyright (c) 2018 OSIsoft, LLC
5+
##
6+
## Licensed under the Apache License, Version 2.0 (the "License");
7+
## you may not use this file except in compliance with the License.
8+
## You may obtain a copy of the License at
9+
##
10+
## http://www.apache.org/licenses/LICENSE-2.0
11+
##
12+
## Unless required by applicable law or agreed to in writing, software
13+
## distributed under the License is distributed on an "AS IS" BASIS,
14+
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
## See the License for the specific language governing permissions and
16+
## limitations under the License.
17+
##--------------------------------------------------------------------
18+
19+
##--------------------------------------------------------------------
20+
##
21+
## @prerm DEBIAN/prerm
22+
## This script is used to execute pre installation tasks.
23+
##
24+
## Author: Ivan Zoratti, Ashwin Gopalakrishnan
25+
##
26+
##--------------------------------------------------------------------
27+
28+
set -e
29+
30+
PKG_NAME="foglamp"
31+
32+
get_foglamp_script () {
33+
foglamp_script=$(dpkg -L $PKG_NAME | grep 'foglamp/bin/foglamp$')
34+
echo $foglamp_script
35+
}
36+
37+
stop_foglamp_service () {
38+
systemctl stop foglamp
39+
}
40+
41+
is_foglamp_running () {
42+
set +e
43+
foglamp_script=$(get_foglamp_script)
44+
foglamp_status_output=$($foglamp_script status 2>&1 | grep 'FogLAMP Uptime')
45+
rc=$((!$?))
46+
echo $rc
47+
set -e
48+
}
49+
50+
kill_foglamp () {
51+
set +e
52+
foglamp_script=$(get_foglamp_script)
53+
foglamp_status_output=$($foglamp_script kill 2>&1)
54+
set -e
55+
}
56+
57+
disable_foglamp_service () {
58+
systemctl disable foglamp
59+
}
60+
61+
remove_foglamp_service_file () {
62+
rm -rf /etc/init.d/foglamp
63+
}
64+
65+
reset_systemctl () {
66+
systemctl daemon-reload
67+
systemctl reset-failed
68+
}
69+
70+
remove_pycache_files () {
71+
set +e
72+
find /usr/local/foglamp -name "*.pyc" -exec rm -rf {} \;
73+
find /usr/local/foglamp -name "__pycache__" -exec rm -rf {} \;
74+
set -e
75+
}
76+
77+
remove_data_files () {
78+
rm -rf /usr/local/foglamp/data
79+
}
80+
81+
# main
82+
83+
IS_FOGLAMP_RUNNING=$(is_foglamp_running)
84+
if [ "$IS_FOGLAMP_RUNNING" -eq "1" ]
85+
then
86+
echo "FogLAMP is currently running."
87+
echo "Stop FogLAMP service."
88+
stop_foglamp_service
89+
echo "Kill FogLAMP."
90+
kill_foglamp
91+
fi
92+
93+
#echo "Remove data directory."
94+
#remove_data_files
95+
echo "Remove python cache files."
96+
remove_pycache_files
97+
echo "Disable FogLAMP service."
98+
disable_foglamp_service
99+
echo "Remove FogLAMP service script"
100+
remove_foglamp_service_file
101+
echo "Reset systemctl"
102+
reset_systemctl
103+

packages/Debian/x86_64/DEBIAN/control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Version: 0.0
33
Section: devel
44
Priority: optional
55
Architecture: amd64
6-
Depends:
6+
Depends: postgresql,libpq-dev,autoconf,libtool,jq,libboost-dev,libboost-system-dev,libboost-thread-dev,sqlite3,python-setuptools,python3-pip
77
Conflicts:
88
Maintainer: Dianomic Systems, Inc. <[email protected]>
99
Homepage: http://www.dianomic.com

0 commit comments

Comments
 (0)