Skip to content

Commit

Permalink
updated installer generators
Browse files Browse the repository at this point in the history
  • Loading branch information
R. S. Doiel committed Jul 11, 2024
1 parent 9d1995e commit 5b08af7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 20 deletions.
24 changes: 18 additions & 6 deletions codemeta-bash-installer.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ 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

#
# Get the name of this script.
Expand All @@ -16,7 +20,7 @@ INSTALLER="$$(basename "$$0")"
#
# Figure out what the zip file is named
#
OS_NAME="$$(uname -o)"
OS_NAME="$$(uname)"
MACHINE="$$(uname -m)"
case "$$OS_NAME" in
Darwin)
Expand All @@ -27,6 +31,11 @@ case "$$OS_NAME" in
;;
esac

if [ "$$1" != "" ]; then
VERSION="$$1"
echo "Version set to v$${VERSION}"
fi

ZIPFILE="$$PACKAGE-v$$VERSION-$$OS_NAME-$$MACHINE.zip"

#
Expand All @@ -43,14 +52,17 @@ cat<<EOT
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
To install $$PACKAGE you need to download
$$ZIPFILE
from
from
$$RELEASE
Expand Down Expand Up @@ -85,14 +97,14 @@ rm .binfiles.tmp
# Make sure $$HOME/bin is in the path
#
case :$$PATH: in
*:$$HOME/bin:*)
*:$$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
Expand All @@ -101,7 +113,7 @@ if [ "$$EXPLAIN_OS_POLICY" = "no" ]; then
You need to take additional steps to complete installation.
Your operating system security policied needs to "allow"
Your operating system security policied needs to "allow"
running programs from $$PACKAGE.
Example: on macOS you can type open the programs in finder.
Expand Down
42 changes: 28 additions & 14 deletions codemeta-ps1-installer.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@
#
# 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$"
$$VERSION = "$version$"
$$GIT_GROUP = "$git_org_or_person$"
$$RELEASE = "https://github.com/$${GIT_GROUP}/$${PACKAGE}/releases/tag/v$${VERSION}"
$$SYSTEM_TYPE = Get-ComputerInfo -Property CsSystemType
Expand All @@ -15,34 +24,39 @@ if ($$SYSTEM_TYPE.CsSystemType.Contains("ARM64")) {
$$MACHINE = "x86_64"
}


# FIGURE OUT Install directory
$$BIN_DIR = "$${Home}\bin"
Write-Output "$${PACKAGE} will be installed in $${BIN_DIR}"
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}"

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}"
#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}"
}

Write-Output "$${PACKAGE} was installed successfully to $${BIN_DIR}"

0 comments on commit 5b08af7

Please sign in to comment.