Skip to content

Commit dd277d1

Browse files
committed
Refactor install scripts for naming consistency
Refactored function names in install.ps1 and install.sh to use consistent and idiomatic naming conventions (snake_case for Bash, -not for PowerShell). Updated all function calls and main logic to match new names. Improved error handling and output messages for clarity. #36
1 parent d68bf7a commit dd277d1

2 files changed

Lines changed: 27 additions & 27 deletions

File tree

‎install/install.ps1‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ else {
4747
# Create VectraCtl Directory
4848
Write-Output "Creating $VectraCtlRootPath directory"
4949
New-Item -ErrorAction Ignore -Path $VectraCtlRootPath -ItemType "directory"
50-
if (!(Test-Path $VectraCtlRootPath -PathType Container)) {
50+
if (-not (Test-Path $VectraCtlRootPath -PathType Container)) {
5151
Write-Warning "Please visit https://github.com/cortexiumlabs/vectractl for instructions on how to install without admin rights."
5252
throw "Cannot create $VectraCtlRootPath"
5353
}
@@ -67,7 +67,7 @@ function GetVersionInfo {
6767
$Releases
6868
)
6969
# Filter windows binary and download archive
70-
if (!$Version) {
70+
if (-not $Version) {
7171
$release = $Releases | Where-Object { $_.tag_name -notlike "*rc*" } | Select-Object -First 1
7272
}
7373
else {
@@ -83,7 +83,7 @@ function GetWindowsAsset {
8383
$Release
8484
)
8585
$windowsAsset = $Release | Select-Object -ExpandProperty assets | Where-Object { $_.name -like "*windows-x64.zip" }
86-
if (!$windowsAsset) {
86+
if (-not $windowsAsset) {
8787
throw "Cannot find the windows VectraCtl binary"
8888
}
8989
[hashtable]$return = @{}
@@ -94,7 +94,7 @@ function GetWindowsAsset {
9494
}
9595

9696
$release = GetVersionInfo -Version $Version -Releases $releases
97-
if (!$release) {
97+
if (-not $release) {
9898
throw "Cannot find the specified VectraCtl binary version"
9999
}
100100
$asset = GetWindowsAsset -Release $release
@@ -109,14 +109,14 @@ $oldProgressPreference = $global:ProgressPreference
109109
$global:ProgressPreference = 'SilentlyContinue'
110110
Invoke-WebRequest -Headers $githubHeader -Uri $zipFileUrl -OutFile $zipFilePath
111111
$global:ProgressPreference = $oldProgressPreference
112-
if (!(Test-Path $zipFilePath -PathType Leaf)) {
112+
if (-not (Test-Path $zipFilePath -PathType Leaf)) {
113113
throw "Failed to download VectraCtl binary - $zipFilePath"
114114
}
115115

116116
# Extract VectraCtl to $VectraCtlRootPath
117117
Write-Output "Extracting $zipFilePath..."
118118
Microsoft.Powershell.Archive\Expand-Archive -Force -Path $zipFilePath -DestinationPath $VectraCtlRootPath
119-
if (!(Test-Path $VectraCtlFilePath -PathType Leaf)) {
119+
if (-not (Test-Path $VectraCtlFilePath -PathType Leaf)) {
120120
throw "Failed to extract VectraCtl archive - $zipFilePath"
121121
}
122122

‎install/install.sh‎

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ VECTRACTL_FILENAME=vectractl
1818

1919
VECTRACTL_FILE="${VECTRACTL_INSTALL_DIR}/${VECTRACTL_FILENAME}"
2020

21-
getSystemInfo() {
21+
get_system_info() {
2222
ARCH=$(uname -m)
2323
case $ARCH in
2424
armv7*) ARCH="arm";;
@@ -36,7 +36,7 @@ getSystemInfo() {
3636
return
3737
}
3838

39-
verifySupported() {
39+
verify_supported() {
4040
releaseTag=$1
4141
local supported=(darwin-x64 linux-x64 linux-arm linux-arm64)
4242
local current_osarch="${OS}-${ARCH}"
@@ -49,7 +49,7 @@ verifySupported() {
4949
done
5050

5151
if [[ "$current_osarch" == "darwin-arm64" ]]; then
52-
if isReleaseAvailable "$releaseTag"; then
52+
if is_release_available "$releaseTag"; then
5353
return
5454
else
5555
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"
@@ -63,7 +63,7 @@ verifySupported() {
6363
exit 1
6464
}
6565

66-
runAsRoot() {
66+
run_as_root() {
6767
local CMD="$*"
6868

6969
if [[ $EUID -ne 0 && $USE_SUDO = "true" ]]; then
@@ -77,7 +77,7 @@ runAsRoot() {
7777
return
7878
}
7979

80-
checkHttpRequestVectraCtl() {
80+
check_http_request_vectractl() {
8181
if type "curl" > /dev/null; then
8282
HTTP_REQUEST_VECTRACTL=curl
8383
elif type "wget" > /dev/null; then
@@ -89,7 +89,7 @@ checkHttpRequestVectraCtl() {
8989
return
9090
}
9191

92-
checkExistingVectraCtl() {
92+
check_existing_vectractl() {
9393
if [[ -f "$VECTRACTL_FILE" ]]; then
9494
echo -e "\nVectraCtl is detected:"
9595
"$VECTRACTL_FILE" --version
@@ -100,7 +100,7 @@ checkExistingVectraCtl() {
100100
return
101101
}
102102

103-
getLatestRelease() {
103+
get_latest_release() {
104104
local vectractl_release_url="https://api.github.com/repos/${GITHUB_ORG}/${GITHUB_REPO}/releases"
105105
local latest_release=""
106106

@@ -118,7 +118,7 @@ getLatestRelease() {
118118
return
119119
}
120120

121-
downloadFile() {
121+
download_file() {
122122
LATEST_RELEASE_TAG=$1
123123

124124
VECTRACTL_ARTIFACT="${VECTRACTL_FILENAME}-${OS}-${ARCH}.tar.gz"
@@ -143,7 +143,7 @@ downloadFile() {
143143
return
144144
}
145145

146-
isReleaseAvailable() {
146+
is_release_available() {
147147
LATEST_RELEASE_TAG=$1
148148

149149
VECTRACTL_ARTIFACT="${VECTRACTL_FILENAME}-${OS}-${ARCH}.tar.gz"
@@ -165,7 +165,7 @@ isReleaseAvailable() {
165165
return 1
166166
}
167167

168-
installFile() {
168+
install_file() {
169169
tar xf "$ARTIFACT_TMP_FILE" -C "$VECTRACTL_TMP_ROOT"
170170
local tmp_root_vectractl="$VECTRACTL_TMP_ROOT/$VECTRACTL_FILENAME"
171171

@@ -175,11 +175,11 @@ installFile() {
175175
fi
176176

177177
if [[ -f "$VECTRACTL_FILE" ]]; then
178-
runAsRoot rm "$VECTRACTL_FILE"
178+
run_as_root rm "$VECTRACTL_FILE"
179179
fi
180180
chmod +x "$tmp_root_vectractl"
181181
mkdir -p "$VECTRACTL_INSTALL_DIR"
182-
runAsRoot cp "$tmp_root_vectractl" "$VECTRACTL_INSTALL_DIR"
182+
run_as_root cp "$tmp_root_vectractl" "$VECTRACTL_INSTALL_DIR"
183183

184184
if [[ -f "$VECTRACTL_FILE" ]]; then
185185
echo "$VECTRACTL_FILENAME installed into $VECTRACTL_INSTALL_DIR successfully."
@@ -209,7 +209,7 @@ cleanup() {
209209
return
210210
}
211211

212-
installCompleted() {
212+
install_completed() {
213213
echo -e "\nTo get started with VectraCtl, please visit https://github.com/cortexiumlabs/vectractl"
214214
return
215215
}
@@ -219,23 +219,23 @@ installCompleted() {
219219
# -----------------------------------------------------------------------------
220220
trap "fail_trap" EXIT
221221

222-
getSystemInfo
223-
checkHttpRequestVectraCtl
222+
get_system_info
223+
check_http_request_vectractl
224224

225225
if [[ -z "$1" ]]; then
226226
echo "Getting the latest VectraCtl..."
227-
getLatestRelease
227+
get_latest_release
228228
else
229229
ret_val=v$1
230230
fi
231231

232-
verifySupported $ret_val
233-
checkExistingVectraCtl
232+
verify_supported $ret_val
233+
check_existing_vectractl
234234

235235
echo "Installing $ret_val VectraCtl..."
236236

237-
downloadFile $ret_val
238-
installFile
237+
download_file $ret_val
238+
install_file
239239
cleanup
240240

241-
installCompleted
241+
install_completed

0 commit comments

Comments
 (0)