forked from v2fly/v2ray-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser-package.sh
executable file
·169 lines (141 loc) · 3.25 KB
/
user-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
#!/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
NOW=$(date '+%Y%m%d-%H%M%S')
TMP=$(mktemp -d)
SRCDIR=$(pwd)
CODENAME="user"
BUILDNAME=$NOW
VERSIONTAG=$(git describe --tags)
GOPATH=$(go env GOPATH)
cleanup () { rm -rf "$TMP"; }
trap cleanup INT TERM ERR
get_source() {
echo ">>> 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}"
echo ">>> 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
echo ">>> Compile v2ctl ..."
env CGO_ENABLED=0 go build -o "$TMP"/v2ctl"${EXESUFFIX}" -tags confonly -ldflags "$LDFLAGS" ./infra/control/main
popd
}
build_dat() {
echo ">>> Downloading newest geoip ..."
curl -s -L -o "$TMP"/geoip.dat "https://github.com/v2ray/geoip/raw/release/geoip.dat"
echo ">>> Downloading newest geosite ..."
curl -s -L -o "$TMP"/geosite.dat "https://github.com/v2ray/domain-list-community/raw/release/dlc.dat"
}
copyconf() {
echo ">>> Copying config..."
pushd "$SRCDIR"/release/config
tar c --exclude "*.dat" . | tar x -C "$TMP"
}
packzip() {
echo ">>> Generating zip package"
pushd "$TMP"
local PKG=${__dir}/v2ray-custom-${GOARCH}-${GOOS}-${PKGSUFFIX}${NOW}.zip
zip -r "$PKG" .
echo ">>> Generated: $(basename "$PKG")"
}
packtgz() {
echo ">>> Generating tgz package"
pushd "$TMP"
local PKG=${__dir}/v2ray-custom-${GOARCH}-${GOOS}-${PKGSUFFIX}${NOW}.tar.gz
tar cvfz "$PKG" .
echo ">>> Generated: $(basename "$PKG")"
}
packtgzAbPath() {
local ABPATH="$1"
echo ">>> Generating tgz package at $ABPATH"
pushd "$TMP"
tar cvfz "$ABPATH" .
echo ">>> Generated: $ABPATH"
}
pkg=zip
nosource=0
nodat=0
noconf=0
GOOS=linux
GOARCH=amd64
EXESUFFIX=
PKGSUFFIX=
for arg in "$@"; do
case $arg in
arm*)
GOARCH=$arg
;;
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=}
;;
esac
done
if [[ $nosource != 1 ]]; then
get_source
fi
export GOOS GOARCH
echo "Build ARGS: GOOS=${GOOS} GOARCH=${GOARCH} CODENAME=${CODENAME} BUILDNAME=${BUILDNAME}"
echo "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