| garciadeblas | 8fed108 | 2022-08-29 11:25:02 +0200 | [diff] [blame] | 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 | |
| 16 | set +eux |
| 17 | |
| 18 | function usage(){ |
| 19 | [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function |
| 20 | echo -e "usage: $0 [OPTIONS]" |
| 21 | echo -e "Install Juju for OSM" |
| 22 | echo -e " OPTIONS" |
| 23 | echo -e " -h / --help: print this help" |
| 24 | echo -e " -D <devops path> use local devops installation path" |
| 25 | echo -e " -H <VCA host> use specific juju host controller IP" |
| 26 | echo -e " -S <VCA secret> use VCA/juju secret key" |
| 27 | echo -e " -P <VCA pubkey> use VCA/juju public key file" |
| 28 | echo -e " -l: LXD cloud yaml file" |
| 29 | echo -e " -L: LXD credentials yaml file" |
| 30 | echo -e " -K: Specifies the name of the controller to use - The controller must be already bootstrapped" |
| 31 | echo -e " --debug: debug mode" |
| 32 | echo -e " --cachelxdimages: cache local lxd images, create cronjob for that cache (will make installation longer)" |
| 33 | echo -e " --nojuju: do not juju, assumes already installed" |
| 34 | [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function |
| 35 | } |
| 36 | |
| 37 | function install_lxd() { |
| 38 | [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function |
| 39 | # Apply sysctl production values for optimal performance |
| 40 | sudo cp ${OSM_DEVOPS}/installers/60-lxd-production.conf /etc/sysctl.d/60-lxd-production.conf |
| 41 | sudo sysctl --system |
| 42 | |
| 43 | # Install LXD snap |
| 44 | sudo apt-get remove --purge -y liblxc1 lxc-common lxcfs lxd lxd-client |
| 45 | snap info lxd | grep installed > /dev/null |
| 46 | if [ $? -eq 0 ]; then |
| 47 | sudo snap refresh lxd --channel $LXD_VERSION/stable |
| 48 | else |
| 49 | sudo snap install lxd --channel $LXD_VERSION/stable |
| 50 | fi |
| 51 | |
| garciadeblas | 45ab04c | 2022-11-25 10:59:03 +0100 | [diff] [blame] | 52 | # Get default iface, IP and MTU |
| 53 | if [ -n "${OSM_DEFAULT_IF}" ]; then |
| 54 | OSM_DEFAULT_IF=$(ip route list|awk '$1=="default" {print $5; exit}') |
| 55 | [ -z "${OSM_DEFAULT_IF}" ] && OSM_DEFAULT_IF=$(route -n |awk '$1~/^0.0.0.0/ {print $8; exit}') |
| garciadeblas | 6003632 | 2023-06-02 11:09:39 +0200 | [diff] [blame] | 56 | [ -z "${OSM_DEFAULT_IF}" ] && FATAL_TRACK lxd "Not possible to determine the interface with the default route 0.0.0.0" |
| garciadeblas | 45ab04c | 2022-11-25 10:59:03 +0100 | [diff] [blame] | 57 | fi |
| 58 | DEFAULT_MTU=$(ip addr show ${OSM_DEFAULT_IF} | perl -ne 'if (/mtu\s(\d+)/) {print $1;}') |
| 59 | OSM_DEFAULT_IP=`ip -o -4 a s ${OSM_DEFAULT_IF} |awk '{split($4,a,"/"); print a[1]; exit}'` |
| garciadeblas | 6003632 | 2023-06-02 11:09:39 +0200 | [diff] [blame] | 60 | [ -z "$OSM_DEFAULT_IP" ] && FATAL_TRACK lxd "Not possible to determine the IP address of the interface with the default route" |
| garciadeblas | 45ab04c | 2022-11-25 10:59:03 +0100 | [diff] [blame] | 61 | |
| garciadeblas | 8fed108 | 2022-08-29 11:25:02 +0200 | [diff] [blame] | 62 | # Configure LXD |
| 63 | sudo usermod -a -G lxd `whoami` |
| garciadeblas | 45ab04c | 2022-11-25 10:59:03 +0100 | [diff] [blame] | 64 | cat ${OSM_DEVOPS}/installers/lxd-preseed.conf | sed 's/^config: {}/config:\n core.https_address: '$OSM_DEFAULT_IP':8443/' | sg lxd -c "lxd init --preseed" |
| garciadeblas | 8fed108 | 2022-08-29 11:25:02 +0200 | [diff] [blame] | 65 | sg lxd -c "lxd waitready" |
| garciadeblas | fa3eb33 | 2022-11-15 14:11:56 +0100 | [diff] [blame] | 66 | |
| 67 | # Configure LXD to work behind a proxy |
| 68 | if [ -n "${OSM_BEHIND_PROXY}" ] ; then |
| 69 | [ -n "${HTTP_PROXY}" ] && sg lxd -c "lxc config set core.proxy_http $HTTP_PROXY" |
| 70 | [ -n "${HTTPS_PROXY}" ] && sg lxd -c "lxc config set core.proxy_https $HTTPS_PROXY" |
| 71 | [ -n "${NO_PROXY}" ] && sg lxd -c "lxc config set core.proxy_ignore_hosts $NO_PROXY" |
| 72 | fi |
| 73 | |
| garciadeblas | 8fed108 | 2022-08-29 11:25:02 +0200 | [diff] [blame] | 74 | [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function |
| 75 | } |
| 76 | |
| 77 | DEBUG_INSTALL="" |
| 78 | LXD_VERSION=5.0 |
| 79 | OSM_DEVOPS= |
| garciadeblas | fa3eb33 | 2022-11-15 14:11:56 +0100 | [diff] [blame] | 80 | OSM_BEHIND_PROXY="" |
| garciadeblas | 8fed108 | 2022-08-29 11:25:02 +0200 | [diff] [blame] | 81 | |
| 82 | # main |
| garciadeblas | fa3eb33 | 2022-11-15 14:11:56 +0100 | [diff] [blame] | 83 | while getopts ":D:d:i:-: hP" o; do |
| garciadeblas | 8fed108 | 2022-08-29 11:25:02 +0200 | [diff] [blame] | 84 | case "${o}" in |
| 85 | i) |
| garciadeblas | 45ab04c | 2022-11-25 10:59:03 +0100 | [diff] [blame] | 86 | OSM_DEFAULT_IF="${OPTARG}" |
| garciadeblas | 8fed108 | 2022-08-29 11:25:02 +0200 | [diff] [blame] | 87 | ;; |
| 88 | d) |
| 89 | OSM_DOCKER_WORK_DIR="${OPTARG}" |
| 90 | ;; |
| 91 | D) |
| 92 | OSM_DEVOPS="${OPTARG}" |
| 93 | ;; |
| garciadeblas | fa3eb33 | 2022-11-15 14:11:56 +0100 | [diff] [blame] | 94 | P) |
| 95 | OSM_BEHIND_PROXY="y" |
| 96 | ;; |
| garciadeblas | 8fed108 | 2022-08-29 11:25:02 +0200 | [diff] [blame] | 97 | -) |
| 98 | [ "${OPTARG}" == "help" ] && usage && exit 0 |
| 99 | [ "${OPTARG}" == "debug" ] && DEBUG_INSTALL="y" && continue |
| 100 | echo -e "Invalid option: '--$OPTARG'\n" >&2 |
| 101 | exit 1 |
| 102 | ;; |
| 103 | :) |
| 104 | echo "Option -$OPTARG requires an argument" >&2 |
| 105 | exit 1 |
| 106 | ;; |
| 107 | \?) |
| 108 | echo -e "Invalid option: '-$OPTARG'\n" >&2 |
| 109 | exit 1 |
| 110 | ;; |
| 111 | h) |
| 112 | usage && exit 0 |
| 113 | ;; |
| 114 | *) |
| 115 | exit 1 |
| 116 | ;; |
| 117 | esac |
| 118 | done |
| 119 | |
| 120 | source $OSM_DEVOPS/common/logging |
| 121 | source $OSM_DEVOPS/common/track |
| 122 | |
| 123 | echo "DEBUG_INSTALL=$DEBUG_INSTALL" |
| garciadeblas | fa3eb33 | 2022-11-15 14:11:56 +0100 | [diff] [blame] | 124 | echo "OSM_BEHIND_PROXY=$OSM_BEHIND_PROXY" |
| garciadeblas | 45ab04c | 2022-11-25 10:59:03 +0100 | [diff] [blame] | 125 | echo "OSM_DEFAULT_IF=$OSM_DEFAULT_IF" |
| garciadeblas | 8fed108 | 2022-08-29 11:25:02 +0200 | [diff] [blame] | 126 | echo "OSM_DEVOPS=$OSM_DEVOPS" |
| 127 | |
| 128 | [ -z "$INSTALL_NOJUJU" ] && install_lxd |
| garciadeblas | 5671dce | 2023-05-18 11:28:16 +0200 | [diff] [blame] | 129 | track prereq lxd_install_ok |
| garciadeblas | 8fed108 | 2022-08-29 11:25:02 +0200 | [diff] [blame] | 130 | |