+ sleep 2
+ sudo service docker restart
+ echo "... restarted Docker service"
+}
+
+function install_docker_compose() {
+ # installs and configures docker-compose
+ echo "Installing Docker Compose ..."
+ sudo curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
+ sudo chmod +x /usr/local/bin/docker-compose
+ echo "... Docker Compose installation done"
+}
+
+function install_juju() {
+ echo "Installing juju"
+ sudo snap install juju --classic
+ sudo dpkg-reconfigure -p medium lxd
+ juju bootstrap localhost osm
+ echo "Finished installation of juju"
+}
+
+function generate_docker_images() {
+ echo "Pulling and generating docker images"
+ newgrp docker << EONG
+ docker pull wurstmeister/kafka
+ docker pull wurstmeister/zookeeper
+ docker pull mongo
+ docker pull mysql:5
+ git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/MON
+ docker build ${LWTEMPDIR}/MON -f ${LWTEMPDIR}/MON/docker/Dockerfile -t osm/mon || ! echo "cannot build MON docker image" >&2
+ docker build ${LWTEMPDIR}/MON/policy_module -f ${LWTEMPDIR}/MON/policy_module/Dockerfile -t osm/pm || ! echo "cannot build PM docker image" >&2
+ git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/NBI
+ docker build ${LWTEMPDIR}/NBI -f ${LWTEMPDIR}/NBI/Dockerfile.local -t osm/nbi || ! echo "cannot build NBI docker image" >&2
+ git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/RO
+ docker build ${LWTEMPDIR}/RO -f ${LWTEMPDIR}/RO/docker/Dockerfile-local -t osm/ro || ! echo "cannot build RO docker image" >&2
+ docker build ${LWTEMPDIR}/RO/lcm -t osm/lcm || ! echo "cannot build LCM docker image" >&2
+ git -C ${LWTEMPDIR} clone https://github.com/superfluidity/osm-light-ui.git
+ docker build ${LWTEMPDIR}/osm-light-ui -t osm/light-ui -f ${LWTEMPDIR}/osm-light-ui/code/docker/Dockerfile
+EONG
+ echo "Finished generation of docker images"
+}
+
+function generate_docker_env_files() {
+ echo "Generating docker env files"
+ OSMLCM_VCA_HOST=`juju show-controller|grep api-endpoints|awk -F\' '{print $2}'|awk -F\: '{print $1}'`
+ OSMLCM_VCA_SECRET=`grep password /home/ubuntu/.local/share/juju/accounts.yaml |awk '{print $2}'`
+ MYSQL_ROOT_PASSWORD=`date +%s | sha256sum | base64 | head -c 32`
+ echo "OSMLCM_VCA_HOST=${OSMLCM_VCA_HOST}" |sudo tee ${OSM_DEVOPS}/installers/docker/lcm.env
+ echo "OSMLCM_VCA_SECRET=${OSMLCM_VCA_SECRET}" |sudo tee -a ${OSM_DEVOPS}/installers/docker/lcm.env
+ echo "MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}" |sudo tee ${OSM_DEVOPS}/installers/docker/ro-db.env
+ echo "RO_DB_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}" |sudo tee ${OSM_DEVOPS}/installers/docker/ro.env
+ echo "OS_NOTIFIER_URI=http://${DEFAULT_IP}:8662" |sudo tee ${OSM_DEVOPS}/installers/docker/mon.env
+ echo "Finished generation of docker env files"
+}
+
+function deploy_lightweight() {
+ echo "Deploying lightweight build"
+ newgrp docker << EONG
+ docker swarm init --advertise-addr ${DEFAULT_IP}
+ docker network create --driver=overlay --attachable --opt com.docker.network.driver.mtu=${DEFAULT_MTU} netOSM
+ docker stack deploy -c ${OSM_DEVOPS}/installers/docker/docker-compose.yaml osm
+ #docker-compose -f /usr/share/osm-devops/installers/docker/docker-compose.yaml up -d
+EONG
+ echo "Finished deployment of lightweight build"
+}
+
+function install_lightweight() {
+ echo "Installing lightweight build of OSM"
+ LWTEMPDIR="$(mktemp -d -q --tmpdir "installosmlight.XXXXXX")"
+ trap 'rm -rf "${LWTEMPDIR}"' EXIT
+ DEFAULT_IF=`route -n |awk '$1~/^0.0.0.0/ {print $8}'`
+ DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
+ DEFAULT_MTU=$(ip addr show ${DEFAULT_IF} | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
+ install_juju
+ install_docker_ce
+ #install_docker_compose
+ generate_docker_images
+ generate_docker_env_files
+ deploy_lightweight
+ install_osmclient
+ return 0