New options in installer to install only docker, k8scluster or deploy-osm
[osm/devops.git] / installers / install_osm.sh
1 #!/bin/bash
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 #
15 REPOSITORY_BASE=https://osm-download.etsi.org/repository/osm/debian
16 RELEASE=ReleaseFIFTEEN
17 REPOSITORY=stable
18 DOCKER_TAG="testing-daily"
19 DEVOPS_PATH=/usr/share/osm-devops
20
21 function usage(){
22 echo -e "usage: $0 [OPTIONS]"
23 echo -e "Install OSM"
24 echo -e " OPTIONS"
25 echo -e " -h / --help: print this help"
26 echo -e " -y: do not prompt for confirmation, assumes yes"
27 echo -e " -r <repo>: use specified repository name for osm packages"
28 echo -e " -R <release>: use specified release for osm binaries (deb packages, lxd images, ...)"
29 echo -e " -u <repo base>: use specified repository url for osm packages"
30 echo -e " -k <repo key>: use specified repository public key url"
31 echo -e " -a <apt proxy url>: use this apt proxy url when downloading apt packages (air-gapped installation)"
32 echo -e " -s <namespace> namespace when installed using k8s, default is osm"
33 echo -e " -H <VCA host> use specific juju host controller IP"
34 echo -e " -S <VCA secret> use VCA/juju secret key"
35 echo -e " -P <VCA pubkey> use VCA/juju public key file"
36 echo -e " -A <VCA apiproxy> use VCA/juju API proxy"
37 echo -e " --pla: install the PLA module for placement support"
38 echo -e " --old-sa: install old Service Assurance framework (MON, POL); do not install Airflow and Pushgateway"
39 echo -e " --ng-sa: install new Service Assurance framework (Airflow, AlertManager and Pushgateway) (enabled by default)"
40 echo -e " -o <COMPONENT>: ONLY installs the specified component (k8s_monitor, ng-sa, k8scluster, docker, deploy-osm)"
41 echo -e " -O <openrc file path/cloud name>: Install OSM to an OpenStack infrastructure. <openrc file/cloud name> is required. If a <cloud name> is used, the clouds.yaml file should be under ~/.config/openstack/ or /etc/openstack/"
42 echo -e " -N <openstack public network name/ID>: Public network name required to setup OSM to OpenStack"
43 echo -e " -f <path to SSH public key>: Public SSH key to use to deploy OSM to OpenStack"
44 echo -e " -F <path to cloud-init file>: Cloud-Init userdata file to deploy OSM to OpenStack"
45 echo -e " -D <devops path> use local devops installation path"
46 echo -e " -w <work dir> Location to store runtime installation"
47 echo -e " -t <docker tag> specify osm docker tag (default is latest)"
48 echo -e " -l: LXD cloud yaml file"
49 echo -e " -L: LXD credentials yaml file"
50 echo -e " -K: Specifies the name of the controller to use - The controller must be already bootstrapped"
51 echo -e " -d <docker registry URL> use docker registry URL instead of dockerhub"
52 echo -e " -p <docker proxy URL> set docker proxy URL as part of docker CE configuration"
53 echo -e " -T <docker tag> specify docker tag for the modules specified with option -m"
54 echo -e " --debug: debug mode"
55 echo -e " --nocachelxdimages: do not cache local lxd images, do not create cronjob for that cache (will save installation time, might affect instantiation time)"
56 echo -e " --cachelxdimages: cache local lxd images, create cronjob for that cache (will make installation longer)"
57 echo -e " --nolxd: do not install and configure LXD, allowing unattended installations (assumes LXD is already installed and confifured)"
58 echo -e " --nodocker: do not install docker, do not initialize a swarm (assumes docker is already installed and a swarm has been initialized)"
59 echo -e " --nojuju: do not juju, assumes already installed"
60 echo -e " --nohostports: do not expose docker ports to host (useful for creating multiple instances of osm on the same host)"
61 echo -e " --nohostclient: do not install the osmclient"
62 echo -e " --uninstall: uninstall OSM: remove the containers and delete NAT rules"
63 echo -e " --k8s_monitor: install the OSM kubernetes monitoring with prometheus and grafana"
64 echo -e " --volume: create a VM volume when installing to OpenStack"
65 echo -e " --showopts: print chosen options and exit (only for debugging)"
66 echo -e " --charmed: Deploy and operate OSM with Charms on k8s"
67 echo -e " [--bundle <bundle path>]: Specify with which bundle to deploy OSM with charms (--charmed option)"
68 echo -e " [--k8s <kubeconfig path>]: Specify with which kubernetes to deploy OSM with charms (--charmed option)"
69 echo -e " [--vca <name>]: Specifies the name of the controller to use - The controller must be already bootstrapped (--charmed option)"
70 echo -e " [--small-profile]: Do not install and configure LXD which aims to use only K8s Clouds (--charmed option)"
71 echo -e " [--lxd <yaml path>]: Takes a YAML file as a parameter with the LXD Cloud information (--charmed option)"
72 echo -e " [--lxd-cred <yaml path>]: Takes a YAML file as a parameter with the LXD Credentials information (--charmed option)"
73 echo -e " [--microstack]: Installs microstack as a vim. (--charmed option)"
74 echo -e " [--overlay]: Add an overlay to override some defaults of the default bundle (--charmed option)"
75 echo -e " [--ha]: Installs High Availability bundle. (--charmed option)"
76 echo -e " [--tag]: Docker image tag. (--charmed option)"
77 echo -e " [--registry]: Docker registry with optional credentials as user:pass@hostname:port (--charmed option)"
78 }
79
80 add_repo() {
81 REPO_CHECK="^$1"
82 grep "${REPO_CHECK/\[arch=amd64\]/\\[arch=amd64\\]}" /etc/apt/sources.list > /dev/null 2>&1
83 if [ $? -ne 0 ]
84 then
85 need_packages_lw="software-properties-common apt-transport-https"
86 echo -e "Checking required packages to add ETSI OSM debian repo: $need_packages_lw"
87 dpkg -l $need_packages_lw &>/dev/null \
88 || ! echo -e "One or several required packages are not installed. Updating apt cache requires root privileges." \
89 || sudo apt-get -qy update \
90 || ! echo "failed to run apt-get update" \
91 || exit 1
92 dpkg -l $need_packages_lw &>/dev/null \
93 || ! echo -e "Installing $need_packages_lw requires root privileges." \
94 || sudo apt-get install -y $need_packages_lw \
95 || ! echo "failed to install $need_packages_lw" \
96 || exit 1
97 wget -q -O OSM-ETSI-Release-key.gpg "$REPOSITORY_BASE/$RELEASE/OSM%20ETSI%20Release%20Key.gpg"
98 sudo APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=1 apt-key add OSM-ETSI-Release-key.gpg \
99 || ! echo -e "Could not add GPG key $REPOSITORY_BASE/$RELEASE/OSM%20ETSI%20Release%20Key.gpg" \
100 || exit 1
101 sudo DEBIAN_FRONTEND=noninteractive add-apt-repository -y "$1"
102 sudo DEBIAN_FRONTEND=noninteractive apt-get -y update
103 return 0
104 fi
105
106 return 1
107 }
108
109 clean_old_repo() {
110 dpkg -s 'osm-devops' &> /dev/null
111 if [ $? -eq 0 ]; then
112 # Clean the previous repos that might exist
113 sudo sed -i "/osm-download.etsi.org/d" /etc/apt/sources.list
114 fi
115 }
116
117 function configure_apt_proxy() {
118 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
119 OSM_APT_PROXY=$1
120 OSM_APT_PROXY_FILE="/etc/apt/apt.conf.d/osm-apt"
121 echo "Configuring apt proxy in file ${OSM_APT_PROXY_FILE}"
122 if [ ! -f ${OSM_APT_PROXY_FILE} ]; then
123 sudo bash -c "cat <<EOF > ${OSM_APT_PROXY}
124 Acquire::http { Proxy \"${OSM_APT_PROXY}\"; }
125 EOF"
126 else
127 sudo sed -i "s|Proxy.*|Proxy \"${OSM_APT_PROXY}\"; }|" ${OSM_APT_PROXY_FILE}
128 fi
129 sudo apt-get -y update || FATAL "Configured apt proxy, but couldn't run 'apt-get update'. Check ${OSM_APT_PROXY_FILE}"
130 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
131 }
132
133 while getopts ":a:b:r:n:k:u:R:D:o:O:m:N:H:S:s:t:U:P:A:l:L:K:d:p:T:f:F:-: hy" o; do
134 case "${o}" in
135 D)
136 DEVOPS_PATH="${OPTARG}"
137 ;;
138 r)
139 REPOSITORY="${OPTARG}"
140 ;;
141 R)
142 RELEASE="${OPTARG}"
143 ;;
144 u)
145 REPOSITORY_BASE="${OPTARG}"
146 ;;
147 t)
148 DOCKER_TAG="${OPTARG}"
149 ;;
150 -)
151 [ "${OPTARG}" == "help" ] && usage && exit 0
152 ;;
153 :)
154 echo "Option -$OPTARG requires an argument" >&2
155 usage && exit 1
156 ;;
157 \?)
158 echo -e "Invalid option: '-$OPTARG'\n" >&2
159 usage && exit 1
160 ;;
161 h)
162 usage && exit 0
163 ;;
164 *)
165 ;;
166 esac
167 done
168
169 clean_old_repo
170 add_repo "deb [arch=amd64] $REPOSITORY_BASE/$RELEASE $REPOSITORY devops"
171 sudo DEBIAN_FRONTEND=noninteractive apt-get -qy update
172 sudo DEBIAN_FRONTEND=noninteractive apt-get -y install osm-devops
173 $DEVOPS_PATH/installers/full_install_osm.sh -R $RELEASE -r $REPOSITORY -u $REPOSITORY_BASE -D $DEVOPS_PATH -t $DOCKER_TAG "$@"