Make selfupdate idempotent.

This commit is contained in:
Marco Vermeulen
2013-06-04 21:57:57 +01:00
parent d9b91b12fa
commit aaf6adf849
7 changed files with 19 additions and 8 deletions

View File

@@ -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
}

View File

@@ -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

View File

@@ -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

View File

@@ -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"

View File

@@ -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

View File

@@ -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()

View File

@@ -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 = ""
}
}