Skip to content

Commit a34c7f5

Browse files
committed
Improve install scripts: path, error, and robustness fixes
Updated install.ps1 to use Join-Path, improved error handling, and clarified output messages. Enhanced install.sh by fixing variable quoting, mktemp usage, and VECTRACTL_INSTALL_DIR comparison. Added checks for empty GitHub API responses and improved binary installation and version checks. #31
1 parent fc2bf2e commit a34c7f5

2 files changed

Lines changed: 26 additions & 23 deletions

File tree

‎install/install.ps1‎

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@ param (
33
[string]$VectraCtlRootPath = "$Env:SystemDrive\vectractl"
44
)
55

6-
Write-Output ""
76
$ErrorActionPreference = 'stop'
87

9-
#Escape space of VectraCtlRoot path
10-
$VectraCtlRootPath = $VectraCtlRootPath -replace ' ', '` '
8+
Write-Output ""
119

1210
# Constants
1311
$VectraCtlFileName = "vectractl.exe"
14-
$VectraCtlFilePath = "${VectraCtlRootPath}\${VectraCtlFileName}"
12+
$VectraCtlFilePath = Join-Path $VectraCtlRootPath $VectraCtlFileName
1513

1614
# GitHub Org and repo hosting VectraCtl
1715
$GitHubOrg = "cortexiumlabs"
@@ -30,16 +28,16 @@ if ((Get-ExecutionPolicy) -gt 'RemoteSigned' -or (Get-ExecutionPolicy) -eq 'ByPa
3028
Write-Output "PowerShell requires an execution policy of 'RemoteSigned'."
3129
Write-Output "To make this change please run:"
3230
Write-Output "'Set-ExecutionPolicy RemoteSigned -scope CurrentUser'"
33-
break
31+
exit 1
3432
}
3533

