1e3a6fe7f27949ae38c81d8a99532cdf7d719925
[ta/remote-installer.git] / scripts / start.sh
1 #!/bin/bash
2 # Copyright 2019 Nokia
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
16 set -e
17
18 cd "$(dirname "$0")"/..
19
20 API_PORT="15101"
21 BASE_DIR=""
22 CONT_NAME="remote-installer"
23 EXT_IP=""
24 HTTPS_PORT="443"
25 IMG_NAME="remote-installer"
26 ROOT_PW="root"
27
28 error()
29 {
30     echo "ERROR : $1"
31     [ -z $2 ] || help
32     exit 1
33 }
34
35 help()
36 {
37     echo -e "$(basename $0) [-h -a <api-port> -c <cont> -i <image> -r <pw> -s <https-port> ] -b <basedir> -e <ip-addr>"
38     echo -e "   -h  display this help"
39     echo -e "   -a  rest API port, default $API_PORT"
40     echo -e "   -c  container name, default $CONT_NAME"
41     echo -e "   -b  base directory, which contains images, certificates, etc."
42     echo -e "   -e  external ip address of  the docker"
43     echo -e "   -i  secure https port, default $IMG_NAME"
44     echo -e "   -p  root password, default $ROOT_PW"
45     echo -e "   -s  secure https port, default $HTTPS_PORT"
46 }
47
48 while getopts "ha:b:e:s:c:p:i:" arg; do
49     case $arg in
50         h)
51             help
52             exit 0
53             ;;
54         b)
55             BASE_DIR="$OPTARG"
56             ;;
57         e)
58             EXT_IP="$OPTARG"
59             ;;
60         s)
61             HTTPS_PORT="$OPTARG"
62             ;;
63         a)
64             API_PORT="$OPTARG"
65             ;;
66         c)
67             CONT_NAME="$OPTARG"
68             ;;
69         i)
70             IMG_NAME="$OPTARG"
71             ;;
72         p)
73             ROOT_PW="$OPTARG"
74             ;;
75         *)
76             error "Unknow argument!" showhelp
77             ;;
78   esac
79 done
80
81 [ -n "$EXT_IP" ] || error "No external IP defined!" showhelp
82 [ -n "$BASE_DIR" ] || error "No base directory defined!" showhelp
83
84 cont_id="$(docker run --detach --rm --privileged \
85      --env API_PORT="$API_PORT" \
86      --env HOST_ADDR="$EXT_IP" \
87      --env HTTPS_PORT="$HTTPS_PORT" \
88      --env PW="$ROOT_PW" \
89      --volume "$BASE_DIR":/opt/remoteinstaller --publish "$HTTPS_PORT":"$HTTPS_PORT" -p 2049:2049 -p "$API_PORT":"$API_PORT" --name "$CONT_NAME" "$IMG_NAME")" \
90        || error "failed to start container"
91
92 echo -e "Container successfully started"
93 echo -e "ID : $cont_id"
94 echo -e "IP : $(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$cont_id")"