Skip to content

Instantly share code, notes, and snippets.

@trungnt2910
Created July 22, 2023 07:29
Show Gist options
  • Save trungnt2910/86ff5965478fbeb558c2d58b52d2fa85 to your computer and use it in GitHub Desktop.
Save trungnt2910/86ff5965478fbeb558c2d58b52d2fa85 to your computer and use it in GitHub Desktop.
Install `net8.0-haiku` using GitHub's NuGet server. Requires a GitHub packages token.
#!/bin/bash -e
DOTNET_PATH="dotnet"
if [ -z "$DOTNET_ROOT" ]; then
DOTNET_PATH=$(command -v dotnet)
else
DOTNET_PATH="$DOTNET_ROOT/dotnet"
fi
if [ -z "$DOTNET_PATH" ]; then
echo "Could not find dotnet. Install dotnet and try again."
exit 1
fi
echo "Using dotnet from $DOTNET_PATH"
DOTNET_VERSION=$(eval "$DOTNET_PATH --version")
echo "Detected .NET SDK version $DOTNET_VERSION"
set +e
prereleaseStart=$(($(expr index "$DOTNET_VERSION" "-") - 1))
if [ "$prereleaseStart" -gt 0 ]; then
firstDot=$(expr index "${DOTNET_VERSION:$(($prereleaseStart + 1)):${#DOTNET_VERSION}}" ".")
firstDot=$(($firstDot + $prereleaseStart))
secondDot=$(expr index "${DOTNET_VERSION:$((firstDot + 1)):${#DOTNET_VERSION}}" ".")
if [ "$secondDot" -eq 0 ]; then
secondDot="${#DOTNET_VERSION}"
else
secondDot=$(($secondDot + $firstDot))
fi
DOTNET_FEATURE_BAND="${DOTNET_VERSION:0:$secondDot}"
else
DOTNET_FEATURE_BAND="${DOTNET_VERSION:0:$((${#DOTNET_VERSION} - 2))}00"
fi
set -e
echo "Detected .NET SDK feature band $DOTNET_FEATURE_BAND"
if [ -z "$GITHUB_NUGET_URL" ]; then
GITHUB_NUGET_URL="https://nuget.pkg.github.com"
fi
if [ -z "$GITHUB_PACKAGE_USER" ]; then
GITHUB_PACKAGE_USER="trungnt2910"
fi
if [ -z "$GITHUB_USERNAME" ]; then
echo "GITHUB_USERNAME environment variable is not set. Set this variable to your GitHub username."
exit 1
fi
if [ -z "$GITHUB_TOKEN" ]; then
echo "GITHUB_TOKEN environment variable is not set. Set this variable to a GitHub token with the read:packages scope."
exit 1
fi
manifestName="trungnt2910.net.sdk.haiku.manifest"
manifestPackageName="$manifestName-$DOTNET_FEATURE_BAND"
manifestPackageVersion="$(curl -L https://nuget.pkg.github.com/trungnt2910/download/$manifestPackageName/index.json -u $GITHUB_USERNAME:$GITHUB_TOKEN | jq -e -r ".versions[0]")"
if [ -z "$manifestPackageVersion" ]; then
echo "Could not find the latest version of the manifest package."
exit 1
fi
echo "Latest manifest package version is $manifestPackageVersion"
manifestPackageUrl="$GITHUB_NUGET_URL/$GITHUB_PACKAGE_USER/download/$manifestPackageName/$manifestPackageVersion/$manifestPackageName.$manifestPackageVersion.nupkg"
echo "Downloading manifest package from $manifestPackageUrl"
manifestInstallDir="$(dirname "$DOTNET_PATH")/sdk-manifests/$DOTNET_FEATURE_BAND/$manifestName"
tmpFilePath="$(mktemp)"
curl -sL $manifestPackageUrl -u $GITHUB_USERNAME:$GITHUB_TOKEN -o $tmpFilePath
unzip -j $tmpFilePath 'data/*.*' -d $manifestInstallDir
rm $tmpFilePath
echo "Installed manifest package to $manifestInstallDir"
echo "Run '$DOTNET_PATH workload install haiku' to install the Haiku workload."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment