Skip to content

Commit

Permalink
Allow bare version numbers to be passed to install scripts.
Browse files Browse the repository at this point in the history
The SHA will be queried for if it is omitted.
  • Loading branch information
mitchell-as committed Oct 9, 2023
1 parent 891e2d2 commit af7cfb6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
12 changes: 10 additions & 2 deletions installers/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,22 @@ function error([string] $msg)
}

if (!$script:VERSION) {
# Determine the latest version to fetch and parse info.
# Determine the latest version to fetch.
$jsonURL = "$script:BASEINFOURL/?channel=$script:CHANNEL&platform=windows&source=install"
} elseif (!($script:VERSION | Select-String -Pattern "-SHA" -SimpleMatch)) {
# Determine the full version SHA to fetch.
$jsonURL = "$script:BASEINFOURL/?channel=$script:CHANNEL&platform=windows&source=install&target-version=$script:VERSION"
}

if ($jsonURL) {
# Parse info.
$infoJson = ConvertFrom-Json -InputObject (download $jsonURL)
$version = $infoJson.Version
$checksum = $infoJson.Sha256
$relUrl = $infoJson.Path
} else {
$relUrl = "$script:CHANNEL/$script:VERSION/windows-amd64/state-windows-amd64-$script:VERSION.zip"
$versionNoSHA = $script:VERSION -replace "-SHA.*", ""
$relUrl = "$script:CHANNEL/$versionNoSHA/windows-amd64/state-windows-amd64-$script:VERSION.zip"
}

# Fetch the requested or latest version.
Expand Down
13 changes: 10 additions & 3 deletions installers/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,14 @@ mkdir -p "$INSTALLERTMPDIR"

if [ -z "$VERSION" ]; then
# Determine the latest version to fetch.
STATEURL="$BASE_INFO_URL?channel=$CHANNEL&source=install&platform=$OS"
$FETCH $INSTALLERTMPDIR/info.json $STATEURL || exit 1
JSONURL="$BASE_INFO_URL?channel=$CHANNEL&source=install&platform=$OS"
elif [ -z "`echo $VERSION | grep -o '\-SHA'`" ]; then
# Determine the full version SHA to fetch.
JSONURL="$BASE_INFO_URL?channel=$CHANNEL&source=install&platform=$OS&target-version=$VERSION"
fi

if [ ! -z "$JSONURL" ]; then
$FETCH $INSTALLERTMPDIR/info.json $JSONURL || exit 1

# Parse info.
VERSION=`cat $INSTALLERTMPDIR/info.json | sed -ne 's/.*"version":[ \t]*"\([^"]*\)".*/\1/p'`
Expand All @@ -126,7 +132,8 @@ if [ -z "$VERSION" ]; then
rm $INSTALLERTMPDIR/info.json

else
RELURL="$CHANNEL/$VERSION/$OS-amd64/state-$OS-amd64-$VERSION$DOWNLOADEXT"
VERSIONNOSHA="`echo $VERSION | sed 's/-SHA.*$//'`"
RELURL="$CHANNEL/$VERSIONNOSHA/$OS-amd64/state-$OS-amd64-$VERSION$DOWNLOADEXT"
fi

# Fetch the requested or latest version.
Expand Down

0 comments on commit af7cfb6

Please sign in to comment.