Skip to content

Commit c8472f2

Browse files
committed
Add returns to shell functions, improve error handling
Added explicit return statements to multiple shell functions for clarity and consistency. Improved architecture detection in getSystemInfo with a default error case. Updated PowerShell -Like to -like for syntax consistency. Renamed variables in getLatestRelease for clarity. #32
1 parent a34c7f5 commit c8472f2

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

‎install/install.ps1‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function GetWindowsAsset {
8282
param (
8383
$Release
8484
)
85-
$windowsAsset = $Release | Select-Object -ExpandProperty assets | Where-Object { $_.name -Like "*windows-x64.zip" }
85+
$windowsAsset = $Release | Select-Object -ExpandProperty assets | Where-Object { $_.name -like "*windows-x64.zip" }
8686
if (!$windowsAsset) {
8787
throw "Cannot find the windows VectraCtl binary"
8888
}

‎install/install.sh‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ getSystemInfo() {
2424
armv7*) ARCH="arm";;
2525
aarch64) ARCH="arm64";;
2626
x86_64) ARCH="x64";;
27+
*) echo "Unsupported architecture: $ARCH"; exit 1;;
2728
esac
2829

2930
OS=$(uname | tr '[:upper:]' '[:lower:]')
@@ -32,6 +33,7 @@ getSystemInfo() {
3233
if [[ "$OS" == "linux" || "$OS" == "darwin" ]] && [[ "$VECTRACTL_INSTALL_DIR" == "/usr/local/bin" ]]; then
3334
USE_SUDO="true"
3435
fi
36+
return
3537
}
3638

3739
verifySupported() {
@@ -72,6 +74,7 @@ runAsRoot() {
7274
echo "Please visit https://github.com/cortexiumlabs/vectractl for instructions on how to install without sudo."
7375
exit 1
7476
}
77+
return
7578
}
7679

7780
checkHttpRequestVectraCtl() {
@@ -83,6 +86,7 @@ checkHttpRequestVectraCtl() {
8386
echo "Either curl or wget is required"
8487
exit 1
8588
fi
89+
return
8690
}
8791

8892
checkExistingVectraCtl() {
@@ -93,23 +97,25 @@ checkExistingVectraCtl() {
9397
else
9498
echo -e "Installing VectraCtl...\n"
9599
fi
100+
return
96101
}
97102

98103
getLatestRelease() {
99-
local vectrActlReleaseUrl="https://api.github.com/repos/${GITHUB_ORG}/${GITHUB_REPO}/releases"
104+
local vectractl_release_url="https://api.github.com/repos/${GITHUB_ORG}/${GITHUB_REPO}/releases"
100105
local latest_release=""
101106

102107
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')
108+
latest_release=$(curl -s "$vectractl_release_url" | grep \"tag_name\" | grep -v rc | awk 'NR==1{print $2}' | sed -n 's/\"\(.*\)\",/\1/p')
104109
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')
110+
latest_release=$(wget -q --header="Accept: application/json" -O - "$vectractl_release_url" | grep \"tag_name\" | grep -v rc | awk 'NR==1{print $2}' | sed -n 's/\"\(.*\)\",/\1/p')
106111
fi
107112

108113
if [[ -z "$latest_release" ]]; then
109114
echo "Failed to get latest VectraCtl release tag from GitHub API"
110115
exit 1
111116
fi
112117
ret_val=$latest_release
118+
return
113119
}
114120

115121
downloadFile() {
@@ -134,6 +140,7 @@ downloadFile() {
134140
echo "failed to download $DOWNLOAD_URL ..."
135141
exit 1
136142
fi
143+
return
137144
}
138145

139146
isReleaseAvailable() {
@@ -182,6 +189,7 @@ installFile() {
182189
echo "Failed to install $VECTRACTL_FILENAME"
183190
exit 1
184191
fi
192+
return
185193
}
186194

187195
fail_trap() {
@@ -198,10 +206,12 @@ cleanup() {
198206
if [[ -d "${VECTRACTL_TMP_ROOT:-}" ]]; then
199207
rm -rf "$VECTRACTL_TMP_ROOT"
200208
fi
209+
return
201210
}
202211

203212
installCompleted() {
204213
echo -e "\nTo get started with VectraCtl, please visit https://github.com/cortexiumlabs/vectractl"
214+
return
205215
}
206216

207217
# -----------------------------------------------------------------------------

0 commit comments

Comments
 (0)