Skip to content

Commit

Permalink
chore: 优化makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
TBXark committed Jan 10, 2025
1 parent 5886a04 commit 93f578c
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 9 deletions.
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ jobs:
mkdir -p assets/dash/dashboard/apps/web-ele/dist
touch assets/dash/dashboard/apps/web-ele/dist/index.html
make init
make generate
make build
- name: Test
Expand Down
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
MODULE := $(shell go list -m)
MODULE_NAME := $(lastword $(subst /, ,$(MODULE)))
BUILD := $(shell git rev-parse --short HEAD)@$(shell date +%s)
CURRENT_OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
CURRENT_ARCH := $(shell uname -m | tr '[:upper:]' '[:lower:]')
CURRENT_OS := $(shell uname | tr "[A-Z]" "[a-z]")
CURRENT_ARCH := $(shell uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/')

DOCKER_IMAGE ?= ghcr.io/tbxark/$(MODULE_NAME)
DOCKER_FILE := cmd/app/Dockerfile
Expand Down Expand Up @@ -66,16 +66,16 @@ dash: ## Build dash
build: ## Build binary
$(GO_BUILD) -o ./build/$(CURRENT_OS)_$(CURRENT_ARCH)/ ./...

.PHONY: build-linux-amd
build-linux-amd: ## Build linux amd64 binary
GOOS=linux GOARCH=amd64 $(GO_BUILD) -o ./build/linux_x86/ ./...
.PHONY: build-linux-amd64
build-linux-amd64: ## Build linux amd64 binary
GOOS=linux GOARCH=amd64 $(GO_BUILD) -o ./build/linux_amd64/ ./...

.PHONY: build-linux-arm
build-linux-arm: ## Build linux arm64 binary
.PHONY: build-linux-arm64
build-linux-arm64: ## Build linux arm64 binary
GOOS=linux GOARCH=arm64 $(GO_BUILD) -o ./build/linux_arm64/ ./...

.PHONY: build-all
build-all: build-linux-amd build-linux-arm ## Build all arch binary
build-all: build-linux-amd64 build-linux-arm64 ## Build all arch binary

.PHONY: build-docker
build-docker: ## Build docker image
Expand Down
60 changes: 60 additions & 0 deletions scripts/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env sh

set -u

type curl > /dev/null || { echo "curl: not found"; exit 1; }

set -e


bin="sphere"
repo="TBXark/sphere"
dest_dir="/usr/local/bin"

get_latest_release() {
local repo="$1"
curl -sSL "https://api.github.com/repos/${repo}/releases/latest" | \
awk 'BEGIN{FS=": |,|\""}; /tag_name/{print $5}'
}

version="$(get_latest_release "${repo}")" # v1.2.0

# if args has version override it and not eq "latest"
if test $# -eq 1; then
if test "$1" != "latest"; then
version="$1"

echo "Install ${version}"
fi
fi

platform="$(uname | tr "[A-Z]" "[a-z]")" # Linux => linux
arch="$(uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/')" # x86_64 => amd64, aarch64 => arm64
package="${bin}_${platform}_${arch}.tar.gz"
package_url="https://github.com/${repo}/releases/download/${version}/${package}"
bin_path="${dest_dir}/${bin}"
tmp_dir="$(mktemp -d)"

trap "rm -r ${tmp_dir}" EXIT

if test -e "${bin_path}"; then
current_version="v$("${bin_path}" -v | awk '{print $NF}')"
if test "${current_version}" = "${version}"; then
echo "${bin} is already updated, no need to upgrade."
exit 0
else
echo "There is a new version of ${bin}, starting to upgrade from ${current_version} to ${version}."
fi
fi
cd "${tmp_dir}"
curl -sSL "${package_url}" | tar xzf -

if test $(id -u) -eq 0; then
mv "${bin}" "${dest_dir}"
else
sudo mv "${bin}" "${dest_dir}"
fi

mkdir -p ~/.${bin}

echo "${bin} ${version} has been installed."

0 comments on commit 93f578c

Please sign in to comment.