-
Notifications
You must be signed in to change notification settings - Fork 147
/
build.sh
executable file
·93 lines (68 loc) · 1.79 KB
/
build.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/sh
#应用的名称
AppName=sagooiot
BuildVersion=$(git describe --abbrev=0 --tags)
BuildTime=$(date +%FT%T%z)
CommitID=$(git rev-parse HEAD)
help() {
echo "Usage: $0 [option]"
echo "Options:"
echo " linux build for Linux"
echo " windows build for Windows"
echo " mac build for macOS"
echo " macOld build for macOS (old version)"
}
linux(){
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $AppName -a -ldflags "-w -s -X main.BuildVersion=${BuildVersion} -X main.CommitID=${CommitID} -X main.BuildTime=${BuildTime}"
copyFile
cp curl.sh bin/
cp $AppName bin/
rm -f $AppName
}
windows(){
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o $AppName.exe -ldflags "-w -s -X main.BuildVersion=${BuildVersion} -X main.CommitID=${CommitID} -X main.BuildTime=${BuildTime}"
copyFile
cp $AppName.exe bin/
rm -f $AppName.exe
}
mac(){
go build -o $AppName -ldflags "-w -s -X main.BuildVersion=${BuildVersion} -X main.CommitID=${CommitID} -X main.BuildTime=${BuildTime}"
copyFile
cp curl.sh bin/
cp $AppName bin/
rm -f $AppName
}
macOld(){
GOARCH=amd64 go build -ldflags "-w -s -X main.BuildVersion=${BuildVersion} -X main.CommitID=${CommitID} -X main.BuildTime=${BuildTime}"
copyFile
cp curl.sh bin/
cp $AppName bin/
rm -f $AppName
}
copyFile() {
rm -rf bin
mkdir bin
mkdir bin/resource
mkdir bin/resource/public
mkdir bin/resource/public/rsa
cp -r ./manifest/config/. bin/config/
cp -r ./resource/rsa/. bin/resource/rsa/
echo "${BuildVersion} $(date +%T)"
}
case "$1" in
"linux")
linux
;;
"windows")
windows
;;
"macOld")
macOld
;;
"mac")
mac
;;
*)
help
;;
esac