-
Notifications
You must be signed in to change notification settings - Fork 13
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
Showing
4 changed files
with
186 additions
and
2 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
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Installation</title> | ||
<style> | ||
pre { | ||
background-color: #f4f4f4; | ||
padding: 15px; | ||
border-radius: 5px; | ||
overflow-x: auto; | ||
line-height: 1.5; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="content"></div> | ||
|
||
<script> | ||
async function loadRawContent() { | ||
try { | ||
const response = await fetch('https://raw.githubusercontent.com/babarot/gomi/main/hack/install'); | ||
const text = await response.text(); | ||
|
||
const escapedText = text | ||
.replace(/&/g, '&') | ||
.replace(/</g, '<') | ||
.replace(/>/g, '>') | ||
.replace(/"/g, '"') | ||
.replace(/'/g, '''); | ||
|
||
document.getElementById('content').innerHTML = `<pre>${escapedText}</pre>`; | ||
} catch (error) { | ||
console.error('Error loading content:', error); | ||
document.getElementById('content').innerHTML = 'Failed to load content.'; | ||
} | ||
} | ||
|
||
loadRawContent(); | ||
</script> | ||
</body> | ||
</html> |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
## Installation script | ||
|
||
Run script from local: | ||
|
||
```console | ||
$ cat hack/install | bash | ||
``` | ||
|
||
Run script via curl (when not cloning repo): | ||
|
||
```console | ||
$ curl -sL https://raw.githubusercontent.com/babarot/gomi/HEAD/hack/install | GOMI_VERSION=v1.2.2 bash | ||
``` | ||
|
||
env | description | default | ||
---|---|--- | ||
`GOMI_VERSION` | gomi version, available versions are on [releases](https://github.com/babarot/gomi/releases) | `latest` | ||
`GOMI_BIN_DIR` | Path to install | `~/bin` |
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 |
---|---|---|
@@ -0,0 +1,125 @@ | ||
#!/usr/bin/env bash | ||
|
||
gomi_bin_dir=${GOMI_BIN_DIR:-~/bin} | ||
gomi_version=${GOMI_VERSION:-latest} | ||
gomi_tmp_dir=${TMPDIR:-/tmp}/gomi-${gomi_version} | ||
|
||
main() { | ||
# Try to download binary executable | ||
local arch | ||
local notfound=false | ||
local tarball | ||
|
||
if [[ -x ${gomi_bin_dir}/gomi ]]; then | ||
echo "already installed: ${gomi_bin_dir}/gomi" | ||
return 0 | ||
fi | ||
|
||
arch="$(uname -sm)" | ||
case "${arch}" in | ||
"Darwin arm64") tarball="gomi_Darwin_arm64.tar.gz" ;; | ||
"Darwin x86_64") tarball="gomi_Darwin_x86_64.tar.gz" ;; | ||
"Linux aarch64") tarball="gomi_Linux_arm64.tar.gz" ;; | ||
"Linux "*64) tarball="gomi_Linux_x86_64.tar.gz" ;; | ||
*) notfound=true ;; | ||
esac | ||
|
||
if ! { download ${tarball} && install -v -m 0755 "${gomi_tmp_dir}/gomi" "${gomi_bin_dir}/gomi"; } || ${notfound}; then | ||
echo "gomi available on your system is not found. So trying to make gomi from Go!" | ||
if command -v go >/dev/null; then | ||
try_go | ||
else | ||
echo "go executable not found. Installation failed." >&2 | ||
return 1 | ||
fi | ||
fi | ||
|
||
command -v gomi &>/dev/null && gomi --version | ||
|
||
echo 'For more information, see: https://github.com/babarot/gomi' | ||
} | ||
|
||
try_curl() { | ||
local file=${1} | ||
command -v curl > /dev/null && | ||
if [[ ${file} =~ tar.gz$ ]]; then | ||
curl --progress-bar -fL "${file}" | tar -xzf - -C "${gomi_tmp_dir}" | ||
else | ||
local tmp=${gomi_tmp_dir}/gomi.zip | ||
curl --progress-bar -fLo "${tmp}" "${file}" && unzip -o "${tmp}" && rm -f "${tmp}" | ||
fi | ||
} | ||
|
||
try_wget() { | ||
local file=${1} | ||
command -v wget > /dev/null && | ||
if [[ ${file} =~ tar.gz$ ]]; then | ||
wget -O - "${file}" | tar -xzf - -C "${gomi_tmp_dir}" | ||
else | ||
local tmp=${gomi_tmp_dir}/gomi.zip | ||
wget -O "${tmp}" "${file}" && unzip -o "${tmp}" && rm -f "${tmp}" | ||
fi | ||
} | ||
|
||
download() { | ||
local tarball="${1}" | ||
local url | ||
|
||
if [[ -z ${tarball} ]]; then | ||
# when not found what to download | ||
return 1 | ||
fi | ||
|
||
mkdir -p "${gomi_bin_dir}" || { | ||
echo "Failed to create directory" >&2 | ||
return 1 | ||
} | ||
|
||
mkdir -p "${gomi_tmp_dir}" || { | ||
echo "Failed to create directory" >&2 | ||
return 1 | ||
} | ||
|
||
if [[ ${gomi_version} == latest ]]; then | ||
url="https://github.com/babarot/gomi/releases/latest/download/${tarball}" | ||
else | ||
url="https://github.com/babarot/gomi/releases/download/${gomi_version}/${tarball}" | ||
fi | ||
|
||
echo "Downloading gomi ..." | ||
if ! (try_curl "${url}" || try_wget "${url}"); then | ||
echo "Failed to download with curl and wget" >&2 | ||
return 1 | ||
fi | ||
|
||
if [[ ! -f ${gomi_tmp_dir}/gomi ]]; then | ||
echo "Failed to download ${tarball}" >&2 | ||
return 1 | ||
fi | ||
} | ||
|
||
try_go() { | ||
local do_cp=false | ||
local path="github.com/babarot/gomi" | ||
local cmd="${path}/cmd" | ||
|
||
echo -n "Building binary (go get -u ${path}) ... " | ||
if [[ -z ${GOPATH} ]]; then | ||
do_cp=true | ||
export GOPATH="${TMPDIR:-/tmp}/gomi-gopath" | ||
mkdir -p "${GOPATH}" | ||
fi | ||
|
||
local ts | ||
ts=$(date "+%Y-%m-%d") | ||
|
||
if go install -ldflags "-s -w -X ${cmd}.Version=${gomi_version} -X ${cmd}.BuildTag=built-by-go -X ${cmd}.BuildSHA=${ts}" ${path}; then | ||
echo "OK" | ||
${do_cp} && cp -v "${GOPATH}/bin/gomi" "${gomi_bin_dir}/gomi" | ||
else | ||
echo "Failed to build binary. Installation failed." >&2 | ||
return 1 | ||
fi | ||
} | ||
|
||
main "${@}" |