3634
# Change security protocol to support TLS 1.2 / 1.1 / 1.0 - old powershell uses TLS 1.0 as a default protocol
37-
[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls"
35+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls
3836

3937
# Check if VectraCtl is installed.
4038
if (Test-Path $VectraCtlFilePath -PathType Leaf) {
4139
Write-Warning "VectraCtl is detected - $VectraCtlFilePath"
42-
Invoke-Expression "$VectraCtlFilePath version"
40+
& $VectraCtlFilePath version
4341
Write-Output "Reinstalling VectraCtl..."
4442
}
4543
else {
@@ -107,19 +105,19 @@ $zipFilePath = $VectraCtlRootPath + "\" + $assetName
107105
Write-Output "Downloading $zipFileUrl ..."
108106

109107
$githubHeader.Accept = "application/octet-stream"
110-
$oldProgressPreference = $progressPreference;
111-
$progressPreference = 'SilentlyContinue';
108+
$oldProgressPreference = $global:ProgressPreference
109+
$global:ProgressPreference = 'SilentlyContinue'
112110
Invoke-WebRequest -Headers $githubHeader -Uri $zipFileUrl -OutFile $zipFilePath
113-
$progressPreference = $oldProgressPreference;
111+
$global:ProgressPreference = $oldProgressPreference
114112
if (!(Test-Path $zipFilePath -PathType Leaf)) {
115-
throw "Failed to download FlowCtl binary - $zipFilePath"
113+
throw "Failed to download VectraCtl binary - $zipFilePath"
116114
}
117115

118116
# Extract VectraCtl to $VectraCtlRootPath
119117
Write-Output "Extracting $zipFilePath..."
120118
Microsoft.Powershell.Archive\Expand-Archive -Force -Path $zipFilePath -DestinationPath $VectraCtlRootPath
121119
if (!(Test-Path $VectraCtlFilePath -PathType Leaf)) {
122-
throw "Failed to download VectraCtl archive - $zipFilePath"
120+
throw "Failed to extract VectraCtl archive - $zipFilePath"
123121
}
124122

125123
# Check the VectraCtl version
@@ -141,5 +139,6 @@ else {
141139
Write-Output "Added $VectraCtlRootPath to User Path - $UserPathEnvironmentVar"
142140
}
143141

144-
Write-Output "`r`nVectraCtl is installed successfully."
142+
Write-Output ""
143+
Write-Output "VectraCtl is installed successfully."
145144
Write-Output "To get started with VectraCtl, please visit https://github.com/cortexiumlabs/vectractl."

‎install/install.sh‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ getSystemInfo() {
2626
x86_64) ARCH="x64";;
2727
esac
2828

29-
OS=$(echo `uname`|tr '[:upper:]' '[:lower:]')
29+
OS=$(uname | tr '[:upper:]' '[:lower:]')
3030

3131
# Most linux distro needs root permission to copy the file to /usr/local/bin
32-
if [[ "$OS" == "linux" || "$OS" == "darwin" ]] && [[ "VECTRACTL_INSTALL_DIR" == "/usr/local/bin" ]]; then
32+
if [[ "$OS" == "linux" || "$OS" == "darwin" ]] && [[ "$VECTRACTL_INSTALL_DIR" == "/usr/local/bin" ]]; then
3333
USE_SUDO="true"
3434
fi
3535
}
@@ -47,7 +47,7 @@ verifySupported() {
4747
done
4848

4949
if [[ "$current_osarch" == "darwin-arm64" ]]; then
50-
if isReleaseAvailable $releaseTag; then
50+
if isReleaseAvailable "$releaseTag"; then
5151
return
5252
else
5353
echo "The darwin_arm64 arch has no native binary for this version of VectraCtl, however you can use the amd64 version so long as you have rosetta installed"
@@ -88,7 +88,7 @@ checkHttpRequestVectraCtl() {
8888
checkExistingVectraCtl() {
8989
if [[ -f "$VECTRACTL_FILE" ]]; then
9090
echo -e "\nVectraCtl is detected:"
91-
$VECTRACTL_FILE --version
91+
"$VECTRACTL_FILE" --version
9292
echo -e "Reinstalling VectraCtl...\n"
9393
else
9494
echo -e "Installing VectraCtl...\n"
@@ -100,11 +100,15 @@ getLatestRelease() {
100100
local latest_release=""
101101

102102
if [[ "$HTTP_REQUEST_VECTRACTL" == "curl" ]]; then
103-
latest_release=$(curl -s $vectrActlReleaseUrl | grep \"tag_name\" | grep -v rc | awk 'NR==1{print $2}' | sed -n 's/\"\(.*\)\",/\1/p')
103+
latest_release=$(curl -s "$vectrActlReleaseUrl" | grep \"tag_name\" | grep -v rc | awk 'NR==1{print $2}' | sed -n 's/\"\(.*\)\",/\1/p')
104104
else
105-
latest_release=$(wget -q --header="Accept: application/json" -O - $vectrActlReleaseUrl | grep \"tag_name\" | grep -v rc | awk 'NR==1{print $2}' | sed -n 's/\"\(.*\)\",/\1/p')
105+
latest_release=$(wget -q --header="Accept: application/json" -O - "$vectrActlReleaseUrl" | grep \"tag_name\" | grep -v rc | awk 'NR==1{print $2}' | sed -n 's/\"\(.*\)\",/\1/p')
106106
fi
107107

108+
if [[ -z "$latest_release" ]]; then
109+
echo "Failed to get latest VectraCtl release tag from GitHub API"
110+
exit 1
111+
fi
108112
ret_val=$latest_release
109113
}
110114

@@ -116,7 +120,7 @@ downloadFile() {
116120
DOWNLOAD_URL="${DOWNLOAD_BASE}/${LATEST_RELEASE_TAG}/${VECTRACTL_ARTIFACT}"
117121

118122
# Create the temp directory
119-
VECTRACTL_TMP_ROOT=$(mktemp -dt vectractl-install-XXXXXX)
123+
VECTRACTL_TMP_ROOT=$(mktemp -d "${TMPDIR:-/tmp}/vectractl-install-XXXXXX")
120124
ARTIFACT_TMP_FILE="$VECTRACTL_TMP_ROOT/$VECTRACTL_ARTIFACT"
121125

122126
echo "Downloading $DOWNLOAD_URL ..."
@@ -166,14 +170,14 @@ installFile() {
166170
if [[ -f "$VECTRACTL_FILE" ]]; then
167171
runAsRoot rm "$VECTRACTL_FILE"
168172
fi
169-
chmod o+x $tmp_root_vectractl
170-
mkdir -p $VECTRACTL_INSTALL_DIR
173+
chmod +x "$tmp_root_vectractl"
174+
mkdir -p "$VECTRACTL_INSTALL_DIR"
171175
runAsRoot cp "$tmp_root_vectractl" "$VECTRACTL_INSTALL_DIR"
172176

173177
if [[ -f "$VECTRACTL_FILE" ]]; then
174178
echo "$VECTRACTL_FILENAME installed into $VECTRACTL_INSTALL_DIR successfully."
175179

176-
$VECTRACTL_FILE --version
180+
"$VECTRACTL_FILE" --version
177181
else
178182
echo "Failed to install $VECTRACTL_FILENAME"
179183
exit 1

0 commit comments

Comments
 (0)