blob: a9d0c37e1c2b85d5b12552bc74646ec271416497 [file] [log] [blame]
tierno205d1022016-07-21 11:26:22 +02001#!/bin/bash
2
3##
4# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
5# This file is part of openmano
6# All Rights Reserved.
7#
8# Licensed under the Apache License, Version 2.0 (the "License"); you may
9# not use this file except in compliance with the License. You may obtain
10# a copy of the License at
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing, software
15# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17# License for the specific language governing permissions and limitations
18# under the License.
19#
20# For those usages not covered by the Apache License, Version 2.0 please
21# contact with: nfvlabs@tid.es
22##
23
24#ONLY TESTED for Ubuntu 16.04
25#it configures openmano to run as a service
26
27function usage(){
28 echo -e "usage: sudo $0 [OPTIONS]"
29 echo -e "Configures openmano to run as a service"
30 echo -e " OPTIONS"
31 echo -e " -u USER user to run openmano, 'root' by default"
32 echo -e " -f PATH path where openmano source is located. If missing it download from git"
33 echo -e " -q: install in an unattended mode"
34 echo -e " -h: show this help"
35}
36
37
38USER="root"
39QUIET_MODE=""
40FILE=""
41DELETE=""
42while getopts ":u:f:hq-:" o; do
43 case "${o}" in
44 u)
45 export USER="$OPTARG"
46 ;;
47 f)
48 export FILE="$OPTARG"
49 ;;
50 q)
51 export QUIET_MODE=yes
52 ;;
53 h)
54 usage && exit 0
55 ;;
56 -)
57 [ "${OPTARG}" == "help" ] && usage && exit 0
58 echo -e "Invalid option: '--$OPTARG'\nTry $0 --help for more information" >&2
59 exit 1
60 ;;
61 \?)
62 echo -e "Invalid option: '-$OPTARG'\nTry $0 --help for more information" >&2
63 exit 1
64 ;;
65 :)
66 echo -e "Option '-$OPTARG' requires an argument\nTry $0 --help for more information" >&2
67 exit 1
68 ;;
69 *)
70 usage >&2
71 exit -1
72 ;;
73 esac
74done
75
76#check root privileges and non a root user behind
77[ "$USER" != "root" ] && echo "Needed root privileges" >&2 && exit 1
78
79#Discover Linux distribution
80#try redhat type
81[ -f /etc/redhat-release ] && _DISTRO=$(cat /etc/redhat-release 2>/dev/null | cut -d" " -f1)
82#if not assuming ubuntu type
83[ -f /etc/redhat-release ] || _DISTRO=$(lsb_release -is 2>/dev/null)
84if [ "$_DISTRO" == "Ubuntu" ]
85then
86 _RELEASE=`lsb_release -rs`
87 if ! lsb_release -rs | grep -q -e "16.04"
88 then
89 echo "Only tested in Ubuntu Server 16.04" >&2 && exit 1
90 fi
91else
92 echo "Only tested in Ubuntu Server 16.04" >&2 && exit 1
93fi
94
95
96if [[ -z $FILE ]]
97then
98 git clone https://osm.etsi.org/gerrit/osm/RO.git openmano
99 FILE=./openmano
100 DELETE=y
101fi
102cp -r $FILE /opt/openmano
103cp ${FILE}/openmano /usr/sbin/
104mv /opt/openmano/openmanod.cfg /etc/default/openmanod.cfg
105mkdir -p /var/log/openmano/
106mkdir -p etc/systemd/system/
107
108
109cat >> /etc/systemd/system/openmano.service << EOF
110[Unit]
111Description=openmano server
112
113[Service]
114User=${USER}
115ExecStart=/opt/openmano/openmanod.py -c /etc/default/openmanod.cfg --log-file=/var/log/openmano/openmano.log
116Restart=always
117
118[Install]
119WantedBy=multi-user.target
120EOF
121
122[[ -n $DELETE ]] && rm -rf $FILE
123
124service openmano start
125
126echo Done
127exit