forked from v2fly/docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ci-package.sh
executable file
·214 lines (184 loc) · 4.68 KB
/
ci-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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/usr/bin/env bash
# Bash3 Boilerplate. Copyright (c) 2014, kvz.io
set -o errexit
set -o pipefail
set -o nounset
# set -o xtrace
trap 'echo -e "Aborted, error $? in command: $BASH_COMMAND"; trap ERR; exit 1' ERR
# Set magic variables for current file & dir
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
__base="$(basename ${__file} .sh)"
__root="$(cd "$(dirname "${__dir}")" && pwd)" # <-- change this as it depends on your app
black() { echo -e "$(tput -T xterm setaf 0)$*$(tput -T xterm setaf 9)"; }
red() { echo -e "$(tput -T xterm setaf 1)$*$(tput -T xterm setaf 9)"; }
green() { echo -e "$(tput -T xterm setaf 2)$*$(tput -T xterm setaf 9)"; }
yellow() { echo -e "$(tput -T xterm setaf 3)$*$(tput -T xterm setaf 9)"; }
blue() { echo -e "$(tput -T xterm setaf 4)$*$(tput -T xterm setaf 9)"; }
magenta() { echo -e "$(tput -T xterm setaf 5)$*$(tput -T xterm setaf 9)"; }
cyan() { echo -e "$(tput -T xterm setaf 6)$*$(tput -T xterm setaf 9)"; }
white() { echo -e "$(tput -T xterm setaf 7)$*$(tput -T xterm setaf 9)"; }
NOW=$(date '+%Y%m%d-%H%M%S')
TMP=$(mktemp -d)
SRCDIR=$(pwd)
CODENAME="user"
BUILDNAME=""
VERSIONTAG=""
GOPATH=$(go env GOPATH)
cleanup () { rm -rf $TMP; }
trap cleanup INT TERM ERR
get_source() {
yellow ">>> Getting v2ray sources ..."
go get -insecure -v -t v2ray.com/core/...
SRCDIR="$GOPATH/src/v2ray.com/core"
}
build_v2() {
pushd $SRCDIR
LDFLAGS="-s -w -X v2ray.com/core.codename=${CODENAME} -X v2ray.com/core.build=${BUILDNAME} -X v2ray.com/core.version=${VERSIONTAG}"
yellow ">>> Compile v2ray ..."
env CGO_ENABLED=0 go build -o $TMP/v2ray${EXESUFFIX} -ldflags "$LDFLAGS" ./main
if [[ $GOOS == "windows" ]];then
env CGO_ENABLED=0 go build -o $TMP/wv2ray${EXESUFFIX} -ldflags "-H windowsgui $LDFLAGS" ./main
fi
yellow ">>> Compile v2ctl ..."
env CGO_ENABLED=0 go build -o $TMP/v2ctl${EXESUFFIX} -tags confonly -ldflags "$LDFLAGS" ./infra/control/main
popd
}
build_dat() {
CACHE=$__dir
if [[ ! -f $CACHE/geoip.dat ]]; then
yellow ">>> Downloading lastest geoip ..."
pushd $CACHE
wget -qO - https://api.github.com/repos/v2ray/geoip/releases/latest \
| jq -r '.assets[] | .browser_download_url' \
| wget -i -
if ! sha256sum -c geoip.dat.sha256sum; then
red "geoip.dat checksum error"
exit 1
fi
popd
fi
if [[ ! -f $CACHE/dlc.dat ]]; then
yellow ">>> Downloading latest geosite ..."
pushd $CACHE
wget -qO - https://api.github.com/repos/v2ray/domain-list-community/releases/latest \
| jq -r '.assets[] | .browser_download_url' \
| wget -i -
if ! sha256sum -c dlc.dat.sha256sum; then
red "dlc.dat checksum error"
exit 1
fi
popd
fi
cp -v $CACHE/geoip.dat $TMP/geoip.dat
cp -v $CACHE/dlc.dat $TMP/geosite.dat
}
copyconf() {
yellow ">>> Copying config..."
pushd $SRCDIR/release/config
tar c --exclude "*.dat" . | tar x -C $TMP
}
packzip() {
yellow ">>> Generating zip package"
pushd $TMP
local PKG=${__dir}/v2ray-custom-${GOARCH}-${GOOS}-${PKGSUFFIX}${NOW}.zip
zip -r $PKG .
yellow ">>> Generated: $(basename $PKG)"
}
packtgz() {
yellow ">>> Generating tgz package"
pushd $TMP
local PKG=${__dir}/v2ray-custom-${GOARCH}-${GOOS}-${PKGSUFFIX}${NOW}.tar.gz
tar cvfz $PKG .
yellow ">>> Generated: $(basename $PKG)"
}
packtgzAbPath() {
local ABPATH="$1"
yellow ">>> Generating tgz package at $ABPATH"
pushd $TMP
tar cvfz $ABPATH .
yellow ">>> Generated: $ABPATH"
}
pkg=zip
nosource=0
nodat=0
noconf=0
GOOS=linux
GOARCH=amd64
GOARM=
EXESUFFIX=
PKGSUFFIX=
for arg in "$@"; do
case $arg in
arm64)
GOARCH=arm64
;;
arm7)
GOARM=7
GOARCH=arm
;;
mips*)
GOARCH=$arg
;;
386)
GOARCH=386
;;
windows)
GOOS=windows
EXESUFFIX=.exe
;;
darwin)
GOOS=$arg
;;
nodat)
nodat=1
PKGSUFFIX=${PKGSUFFIX}nodat-
;;
noconf)
noconf=1
;;
nosource)
nosource=1
;;
tgz)
pkg=tgz
;;
abpathtgz=*)
pkg=${arg##abpathtgz=}
;;
codename=*)
CODENAME=${arg##codename=}
;;
buildname=*)
BUILDNAME=${arg##buildname=}
;;
versiontag=*)
VERSIONTAG=${arg##versiontag=}
;;
esac
done
if [[ $nosource != 1 ]]; then
get_source
fi
export GOOS GOARCH
green "Build ARGS: GOOS=${GOOS} GOARCH=${GOARCH} CODENAME=${CODENAME} BUILDNAME=${BUILDNAME} VERSIONTAG=${VERSIONTAG}"
if [[ $GOARCH == "arm" ]]; then
green "Build ARGS: GOARM=${GOARM}"
export GOARM
fi
green "PKG ARGS: pkg=${pkg}"
build_v2
if [[ $nodat != 1 ]]; then
build_dat
fi
if [[ $noconf != 1 ]]; then
copyconf
fi
if [[ $pkg == "zip" ]]; then
packzip
elif [[ $pkg == "tgz" ]]; then
packtgz
else
packtgzAbPath $pkg
fi
cleanup