-
Notifications
You must be signed in to change notification settings - Fork 5
/
codemeta-ps1-installer.tmpl
62 lines (54 loc) · 1.97 KB
/
codemeta-ps1-installer.tmpl
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
#!/usr/bin/env pwsh
# Generated with codemeta-ps1-installer.tmpl, see https://github.com/caltechlibrary/codemeta-pandoc-examples
#
# Set the package name and version to install
#
param(
[Parameter()]
[String]$$VERSION = "$version$"
)
[String]$$PKG_VERSION = [Environment]::GetEnvironmentVariable("PKG_VERSION")
if ($$PKG_VERSION) {
$$VERSION = "$${PKG_VERSION}"
Write-Output "Using '$${PKG_VERSION}' for version value '$${VERSION}'"
}
$$PACKAGE = "$name$"
$$GIT_GROUP = "$git_org_or_person$"
$$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"
}
# 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"
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 ([System.IO.File]::Exists($$ZIPFILE)) {
if (!(Test-Path $$ZIPFILE)) {
Write-Output "Failed to download $${ZIPFILE} from $${DOWNLOAD_URL}"
} else {
tar.exe xf "$${ZIPFILE}" -C "$${Home}"
#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}"
}