blob: 539f19fe8b1daf2c61cf27d3ad8f55088fe63b60 [file] [log] [blame]
garciadeblas6e0f2002017-11-22 16:02:00 +01001#!/bin/bash
2# Copyright 2017 Telefónica Investigación y Desarrollo S.A.U.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16function usage(){
17 echo -e "usage: $0 [OPTIONS]"
18 echo -e "Install OSM from binaries or source code (by default, from binaries)"
19 echo -e " OPTIONS"
20 echo -e " --uninstall: uninstall OSM: remove the containers and delete NAT rules"
21 echo -e " --source: install OSM from source code using the latest stable tag"
22 echo -e " -r <repo>: use specified repository name for osm packages"
23 echo -e " -R <release>: use specified release for osm binaries (deb packages, lxd images, ...)"
24 echo -e " -u <repo base>: use specified repository url for osm packages"
25 echo -e " -k <repo key>: use specified repository public key url"
26 echo -e " -b <refspec>: install OSM from source code using a specific branch (master, v2.0, ...) or tag"
27 echo -e " -b master (main dev branch)"
28 echo -e " -b v2.0 (v2.0 branch)"
29 echo -e " -b tags/v1.1.0 (a specific tag)"
30 echo -e " ..."
31 echo -e " --lxdimages: download lxd images from OSM repository instead of creating them from scratch"
32 echo -e " -l <lxd_repo>: use specified repository url for lxd images"
33 echo -e " --develop: (deprecated, use '-b master') install OSM from source code using the master branch"
34# echo -e " --reconfigure: reconfigure the modules (DO NOT change NAT rules)"
35 echo -e " --nat: install only NAT rules"
36 echo -e " --noconfigure: DO NOT install osmclient, DO NOT install NAT rules, DO NOT configure modules"
37# echo -e " --update: update to the latest stable release or to the latest commit if using a specific branch"
38 echo -e " --showopts: print chosen options and exit (only for debugging)"
39 echo -e " -y: do not prompt for confirmation, assumes yes"
40 echo -e " -h / --help: print this help"
41}
42
43function FATAL() {
44 echo -e $1
45 exit 1
46}
47
48TEST_INSTALLER=""
49LATEST_STABLE_DEVOPS=""
50
51while getopts ":h" o; do
52 case "${o}" in
53 h)
54 usage && exit 0
55 ;;
56 -)
57 [ "${OPTARG}" == "help" ] && usage && exit 0
58 [ "${OPTARG}" == "test" ] && TEST_INSTALLER="y" && continue
59 ;;
60 esac
61done
62
63if [ -n "$TEST_INSTALLER" ]; then
64 echo -e "\nUsing local devops repo for OSM installation"
65 TEMPDIR="$(dirname $(realpath $(dirname $0)))"
66else
67 echo -e "\nCreating temporary dir for OSM installation"
68 TEMPDIR="$(mktemp -d -q --tmpdir "installosm.XXXXXX")"
69 trap 'rm -rf "$TEMPDIR"' EXIT
70fi
71
72if [ -z "$TEST_INSTALLER" ]; then
73 need_packages="git"
74 for package in $need_packages; do
75 echo -e "Checking required packages: $package"
76 dpkg -l $package &>/dev/null \
77 || ! echo -e " $package not installed.\nInstalling $package requires root privileges" \
78 || sudo apt-get install -y $package \
79 || FATAL "failed to install $package"
80 done
81 echo -e "\nCloning devops repo temporarily"
82 git clone https://osm.etsi.org/gerrit/osm/devops.git $TEMPDIR
83 echo -e "\nGuessing the current stable release"
84 LATEST_STABLE_DEVOPS=`git -C $TEMPDIR tag -l v[0-9].* | sort -V | tail -n1`
85 [ -z "$LATEST_STABLE_DEVOPS" ] && FATAL "Could not find the current latest stable release"
86 echo "Using latest tag in devops repo: $LATEST_STABLE_DEVOPS"
87 git -C $TEMPDIR checkout tags/$LATEST_STABLE_DEVOPS || FATAL "Could not checkout latest tag"
88fi
89
90$TEMPDIR/installers/install_osm.sh --test $*
91