blob: 4fda0901d0828fc78f68d2a49c0a89be1ec73033 [file] [log] [blame]
garciadeblascf603f52025-06-04 11:57:28 +02001#######################################################################################
2# Copyright ETSI Contributors and Others.
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
13# implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#######################################################################################
17
18
19function setup_external_ip() {
20 echo "Determining IP address of the interface with the default route"
21 [ -z "$OSM_DEFAULT_IF" ] && OSM_DEFAULT_IF=$(ip route list|awk '$1=="default" {print $5; exit}')
22 [ -z "$OSM_DEFAULT_IF" ] && OSM_DEFAULT_IF=$(route -n |awk '$1~/^0.0.0.0/ {print $8; exit}')
23 [ -z "$OSM_DEFAULT_IF" ] && FATAL "Not possible to determine the interface with the default route 0.0.0.0"
24 OSM_DEFAULT_IP=`ip -o -4 a s ${OSM_DEFAULT_IF} |awk '{split($4,a,"/"); print a[1]; exit}'`
25 [ -z "$OSM_DEFAULT_IP" ] && FATAL "Not possible to determine the IP address of the interface with the default route"
26 OSM_K8S_EXTERNAL_IP=${OSM_K8S_EXTERNAL_IP:-${OSM_DEFAULT_IP}}
27}
28
29function parse_docker_registry_url() {
30 DOCKER_REGISTRY_USER=$(echo "$1" | awk '{split($1,a,"@"); split(a[1],b,":"); print b[1]}')
31 DOCKER_REGISTRY_PASSWORD=$(echo "$1" | awk '{split($1,a,"@"); split(a[1],b,":"); print b[2]}')
32 DOCKER_REGISTRY_URL=$(echo "$1" | awk '{split($1,a,"@"); print a[2]}')
33}
34
35function configure_apt_proxy() {
36 OSM_APT_PROXY=$1
37 OSM_APT_PROXY_FILE="/etc/apt/apt.conf.d/osm-apt"
38 echo "Configuring apt proxy in file ${OSM_APT_PROXY_FILE}"
39 if [ ! -f ${OSM_APT_PROXY_FILE} ]; then
40 sudo bash -c "cat <<EOF > ${OSM_APT_PROXY}
41Acquire::http { Proxy \"${OSM_APT_PROXY}\"; }
42EOF"
43 else
44 sudo sed -i "s|Proxy.*|Proxy \"${OSM_APT_PROXY}\"; }|" ${OSM_APT_PROXY_FILE}
45 fi
46 sudo apt-get update || FATAL "Configured apt proxy, but couldn't run 'apt-get update'. Check ${OSM_APT_PROXY_FILE}"
47 track prereq apt_proxy_configured_ok
48 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
49}
50
51function ask_user(){
52 # ask to the user and parse a response among 'y', 'yes', 'n' or 'no'. Case insensitive
53 # Params: $1 text to ask; $2 Action by default, can be 'y' for yes, 'n' for no, other or empty for not allowed
54 # Return: true(0) if user type 'yes'; false (1) if user type 'no'
55 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
56 read -e -p "$1" USER_CONFIRMATION
57 while true ; do
58 [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'y' ] && return 0
59 [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'n' ] && return 1
60 [ "${USER_CONFIRMATION,,}" == "yes" ] || [ "${USER_CONFIRMATION,,}" == "y" ] && return 0
61 [ "${USER_CONFIRMATION,,}" == "no" ] || [ "${USER_CONFIRMATION,,}" == "n" ] && return 1
62 read -e -p "Please type 'yes' or 'no': " USER_CONFIRMATION
63 done
64 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
65}
66
67function docker_login() {
68 echo "Docker login"
69 DEBUG "Docker registry user: ${DOCKER_REGISTRY_USER}"
70 sg docker -c "docker login -u ${DOCKER_REGISTRY_USER} -p ${DOCKER_REGISTRY_PASSWORD} --password-stdin"
71}
72
73function ask_proceed() {
74 [ -z "$ASSUME_YES" ] && ! ask_user "The installation will do the following
75 1. Install client tools (helm, kubectl, osmclient, wget, git, curl, tar, yq, flux, argo, kustomize)
76 2. Deploy auxiliary services (Git, S3)
77 3. Deploy mgmt cluster
78 4. Deploy OSM
79 5. Provision OSM
80 Do you want to proceed (Y/n)? " y && echo "Cancelled!" && exit 1
81}
82
83function check_osm_behind_proxy() {
84 export OSM_BEHIND_PROXY=""
85 export OSM_PROXY_ENV_VARIABLES=""
86 [ -n "${http_proxy}" ] && OSM_BEHIND_PROXY="y" && echo "http_proxy=${http_proxy}" && OSM_PROXY_ENV_VARIABLES="${OSM_PROXY_ENV_VARIABLES} http_proxy"
87 [ -n "${https_proxy}" ] && OSM_BEHIND_PROXY="y" && echo "https_proxy=${https_proxy}" && OSM_PROXY_ENV_VARIABLES="${OSM_PROXY_ENV_VARIABLES} https_proxy"
88 [ -n "${HTTP_PROXY}" ] && OSM_BEHIND_PROXY="y" && echo "HTTP_PROXY=${HTTP_PROXY}" && OSM_PROXY_ENV_VARIABLES="${OSM_PROXY_ENV_VARIABLES} HTTP_PROXY"
89 [ -n "${HTTPS_PROXY}" ] && OSM_BEHIND_PROXY="y" && echo "HTTPS_PROXY=${HTTPS_PROXY}" && OSM_PROXY_ENV_VARIABLES="${OSM_PROXY_ENV_VARIABLES} HTTPS_PROXY"
90 [ -n "${no_proxy}" ] && echo "no_proxy=${no_proxy}" && OSM_PROXY_ENV_VARIABLES="${OSM_PROXY_ENV_VARIABLES} no_proxy"
91 [ -n "${NO_PROXY}" ] && echo "NO_PROXY=${NO_PROXY}" && OSM_PROXY_ENV_VARIABLES="${OSM_PROXY_ENV_VARIABLES} NO_PROXY"
92
93 echo "OSM_BEHIND_PROXY=${OSM_BEHIND_PROXY}"
94 echo "OSM_PROXY_ENV_VARIABLES=${OSM_PROXY_ENV_VARIABLES}"
95
96 if [ -n "${OSM_BEHIND_PROXY}" ]; then
97 [ -z "$ASSUME_YES" ] && ! ask_user "
98The following env variables have been found for the current user:
99${OSM_PROXY_ENV_VARIABLES}.
100
101This suggests that this machine is behind a proxy and a special configuration is required.
102The installer will install Docker CE and a Kubernetes to work behind a proxy using those
103env variables.
104
105Take into account that the installer uses apt, curl, wget and docker.
106Depending on the program, the env variables to work behind a proxy might be different
107(e.g. http_proxy vs HTTP_PROXY).
108
109For that reason, it is strongly recommended that at least http_proxy, https_proxy, HTTP_PROXY
110and HTTPS_PROXY are defined.
111
112Finally, some of the programs (apt) are run as sudoer, requiring that those env variables
113are also set for root user. If you are not sure whether those variables are configured for
114the root user, you can stop the installation now.
115
116Do you want to proceed with the installation (Y/n)? " y && echo "Cancelled!" && exit 1
117 else
118 echo "This machine is not behind a proxy"
119 fi
120}
121