Remove the old osm package at install time
[osm/devops.git] / installers / install_osm.sh
index 50c1111..5be2670 100755 (executable)
@@ -13,9 +13,9 @@
 #   limitations under the License.
 #
 REPOSITORY_BASE=https://osm-download.etsi.org/repository/osm/debian
-RELEASE=ReleaseSIX
-REPOSITORY=stable
-DOCKER_TAG=6
+RELEASE=ReleaseSEVEN-daily
+REPOSITORY=testing
+DOCKER_TAG=releaseseven
 
 function usage(){
     echo -e "usage: $0 [OPTIONS]"
@@ -61,6 +61,7 @@ function usage(){
     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 "     --showopts:     print chosen options and exit (only for debugging)"
+    #echo -e "     --clean_volumes To clear all the mounted volumes from docker swarm"
     echo -e "     -y:             do not prompt for confirmation, assumes yes"
     echo -e "     -h / --help:    print this help"
 }
@@ -90,7 +91,37 @@ add_repo() {
   return 1
 }
 
-while getopts "hr:R:u:t:" o; do
+clean_old_packages() {
+dpkg -s 'osm-devops' &> /dev/null
+
+if [ $? -eq 0 ]; then
+
+  # Remove old packages
+  echo "Removing the old OSM packages"
+  sudo apt-get remove -y osm-devops
+  sudo apt-get remove -y osm-imdocs
+  sudo apt-get remove -y python3-osmclient
+  sudo apt-get remove -y python3-osm-im
+  # Clean the previous repos that might exist
+  sudo sed -i "/osm-download.etsi.org/d" /etc/apt/sources.list
+fi
+}
+
+#TBD
+clean_volumes(){
+  result=`docker stack ls|wc -l`
+  echo "Stack is running ####%%%%% $result"
+  if [ $result -gt 1 ]; then
+    echo "Inside $result > 1"
+        #TBD take user confirmation
+    docker stack ls |awk '{print $1}' |tail -n+2|xargs docker stack rm
+    sleep 3m
+    docker volume ls|awk '/_mon_db|_mongo_db|_osm_packages|_pol_db|_prom_db|_ro|_ro_db/{print $2}' \
+        |xargs -r --no-run-if-empty docker volume rm
+  fi
+}
+
+while getopts ":hr:R:u:t:-:" o; do
     case "${o}" in
         h)
             usage && exit 0
@@ -107,11 +138,16 @@ while getopts "hr:R:u:t:" o; do
         t)
             OSM_DOCKER_TAG="${OPTARG}"
             ;;
+        -)
+            [ "${OPTARG}" == "help" ] && usage && exit 0
+            continue
+           ;;
         *)
             ;;
     esac
 done
 
+clean_old_packages
 add_repo "deb [arch=amd64] $REPOSITORY_BASE/$RELEASE $REPOSITORY devops"
 sudo DEBIAN_FRONTEND=noninteractive apt-get -q update
 sudo DEBIAN_FRONTEND=noninteractive apt-get install osm-devops