-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstaller.ps1
More file actions
executable file
·111 lines (101 loc) · 3.86 KB
/
Copy pathinstaller.ps1
File metadata and controls
executable file
·111 lines (101 loc) · 3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env pwsh
# generated with CMTools 0.0.46 93a5076
#
# Set the package name and version to install
#
param(
[Parameter()]
[String]$VERSION = "0.0.46"
)
[String]$PKG_VERSION = [Environment]::GetEnvironmentVariable("PKG_VERSION")
if ($PKG_VERSION) {
$VERSION = "${PKG_VERSION}"
Write-Output "Using '${PKG_VERSION}' for version value '${VERSION}'"
}
$PACKAGE = "CMTools"
$GIT_GROUP = "caltechlibrary"
$RELEASE = "https://github.com/${GIT_GROUP}/${PACKAGE}/releases/tag/v${VERSION}"
$SYSTEM_TYPE = Get-ComputerInfo -Property CsSystemType
if ($SYSTEM_TYPE.CsSystemType.Contains("ARM64")) {
$MACHINE = "arm64"
} else {
$MACHINE = "x86_64"
}
Write-Output "Using release ${RELEASE}"
# FIGURE OUT Install directory
$BIN_DIR = "${Home}\bin"
Write-Output "${PACKAGE} v${VERSION} will be installed in ${BIN_DIR}"
#
# Figure out what the zip file is named
#
$ZIPFILE = "${PACKAGE}-v${VERSION}-Windows-${MACHINE}.zip"
$CHECKSUM_FILE = "${PACKAGE}-v${VERSION}-checksums.txt"
Write-Output "Fetching Zipfile ${ZIPFILE}"
#
# Check to see if this zip file has been downloaded.
#
$DOWNLOAD_URL = "https://github.com/${GIT_GROUP}/${PACKAGE}/releases/download/v${VERSION}/${ZIPFILE}"
Write-Output "Download URL ${DOWNLOAD_URL}"
if (!(Test-Path $BIN_DIR)) {
New-Item $BIN_DIR -ItemType Directory | Out-Null
}
curl.exe -Lo "${ZIPFILE}" "${DOWNLOAD_URL}"
if (!(Test-Path $ZIPFILE)) {
Write-Output "Failed to download ${ZIPFILE} from ${DOWNLOAD_URL}"
} else {
# Verify checksum
$CHECKSUM_URL = "https://github.com/${GIT_GROUP}/${PACKAGE}/releases/download/v${VERSION}/${CHECKSUM_FILE}"
try {
curl.exe -Lo "${CHECKSUM_FILE}" "${CHECKSUM_URL}"
if (Test-Path $CHECKSUM_FILE) {
$expectedLine = Get-Content $CHECKSUM_FILE | Where-Object { $_ -match [regex]::Escape($ZIPFILE) }
if ($expectedLine) {
$expectedHash = ($expectedLine -split 's+')[0].ToLower()
$actualHash = (Get-FileHash -Path $ZIPFILE -Algorithm SHA256).Hash.ToLower()
if ($expectedHash -eq $actualHash) {
Write-Output "Checksum verified: ${ZIPFILE}"
} else {
Write-Warning "Checksum mismatch for ${ZIPFILE}"
Write-Warning " Expected: ${expectedHash}"
Write-Warning " Actual: ${actualHash}"
Write-Warning " Proceeding anyway — verify the download manually if concerned"
}
} else {
Write-Warning "${ZIPFILE} not found in checksum file, skipping verification"
}
Remove-Item $CHECKSUM_FILE -ErrorAction SilentlyContinue
}
} catch {
Write-Warning "Could not download ${CHECKSUM_FILE}, skipping verification"
}
# Do we have a zip file or tar.gz file?
$fileInfo = Get-Item "${ZIPFILE}"
# Handle zip or tar.gz files
switch ($fileInfo.Extension) {
".zip" {
Expand-Archive -Force -Path "${ZIPFILE}" "${Home}"
break
}
".gz" {
tar.exe xf "${ZIPFILE}" -C "${Home}"
break
}
".tgz" {
tar.exe xf "${ZIPFILE}" -C "${Home}"
break
}
default {
Write-Output "The ${ZIPFILE} from ${DOWNLOAD_URL} is neither a ZIP file nor a gzipped tar file."
exit 1
}
}
#Remove-Item $ZIPFILE
$User = [System.EnvironmentVariableTarget]::User
$Path = [System.Environment]::GetEnvironmentVariable('Path', $User)
if (!(";${Path};".ToLower() -like "*;${BIN_DIR};*".ToLower())) {
[System.Environment]::SetEnvironmentVariable('Path', "${Path};${BIN_DIR}", $User)
$Env:Path += ";${BIN_DIR}"
}
Write-Output "${PACKAGE} was installed successfully to ${BIN_DIR}"
Write-Output "If you get a security warning on Windows or macOS please see INSTALL_NOTES_Windows.md or INSTALL_NOTES_macOS.md"
}