-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
R. S. Doiel
committed
Sep 17, 2024
1 parent
86482c5
commit ad41bd2
Showing
2 changed files
with
98 additions
and
290 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,158 +1,62 @@ | ||
#!/bin/sh | ||
#!/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 | ||
# | ||
PACKAGE="$name$" | ||
VERSION="$version$" | ||
GIT_GROUP="$git_org_or_person$" | ||
RELEASE="https://github.com/$$GIT_GROUP/$$PACKAGE/releases/tag/v$$VERSION" | ||
if [ "$$PKG_VERSION" != "" ]; then | ||
VERSION="$${PKG_VERSION}" | ||
echo "$${PKG_VERSION} used for version v$${VERSION}" | ||
fi | ||
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}'" | ||
} | ||
|
||
# | ||
# Get the name of this script. | ||
# | ||
INSTALLER="$$(basename "$$0")" | ||
|
||
# | ||
# Figure out what the zip file is named | ||
# | ||
OS_NAME="$$(uname)" | ||
MACHINE="$$(uname -m)" | ||
case "$$OS_NAME" in | ||
Darwin) | ||
OS_NAME="macOS" | ||
;; | ||
GNU/Linux) | ||
OS_NAME="Linux" | ||
;; | ||
esac | ||
|
||
if [ "$$1" != "" ]; then | ||
VERSION="$$1" | ||
echo "Version set to v$${VERSION}" | ||
fi | ||
|
||
ZIPFILE="$$PACKAGE-v$$VERSION-$$OS_NAME-$$MACHINE.zip" | ||
|
||
# | ||
# Check to see if this zip file has been downloaded. | ||
# | ||
DOWNLOAD_URL="https://github.com/$$GIT_GROUP/$$PACKAGE/releases/download/v$$VERSION/$$ZIPFILE" | ||
if ! curl -L -o "$$HOME/Downloads/$$ZIPFILE" "$$DOWNLOAD_URL"; then | ||
echo "Curl failed to get $$DOWNLOAD_URL" | ||
fi | ||
cat<<EOT | ||
Retrieved $$DOWNLOAD_URL | ||
Saved as $$HOME/Downloads/$$ZIPFILE | ||
EOT | ||
|
||
if [ ! -d "$$HOME/Downloads" ]; then | ||
mkdir -p "$$HOME/Downloads" | ||
fi | ||
if [ ! -f "$$HOME/Downloads/$$ZIPFILE" ]; then | ||
cat<<EOT | ||
To install $$PACKAGE you need to download | ||
$$ZIPFILE | ||
from | ||
$$RELEASE | ||
$$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" | ||
} | ||
|
||
You can do that with your web browser. After | ||
that you should be able to re-run $$INSTALLER | ||
|
||
EOT | ||
exit 1 | ||
fi | ||
|
||
START="$$(pwd)" | ||
mkdir -p "$$HOME/.$$PACKAGE/installer" | ||
cd "$$HOME/.$$PACKAGE/installer" || exit 1 | ||
unzip "$$HOME/Downloads/$$ZIPFILE" "bin/*" "man/*" | ||
# FIGURE OUT Install directory | ||
$$BIN_DIR = "$${Home}\bin" | ||
Write-Output "$${PACKAGE} v$${VERSION} will be installed in $${BIN_DIR}" | ||
|
||
# | ||
# Copy the application into place | ||
# Figure out what the zip file is named | ||
# | ||
mkdir -p "$$HOME/bin" | ||
EXPLAIN_OS_POLICY="yes" | ||
find bin -type f >.binfiles.tmp | ||
while read -r APP; do | ||
V=$$("./$$APP" --version) | ||
if [ "$$V" = "" ]; then | ||
EXPLAIN_OS_POLICY="yes" | ||
fi | ||
mv "$$APP" "$$HOME/bin/" | ||
done <.binfiles.tmp | ||
rm .binfiles.tmp | ||
$$ZIPFILE = "$${PACKAGE}-v$${VERSION}-Windows-$${MACHINE}.zip" | ||
Write-Output "Fetching Zipfile $${ZIPFILE}" | ||
|
||
# | ||
# Make sure $$HOME/bin is in the path | ||
# | ||
case :$$PATH: in | ||
*:$$HOME/bin:*) | ||
;; | ||
*) | ||
# shellcheck disable=SC2016 | ||
echo 'export PATH="$$HOME/bin:$$PATH"' >>"$$HOME/.bashrc" | ||
# shellcheck disable=SC2016 | ||
echo 'export PATH="$$HOME/bin:$$PATH"' >>"$$HOME/.zshrc" | ||
;; | ||
esac | ||
|
||
# shellcheck disable=SC2031 | ||
if [ "$$EXPLAIN_OS_POLICY" = "no" ]; then | ||
cat <<EOT | ||
You need to take additional steps to complete installation. | ||
Your operating system security policied needs to "allow" | ||
running programs from $$PACKAGE. | ||
Example: on macOS you can type open the programs in finder. | ||
open $$HOME/bin | ||
Find the program(s) and right click on the program(s) | ||
installed to enable them to run. | ||
EOT | ||
|
||
fi | ||
|
||
# | ||
# Copy the manual pages into place | ||
# Check to see if this zip file has been downloaded. | ||
# | ||
EXPLAIN_MAN_PATH="no" | ||
for SECTION in 1 2 3 4 5 6 7; do | ||
if [ -d "man/man$${SECTION}" ]; then | ||
EXPLAIN_MAN_PATH="yes" | ||
mkdir -p "$$HOME/man/man$${SECTION}" | ||
find "man/man$${SECTION}" -type f | while read -r MAN; do | ||
cp -v "$$MAN" "$$HOME/man/man$${SECTION}/" | ||
done | ||
fi | ||
done | ||
|
||
if [ "$$EXPLAIN_MAN_PATH" = "yes" ]; then | ||
cat <<EOT | ||
The man pages have been installed at '$$HOME/man'. You | ||
need to have that location in your MANPATH for man to | ||
find the pages. E.g. For the Bash shell add the | ||
following to your following to your '$$HOME/.bashrc' file. | ||
export MANPATH="$$HOME/man:$$MANPATH" | ||
EOT | ||
|
||
fi | ||
|
||
rm -fR "$$HOME/.$$PACKAGE/installer" | ||
cd "$$START" || exit 1 | ||
$$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}" | ||
} |
Oops, something went wrong.