From 93f578c2ef327901b716470df1f6f42530e31d71 Mon Sep 17 00:00:00 2001 From: tbxark Date: Fri, 10 Jan 2025 10:18:23 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E4=BC=98=E5=8C=96makefile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 1 - Makefile | 16 +++++----- scripts/install.sh | 60 +++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 9 deletions(-) create mode 100644 scripts/install.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ade77c6..7b413e8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 diff --git a/Makefile b/Makefile index 29f506c..90f0f58 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 diff --git a/scripts/install.sh b/scripts/install.sh new file mode 100644 index 0000000..dde1570 --- /dev/null +++ b/scripts/install.sh @@ -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."