2019-07-13 07:30:18 -04:00
|
|
|
#!/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)
|
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-12-17 02:34:13 -05:00
|
|
|
VERSIONTAG=$(git describe --tags)
|
2019-07-13 07:30:18 -04:00
|
|
|
GOPATH=$(go env GOPATH)
|
|
|
|
|
|
|
|
cleanup () { rm -rf $TMP; }
|
|
|
|
trap cleanup INT TERM ERR
|
|
|
|
|
|
|
|
get_source() {
|
2019-07-15 01:32:49 -04:00
|
|
|
echo ">>> Getting v2ray sources ..."
|
2019-10-10 02:56:01 -04:00
|
|
|
go get -insecure -v -t v2ray.com/core/...
|
2019-12-17 02:34:13 -05:00
|
|
|
SRCDIR="$GOPATH/src/v2ray.com/core"
|
2019-07-13 07:30:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
build_v2() {
|
2019-12-17 02:34:13 -05:00
|
|
|
pushd $SRCDIR
|
2019-12-17 05:36:10 -05:00
|
|
|
LDFLAGS="-s -w -X v2ray.com/core.codename=${CODENAME} -X v2ray.com/core.build=${BUILDNAME} -X v2ray.com/core.version=${VERSIONTAG}"
|
2019-07-13 07:30:18 -04:00
|
|
|
|
2019-07-15 01:32:49 -04:00
|
|
|
echo ">>> Compile v2ray ..."
|
2019-12-17 05:36:10 -05:00
|
|
|
env CGO_ENABLED=0 go build -o $TMP/v2ray${EXESUFFIX} -ldflags "$LDFLAGS" ./main
|
2019-07-15 01:32:49 -04:00
|
|
|
if [[ $GOOS == "windows" ]];then
|
2019-12-17 05:36:10 -05:00
|
|
|
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 ..."
|
2019-12-17 05:36:10 -05: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
|
|
|
popd
|
|
|
|
}
|
|
|
|
|
|
|
|
build_dat() {
|
2019-07-15 01:32:49 -04:00
|
|
|
echo ">>> Downloading newest geoip ..."
|
2019-07-13 07:30:18 -04:00
|
|
|
wget -qO - https://api.github.com/repos/v2ray/geoip/releases/latest \
|
|
|
|
| grep browser_download_url | cut -d '"' -f 4 \
|
|
|
|
| wget -i - -O $TMP/geoip.dat
|
|
|
|
|
2019-07-15 01:32:49 -04:00
|
|
|
echo ">>> Downloading newest geosite ..."
|
2019-07-13 07:30:18 -04:00
|
|
|
wget -qO - https://api.github.com/repos/v2ray/domain-list-community/releases/latest \
|
|
|
|
| grep browser_download_url | cut -d '"' -f 4 \
|
|
|
|
| wget -i - -O $TMP/geosite.dat
|
|
|
|
}
|
|
|
|
|
|
|
|
copyconf() {
|
2019-07-15 01:32:49 -04:00
|
|
|
echo ">>> Copying config..."
|
2019-12-17 02:34:13 -05:00
|
|
|
pushd $SRCDIR/release/config
|
2019-07-13 07:30:18 -04:00
|
|
|
tar c --exclude "*.dat" . | tar x -C $TMP
|
|
|
|
}
|
|
|
|
|
2019-07-15 01:32:49 -04:00
|
|
|
packzip() {
|
|
|
|
echo ">>> Generating zip package"
|
2019-07-13 07:30:18 -04:00
|
|
|
pushd $TMP
|
|
|
|
local PKG=${__dir}/v2ray-custom-${GOARCH}-${GOOS}-${PKGSUFFIX}${NOW}.zip
|
|
|
|
zip -r $PKG .
|
2019-07-15 01:32:49 -04:00
|
|
|
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)"
|
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"
|
|
|
|
pushd $TMP
|
|
|
|
tar cvfz $ABPATH .
|
|
|
|
echo ">>> Generated: $ABPATH"
|
|
|
|
}
|
|
|
|
|
2019-07-13 07:30:18 -04:00
|
|
|
|
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
|
|
|
|
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
|
|
|
|
;;
|
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=}
|
|
|
|
;;
|
2019-07-13 07:30:18 -04:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if [[ $nosource != 1 ]]; then
|
|
|
|
get_source
|
|
|
|
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
|
|
|
|
build_dat
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $noconf != 1 ]]; then
|
|
|
|
copyconf
|
|
|
|
fi
|
|
|
|
|
2019-07-15 01:32:49 -04:00
|
|
|
if [[ $pkg == "zip" ]]; then
|
|
|
|
packzip
|
2019-10-30 23:20:06 -04:00
|
|
|
elif [[ $pkg == "tgz" ]]; then
|
2019-07-15 01:32:49 -04:00
|
|
|
packtgz
|
2019-10-30 23:20:06 -04:00
|
|
|
else
|
|
|
|
packtgzAbPath $pkg
|
2019-07-15 01:32:49 -04:00
|
|
|
fi
|
|
|
|
|
2019-10-30 23:20:06 -04:00
|
|
|
|
2019-07-13 07:30:18 -04:00
|
|
|
cleanup
|
2019-07-15 01:32:49 -04:00
|
|
|
|