|
| 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 | + |
0 commit comments