-
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.
Merge pull request #9 from tukaelu/feat/github-action
build(action): support github actions
- Loading branch information
Showing
3 changed files
with
131 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,10 @@ | ||
name: zgsync | ||
description: setup zgsync | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: setup zgsync | ||
shell: bash | ||
run: | | ||
cd "${GITHUB_WORKSPACE}" || exit 1 | ||
/bin/bash -c "$(curl -fsfL https://raw.githubusercontent.com/tukaelu/zgsync/master/install.sh) |
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,115 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -Eeuo pipefail | ||
|
||
BINDIR="${BINDIR:-/usr/local/bin}" | ||
|
||
REPO_OWNER="tukaelu" | ||
PROG_NAME="zgsync" | ||
|
||
if ! \curl --version >/dev/null 2>&1; then | ||
echo "curl command is required to install ${PROG_NAME}" 2>&1 | ||
echo "Please install curl and try again." 2>&1 | ||
exit 1 | ||
fi | ||
|
||
get_goos() { | ||
os=$(uname -s) | ||
case $os in | ||
"Linux") | ||
echo "linux" | ||
;; | ||
"Darwin") | ||
echo "darwin" | ||
;; | ||
"FreeBSD") | ||
echo "freebsd" | ||
;; | ||
*) | ||
echo "unsupported OS: ${os}" | ||
exit 1 | ||
;; | ||
esac | ||
} | ||
|
||
get_goarch() { | ||
arch=$(uname -m) | ||
case $arch in | ||
"amd64" | "x86_64") | ||
echo "amd64" | ||
;; | ||
"arm64" | "aarch64") | ||
echo "arm64" | ||
;; | ||
*) | ||
echo "unsupported arch: ${arch}" | ||
exit 1 | ||
;; | ||
esac | ||
} | ||
|
||
get_latest_version() { | ||
version=$( | ||
curl -fsSL https://api.github.com/repos/${REPO_OWNER}/${PROG_NAME}/releases/latest | | ||
grep tag_name | | ||
cut -d: -f2-3 | | ||
sed -e 's/["v, ]//g' | ||
) | ||
echo "${version}" | ||
} | ||
|
||
get_ext() { | ||
case $goos in | ||
"linux" | "freebsd") | ||
echo ".tar.gz" | ||
;; | ||
"darwin") | ||
echo ".zip" | ||
;; | ||
*) | ||
echo "unsupported OS: ${os}" | ||
exit 1 | ||
;; | ||
esac | ||
} | ||
|
||
do_extract() { | ||
local path=$1 | ||
local fname=$2 | ||
local ext=$3 | ||
case ${ext} in | ||
".tar.gz") | ||
tar -C "${path}" -xzf "${path}/${fname}" | ||
;; | ||
".zip") | ||
unzip -d "${path}" "${path}/${fname}" | ||
;; | ||
*) | ||
echo "unsupported ext: ${ext}" | ||
exit 1 | ||
;; | ||
esac | ||
} | ||
|
||
goos=$(get_goos) | ||
goarch=$(get_goarch) | ||
ext=$(get_ext) | ||
latest_version=$(get_latest_version) | ||
|
||
fname="${PROG_NAME}_${latest_version}_${goos}_${goarch}${ext}" | ||
release_url="https://github.com/${REPO_OWNER}/${PROG_NAME}/releases/download/v${latest_version}/${fname}" | ||
|
||
tmpdir=$(mktemp -d) | ||
|
||
echo "Downloading ${fname} from ${release_url} ... " | ||
curl -fSL -o "${tmpdir}/${fname}" "${release_url}" | ||
echo "done." | ||
|
||
echo -n "Extracting ... " | ||
do_extract "${tmpdir}" "${fname}" "${ext}" | ||
echo "done." | ||
|
||
echo -n "Installing ... " | ||
mv "${tmpdir}/${PROG_NAME}" "${BINDIR}/${PROG_NAME}" | ||
chmod +x "${BINDIR}/${PROG_NAME}" | ||
echo "done." |