Merge "Add build_dir variable for build"
[osm/devops.git] / installers / full_install_osm.sh
index ffd4a27..cee7c8d 100755 (executable)
@@ -17,8 +17,6 @@ function usage(){
     echo -e "usage: $0 [OPTIONS]"
     echo -e "Install OSM from binaries or source code (by default, from binaries)"
     echo -e "  OPTIONS"
-    echo -e "     --uninstall:    uninstall OSM: remove the containers and delete NAT rules"
-    echo -e "     --source:       install OSM from source code using the latest stable tag"
     echo -e "     -r <repo>:      use specified repository name for osm packages"
     echo -e "     -R <release>:   use specified release for osm binaries (deb packages, lxd images, ...)"
     echo -e "     -u <repo base>: use specified repository url for osm packages"
@@ -28,23 +26,27 @@ function usage(){
     echo -e "                     -b v2.0            (v2.0 branch)"
     echo -e "                     -b tags/v1.1.0     (a specific tag)"
     echo -e "                     ..."
-    echo -e "     --lxdimages:    download lxd images from OSM repository instead of creating them from scratch"
-    echo -e "     -l <lxd_repo>:  use specified repository url for lxd images"
-    echo -e "     -p <path>:      use specified repository path for lxd images"
-    echo -e "     --lightweight:  install lightweight build of OSM (default installation)"
-    echo -e "     --soui:         install classic build of OSM (Rel THREE v3.1, based on LXD containers, with SO and UI)"
     echo -e "     --vimemu:       additionally deploy the VIM emulator as a docker container"
     echo -e "     --elk_stack:    additionally deploy an ELK docker stack for event logging"
     echo -e "     --pm_stack:     additionally deploy a Prometheus+Grafana stack for performance monitoring (PM)"
+    echo -e "     -m <MODULE>:    install OSM but only rebuild the specified docker images (RO, LCM, NBI, LW-UI, MON, KAFKA, MONGO, NONE)"
     echo -e "     -o <ADDON>:     do not install OSM, but ONLY one of the addons (vimemu, elk_stack, pm_stack) (assumes OSM is already installed)"
+    echo -e "     -D <devops path> use local devops installation path"
+    echo -e "     --nolxd:        do not install and configure LXD, allowing unattended installations (assumes LXD is already installed and confifured)"
+    echo -e "     --nodocker:     do not install docker, do not initialize a swarm (assumes docker is already installed and a swarm has been initialized)"
+    echo -e "     --uninstall:    uninstall OSM: remove the containers and delete NAT rules"
+    echo -e "     --source:       install OSM from source code using the latest stable tag"
     echo -e "     --develop:      (deprecated, use '-b master') install OSM from source code using the master branch"
+    echo -e "     --soui:         install classic build of OSM (Rel THREE v3.1, based on LXD containers, with SO and UI)"
+    echo -e "     --lxdimages:    (only for Rel THREE with --soui) download lxd images from OSM repository instead of creating them from scratch"
+    echo -e "     -l <lxd_repo>:  (only for Rel THREE with --soui) use specified repository url for lxd images"
+    echo -e "     -p <path>:      (only for Rel THREE with --soui) use specified repository path for lxd images"
 #    echo -e "     --reconfigure:  reconfigure the modules (DO NOT change NAT rules)"
-    echo -e "     --nat:          install only NAT rules"
-    echo -e "     --noconfigure:  DO NOT install osmclient, DO NOT install NAT rules, DO NOT configure modules"
+    echo -e "     --nat:          (only for Rel THREE with --soui) install only NAT rules"
+    echo -e "     --noconfigure:  (only for Rel THREE with --soui) DO NOT install osmclient, DO NOT install NAT rules, DO NOT configure modules"
 #    echo -e "     --update:       update to the latest stable release or to the latest commit if using a specific branch"
     echo -e "     --showopts:     print chosen options and exit (only for debugging)"
     echo -e "     -y:             do not prompt for confirmation, assumes yes"
-    echo -e "     -D <devops path> use local devops installation path"
     echo -e "     -h / --help:    print this help"
 }
 
@@ -70,33 +72,50 @@ function uninstall(){
     return 0
 }
 
-#Uninstall lightweight OSM: remove dockers
-function uninstall_lightweight(){
-    echo -e "\nUninstalling lightweight OSM"
-    docker stack rm osm
-    COUNTER=0
-    result=11
-    while [ ${COUNTER} -lt 30 ]; do
-        sleep 1
-        result=$(docker stack ps osm | wc -l)
-        #echo "Dockers running: $result"
+function remove_stack() {
+    stack=$1
+    if sg docker -c "docker stack ps ${stack}" ; then
+        echo -e "\nRemoving stack ${stack}" && sg docker -c "docker stack rm ${stack}"
+        COUNTER=0
+        result=1
+        while [ ${COUNTER} -lt 30 ]; do
+            result=$(sg docker -c "docker stack ps ${stack}" | wc -l)
+            #echo "Dockers running: $result"
+            if [ "${result}" == "0" ]; then
+                break
+            fi
+            let COUNTER=COUNTER+1
+            sleep 1
+        done
         if [ "${result}" == "0" ]; then
-            break
+            echo "All dockers of the stack ${stack} were removed"
+        else
+            FATAL "Some dockers of the stack ${stack} could not be removed. Could not clean it."
         fi
-        let COUNTER=COUNTER+1
-    done
-    if [ "${result}" == "0" ]; then
-        echo "All dockers of the stack osm were removed"
-    else
-        FATAL "Some dockers of the stack osm could not be removed. Could not uninstall OSM in single shot. Try to uninstall again"
+        sleep 5
     fi
-    sleep 5
+}
+
+#Uninstall lightweight OSM: remove dockers
+function uninstall_lightweight() {
+    echo -e "\nUninstalling lightweight OSM"
+    remove_stack osm
+    echo "Now osm docker images and volumes will be deleted"
+    newgrp docker << EONG
     docker image rm osm/ro
     docker image rm osm/lcm
     docker image rm osm/light-ui
     docker image rm osm/nbi
     docker image rm osm/mon
     docker image rm osm/pm
+    docker volume rm osm_mon_db
+    docker volume rm osm_mongo_db
+    docker volume rm osm_osm_packages
+    docker volume rm osm_ro_db
+EONG
+    echo "Removing /etc/osm and /var/log/osm files"
+    rm -rf /etc/osm
+    rm -rf /var/log/osm
     return 0
 }
 
@@ -540,75 +559,120 @@ function install_docker_compose() {
 function install_juju() {
     echo "Installing juju"
     sudo snap install juju --classic
-    sudo dpkg-reconfigure -p medium lxd
-    sg lxd -c "juju bootstrap localhost osm"
-    [ $(juju status |grep "osm" |wc -l) -eq 1 ] || FATAL "Juju installation failed"
+    [ -z "$INSTALL_NOLXD" ] && sudo dpkg-reconfigure -p medium lxd
+    sg lxd -c "juju bootstrap --bootstrap-series=xenial localhost osm"
+    [ $(sg lxd -c "juju status" |grep "osm" |wc -l) -eq 1 ] || FATAL "Juju installation failed"
     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
-    git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/LCM
-    docker build ${LWTEMPDIR}/LCM -f ${LWTEMPDIR}/LCM/Dockerfile.local -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
-    git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/LW-UI
-    docker build ${LWTEMPDIR}/LW-UI -t osm/light-ui -f ${LWTEMPDIR}/LW-UI/Dockerfile
-EONG
+    if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q KAFKA ; then
+        sg docker -c "docker pull wurstmeister/zookeeper" || FATAL "cannot get zookeeper docker image"
+        sg docker -c "docker pull wurstmeister/kafka" || FATAL "cannot get kafka docker image"
+    fi
+    if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q MONGO ; then
+        sg docker -c "docker pull mongo" || FATAL "cannot get mongo docker image"
+    fi
+    if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q MON ; then
+        git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/MON
+        git -C ${LWTEMPDIR}/MON checkout ${COMMIT_ID}
+        sg docker -c "docker build ${LWTEMPDIR}/MON -f ${LWTEMPDIR}/MON/docker/Dockerfile -t osm/mon --no-cache" || FATAL "cannot build MON docker image"
+        sg docker -c "docker build ${LWTEMPDIR}/MON/policy_module -f ${LWTEMPDIR}/MON/policy_module/Dockerfile -t osm/pm --no-cache" || FATAL "cannot build PM docker image"
+    fi
+    if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q NBI ; then
+        git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/NBI
+        git -C ${LWTEMPDIR}/NBI checkout ${COMMIT_ID}
+        sg docker -c "docker build ${LWTEMPDIR}/NBI -f ${LWTEMPDIR}/NBI/Dockerfile.local -t osm/nbi --no-cache" || FATAL "cannot build NBI docker image"
+    fi
+    if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q RO ; then
+        sg docker -c "docker pull mysql:5" || FATAL "cannot get mysql docker image"
+        git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/RO
+        git -C ${LWTEMPDIR}/RO checkout ${COMMIT_ID}
+        sg docker -c "docker build ${LWTEMPDIR}/RO -f ${LWTEMPDIR}/RO/docker/Dockerfile-local -t osm/ro --no-cache" || FATAL "cannot build RO docker image"
+    fi
+    if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q LCM ; then
+        git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/LCM
+        git -C ${LWTEMPDIR}/LCM checkout ${COMMIT_ID}
+        sg docker -c "docker build ${LWTEMPDIR}/LCM -f ${LWTEMPDIR}/LCM/Dockerfile.local -t osm/lcm --no-cache" || FATAL "cannot build LCM docker image"
+    fi
+    if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q LW-UI ; then
+        git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/LW-UI
+        git -C ${LWTEMPDIR}/LW-UI checkout ${COMMIT_ID}
+        sg docker -c "docker build ${LWTEMPDIR}/LW-UI -t osm/light-ui -f ${LWTEMPDIR}/LW-UI/Dockerfile --no-cache" || FATAL "cannot build LW-UI docker image"
+    fi
     echo "Finished generation of docker images"
 }
 
+function cmp_overwrite() {
+    file1="$1"
+    file2="$2"
+    if ! $(cmp "${file1}" "${file2}" >/dev/null 2>&1); then
+        if [ -f "${file2}" ]; then
+            ask_user "The file ${file2} already exists. Overwrite (y/N)? " n && sudo cp -b ${file1} ${file2}
+        else
+            sudo cp -b ${file1} ${file2}
+        fi
+    fi
+}
+
+function generate_config_log_folders() {
+    echo "Generating config and log folders"
+    sudo mkdir -p /etc/osm/docker
+    sudo cp -b ${OSM_DEVOPS}/installers/docker/docker-compose.yaml /etc/osm/docker/docker-compose.yaml
+    sudo mkdir -p /var/log/osm
+    echo "Finished generation of config and log folders"
+}
+
 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}/.local/share/juju/accounts.yaml |awk '{print $2}'`
+    echo "OSMLCM_VCA_HOST=${OSMLCM_VCA_HOST}" |sudo tee /etc/osm/docker/lcm.env
+    echo "OSMLCM_VCA_SECRET=${OSMLCM_VCA_SECRET}" |sudo tee -a /etc/osm/docker/lcm.env
     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
+    if [ ! -f /etc/osm/docker/ro-db.env ]; then
+        echo "MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}" |sudo tee /etc/osm/docker/ro-db.env
+    fi
+    if [ ! -f /etc/osm/docker/ro.env ]; then
+        echo "RO_DB_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}" |sudo tee /etc/osm/docker/ro.env
+    fi
     echo "OS_NOTIFIER_URI=http://${DEFAULT_IP}:8662" |sudo tee ${OSM_DEVOPS}/installers/docker/mon.env
+    cmp_overwrite ${OSM_DEVOPS}/installers/docker/mon.env /etc/osm/docker/mon.env
     echo "Finished generation of docker env files"
 }
 
-function deploy_lightweight() {
-    echo "Deploying lightweight build"
+function init_docker_swarm() {
     if [ "${DEFAULT_MTU}" != "1500" ]; then
       DOCKER_NETS=`sg docker -c "docker network list" | awk '{print $2}' | egrep -v "^ID$" | paste -d " " -s`
       DOCKER_GW_NET=`sg docker -c "docker network inspect ${DOCKER_NETS}" | grep Subnet | awk -F\" '{print $4}' | egrep "^172" | sort -u | tail -1 |  awk -F\. '{if ($2 != 255) print $1"."$2+1"."$3"."$4; else print "-1";}'`
       sg docker -c "docker network create --subnet ${DOCKER_GW_NET} --opt com.docker.network.bridge.name=docker_gwbridge --opt com.docker.network.bridge.enable_icc=false --opt com.docker.network.bridge.enable_ip_masquerade=true --opt com.docker.network.driver.mtu=${DEFAULT_MTU} docker_gwbridge"
     fi
-    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
+    sg docker -c "docker swarm init --advertise-addr ${DEFAULT_IP}"
+    sg docker -c "docker network create --driver=overlay --attachable --opt com.docker.network.driver.mtu=${DEFAULT_MTU} netOSM"
+    return 0
+}
+
+function deploy_lightweight() {
+    echo "Deploying lightweight build"
+    [ -n "$INSTALL_NODOCKER" ] || init_docker_swarm
+    remove_stack osm
+    sg docker -c "docker stack deploy -c /etc/osm/docker/docker-compose.yaml osm"
+    #docker-compose -f /etc/osm/docker/docker-compose.yaml up -d
     echo "Finished deployment of lightweight build"
 }
 
 function deploy_elk() {
+    sudo mkdir -p /etc/osm/docker/osm_elk
+    sudo cp -b ${OSM_DEVOPS}/installers/docker/osm_elk/* /etc/osm/docker/osm_elk
+    remove_stack osm_elk
     echo "Deploying ELK stack"
-    sg docker -c "docker stack deploy -c ${OSM_DEVOPS}/installers/docker/osm_elk/docker-compose.yml osm_elk"
+    sg docker -c "docker stack deploy -c /etc/osm/docker/osm_elk/docker-compose.yml osm_elk"
     echo "Waiting for ELK stack to be up and running"
     time=0
     step=2
     timelength=20
     elk_is_up=1
     while [ $time -le $timelength ]; do
-        if [[ $(curl -XGET http://localhost:5601/status -I | grep "HTTP/1.1 200 OK" | wc -l ) -eq 1 ]]; then
+        if [[ $(curl -XGET http://127.0.0.1:5601/status -I | grep "HTTP/1.1 200 OK" | wc -l ) -eq 1 ]]; then
             elk_is_up=0
             break
         fi
@@ -619,20 +683,20 @@ function deploy_elk() {
         echo "ELK is up and running. Trying to create index pattern..."
         #Create index pattern
         curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
-          "http://localhost:5601/api/saved_objects/index-pattern/logstash-*" \
+          "http://127.0.0.1:5601/api/saved_objects/index-pattern/logstash-*" \
           -d"{\"attributes\":{\"title\":\"logstash-*\",\"timeFieldName\":\"@timestamp\"}}"
         #Make it the default index
         curl -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
-          "http://localhost:5601/api/kibana/settings/defaultIndex" \
+          "http://127.0.0.1:5601/api/kibana/settings/defaultIndex" \
           -d"{\"value\":\"logstash-*\"}"
     else
         echo "Cannot connect to Kibana to create index pattern."
         echo "Once Kibana is running, you can use the following instructions to create index pattern:"
         echo 'curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
-          "http://localhost:5601/api/saved_objects/index-pattern/logstash-*" \
+          "http://127.0.0.1:5601/api/saved_objects/index-pattern/logstash-*" \
           -d"{\"attributes\":{\"title\":\"logstash-*\",\"timeFieldName\":\"@timestamp\"}}"'
         echo 'curl -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
-          "http://localhost:5601/api/kibana/settings/defaultIndex" \
+          "http://127.0.0.1:5601/api/kibana/settings/defaultIndex" \
           -d"{\"value\":\"logstash-*\"}"'
     fi
     echo "Finished deployment of ELK stack"
@@ -641,39 +705,55 @@ function deploy_elk() {
 
 function deploy_perfmon() {
     echo "Generating osm/kafka-exporter docker image"
-    sg docker -c "docker build ${OSM_DEVOPS}/installers/docker/osm_metrics/kafka-exporter -f ${OSM_DEVOPS}/installers/docker/osm_metrics/kafka-exporter/Dockerfile -t osm/kafka-exporter || ! echo 'cannot build kafka-exporter docker image' >&2"
+    sg docker -c "docker build ${OSM_DEVOPS}/installers/docker/osm_metrics/kafka-exporter -f ${OSM_DEVOPS}/installers/docker/osm_metrics/kafka-exporter/Dockerfile -t osm/kafka-exporter --no-cache" || FATAL "cannot build kafka-exporter docker image"
     echo "Finished generation of osm/kafka-exporter docker image"
+    sudo mkdir -p /etc/osm/docker/osm_metrics
+    sudo cp -b ${OSM_DEVOPS}/installers/docker/osm_metrics/*.yml /etc/osm/docker/osm_metrics
+    sudo cp -b ${OSM_DEVOPS}/installers/docker/osm_metrics/*.json /etc/osm/docker/osm_metrics
+    remove_stack osm_metrics
     echo "Deploying PM stack (Kafka exporter + Prometheus + Grafana)"
-    sg docker -c "docker stack deploy -c ${OSM_DEVOPS}/installers/docker/osm_metrics/docker-compose.yml osm_metrics"
+    sg docker -c "docker stack deploy -c /etc/osm/docker/osm_metrics/docker-compose.yml osm_metrics"
     echo "Finished deployment of PM stack"
     return 0
 }
 
 function install_lightweight() {
     [ "$USER" == "root" ] && FATAL "You are running the installer as root. The installer is prepared to be executed as a normal user with sudo privileges."
+    [ -z "$ASSUME_YES" ] && ! ask_user "The installation will configure LXD, install juju, install docker CE and init a docker swarm, as pre-requirements. Do you want to proceed (Y/n)? " y && echo "Cancelled!" && exit 1
+    track proceed
     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}'`
+    [ -z "$DEFAULT_IF" ] && FATAL "Not possible to determine the interface with the default route 0.0.0.0"
     DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
+    [ -z "$DEFAULT_IP" ] && FATAL "Not possible to determine the IP address of the interface with the default route"
     DEFAULT_MTU=$(ip addr show ${DEFAULT_IF} | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
-    need_packages_lw="lxd"
-    echo -e "Checking required packages: $need_packages_lw"
-    dpkg -l $need_packages_lw &>/dev/null \
-      || ! echo -e "One or several required packages are not installed. Updating apt cache requires root privileges." \
-      || sudo apt-get update \
-      || FATAL "failed to run apt-get update"
-    dpkg -l $need_packages_lw &>/dev/null \
-      || ! echo -e "Installing $need_packages_lw requires root privileges." \
-      || sudo apt-get install -y $need_packages_lw \
-      || FATAL "failed to install $need_packages_lw"
+    if [ -z "$INSTALL_NOLXD" ]; then
+        need_packages_lw="lxd"
+        echo -e "Checking required packages: $need_packages_lw"
+        dpkg -l $need_packages_lw &>/dev/null \
+          || ! echo -e "One or several required packages are not installed. Updating apt cache requires root privileges." \
+          || sudo apt-get update \
+          || FATAL "failed to run apt-get update"
+        dpkg -l $need_packages_lw &>/dev/null \
+          || ! echo -e "Installing $need_packages_lw requires root privileges." \
+          || sudo apt-get install -y $need_packages_lw \
+          || FATAL "failed to install $need_packages_lw"
+    fi
+    track prereqok
     install_juju
+    OSMLCM_VCA_HOST=`sg lxd -c "juju show-controller"|grep api-endpoints|awk -F\' '{print $2}'|awk -F\: '{print $1}'`
+    OSMLCM_VCA_SECRET=`grep password ${HOME}/.local/share/juju/accounts.yaml |awk '{print $2}'`
+    [ -z "$OSMLCM_VCA_HOST" ] && FATAL "Cannot obtain juju controller IP address"
+    [ -z "$OSMLCM_VCA_SECRET" ] && FATAL "Cannot obtain juju secret"
     track juju
-    install_docker_ce
+    [ -n "$INSTALL_NODOCKER" ] || install_docker_ce
     track docker_ce
     #install_docker_compose
     generate_docker_images
     track docker_build
+    generate_config_log_folders
     generate_docker_env_files
     deploy_lightweight
     track docker_deploy
@@ -696,15 +776,15 @@ function install_vimemu() {
     git clone https://osm.etsi.org/gerrit/osm/vim-emu.git $EMUTEMPDIR
     # build vim-emu docker
     echo "Building vim-emu Docker container..."
-    sudo docker build -t vim-emu-img -f $EMUTEMPDIR/Dockerfile $EMUTEMPDIR/
+    sudo docker build -t vim-emu-img -f $EMUTEMPDIR/Dockerfile --no-cache $EMUTEMPDIR/ || FATAL "cannot build vim-emu-img docker image"
     # start vim-emu container as daemon
     echo "Starting vim-emu Docker container 'vim-emu' ..."
     if [ -n "$INSTALL_LIGHTWEIGHT" ]; then
         # in lightweight mode, the emulator needs to be attached to netOSM
-        sudo docker run --name vim-emu -t -d --rm --privileged --pid='host' --network=netOSM -v /var/run/docker.sock:/var/run/docker.sock vim-emu-img python examples/osm_default_daemon_topology_2_pop.py
+        sudo docker run --name vim-emu -t -d --restart always --privileged --pid='host' --network=netOSM -v /var/run/docker.sock:/var/run/docker.sock vim-emu-img python examples/osm_default_daemon_topology_2_pop.py
     else
         # classic build mode
-        sudo docker run --name vim-emu -t -d --rm --privileged --pid='host' -v /var/run/docker.sock:/var/run/docker.sock vim-emu-img python examples/osm_default_daemon_topology_2_pop.py
+        sudo docker run --name vim-emu -t -d --restart always --privileged --pid='host' -v /var/run/docker.sock:/var/run/docker.sock vim-emu-img python examples/osm_default_daemon_topology_2_pop.py
     fi
     echo "Waiting for 'vim-emu' container to start ..."
     sleep 5
@@ -734,6 +814,9 @@ function dump_vars(){
     echo "INSTALL_ONLY=$INSTALL_ONLY"
     echo "INSTALL_ELK=$INSTALL_ELK"
     echo "INSTALL_PERFMON=$INSTALL_PERFMON"
+    echo "TO_REBUILD=$TO_REBUILD"
+    echo "INSTALL_NOLXD=$INSTALL_NOLXD"
+    echo "INSTALL_NODOCKER=$INSTALL_NODOCKER"
     echo "RELEASE=$RELEASE"
     echo "REPOSITORY=$REPOSITORY"
     echo "REPOSITORY_BASE=$REPOSITORY_BASE"
@@ -768,7 +851,7 @@ SHOWOPTS=""
 COMMIT_ID=""
 ASSUME_YES=""
 INSTALL_FROM_SOURCE=""
-RELEASE="-R ReleaseTHREE"
+RELEASE="-R ReleaseFOUR"
 REPOSITORY="-r stable"
 INSTALL_VIMEMU=""
 INSTALL_FROM_LXDIMAGES=""
@@ -778,12 +861,15 @@ INSTALL_LIGHTWEIGHT="y"
 INSTALL_ONLY=""
 INSTALL_ELK=""
 INSTALL_PERFMON=""
+TO_REBUILD=""
+INSTALL_NOLXD=""
+INSTALL_NODOCKER=""
 NOCONFIGURE=""
 RELEASE_DAILY=""
 SESSION_ID=`date +%s`
 OSM_DEVOPS=
 
-while getopts ":hy-:b:r:k:u:R:l:p:D:o:" o; do
+while getopts ":hy-:b:r:k:u:R:l:p:D:o:m:" o; do
     case "${o}" in
         h)
             usage && exit 0
@@ -818,6 +904,16 @@ while getopts ":hy-:b:r:k:u:R:l:p:D:o:" o; do
             [ "${OPTARG}" == "elk_stack" ] && INSTALL_ELK="y" && continue
             [ "${OPTARG}" == "pm_stack" ] && INSTALL_PERFMON="y" && continue
             ;;
+        m)
+            [ "${OPTARG}" == "RO" ] && TO_REBUILD="$TO_REBUILD RO" && continue
+            [ "${OPTARG}" == "LCM" ] && TO_REBUILD="$TO_REBUILD LCM" && continue
+            [ "${OPTARG}" == "NBI" ] && TO_REBUILD="$TO_REBUILD NBI" && continue
+            [ "${OPTARG}" == "LW-UI" ] && TO_REBUILD="$TO_REBUILD LW-UI" && continue
+            [ "${OPTARG}" == "MON" ] && TO_REBUILD="$TO_REBUILD MON" && continue
+            [ "${OPTARG}" == "KAFKA" ] && TO_REBUILD="$TO_REBUILD KAFKA" && continue
+            [ "${OPTARG}" == "MONGO" ] && TO_REBUILD="$TO_REBUILD MONGO" && continue
+            [ "${OPTARG}" == "NONE" ] && TO_REBUILD="$TO_REBUILD NONE" && continue
+            ;;
         -)
             [ "${OPTARG}" == "help" ] && usage && exit 0
             [ "${OPTARG}" == "source" ] && INSTALL_FROM_SOURCE="y" && continue
@@ -828,9 +924,11 @@ while getopts ":hy-:b:r:k:u:R:l:p:D:o:" o; do
             [ "${OPTARG}" == "reconfigure" ] && RECONFIGURE="y" && continue
             [ "${OPTARG}" == "test" ] && TEST_INSTALLER="y" && continue
             [ "${OPTARG}" == "lxdinstall" ] && INSTALL_LXD="y" && continue
+            [ "${OPTARG}" == "nolxd" ] && INSTALL_NOLXD="y" && continue
+            [ "${OPTARG}" == "nodocker" ] && INSTALL_NODOCKER="y" && continue
             [ "${OPTARG}" == "lxdimages" ] && INSTALL_FROM_LXDIMAGES="y" && continue
             [ "${OPTARG}" == "lightweight" ] && INSTALL_LIGHTWEIGHT="y" && continue
-            [ "${OPTARG}" == "soui" ] && INSTALL_LIGHTWEIGHT="" && RELEASE="-R ReleaseTHREE-Classic" && REPOSITORY="-r testing" && continue
+            [ "${OPTARG}" == "soui" ] && INSTALL_LIGHTWEIGHT="" && RELEASE="-R ReleaseTHREE" && REPOSITORY="-r stable" && continue
             [ "${OPTARG}" == "vimemu" ] && INSTALL_VIMEMU="y" && continue
             [ "${OPTARG}" == "elk_stack" ] && INSTALL_ELK="y" && continue
             [ "${OPTARG}" == "pm_stack" ] && INSTALL_PERFMON="y" && continue
@@ -854,6 +952,13 @@ while getopts ":hy-:b:r:k:u:R:l:p:D:o:" o; do
 done
 
 [ -n "$INSTALL_FROM_LXDIMAGES" ] && [ -n "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible options: --lxd can only be used with --soui"
+[ -n "$NAT" ] && [ -n "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible options: --nat can only be used with --soui"
+[ -n "$NOCONFIGURE" ] && [ -n "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible options: --noconfigure can only be used with --soui"
+[ -n "$RELEASE_DAILY" ] && [ -n "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible options: --daily can only be used with --soui"
+[ -n "$INSTALL_NOLXD" ] && [ -z "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible option: --nolxd cannot be used with --soui"
+[ -n "$INSTALL_NODOCKER" ] && [ -z "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible option: --nodocker cannot be used with --soui"
+[ -n "$TO_REBUILD" ] && [ -z "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible option: -m cannot be used with --soui"
+[ -n "$TO_REBUILD" ] && [ "$TO_REBUILD" != " NONE" ] && echo $TO_REBUILD | grep -q NONE && FATAL "Incompatible option: -m NONE cannot be used with other -m options"
 
 if [ -n "$SHOWOPTS" ]; then
     dump_vars