2019-07-13 07:30:18 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
NOW=$(date '+%Y%m%d-%H%M%S')
|
|
|
|
TMP=$(mktemp -d)
|
2019-12-17 02:34:13 -05:00
|
|
|
SRCDIR=$(pwd)
|
2019-07-13 07:30:18 -04:00
|
|
|
|
2019-07-15 01:32:49 -04:00
|
|
|
CODENAME="user"
|
|
|
|
BUILDNAME=$NOW
|
2019-07-13 07:30:18 -04:00
|
|
|
|
2020-10-07 02:29:07 -04:00
|
|
|
cleanup() { rm -rf "$TMP"; }
|
2019-07-13 07:30:18 -04:00
|
|
|
trap cleanup INT TERM ERR
|
|
|
|
|
|
|
|
get_source() {
|
2020-10-07 03:02:29 -04:00
|
|
|
echo ">>> Clone v2fly/v2ray-core repo..."
|
2020-10-07 02:29:07 -04:00
|
|
|
git clone https://github.com/v2fly/v2ray-core.git
|
2020-10-07 03:02:29 -04:00
|
|
|
cd v2ray-core
|
2020-10-07 02:29:07 -04:00
|
|
|
go mod download
|
2019-07-13 07:30:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
build_v2() {
|
2020-10-07 02:29:07 -04:00
|
|
|
if [[ $nosource != 1 ]]; then
|
2020-10-07 03:02:29 -04:00
|
|
|
cd ${SRCDIR}/v2ray-core
|
2020-10-07 02:29:07 -04:00
|
|
|
local VERSIONTAG=$(git describe --abbrev=0 --tags)
|
|
|
|
else
|
|
|
|
echo ">>> Use current directory as WORKDIR"
|
|
|
|
local VERSIONTAG=$(git describe --abbrev=0 --tags)
|
|
|
|
fi
|
|
|
|
|
2021-02-16 15:31:50 -05:00
|
|
|
LDFLAGS="-s -w -buildid= -X github.com/v2fly/v2ray-core/v4.codename=${CODENAME} -X github.com/v2fly/v2ray-core/v4.build=${BUILDNAME} -X github.com/v2fly/v2ray-core/v4.version=${VERSIONTAG}"
|
2019-07-13 07:30:18 -04:00
|
|
|
|
2019-07-15 01:32:49 -04:00
|
|
|
echo ">>> Compile v2ray ..."
|
2020-03-15 16:31:24 -04:00
|
|
|
env CGO_ENABLED=0 go build -o "$TMP"/v2ray"${EXESUFFIX}" -ldflags "$LDFLAGS" ./main
|
2020-10-07 02:29:07 -04:00
|
|
|
if [[ $GOOS == "windows" ]]; then
|
|
|
|
env CGO_ENABLED=0 go build -o "$TMP"/wv2ray"${EXESUFFIX}" -ldflags "-H windowsgui $LDFLAGS" ./main
|
2019-07-15 01:32:49 -04:00
|
|
|
fi
|
2019-07-13 07:30:18 -04:00
|
|
|
|
2019-07-15 01:32:49 -04:00
|
|
|
echo ">>> Compile v2ctl ..."
|
2020-03-15 16:31:24 -04:00
|
|
|
env CGO_ENABLED=0 go build -o "$TMP"/v2ctl"${EXESUFFIX}" -tags confonly -ldflags "$LDFLAGS" ./infra/control/main
|
2019-07-13 07:30:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
build_dat() {
|
2020-10-07 02:29:07 -04:00
|
|
|
echo ">>> Download latest geoip..."
|
2020-09-25 14:39:08 -04:00
|
|
|
curl -s -L -o "$TMP"/geoip.dat "https://github.com/v2fly/geoip/raw/release/geoip.dat"
|
2019-07-13 07:30:18 -04:00
|
|
|
|
2020-10-07 02:29:07 -04:00
|
|
|
echo ">>> Download latest geosite..."
|
2020-09-25 14:39:08 -04:00
|
|
|
curl -s -L -o "$TMP"/geosite.dat "https://github.com/v2fly/domain-list-community/raw/release/dlc.dat"
|
2019-07-13 07:30:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
copyconf() {
|
2019-07-15 01:32:49 -04:00
|
|
|
echo ">>> Copying config..."
|
2020-10-07 03:02:29 -04:00
|
|
|
cd ./release/config
|
2020-10-07 21:53:25 -04:00
|
|
|
if [[ $GOOS == "linux" ]]; then
|
|
|
|
tar c --exclude "*.dat" . | tar x -C "$TMP"
|
|
|
|
else
|
|
|
|
tar c --exclude "*.dat" --exclude "systemd/**" . | tar x -C "$TMP"
|
|
|
|
fi
|
2019-07-13 07:30:18 -04:00
|
|
|
}
|
|
|
|
|
2019-07-15 01:32:49 -04:00
|
|
|
packzip() {
|
|
|
|
echo ">>> Generating zip package"
|
2020-10-07 03:02:29 -04:00
|
|
|
cd "$TMP"
|
2020-10-07 02:29:07 -04:00
|
|
|
local PKG=${SRCDIR}/v2ray-custom-${GOARCH}-${GOOS}-${PKGSUFFIX}${NOW}.zip
|
2020-03-15 16:31:24 -04:00
|
|
|
zip -r "$PKG" .
|
2020-10-07 02:29:07 -04:00
|
|
|
echo ">>> Generated: $(basename "$PKG") at $(dirname "$PKG")"
|
2019-07-15 01:32:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
packtgz() {
|
|
|
|
echo ">>> Generating tgz package"
|
2020-10-07 03:02:29 -04:00
|
|
|
cd "$TMP"
|
2020-10-07 02:29:07 -04:00
|
|
|
local PKG=${SRCDIR}/v2ray-custom-${GOARCH}-${GOOS}-${PKGSUFFIX}${NOW}.tar.gz
|
2020-03-15 16:31:24 -04:00
|
|
|
tar cvfz "$PKG" .
|
2020-10-07 02:29:07 -04:00
|
|
|
echo ">>> Generated: $(basename "$PKG") at $(dirname "$PKG")"
|
2019-07-13 07:30:18 -04:00
|
|
|
}
|
|
|
|
|
2019-10-30 23:20:06 -04:00
|
|
|
packtgzAbPath() {
|
|
|
|
local ABPATH="$1"
|
|
|
|
echo ">>> Generating tgz package at $ABPATH"
|
2020-10-07 03:02:29 -04:00
|
|
|
cd "$TMP"
|
2020-03-15 16:31:24 -04:00
|
|
|
tar cvfz "$ABPATH" .
|
2019-10-30 23:20:06 -04:00
|
|
|
echo ">>> Generated: $ABPATH"
|
|
|
|
}
|
|
|
|
|
2019-07-15 01:32:49 -04:00
|
|
|
pkg=zip
|
2019-07-13 07:30:18 -04:00
|
|
|
nosource=0
|
|
|
|
nodat=0
|
|
|
|
noconf=0
|
|
|
|
GOOS=linux
|
|
|
|
GOARCH=amd64
|
|
|
|
EXESUFFIX=
|
|
|
|
PKGSUFFIX=
|
|
|
|
|
|
|
|
for arg in "$@"; do
|
2020-10-07 02:29:07 -04:00
|
|
|
case $arg in
|
2020-10-07 21:53:25 -04:00
|
|
|
386 | arm* | mips* | ppc64* | riscv64 | s390x)
|
2019-07-13 07:30:18 -04:00
|
|
|
GOARCH=$arg
|
|
|
|
;;
|
|
|
|
windows)
|
2020-10-07 21:53:25 -04:00
|
|
|
GOOS=$arg
|
2019-07-13 07:30:18 -04:00
|
|
|
EXESUFFIX=.exe
|
|
|
|
;;
|
2020-10-07 21:53:25 -04:00
|
|
|
darwin | dragonfly | freebsd | openbsd)
|
2019-07-13 07:30:18 -04:00
|
|
|
GOOS=$arg
|
|
|
|
;;
|
|
|
|
nodat)
|
|
|
|
nodat=1
|
|
|
|
PKGSUFFIX=${PKGSUFFIX}nodat-
|
|
|
|
;;
|
|
|
|
noconf)
|
|
|
|
noconf=1
|
|
|
|
;;
|
|
|
|
nosource)
|
|
|
|
nosource=1
|
|
|
|
;;
|
2019-07-15 01:32:49 -04:00
|
|
|
tgz)
|
|
|
|
pkg=tgz
|
|
|
|
;;
|
2019-10-30 23:20:06 -04:00
|
|
|
abpathtgz=*)
|
|
|
|
pkg=${arg##abpathtgz=}
|
|
|
|
;;
|
2019-10-30 23:44:57 -04:00
|
|
|
codename=*)
|
|
|
|
CODENAME=${arg##codename=}
|
|
|
|
;;
|
|
|
|
buildname=*)
|
|
|
|
BUILDNAME=${arg##buildname=}
|
|
|
|
;;
|
2020-10-07 02:29:07 -04:00
|
|
|
esac
|
2019-07-13 07:30:18 -04:00
|
|
|
done
|
|
|
|
|
|
|
|
if [[ $nosource != 1 ]]; then
|
2020-10-07 02:29:07 -04:00
|
|
|
get_source
|
2019-07-13 07:30:18 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
export GOOS GOARCH
|
2019-10-30 23:44:57 -04:00
|
|
|
echo "Build ARGS: GOOS=${GOOS} GOARCH=${GOARCH} CODENAME=${CODENAME} BUILDNAME=${BUILDNAME}"
|
|
|
|
echo "PKG ARGS: pkg=${pkg}"
|
2019-07-13 07:30:18 -04:00
|
|
|
build_v2
|
|
|
|
|
|
|
|
if [[ $nodat != 1 ]]; then
|
2020-10-07 02:29:07 -04:00
|
|
|
build_dat
|
2019-07-13 07:30:18 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $noconf != 1 ]]; then
|
2020-10-07 02:29:07 -04:00
|
|
|
copyconf
|
2019-07-13 07:30:18 -04:00
|
|
|
fi
|
|
|
|
|
2019-07-15 01:32:49 -04:00
|
|
|
if [[ $pkg == "zip" ]]; then
|
2020-10-07 02:29:07 -04:00
|
|
|
packzip
|
2019-10-30 23:20:06 -04:00
|
|
|
elif [[ $pkg == "tgz" ]]; then
|
2020-10-07 02:29:07 -04:00
|
|
|
packtgz
|
2019-10-30 23:20:06 -04:00
|
|
|
else
|
2020-03-15 16:31:24 -04:00
|
|
|
packtgzAbPath "$pkg"
|
2019-07-15 01:32:49 -04:00
|
|
|
fi
|
|
|
|
|
2019-07-13 07:30:18 -04:00
|
|
|
cleanup
|