From aaf6adf8496f526ed2e9b7ba7a487cd1ff2ace4f Mon Sep 17 00:00:00 2001 From: Marco Vermeulen Date: Tue, 4 Jun 2013 21:57:57 +0100 Subject: [PATCH] Make selfupdate idempotent. --- src/main/bash/gvm-common.sh | 4 ++-- src/main/bash/gvm-main.sh | 2 +- src/main/bash/gvm-selfupdate.sh | 8 ++++++-- src/test/cucumber/gvm/self_update.feature | 5 +++-- src/test/steps/gvm/env.groovy | 1 + src/test/steps/gvm/initialisation_steps.groovy | 5 +++++ src/test/steps/gvm/selfupdate_steps.groovy | 2 +- 7 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/main/bash/gvm-common.sh b/src/main/bash/gvm-common.sh index a889aef3..b4411632 100644 --- a/src/main/bash/gvm-common.sh +++ b/src/main/bash/gvm-common.sh @@ -160,9 +160,9 @@ function __gvmtool_default_environment_variables { } function __gvmtool_check_upgrade_available { - UPGRADE_AVAILABLE="" + UPGRADE_AVAILABLE="false" UPGRADE_NOTICE=$(echo "${BROADCAST_LIVE}" | grep 'Your version of GVM is out of date!') - if [[ -n "${UPGRADE_NOTICE}" && ( "${COMMAND}" != 'selfupdate' ) ]]; then + if [[ -n "$UPGRADE_NOTICE" && "$COMMAND" != 'selfupdate' ]]; then UPGRADE_AVAILABLE="true" fi } diff --git a/src/main/bash/gvm-main.sh b/src/main/bash/gvm-main.sh index 5e80f753..6832a608 100644 --- a/src/main/bash/gvm-main.sh +++ b/src/main/bash/gvm-main.sh @@ -47,7 +47,7 @@ function gvm { __gvmtool_check_upgrade_available - if [[ -n "${UPGRADE_AVAILABLE}" && "$1" != "broadcast" && "$1" != "selfupdate" ]]; then + if [[ "${UPGRADE_AVAILABLE}" == "true" && "$1" != "broadcast" && "$1" != "selfupdate" ]]; then echo "${BROADCAST_LIVE}" echo "" else diff --git a/src/main/bash/gvm-selfupdate.sh b/src/main/bash/gvm-selfupdate.sh index ee7d351f..31402230 100644 --- a/src/main/bash/gvm-selfupdate.sh +++ b/src/main/bash/gvm-selfupdate.sh @@ -17,8 +17,12 @@ # function __gvmtool_selfupdate { - if [[ "${GVM_ONLINE}" == "false" ]]; then - echo "${OFFLINE_MESSAGE}" + if [[ "$GVM_AVAILABLE" == "false" ]]; then + echo "$OFFLINE_MESSAGE" + + elif [[ "$UPGRADE_AVAILABLE" == "false" ]]; then + echo "No update available at this time." + else curl -s "${GVM_SERVICE}/selfupdate" | bash fi diff --git a/src/test/cucumber/gvm/self_update.feature b/src/test/cucumber/gvm/self_update.feature index 44d516ba..862b53a6 100644 --- a/src/test/cucumber/gvm/self_update.feature +++ b/src/test/cucumber/gvm/self_update.feature @@ -1,8 +1,9 @@ Feature: Self Update Background: - Given the internet is reachable - And an initialised system + Given an initialised system + And an outdated system + And the internet is reachable Scenario: Upgrade an outdated installation When I enter "gvm selfupdate" diff --git a/src/test/steps/gvm/env.groovy b/src/test/steps/gvm/env.groovy index 4902eb6e..14c5f5e3 100644 --- a/src/test/steps/gvm/env.groovy +++ b/src/test/steps/gvm/env.groovy @@ -12,6 +12,7 @@ counter = "${(Math.random() * 10000).toInteger()}".padLeft(4, "0") localGroovyCandidate = "/tmp/groovy-core" as File gvmVersion = "x.y.z" +gvmVersionOutdated = "x.y.y" gvmBaseEnv = "/tmp/gvm-$counter" gvmBaseDir = gvmBaseEnv as File diff --git a/src/test/steps/gvm/initialisation_steps.groovy b/src/test/steps/gvm/initialisation_steps.groovy index ad68f473..8eeb9eaa 100644 --- a/src/test/steps/gvm/initialisation_steps.groovy +++ b/src/test/steps/gvm/initialisation_steps.groovy @@ -40,6 +40,11 @@ Given(~'^an initialised shell$') { -> assert initScript.exists() } +Given(~'^an outdated system$') {-> + def initScript = "$gvmDir/bin/gvm-init.sh" as File + initScript.text = initScript.text.replace(gvmVersion, gvmVersionOutdated) +} + When(~'^I reinitialise the shell$') { -> def initScript = "$gvmDir/bin/gvm-init.sh" as File assert initScript.exists() diff --git a/src/test/steps/gvm/selfupdate_steps.groovy b/src/test/steps/gvm/selfupdate_steps.groovy index d4dc93b2..6cb19e10 100644 --- a/src/test/steps/gvm/selfupdate_steps.groovy +++ b/src/test/steps/gvm/selfupdate_steps.groovy @@ -69,4 +69,4 @@ And(~'^the staging folder is cleaned up$') {-> Given(~'^an empty configuration file$') {-> def configFile = "$gvmDir/ext/config" as File configFile.text = "" -} \ No newline at end of file +}