|
|
|
@ -1,5 +1,4 @@
|
|
|
|
|
#!/usr/bin/env bash |
|
|
|
|
# Bash3 Boilerplate. Copyright (c) 2014, kvz.io |
|
|
|
|
|
|
|
|
|
set -o errexit |
|
|
|
|
set -o pipefail |
|
|
|
@ -8,74 +7,72 @@ set -o nounset
|
|
|
|
|
|
|
|
|
|
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"; } |
|
|
|
|
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" |
|
|
|
|
echo ">>> Getting v2ray sources..." |
|
|
|
|
git clone https://github.com/v2fly/v2ray-core.git |
|
|
|
|
pushd v2ray-core |
|
|
|
|
go mod download |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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}" |
|
|
|
|
if [[ $nosource != 1 ]]; then |
|
|
|
|
pushd ${SRCDIR}/v2ray-core |
|
|
|
|
local VERSIONTAG=$(git describe --abbrev=0 --tags) |
|
|
|
|
else |
|
|
|
|
echo ">>> Use current directory as WORKDIR" |
|
|
|
|
local VERSIONTAG=$(git describe --abbrev=0 --tags) |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
LDFLAGS="-s -w -buildid= -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 |
|
|
|
|
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 ..." |
|
|
|
|
echo ">>> Download latest geoip..." |
|
|
|
|
curl -s -L -o "$TMP"/geoip.dat "https://github.com/v2fly/geoip/raw/release/geoip.dat" |
|
|
|
|
|
|
|
|
|
echo ">>> Downloading newest geosite ..." |
|
|
|
|
echo ">>> Download latest geosite..." |
|
|
|
|
curl -s -L -o "$TMP"/geosite.dat "https://github.com/v2fly/domain-list-community/raw/release/dlc.dat" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
copyconf() { |
|
|
|
|
echo ">>> Copying config..." |
|
|
|
|
pushd "$SRCDIR"/release/config |
|
|
|
|
tar c --exclude "*.dat" . | tar x -C "$TMP" |
|
|
|
|
pushd ./release/config |
|
|
|
|
tar c --exclude "*.dat" --exclude "systemd/**" . | tar x -C "$TMP" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
packzip() { |
|
|
|
|
echo ">>> Generating zip package" |
|
|
|
|
pushd "$TMP" |
|
|
|
|
local PKG=${__dir}/v2ray-custom-${GOARCH}-${GOOS}-${PKGSUFFIX}${NOW}.zip |
|
|
|
|
local PKG=${SRCDIR}/v2ray-custom-${GOARCH}-${GOOS}-${PKGSUFFIX}${NOW}.zip |
|
|
|
|
zip -r "$PKG" . |
|
|
|
|
echo ">>> Generated: $(basename "$PKG")" |
|
|
|
|
echo ">>> Generated: $(basename "$PKG") at $(dirname "$PKG")" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
packtgz() { |
|
|
|
|
echo ">>> Generating tgz package" |
|
|
|
|
pushd "$TMP" |
|
|
|
|
local PKG=${__dir}/v2ray-custom-${GOARCH}-${GOOS}-${PKGSUFFIX}${NOW}.tar.gz |
|
|
|
|
local PKG=${SRCDIR}/v2ray-custom-${GOARCH}-${GOOS}-${PKGSUFFIX}${NOW}.tar.gz |
|
|
|
|
tar cvfz "$PKG" . |
|
|
|
|
echo ">>> Generated: $(basename "$PKG")" |
|
|
|
|
echo ">>> Generated: $(basename "$PKG") at $(dirname "$PKG")" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
packtgzAbPath() { |
|
|
|
@ -86,7 +83,6 @@ packtgzAbPath() {
|
|
|
|
|
echo ">>> Generated: $ABPATH" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pkg=zip |
|
|
|
|
nosource=0 |
|
|
|
|
nodat=0 |
|
|
|
@ -97,7 +93,7 @@ EXESUFFIX=
|
|
|
|
|
PKGSUFFIX= |
|
|
|
|
|
|
|
|
|
for arg in "$@"; do |
|
|
|
|
case $arg in |
|
|
|
|
case $arg in |
|
|
|
|
arm*) |
|
|
|
|
GOARCH=$arg |
|
|
|
|
;; |
|
|
|
@ -136,11 +132,11 @@ case $arg in
|
|
|
|
|
buildname=*) |
|
|
|
|
BUILDNAME=${arg##buildname=} |
|
|
|
|
;; |
|
|
|
|
esac |
|
|
|
|
esac |
|
|
|
|
done |
|
|
|
|
|
|
|
|
|
if [[ $nosource != 1 ]]; then |
|
|
|
|
get_source |
|
|
|
|
get_source |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
export GOOS GOARCH |
|
|
|
@ -149,21 +145,19 @@ echo "PKG ARGS: pkg=${pkg}"
|
|
|
|
|
build_v2 |
|
|
|
|
|
|
|
|
|
if [[ $nodat != 1 ]]; then |
|
|
|
|
build_dat |
|
|
|
|
build_dat |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
if [[ $noconf != 1 ]]; then |
|
|
|
|
copyconf |
|
|
|
|
copyconf |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
if [[ $pkg == "zip" ]]; then |
|
|
|
|
packzip |
|
|
|
|
packzip |
|
|
|
|
elif [[ $pkg == "tgz" ]]; then |
|
|
|
|
packtgz |
|
|
|
|
packtgz |
|
|
|
|
else |
|
|
|
|
packtgzAbPath "$pkg" |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cleanup |
|
|
|
|
|
|
|
|
|