Skip to content

Commit

Permalink
update env
Browse files Browse the repository at this point in the history
  • Loading branch information
voocel committed Jul 10, 2022
1 parent bc561d2 commit 0864f56
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 30 deletions.
30 changes: 15 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@ default:build
build: build-linux-amd64 build-linux-arm64 build-darwin-amd64 build-darwin-arm64 build-windows-amd64

build-linux-amd64:
echo "building linux amd 64"
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags '-w -s' -o svbin/sv-linux-amd-64
echo "build successfully linux amd 64"
@echo "\033[33mBuilding linux amd 64 \033[0m"
@CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags '-w -s' -o svbin/sv-linux-amd-64
@echo "\033[32mBuild successfully sv-linux-amd-64 \033[0m\n"

build-linux-arm64:
echo "building linux arm 64"
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags '-w -s' -o svbin/sv-linux-arm-64
echo "build successfully linux arm 64"
@echo "\033[33mBuilding linux arm 64"
@CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags '-w -s' -o svbin/sv-linux-arm-64
@echo "\033[32mBuild successfully sv-linux-arm-64 \033[0m\n"

build-darwin-amd64:
echo "building darwin amd 64"
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags '-w -s' -o svbin/sv-darwin-amd-64
echo "build successfully darwin amd 64"
@echo "\033[33mBuilding darwin amd 64"
@CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags '-w -s' -o svbin/sv-darwin-amd-64
@echo "\033[32mBuild successfully sv-darwin-amd-64 \033[0m\n"

build-darwin-arm64:
echo "building darwin arm 64 (m1)"
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags '-w -s' -o svbin/sv-darwin-arm-64
echo "build successfully darwin arm 64 (m1)"
@echo "\033[33mBuilding darwin arm 64 (m1)"
@CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags '-w -s' -o svbin/sv-darwin-arm-64
@echo "\033[32mBuild successfully sv-darwin-arm-64 (m1) \033[0m\n"

build-windows-amd64:
echo "building windows amd 64"
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags '-w -s' -o svbin/sv-windows-amd-64.exe
echo "build successfully windows amd 64"
@echo "\033[33mBuilding windows amd 64"
@CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags '-w -s' -o svbin/sv-windows-amd-64.exe
@echo "\033[32mBuild successfully sv-windows-amd-64.exe \033[0m\n"

clean:
rm -f svbin/*
Expand Down
35 changes: 20 additions & 15 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

set -eu

GOPATH=${GOPATH:-$HOME/go}
GOROOT=${GOROOT:-$HOME/.sv/go}

if [ "$(echo "$GOROOT" | cut -c1)" != "/" ]; then
Expand Down Expand Up @@ -108,31 +109,32 @@ get_shell_profile() {
fi
}

set_env() {
gen_env() {
cat>"$HOME/.sv/env"<<EOF
#!/bin/sh
# sv shell setup
case ":${PATH}:" in
*:"$HOME/.sv/go/bin":*)
*:"$HOME/.sv/go/bin:$HOME/.sv/bin":*)
;;
*)
export PATH="$HOME/.sv/go:$PATH"
export PATH="$HOME/.sv/bin:$PATH"
export GO111MODULE=auto
export GOROOT=$HOME/.sv/go
export GOPROXY=https://goproxy.cn,direct
export PATH="$HOME/.sv/go/bin:$HOME/.sv/bin:$PATH"
;;
esac
EOF
}

init_env() {
set_env() {
local envStr='. "$HOME/.sv/env"'
if grep -q "$envStr" "${shell_profile}"; then
echo "${BLUE}SV env has exists in $shell_profile${RESET}"
else
echo $envStr >> "${shell_profile}"
fi

. ${shell_profile}
source ${shell_profile}
# . ${shell_profile}
}

check_curl() {
Expand Down Expand Up @@ -185,14 +187,13 @@ main() {
echo "${YELLOW}[1/3] Get sv latest version${RESET}"
get_latest_tag
if [ -z "$release" ]; then
print_error "Get sv latest version error"
print_error "Get sv latest version error, please try again"
fi
printf "${GREEN}The sv latest version is %s${RESET}\n" $release

# local os="$(uname -s | awk '{print tolower($0)}')"
local os=`get_os|tr "[A-Z]" "[a-z]"`
print_banner
echo $os

if [ -f ~/.bash_profile ]; then
. ~/.bash_profile
Expand All @@ -205,17 +206,21 @@ main() {
if [ ! -d $HOME/.sv/bin ];then
mkdir -p $HOME/.sv/bin
fi
echo https://github.com/voocel/sv/releases/download/$release/$SV_BIN
curl -kLs https://github.com/voocel/sv/releases/download/$release/$SV_BIN -o $HOME/.sv/bin/sv

download_url=https://github.com/voocel/sv/releases/download/$release/$SV_BIN
echo download_url
http_code=$(curl -I -w '%{http_code}' -s -o /dev/null "$download_url")
if [ "$http_code" -eq 404 ] || [ "$http_code" -eq 403 ]; then
print_error "URL: ${download_url} returned status ${http_code}"
fi
curl -kLs download_url -o $HOME/.sv/bin/sv
chmod +x $HOME/.sv/bin/sv
echo "${GREEN}Installed successfully to: $HOME/.sv/bin/sv${RESET}"

echo "${YELLOW}[3/3] Setting environment variables${RESET}"
set_env
gen_env
get_shell_profile
echo ${shell_profile}

init_env
set_env
echo "${GREEN}Set env successfully${RESET}"


Expand Down

0 comments on commit 0864f56

Please sign in to comment.