-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpackage.sh
executable file
·70 lines (59 loc) · 1.51 KB
/
package.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env bash
set -e
function get_arch() {
a=$(uname -m)
case ${a} in
"x86_64" | "amd64")
echo "amd64"
;;
"i386" | "i486" | "i586")
echo "386"
;;
"aarch64" | "arm64")
echo "arm64"
;;
*)
echo ${NIL}
;;
esac
}
function get_os() {
echo $(uname -s | awk '{print tolower($0)}')
}
function package() {
printf "============Pakcage for %s============\n" $3
local rootdir=${1}
local release=${2}
local osarch=(${3//_/ })
local os=${osarch[0]}
local arch=${osarch[1]}
printf "[1/4] Cross compile@%s_%s\n" ${os} ${arch}
GOOS=${os} GOARCH=${arch} gbb
local bindir=""
if [ $(get_os) = ${os} ] && [ $(get_arch) = ${arch} ]; then
bindir=$GOPATH/bin
else
bindir=$GOPATH/bin/${os}_${arch}
fi
printf "[2/4] Change directory to %s\n" ${bindir}
cd ${bindir}
printf "[3/4] Package\n"
if [ ${os} == "windows" ]; then
zip $rootdir/g${release}.${os}-${arch}.zip ./g.exe
else
tar -czv -f $rootdir/g${release}.${os}-${arch}.tar.gz ./g
fi
printf "[4/4] Change directory to %s\n\n" ${rootdir}
cd ${rootdir}
}
main() {
export CGO_ENABLED="0"
export GO111MODULE="on"
export GOPROXY="https://goproxy.cn,direct"
local release="1.2.0"
local rootdir="$(pwd)"
for item in "darwin_amd64" "linux_386" "linux_amd64" "linux_arm" "linux_arm64" "windows_386" "windows_amd64"; do
package ${rootdir} ${release} ${item}
done
}
main