From 79557e05ff406d2f0188872144719c510b4b633a Mon Sep 17 00:00:00 2001 From: ruokun-niu Date: Mon, 23 Sep 2024 14:30:01 -0700 Subject: [PATCH 1/7] Updated CLI installation script --- cli/installers/install-drasi-cli-github.sh | 193 --------------------- cli/installers/install-drasi-cli.ps1 | 150 ++++++++++++++++ cli/installers/install-drasi-cli.sh | 92 ++++++---- cli/installers/install.ps1 | 77 -------- 4 files changed, 209 insertions(+), 303 deletions(-) delete mode 100755 cli/installers/install-drasi-cli-github.sh create mode 100644 cli/installers/install-drasi-cli.ps1 delete mode 100755 cli/installers/install.ps1 diff --git a/cli/installers/install-drasi-cli-github.sh b/cli/installers/install-drasi-cli-github.sh deleted file mode 100755 index 434beecc..00000000 --- a/cli/installers/install-drasi-cli-github.sh +++ /dev/null @@ -1,193 +0,0 @@ -: ${DRASI_INSTALL_DIR:="/usr/local/bin"} -: ${USE_SUDO:="false"} - - -DRASI_HTTP_REQUEST_CLI=curl -GITHUB_ORG=project-drasi -GITHUB_REPO=drasi-platform -GITHUB_TOKEN=$1 - -DRASI_CLI_FILENAME=drasi -DRASI_CLI_FILE="${DRASI_INSTALL_DIR}/${DRASI_CLI_FILENAME}" - -getSystemInfo() { - ARCH=$(uname -m) - case $ARCH in - armv7*) ARCH="arm";; - aarch64) ARCH="arm64";; - x86_64) ARCH="x64";; - esac - - - OS=$(echo `uname`|tr '[:upper:]' '[:lower:]') - - - if [[ ("$OS" == "linux" || ( "$OS" == "darwin" && ( "$ARCH" == "arm" || "$ARCH" == "arm64" ))) && "$DRASI_INSTALL_DIR" == "/usr/local/bin" ]]; - then - USE_SUDO="true" - fi -} - -verifySupported() { - local supported=(darwin-x64 darwin-arm64 linux-x64 linux-arm64) - local current_osarch="${OS}-${ARCH}" - - for osarch in "${supported[@]}"; do - if [ "$osarch" == "$current_osarch" ]; then - echo "Your system is ${OS}_${ARCH}" - return - fi - done - - echo "No prebuilt binary for ${current_osarch}" - exit 1 -} - -runAsRoot() { - local CMD="$*" - - if [ $EUID -ne 0 -a $USE_SUDO = "true" ]; then - echo "Additional permissions needed. Please enter your sudo password..." - CMD="sudo $CMD" - fi - - $CMD -} - -getLatestRelease() { - local releaseUrl="https://api.github.com/repos/${GITHUB_ORG}/${GITHUB_REPO}/releases" - - local latest_release="" - - if [ $DRASI_HTTP_REQUEST_CLI == "curl" ]; then - latest_release=$(curl -s -H "Authorization: Bearer ${GITHUB_TOKEN}" $releaseUrl | grep \"tag_name\" | grep -v rc | awk 'NR==1{print $2}' | sed -n 's/\"\(.*\)\",/\1/p') - else - latest_release=$(wget -q --header="Accept: application/json" --header="Authorization: Bearer ${GITHUB_TOKEN}" -O - $releaseUrl | grep \"tag_name\" | grep -v rc | awk 'NR==1{print $2}' | sed -n 's/\"\(.*\)\",/\1/p') - fi - - ret_val=$latest_release -} - -getAssetId() { - # To download the asset using Github API, we need to find the asset id - local VERSION=$1 - OS_ARCH="${OS}-${ARCH}" - DRASI_ARTIFACT="drasi-${OS_ARCH}" - - # Fetch the releases - response=$(curl -s -H "Authorization: token ${GITHUB_TOKEN}" https://api.github.com/repos/${GITHUB_ORG}/${GITHUB_REPO}/releases/tags/${VERSION}) - # Extract the URL of the asset - eval $(echo "$response" | grep -C3 "name.:.\+${DRASI_ARTIFACT}" | grep -w id | tr : = | tr -cd '[[:alnum:]]=') - [ "$id" ] || { echo "Error: Failed to get asset id, response: $response" | awk 'length($0)<100' >&2; exit 1; } - - ASSET_ID=$id -} - -checkHttpRequestCLI() { - if type "curl" > /dev/null; then - DRASI_HTTP_REQUEST_CLI=curl - elif type "wget" > /dev/null; then - DRASI_HTTP_REQUEST_CLI=wget - else - echo "Either curl or wget is required" - exit 1 - fi -} - -checkExistingInstallation() { - if [ -f "DRASI_CLI_FILE" ]; then - echo "Drasi CLI is already installed in $DRASI_CLI_FILE" - echo "Reinstalling Drasi CLI...\n" - else - echo "Installing Drasi CLI...\n" - fi -} - -cleanup() { - if [[ -d "${DRASI_TMP_ROOT:-}" ]]; then - rm -rf "$DRASI_TMP_ROOT" - fi -} - -downloadFile() { - local ASSET_ID=$1 - OS_ARCH="${OS}-${ARCH}" - DRASI_CLI_ARTIFACT="drasi-${OS_ARCH}" - - DOWNLOAD_URL="https://api.github.com/repos/${GITHUB_ORG}/${GITHUB_REPO}/releases/assets/${ASSET_ID}" - - DRASI_TMP_ROOT=$(mktemp -dt Drasi-install-XXXXXX) - ARTIFACT_TMP_FILE="$DRASI_TMP_ROOT/$DRASI_CLI_ARTIFACT" - - - echo "Downloading the Drasi CLI" - if [ "$DRASI_HTTP_REQUEST_CLI" == "curl" ]; then - curl -SsL -H "Accept: application/octet-stream" -H "Authorization: Bearer ${GITHUB_TOKEN}" "$DOWNLOAD_URL" -o "$ARTIFACT_TMP_FILE" - else - wget -q --header="Accept: application/octet-stream" --header="Authorization: Bearer ${GITHUB_TOKEN}" -O "$ARTIFACT_TMP_FILE" "$DOWNLOAD_URL" - fi - - if [ ! -f "$ARTIFACT_TMP_FILE" ]; then - echo "failed to download ${DOWNLOAD_URL}..." - exit 1 - fi -} - - -installFile() { - OS_ARCH="${OS}-${ARCH}" - DRASI_CLI_ARTIFACT="drasi-${OS_ARCH}" - local tmp_root_Drasi_cli="$DRASI_TMP_ROOT/$DRASI_CLI_ARTIFACT" - - if [ ! -f "$tmp_root_Drasi_cli" ]; then - echo "Failed to download Drasi CLI executable." - exit 1 - fi - - chmod a+x $tmp_root_Drasi_cli - - mkdir -p "$DRASI_INSTALL_DIR" - runAsRoot cp "$tmp_root_Drasi_cli" "$DRASI_INSTALL_DIR" - runAsRoot mv "${DRASI_INSTALL_DIR}/${DRASI_CLI_FILENAME}-${OS}-${ARCH}" "${DRASI_INSTALL_DIR}/${DRASI_CLI_FILENAME}" - - if [ -f "$DRASI_CLI_FILE" ]; then - echo "Drasi CLI was installed successfully to $DRASI_CLI_FILE" - - else - echo "Failed to install Drasi CLI" - exit 1 - fi -} - -fail_trap() { - result=$? - if [ "$result" != "0" ]; then - echo "Failed to install Drasi CLI" - fi - cleanup - exit $result -} - - -trap "fail_trap" EXIT - -getSystemInfo -checkHttpRequestCLI - -if [ -z "$2" ]; then - echo "Getting the latest Drasi CLI..." - getLatestRelease -else - ret_val=v$2 -fi - -getAssetId $ret_val - -verifySupported -checkExistingInstallation - -downloadFile $ASSET_ID -installFile -cleanup - -echo "Drasi CLI was installed successfully. Run 'drasi --help' to get started" \ No newline at end of file diff --git a/cli/installers/install-drasi-cli.ps1 b/cli/installers/install-drasi-cli.ps1 new file mode 100644 index 00000000..fc948234 --- /dev/null +++ b/cli/installers/install-drasi-cli.ps1 @@ -0,0 +1,150 @@ +param ( + [string]$Version, + [string]$DrasiRoot = "$env:LOCALAPPDATA\drasi" +) + +Write-Output "" +$ErrorActionPreference = 'stop' + +$DrasiRoot = $DrasiRoot -replace ' ', '` ' + +$DrasiCliFileName = "drasi.exe" +$DrasiCliFilePath = "${DrasiRoot}\${DrasiCliFileName}" +$OS = "windows" +$Arch = "x64" +$GitHubOrg = "drasi-project" +$GitHubRepo = "drasi-platform" +$GitHubReleaseJsonUrl = "https://api.github.com/repos/${GitHubOrg}/${GitHubRepo}/releases" + + +function GetVersionInfo { + param ( + [string]$Version, + $Releases + ) + # Filter windows binary and download archive + if (!$Version) { + $release = $Releases | Where-Object { $_.tag_name -notlike "*rc*" } | Select-Object -First 1 + } + else { + $release = $Releases | Where-Object { $_.tag_name -eq "v$Version" } | Select-Object -First 1 + } + + return $release +} + + +function GetWindowsAsset { + param ( + $Release + ) + $windowsAsset = $Release | Select-Object -ExpandProperty assets | Where-Object { $_.name -Like "*${OS}-${Arch}.exe" } + if (!$windowsAsset) { + throw "Cannot find the Windows drasi CLI binary" + } + [hashtable]$return = @{} + $return.url = $windowsAsset.url + $return.name = $windowsAsset.name + + return $return +} + + +if ($Env:GITHUB_USER) { + $basicAuth = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($Env:GITHUB_USER + ":" + $Env:GITHUB_TOKEN)); + $githubHeader = @{"Authorization" = "Basic $basicAuth" } +} +else { + $githubHeader = @{} +} + +if ((Get-ExecutionPolicy) -gt 'RemoteSigned' -or (Get-ExecutionPolicy) -eq 'ByPass') { + Write-Output "PowerShell requires an execution policy of 'RemoteSigned'." + Write-Output "To make this change please run:" + Write-Output "'Set-ExecutionPolicy RemoteSigned -scope CurrentUser'" + break +} + +# Change security protocol to support TLS 1.2 / 1.1 / 1.0 - old powershell uses TLS 1.0 as a default protocol +[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls" + +if (Test-Path $DrasiCliFilePath -PathType Leaf) { + Write-Output "Previous Drasi CLI detected" + Write-Output "Reinstalling Drasi CLI..." +} +else { + Write-Output "Installing Drasi CLI..." +} + +if (-Not (Test-Path $DrasiRoot -PathType Container)) { + Write-Output "Creating $DrasiRoot directory..." + New-Item -ErrorAction Ignore -Path $DrasiRoot -ItemType "directory" | Out-Null + if (!(Test-Path $DrasiRoot -PathType Container)) { + throw "Cannot create $DrasiRoot" + } +} + +$releases = Invoke-RestMethod -Uri $GitHubReleaseJsonUrl -Headers $githubHeader -Method Get +if ($releases.Count -eq 0) { + throw "No releases from github.com/${GitHubOrg}/${GitHubRepo}" +} + +$release = GetVersionInfo -Version $Version -Releases $releases +if (!$release) { + throw "Cannot find the specified drasi CLI binary version" +} + +$asset = GetWindowsAsset -Release $release +$assetName = $asset.name +$exeFileUrl = $asset.url +$exeFilePath = "${DrasiRoot}\${assetName}" + +try { + Write-Output "Downloading $exeFileUrl" + githubHeader.Accept = "application/octet-stream" + $oldProgressPreference = $ProgressPreference + $ProgressPreference = "SilentlyContinue" # Do not show progress bar + Invoke-WebRequest -Headers $githubHeader -Uri $exeFileUrl -OutFile $exeFilePath +} +catch [Net.WebException] { + throw "ERROR: The specified release version: $Version does not exist." +} +finally { + $ProgressPreference = $oldProgressPreference; +} + +if (!(Test-Path $exeFilePath -PathType Leaf)) { + throw "Failed to download drasi CLI binary - $exeFilePath" +} + +# Remove old drasi CLI if exists +if (Test-Path $DrasiCliFilePath -PathType Leaf) { + Remove-Item -Recurse -Force $DrasiCliFilePath +} + +# Rename the downloaded drasi CLI binary +Rename-Item -Path $exeFilePath -NewName $DrasiCliFilePath -Force + +if (!(Test-Path $DrasiCliFilePath -PathType Leaf)) { + throw "Failed to download drasi CLI binary - $exeFilePath" +} + +# Version string +Write-Output "drasi CLI version: $(&$DrasiCliFilePath version -o json | ConvertFrom-JSON | Select-Object -ExpandProperty version)" + + +$UserPathEnvironmentVar = (Get-Item -Path HKCU:\Environment).GetValue( + 'PATH', # the registry-value name + $null, # the default value to return if no such value exists. + 'DoNotExpandEnvironmentNames' # the option that suppresses expansion +) + +if (-Not ($UserPathEnvironmentVar -like '*drasi*')) { + Write-Output "Adding $DrasiRoot to User Path..." + # [Environment]::SetEnvironmentVariable sets the value kind as REG_SZ, use the function below to set a value of kind REG_EXPAND_SZ + Set-ItemProperty HKCU:\Environment "PATH" "$UserPathEnvironmentVar;$DrasiRoot" -Type ExpandString + # Also add the path to the current session + $env:PATH += ";$DrasiRoot" +} + +Write-Output "drasi CLI has been successfully installed" \ No newline at end of file diff --git a/cli/installers/install-drasi-cli.sh b/cli/installers/install-drasi-cli.sh index 9ca36245..a47cce38 100755 --- a/cli/installers/install-drasi-cli.sh +++ b/cli/installers/install-drasi-cli.sh @@ -1,7 +1,10 @@ : ${DRASI_INSTALL_DIR:="/usr/local/bin"} : ${USE_SUDO:="false"} +GITHUB_ORG=drasi-project +GITHUB_REPO=drasi-platform +# HTTP request CLI DRASI_HTTP_REQUEST_CLI=curl # DRASI CLI filename @@ -20,12 +23,7 @@ getSystemInfo() { OS=$(echo `uname`|tr '[:upper:]' '[:lower:]') - # if [ "$OS" == "darwin" ]; then - # OS="macos" - # fi - - if [[ ("$OS" == "linux" || ( "$OS" == "darwin" && ( "$ARCH" == "arm" || "$ARCH" == "arm64" ))) && "$DRASI_INSTALL_DIR" == "/usr/local/bin" ]]; - then + if [[ "$OS" == "linux" || "$OS" == "darwin" ]] && [ "$DRASI_INSTALL_DIR" == "/usr/local/bin" ]; then USE_SUDO="true" fi } @@ -49,7 +47,6 @@ runAsRoot() { local CMD="$*" if [ $EUID -ne 0 -a $USE_SUDO = "true" ]; then - echo "Additional permissions needed. Please enter your sudo password..." CMD="sudo $CMD" fi @@ -70,9 +67,9 @@ checkHttpRequestCLI() { checkExistingInstallation() { if [ -f "DRASI_CLI_FILE" ]; then echo "Drasi CLI is already installed in $DRASI_CLI_FILE" - echo "Reinstalling Drasi CLI...\n" + echo -e "Reinstalling Drasi CLI...\n" else - echo "Installing Drasi CLI...\n" + echo -e "Installing Drasi CLI...\n" fi } @@ -82,31 +79,35 @@ cleanup() { fi } -downloadFile() { - OS_ARCH="${OS}-${ARCH}" - DRASI_CLI_ARTIFACT="drasi" - - DOWNLOAD_BASE="https://drasi.blob.core.windows.net/installs" - DOWNLOAD_URL="${DOWNLOAD_BASE}/${OS_ARCH}/${DRASI_CLI_ARTIFACT}" - - DRASI_TMP_ROOT=$(mktemp -dt Drasi-install-XXXXXX) - ARTIFACT_TMP_FILE="$DRASI_TMP_ROOT/$DRASI_CLI_ARTIFACT" +getLatestRelease() { + local cliReleaseUrl="https://api.github.com/repos/${GITHUB_ORG}/${GITHUB_REPO}/releases" + local latest_release="" if [ "$DRASI_HTTP_REQUEST_CLI" == "curl" ]; then - if ! curl --output /dev/null --silent --head --fail "$DOWNLOAD_URL"; then - echo $DOWNLOAD_URL - echo "ERROR: The specified version of the Drasi CLI does not exist." - exit 1 - fi + latest_release=$(curl -s $cliReleaseUrl | grep -o '\"tag_name\":\s*\"[^\"]*\"' | sed -n 's/.*\"tag_name\":\s*\"\([^\"]*\)\".*/\1/p' | sort -V | tail -n 1) else - if ! wget --spider "$DOWNLOAD_URL" 2>/dev/null; then - echo "ERROR: The specified version of the Drasi CLI does not exist." - exit 1 - fi + latest_release=$(wget -q --header="Accept: application/json" -O - $cliReleaseUrl | grep \"tag_name\" | grep -v rc | awk 'NR==1{print $2}' | sed -n 's/\"\(.*\)\",/\1/p') fi - echo "Downloading ${DOWNLOAD_URL}" + ret_val=$latest_release +} + + + +downloadFile() { + RELEASE_TAG=$1 + + DRASI_CLI_ARTIFACT="${DRASI_CLI_FILENAME}-${OS}-${ARCH}" + + echo "Downloading Drasi CLI from the release $RELEASE_TAG..." + DOWNLOAD_BASE="https://github.com/${GITHUB_ORG}/${GITHUB_REPO}/releases/download" + DOWNLOAD_URL="${DOWNLOAD_BASE}/${RELEASE_TAG}/${DRASI_CLI_ARTIFACT}" + + DRASI_TMP_ROOT=$(mktemp -dt Drasi-install-XXXXXX) + ARTIFACT_TMP_FILE="$DRASI_TMP_ROOT/$DRASI_CLI_ARTIFACT" + + echo "Downloading $DOWNLOAD_URL ..." if [ "$DRASI_HTTP_REQUEST_CLI" == "curl" ]; then curl -SsL "$DOWNLOAD_URL" -o "$ARTIFACT_TMP_FILE" else @@ -114,22 +115,29 @@ downloadFile() { fi if [ ! -f "$ARTIFACT_TMP_FILE" ]; then - echo "failed to download ${DOWNLOAD_URL}..." + echo "failed to download $DOWNLOAD_URL ..." exit 1 fi } installFile() { - local tmp_root_Drasi_cli="$DRASI_TMP_ROOT/$DRASI_CLI_FILENAME" + DRASI_CLI_ARTIFACT="${DRASI_CLI_FILENAME}-${OS}-${ARCH}" + local tmp_root_Drasi_cli="$DRASI_TMP_ROOT/$DRASI_CLI_ARTIFACT" if [ ! -f "$tmp_root_Drasi_cli" ]; then echo "Failed to download Drasi CLI executable." exit 1 fi + if [ -f "$DRASI_CLI_FILE" ]; then + rm "$DRASI_CLI_FILE" + fi + chmod a+x $tmp_root_Drasi_cli + mkdir -p "$DRASI_INSTALL_DIR" runAsRoot cp "$tmp_root_Drasi_cli" "$DRASI_INSTALL_DIR" + runAsRoot mv "${DRASI_INSTALL_DIR}/${DRASI_CLI_ARTIFACT}" "${DRASI_INSTALL_DIR}/${DRASI_CLI_FILENAME}" if [ -f "$DRASI_CLI_FILE" ]; then echo "Drasi CLI was installed successfully to $DRASI_CLI_FILE" @@ -149,15 +157,33 @@ fail_trap() { exit $result } +installCompleted() { + echo -e "\nDrasi is installed!" +} + +# ----------------------------------------------------------------------------- +# main +# ----------------------------------------------------------------------------- trap "fail_trap" EXIT getSystemInfo -verifySupported -checkExistingInstallation checkHttpRequestCLI -downloadFile +if [ -z "$1"]; then + echo "Getting the latest Drasi CLI..." + getLatestRelease +else + ret_val=$1 +fi + + +verifySupported $ret_val +checkExistingInstallation + +echo "Installing $ret_val Drasi CLI..." + +downloadFile $ret_val installFile cleanup diff --git a/cli/installers/install.ps1 b/cli/installers/install.ps1 deleted file mode 100755 index eef49cd7..00000000 --- a/cli/installers/install.ps1 +++ /dev/null @@ -1,77 +0,0 @@ -param ( - [string]$Version, - [string]$DrasiRoot = "$env:LOCALAPPDATA\drasi" -) - -Write-Output "" -$ErrorActionPreference = 'stop' - -$DrasiRoot = $DrasiRoot -replace ' ', '` ' - -$DrasiCliFileName = "drasi.exe" -$DrasiCliFilePath = "${DrasiRoot}\${DrasiCliFileName}" -$OsArch = "windows-x64" -$BaseDownloadUrl = "https://drasi.blob.core.windows.net/installs" - -if ((Get-ExecutionPolicy) -gt 'RemoteSigned' -or (Get-ExecutionPolicy) -eq 'ByPass') { - Write-Output "PowerShell requires an execution policy of 'RemoteSigned'." - Write-Output "To make this change please run:" - Write-Output "'Set-ExecutionPolicy RemoteSigned -scope CurrentUser'" - break -} - -[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls" - -if (Test-Path $DrasiCliFilePath -PathType Leaf) { - Write-Output "Previous Drasi CLI detected" - Write-Output "Reinstalling Drasi CLI..." -} -else { - Write-Output "Installing Drasi CLI..." -} - -if (-Not (Test-Path $DrasiRoot -PathType Container)) { - Write-Output "Creating $DrasiRoot directory..." - New-Item -ErrorAction Ignore -Path $DrasiRoot -ItemType "directory" | Out-Null - if (!(Test-Path $DrasiRoot -PathType Container)) { - throw "Cannot create $DrasiRoot" - } -} - -$urlParts = @( - $BaseDownloadUrl, - $OsArch, - $DrasiCliFileName -) -$binaryUrl = $urlParts -join "/" -Write-Output "Downloading $binaryUrl" -$binaryFilePath = $DrasiRoot + "\" + $DrasiCliFileName - -try { - $ProgressPreference = "SilentlyContinue" # Do not show progress bar - Invoke-WebRequest -Uri $binaryUrl -OutFile $binaryFilePath -UseBasicParsing - if (!(Test-Path $binaryFilePath -PathType Leaf)) { - throw "Failed to download Drasi Cli binary - $binaryFilePath" - } -} -catch [Net.WebException] { - throw "ERROR: The specified release version does not exist." -} - - -$UserPathEnvironmentVar = (Get-Item -Path HKCU:\Environment).GetValue( - 'PATH', # the registry-value name - $null, # the default value to return if no such value exists. - 'DoNotExpandEnvironmentNames' # the option that suppresses expansion -) - -if (-Not ($UserPathEnvironmentVar -like '*drasi*')) { - Write-Output "Adding $DrasiRoot to User Path..." - # [Environment]::SetEnvironmentVariable sets the value kind as REG_SZ, use the function below to set a value of kind REG_EXPAND_SZ - Set-ItemProperty HKCU:\Environment "PATH" "$UserPathEnvironmentVar;$DrasiRoot" -Type ExpandString - # Also add the path to the current session - $env:PATH += ";$DrasiRoot" -} - -Write-Output "Drasi CLI has been successfully installed" - From a60a8533d5ff069e1a20ff5fe6a68abd75c1c3bc Mon Sep 17 00:00:00 2001 From: ruokun-niu Date: Mon, 23 Sep 2024 15:05:56 -0700 Subject: [PATCH 2/7] updated ps1 based on comment --- cli/installers/install-drasi-cli.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/installers/install-drasi-cli.ps1 b/cli/installers/install-drasi-cli.ps1 index fc948234..17f18fd8 100644 --- a/cli/installers/install-drasi-cli.ps1 +++ b/cli/installers/install-drasi-cli.ps1 @@ -1,6 +1,6 @@ param ( [string]$Version, - [string]$DrasiRoot = "$env:LOCALAPPDATA\drasi" + [string]$DrasiRoot = "$env:ProgramFiles\drasi" ) Write-Output "" @@ -27,7 +27,7 @@ function GetVersionInfo { $release = $Releases | Where-Object { $_.tag_name -notlike "*rc*" } | Select-Object -First 1 } else { - $release = $Releases | Where-Object { $_.tag_name -eq "v$Version" } | Select-Object -First 1 + $release = $Releases | Where-Object { $_.tag_name -eq "$Version" } | Select-Object -First 1 } return $release @@ -130,7 +130,7 @@ if (!(Test-Path $DrasiCliFilePath -PathType Leaf)) { } # Version string -Write-Output "drasi CLI version: $(&$DrasiCliFilePath version -o json | ConvertFrom-JSON | Select-Object -ExpandProperty version)" +Write-Output "drasi CLI version: $($release.tag_name)" $UserPathEnvironmentVar = (Get-Item -Path HKCU:\Environment).GetValue( From 09338658206b0983847ad92633e6483512331a36 Mon Sep 17 00:00:00 2001 From: Halfsugar7 Date: Mon, 23 Sep 2024 20:17:01 -0700 Subject: [PATCH 3/7] nit --- cli/installers/install-drasi-cli.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/installers/install-drasi-cli.ps1 b/cli/installers/install-drasi-cli.ps1 index 17f18fd8..0d7f935e 100644 --- a/cli/installers/install-drasi-cli.ps1 +++ b/cli/installers/install-drasi-cli.ps1 @@ -1,6 +1,6 @@ param ( [string]$Version, - [string]$DrasiRoot = "$env:ProgramFiles\drasi" + [string]$DrasiRoot = "$env:LOCALAPPDATA\drasi" ) Write-Output "" From 14091a59a0794b1af517b8a4e87b7b2890edebea Mon Sep 17 00:00:00 2001 From: Halfsugar7 Date: Mon, 23 Sep 2024 20:19:48 -0700 Subject: [PATCH 4/7] nit --- cli/installers/install-drasi-cli.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/cli/installers/install-drasi-cli.ps1 b/cli/installers/install-drasi-cli.ps1 index 0d7f935e..fcc4f92d 100644 --- a/cli/installers/install-drasi-cli.ps1 +++ b/cli/installers/install-drasi-cli.ps1 @@ -99,6 +99,7 @@ $assetName = $asset.name $exeFileUrl = $asset.url $exeFilePath = "${DrasiRoot}\${assetName}" +Write-Output "path $exeFilePath" try { Write-Output "Downloading $exeFileUrl" githubHeader.Accept = "application/octet-stream" From 880c109f27b6c932c3e0d1ed83b5e1620e0588d8 Mon Sep 17 00:00:00 2001 From: Halfsugar7 Date: Mon, 23 Sep 2024 20:25:41 -0700 Subject: [PATCH 5/7] fixed windows --- cli/installers/install-drasi-cli.ps1 | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/cli/installers/install-drasi-cli.ps1 b/cli/installers/install-drasi-cli.ps1 index fcc4f92d..701f51d3 100644 --- a/cli/installers/install-drasi-cli.ps1 +++ b/cli/installers/install-drasi-cli.ps1 @@ -50,13 +50,13 @@ function GetWindowsAsset { } -if ($Env:GITHUB_USER) { - $basicAuth = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($Env:GITHUB_USER + ":" + $Env:GITHUB_TOKEN)); - $githubHeader = @{"Authorization" = "Basic $basicAuth" } -} -else { - $githubHeader = @{} -} +# if ($Env:GITHUB_USER) { +# $basicAuth = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($Env:GITHUB_USER + ":" + $Env:GITHUB_TOKEN)); +# $githubHeader = @{"Authorization" = "Basic $basicAuth" } +# } +# else { +# $githubHeader = @{} +# } if ((Get-ExecutionPolicy) -gt 'RemoteSigned' -or (Get-ExecutionPolicy) -eq 'ByPass') { Write-Output "PowerShell requires an execution policy of 'RemoteSigned'." @@ -102,7 +102,10 @@ $exeFilePath = "${DrasiRoot}\${assetName}" Write-Output "path $exeFilePath" try { Write-Output "Downloading $exeFileUrl" - githubHeader.Accept = "application/octet-stream" + $githubHeader = @{ + Accept = "application/octet-stream" + } + $oldProgressPreference = $ProgressPreference $ProgressPreference = "SilentlyContinue" # Do not show progress bar Invoke-WebRequest -Headers $githubHeader -Uri $exeFileUrl -OutFile $exeFilePath From 59dd009013db8e43d7c604dc0d1b3aed0a1444b2 Mon Sep 17 00:00:00 2001 From: Halfsugar7 Date: Mon, 23 Sep 2024 20:28:18 -0700 Subject: [PATCH 6/7] updated ps1 --- cli/installers/install-drasi-cli.ps1 | 8 -------- 1 file changed, 8 deletions(-) diff --git a/cli/installers/install-drasi-cli.ps1 b/cli/installers/install-drasi-cli.ps1 index 701f51d3..6d199d8c 100644 --- a/cli/installers/install-drasi-cli.ps1 +++ b/cli/installers/install-drasi-cli.ps1 @@ -50,13 +50,6 @@ function GetWindowsAsset { } -# if ($Env:GITHUB_USER) { -# $basicAuth = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($Env:GITHUB_USER + ":" + $Env:GITHUB_TOKEN)); -# $githubHeader = @{"Authorization" = "Basic $basicAuth" } -# } -# else { -# $githubHeader = @{} -# } if ((Get-ExecutionPolicy) -gt 'RemoteSigned' -or (Get-ExecutionPolicy) -eq 'ByPass') { Write-Output "PowerShell requires an execution policy of 'RemoteSigned'." @@ -105,7 +98,6 @@ try { $githubHeader = @{ Accept = "application/octet-stream" } - $oldProgressPreference = $ProgressPreference $ProgressPreference = "SilentlyContinue" # Do not show progress bar Invoke-WebRequest -Headers $githubHeader -Uri $exeFileUrl -OutFile $exeFilePath From 12af6f87de7ec359cb8a7c05ecee4f4624a45c25 Mon Sep 17 00:00:00 2001 From: ruokun-niu Date: Tue, 24 Sep 2024 09:31:34 -0700 Subject: [PATCH 7/7] nit --- cli/installers/install-drasi-cli.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/installers/install-drasi-cli.sh b/cli/installers/install-drasi-cli.sh index a47cce38..e0bdf274 100755 --- a/cli/installers/install-drasi-cli.sh +++ b/cli/installers/install-drasi-cli.sh @@ -170,7 +170,7 @@ trap "fail_trap" EXIT getSystemInfo checkHttpRequestCLI -if [ -z "$1"]; then +if [ -z "$1" ]; then echo "Getting the latest Drasi CLI..." getLatestRelease else