From: garciadeblas Date: Fri, 31 Jan 2020 13:27:29 +0000 (+0100) Subject: install_osm.sh: clean deb repos, but do not remove packages X-Git-Tag: v7.0.1~1^2~2 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=25e87d22a56148f402139f1096f227857be38aca;p=osm%2Fdevops.git install_osm.sh: clean deb repos, but do not remove packages The script install_osm.sh has been updated to: - clean deb repos - do not remove all packages - admit all options in get opt - capture errors for options expecting an argument The script full_install_osm.sh has been updated to: - order the case options in getopts as they appear in the getopts line - capture errors for options expecting an argument Change-Id: I53681cfddf4d6668a31646d3bce0c80e750a6d3c Signed-off-by: garciadeblas --- diff --git a/installers/full_install_osm.sh b/installers/full_install_osm.sh index ec682389..ed4d2a4c 100755 --- a/installers/full_install_osm.sh +++ b/installers/full_install_osm.sh @@ -1494,11 +1494,8 @@ POD_NETWORK_CIDR=10.244.0.0/16 K8S_MANIFEST_DIR="/etc/kubernetes/manifests" RE_CHECK='^[a-z0-9]([-a-z0-9]*[a-z0-9])?$' -while getopts ":hy-:b:r:c:k:u:R:l:p:D:o:m:H:S:s:w:t:U:P:A:" o; do +while getopts ":b:r:c:k:u:R:l:p:D:o:m:H:S:s:w:t:U:P:A:-: hy" o; do case "${o}" in - h) - usage && exit 0 - ;; b) COMMIT_ID=${OPTARG} PULL_IMAGES="" @@ -1513,10 +1510,6 @@ while getopts ":hy-:b:r:c:k:u:R:l:p:D:o:m:H:S:s:w:t:U:P:A:" o; do echo -e "Invalid argument for -i : ' $OPTARG'\n" >&2 usage && exit 1 ;; - R) - RELEASE="${OPTARG}" - REPO_ARGS+=(-R "$RELEASE") - ;; k) REPOSITORY_KEY="${OPTARG}" REPO_ARGS+=(-k "$REPOSITORY_KEY") @@ -1525,8 +1518,9 @@ while getopts ":hy-:b:r:c:k:u:R:l:p:D:o:m:H:S:s:w:t:U:P:A:" o; do REPOSITORY_BASE="${OPTARG}" REPO_ARGS+=(-u "$REPOSITORY_BASE") ;; - U) - DOCKER_USER="${OPTARG}" + R) + RELEASE="${OPTARG}" + REPO_ARGS+=(-R "$RELEASE") ;; l) LXD_REPOSITORY_BASE="${OPTARG}" @@ -1537,29 +1531,6 @@ while getopts ":hy-:b:r:c:k:u:R:l:p:D:o:m:H:S:s:w:t:U:P:A:" o; do D) OSM_DEVOPS="${OPTARG}" ;; - s) - OSM_STACK_NAME="${OPTARG}" && [ -n "$KUBERNETES" ] && [[ ! "${OPTARG}" =~ $RE_CHECK ]] && echo "Namespace $OPTARG is invalid. Regex used for validation is $RE_CHECK" && exit 0 - ;; - H) - OSM_VCA_HOST="${OPTARG}" - ;; - S) - OSM_VCA_SECRET="${OPTARG}" - ;; - P) - OSM_VCA_PUBKEY=$(cat ${OPTARG}) - ;; - A) - OSM_VCA_APIPROXY="${OPTARG}" - ;; - w) - # when specifying workdir, do not use sudo for access - WORKDIR_SUDO= - OSM_WORK_DIR="${OPTARG}" - ;; - t) - OSM_DOCKER_TAG="${OPTARG}" - ;; o) INSTALL_ONLY="y" [ "${OPTARG}" == "vimemu" ] && INSTALL_VIMEMU="y" && continue @@ -1580,6 +1551,32 @@ while getopts ":hy-:b:r:c:k:u:R:l:p:D:o:m:H:S:s:w:t:U:P:A:" o; do [ "${OPTARG}" == "GRAFANA" ] && TO_REBUILD="$TO_REBUILD GRAFANA" && continue [ "${OPTARG}" == "NONE" ] && TO_REBUILD="$TO_REBUILD NONE" && continue ;; + H) + OSM_VCA_HOST="${OPTARG}" + ;; + S) + OSM_VCA_SECRET="${OPTARG}" + ;; + s) + OSM_STACK_NAME="${OPTARG}" && [ -n "$KUBERNETES" ] && [[ ! "${OPTARG}" =~ $RE_CHECK ]] && echo "Namespace $OPTARG is invalid. Regex used for validation is $RE_CHECK" && exit 0 + ;; + w) + # when specifying workdir, do not use sudo for access + WORKDIR_SUDO= + OSM_WORK_DIR="${OPTARG}" + ;; + t) + OSM_DOCKER_TAG="${OPTARG}" + ;; + U) + DOCKER_USER="${OPTARG}" + ;; + P) + OSM_VCA_PUBKEY=$(cat ${OPTARG}) + ;; + A) + OSM_VCA_APIPROXY="${OPTARG}" + ;; -) [ "${OPTARG}" == "help" ] && usage && exit 0 [ "${OPTARG}" == "source" ] && INSTALL_FROM_SOURCE="y" && PULL_IMAGES="" && continue @@ -1609,10 +1606,17 @@ while getopts ":hy-:b:r:c:k:u:R:l:p:D:o:m:H:S:s:w:t:U:P:A:" o; do echo -e "Invalid option: '--$OPTARG'\n" >&2 usage && exit 1 ;; + :) + echo "Option -$OPTARG requires an argument" >&2 + usage && exit 1 + ;; \?) echo -e "Invalid option: '-$OPTARG'\n" >&2 usage && exit 1 ;; + h) + usage && exit 0 + ;; y) ASSUME_YES="y" ;; diff --git a/installers/install_osm.sh b/installers/install_osm.sh index 5be26707..2481cd5f 100755 --- a/installers/install_osm.sh +++ b/installers/install_osm.sh @@ -91,41 +91,16 @@ add_repo() { return 1 } -clean_old_packages() { +clean_old_repo() { 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 +while getopts ":b:r:c:k:u:R:l:p:D:o:m:H:S:s:w:t:U:P:A:-: hy" o; do case "${o}" in - h) - usage && exit 0 - ;; r) REPOSITORY="${OPTARG}" ;; @@ -136,18 +111,28 @@ while getopts ":hr:R:u:t:-:" o; do REPOSITORY_BASE="${OPTARG}" ;; t) - OSM_DOCKER_TAG="${OPTARG}" + DOCKER_TAG="${OPTARG}" ;; -) [ "${OPTARG}" == "help" ] && usage && exit 0 - continue ;; + :) + echo "Option -$OPTARG requires an argument" >&2 + usage && exit 1 + ;; + \?) + echo -e "Invalid option: '-$OPTARG'\n" >&2 + usage && exit 1 + ;; + h) + usage && exit 0 + ;; *) ;; esac done -clean_old_packages +clean_old_repo 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