diff --git a/.github/workflows/blank.yml b/.github/workflows/blank.yml index 0ede41c..cdaa5cc 100644 --- a/.github/workflows/blank.yml +++ b/.github/workflows/blank.yml @@ -33,7 +33,7 @@ jobs: - name: Build Nekoray run: | - bash nekoray_macos_builder.sh + bash builder.sh - name: Upload Artifact for amd64 uses: actions/upload-artifact@v2 with: diff --git a/builder.sh b/builder.sh new file mode 100644 index 0000000..0326d4b --- /dev/null +++ b/builder.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +set -e + +# set environment variables from sh file +echo "Setting environment variables" +source config_environment.sh +init_script_variable + +# get dependencies and first configure +echo "Getting dependencies" +bash get_dependencies.sh + +# clone or update source codes +echo "Cloning or updating source codes" +bash get_sources.sh + +# Create or clean build directory +if [ ! -d "$nPath/build" ]; then + mkdir -p "$nPath/build" +else + + read -p "Do you want to clean 'build' and 'libs/deps' directories ? [y/n] " -n 1 -r + echo + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + exit 1 + fi + + rm -rf "$nPath/libs/deps" + rm -rf "$nPath/build" + mkdir -p "$nPath/build" +fi + +# get dependencies (official source) +echo "Getting dependencies (official source)" +bash build_deps_all.sh + +# package nekoray +echo "Packaging nekoray" +bash packaging_nekoray.sh + +# Build nekobox_core and nekoray_core +echo "Building nekobox_core and nekoray_core" +bash core_builder.sh + +#zip nekoray by arch +echo "Zipping nekoray" +if [ -n "$GITHUB_ACTIONS" ]; then + for arch in "amd64" "arm64"; do + TEMP_PATH=$(pwd) + cd "$nPath/build" + zip -r "nekoray_$arch.zip" "nekoray_$arch.app" + cd "$TEMP_PATH" + done +else + for arch in "amd64" "arm64"; do + zip -r "$nPath/build/nekoray_$arch.zip" "$nPath/build/nekoray_$arch.app" + done +fi + +echo "Build finished and output files are in $nPath/build" +cd "$nPath" +open "$nPath/build" diff --git a/config_environment.sh b/config_environment.sh new file mode 100644 index 0000000..1547828 --- /dev/null +++ b/config_environment.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# first config environment variables +export MACOSX_DEPLOYMENT_TARGET="10.13" + +init_script_variable() { + nRoot="$(pwd)" + nPath="$(pwd)/temp/nekoray" + nApp=$nPath/build/nekoray.app +} + +init_nekoray_local() { + neko_common="github.com/matsuridayo/libneko/neko_common" + cd $nRoot/v2ray-core + version_v2ray=$(git log --pretty=format:'%h' -n 1) + cd $nPath + version_standalone="nekoray-"$(cat $nPath/nekoray_version.txt) +} diff --git a/core_builder.sh b/core_builder.sh new file mode 100644 index 0000000..ec5a46c --- /dev/null +++ b/core_builder.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# set environment variables from sh file +source config_environment.sh + +# Build nekobox_core and nekoray_core for both amd64 and arm64 +for cmd in "nekobox_core" "nekoray_core"; do + for arch in "amd64" "arm64"; do + cd "$nPath/go/cmd/$cmd" + GOARCH="$arch" + + if [ "$cmd" = "nekoray_core" ]; then + go build -o "${cmd}_${arch}" -v -trimpath -ldflags "-w -s -X $neko_common.Version_v2ray=$version_v2ray -X $neko_common.Version_neko=$version_standalone" + else + go build -o "${cmd}_${arch}" -v -trimpath -ldflags "-w -s -X $neko_common.Version_neko=$version_standalone" -tags "with_grpc,with_gvisor,with_quic,with_wireguard,with_utls,with_clash_api" + fi + + cp "${cmd}_${arch}" "$nPath/build/nekoray_$arch.app/Contents/MacOS/$cmd" + done +done \ No newline at end of file diff --git a/get_dependencies.sh b/get_dependencies.sh new file mode 100644 index 0000000..403d657 --- /dev/null +++ b/get_dependencies.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# set environment variables from sh file +source config_environment.sh + +# Install dependencies if they are not already installed + +command -v "brew" >/dev/null 2>&1 || { + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" +} + +check_and_install() { + local cmd="$1" + local package="$2" + command -v "$cmd" >/dev/null 2>&1 || { + echo "$cmd could not be found, installing $package" + brew install "$package" + } +} + +check_and_install "cmake" "cmake" +check_and_install "ninja" "ninja" +check_and_install "go" "go" +check_and_install "curl" "curl" + +# Set environment variables +export PATH="/usr/local/opt/qt@5/bin:$PATH" +export LDFLAGS="-L/usr/local/opt/qt@5/lib" +export CPPFLAGS="-I/usr/local/opt/qt@5/include" +export PKG_CONFIG_PATH="/usr/local/opt/qt@5/lib/pkgconfig" + +check_and_install "macdeployqt" "qt@5" + +# golang dependencies +go get github.com/sagernet/sing-box/experimental/clashapi/trafficontrol@v1.0.0 \ No newline at end of file diff --git a/get_sources.sh b/get_sources.sh new file mode 100644 index 0000000..612480f --- /dev/null +++ b/get_sources.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +# set environment variables from sh file +source config_environment.sh + +# if this script running in github action then +# remove unessary directories with check if exist (nekoray, v2ray-core, sing-box-extra, sing-box, libneko) + +if [ -n "$GITHUB_ACTIONS" ]; then + if [ -d "nekoray" ]; then + rm -rf nekoray + fi + if [ -d "v2ray-core" ]; then + rm -rf v2ray-core + fi + if [ -d "sing-box-extra" ]; then + rm -rf sing-box-extra + fi + if [ -d "sing-box" ]; then + rm -rf sing-box + fi + if [ -d "libneko" ]; then + rm -rf libneko + fi +fi + +# Clone or update repositories + +clone_last_valid_source() { + local repo="$1" + local url="$2" + if [ -d "$repo" ]; then + git -C "$repo" reset --hard + git -C "$repo" fetch --all --tags --prune + else + git clone --recursive "$url" "$repo" + fi + if [ -n "$(git -C "$repo" tag --list)" ]; then + git -C "$repo" checkout "$(git -C "$repo" describe --tags $(git -C "$repo" rev-list --tags --max-count=1))" + fi +} + +clone_last_valid_source "nekoray" "https://github.com/MatsuriDayo/nekoray.git" +clone_last_valid_source "v2ray-core" "https://github.com/MatsuriDayo/v2ray-core.git" +clone_last_valid_source "sing-box-extra" "https://github.com/MatsuriDayo/sing-box-extra.git" +clone_last_valid_source "sing-box" "https://github.com/MatsuriDayo/sing-box.git" +clone_last_valid_source "libneko" "https://github.com/MatsuriDayo/libneko.git" \ No newline at end of file diff --git a/libneko b/libneko deleted file mode 160000 index 67ece2c..0000000 --- a/libneko +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 67ece2c5478fbc61a2551ee2b525f4da803071c8 diff --git a/nekoray b/nekoray deleted file mode 160000 index 5668208..0000000 --- a/nekoray +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 5668208cb8d1264320c08074b12e1d1e4a6d4798 diff --git a/nekoray_macos_builder.sh b/nekoray_macos_builder.sh deleted file mode 100644 index 6e6ccc7..0000000 --- a/nekoray_macos_builder.sh +++ /dev/null @@ -1,175 +0,0 @@ -#!/bin/bash - -set -e - -# first initialize and configure -export MACOSX_DEPLOYMENT_TARGET="10.13" - -# if this script running in github action then -# remove unessary directories with check if exist (nekoray, v2ray-core, sing-box-extra, sing-box, libneko) -if [ -n "$GITHUB_ACTIONS" ]; then - if [ -d "nekoray" ]; then - rm -rf nekoray - fi - if [ -d "v2ray-core" ]; then - rm -rf v2ray-core - fi - if [ -d "sing-box-extra" ]; then - rm -rf sing-box-extra - fi - if [ -d "sing-box" ]; then - rm -rf sing-box - fi - if [ -d "libneko" ]; then - rm -rf libneko - fi -fi - -# Clone or update repositories -clone_last_valid_source() { - local repo="$1" - local url="$2" - if [ -d "$repo" ]; then - git -C "$repo" reset --hard - git -C "$repo" fetch --all --tags --prune - else - git clone --recursive "$url" "$repo" - fi - if [ -n "$(git -C "$repo" tag --list)" ]; then - git -C "$repo" checkout "$(git -C "$repo" describe --tags $(git -C "$repo" rev-list --tags --max-count=1))" - fi -} - -clone_last_valid_source "nekoray" "https://github.com/MatsuriDayo/nekoray.git" -clone_last_valid_source "v2ray-core" "https://github.com/MatsuriDayo/v2ray-core.git" -clone_last_valid_source "sing-box-extra" "https://github.com/MatsuriDayo/sing-box-extra.git" -clone_last_valid_source "sing-box" "https://github.com/MatsuriDayo/sing-box.git" -clone_last_valid_source "libneko" "https://github.com/MatsuriDayo/libneko.git" - -# Install dependencies if they are not already installed - -command -v "brew" >/dev/null 2>&1 || { - /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" -} - -check_and_install() { - local cmd="$1" - local package="$2" - command -v "$cmd" >/dev/null 2>&1 || { - echo "$cmd could not be found, installing $package" - brew install "$package" - } -} - -check_and_install "cmake" "cmake" -check_and_install "ninja" "ninja" -check_and_install "go" "go" -check_and_install "curl" "curl" - -# Set environment variables -export PATH="/usr/local/opt/qt@5/bin:$PATH" -export LDFLAGS="-L/usr/local/opt/qt@5/lib" -export CPPFLAGS="-I/usr/local/opt/qt@5/include" -export PKG_CONFIG_PATH="/usr/local/opt/qt@5/lib/pkgconfig" - -check_and_install "macdeployqt" "qt@5" - -nRoot="$(pwd)" -nPath="$(pwd)/nekoray" - -# Create or clean build directory -if [ ! -d "$nPath/build" ]; then - mkdir -p "$nPath/build" -else - - read -p "Do you want to clean 'build' and 'libs/deps' directories ? [y/n] " -n 1 -r - echo - if [[ ! $REPLY =~ ^[Yy]$ ]]; then - exit 1 - fi - - rm -rf "$nPath/libs/deps" - rm -rf "$nPath/build" - mkdir -p "$nPath/build" -fi - -# Get and Build dependencies -bash build_deps_all.sh - -cd "$nPath/build" -cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DNKR_PACKAGE_MACOS=1 .. -ninja - -cd $nPath - -nApp=$nPath/build/nekoray.app - -# Deploy frameworks using macdeployqt -macdeployqt "$nApp" -verbose=3 - -# Download data files for both amd64 and arm64 -curl -fLso $nApp/Contents/MacOS/geoip.dat "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat" -curl -fLso $nApp/Contents/MacOS/geosite.dat "https://github.com/v2fly/domain-list-community/releases/latest/download/dlc.dat" -curl -fLso $nApp/Contents/MacOS/geoip.db "https://github.com/SagerNet/sing-geoip/releases/latest/download/geoip.db" -curl -fLso $nApp/Contents/MacOS/geosite.db "https://github.com/SagerNet/sing-geosite/releases/latest/download/geosite.db" - -# copy fa_IR.qm and zh_CN.qm to nekoray.app/Contents/MacOS -for file in "fa_IR.qm" "zh_CN.qm"; do - cp "$nPath/build/$file" "$nApp/Contents/MacOS" -done - -# remove updater shortcut with check if exist -cd $nApp/Contents/MacOS/ -if [ -f "updater" ]; then - rm updater -fi -cd $nPath - -# Build nekoray for both amd64 and arm64 -for arch in "amd64" "arm64"; do - rm -rf "$nPath/build/nekoray_$arch.app" - cp -r $nApp "$nPath/build/nekoray_$arch.app" -done - -rm -rf $nApp - -neko_common="github.com/matsuridayo/libneko/neko_common" -cd $nRoot/v2ray-core -version_v2ray=$(git log --pretty=format:'%h' -n 1) -cd $nPath -version_standalone="nekoray-"$(cat $nPath/nekoray_version.txt) - - -# Build nekobox_core and nekoray_core for both amd64 and arm64 -for cmd in "nekobox_core" "nekoray_core"; do - for arch in "amd64" "arm64"; do - cd "$nPath/go/cmd/$cmd" - GOARCH="$arch" - - if [ "$cmd" = "nekoray_core" ]; then - go build -o "${cmd}_${arch}" -v -trimpath -ldflags "-w -s -X $neko_common.Version_v2ray=$version_v2ray -X $neko_common.Version_neko=$version_standalone" - else - go build -o "${cmd}_${arch}" -v -trimpath -ldflags "-w -s -X $neko_common.Version_neko=$version_standalone" -tags "with_grpc,with_gvisor,with_quic,with_wireguard,with_utls,with_clash_api" - fi - - cp "${cmd}_${arch}" "$nPath/build/nekoray_$arch.app/Contents/MacOS/$cmd" - done -done - -#zip nekoray by arch -if [ -n "$GITHUB_ACTIONS" ]; then - for arch in "amd64" "arm64"; do - TEMP_PATH=$(pwd) - cd "$nPath/build" - zip -r "nekoray_$arch.zip" "nekoray_$arch.app" - cd "$TEMP_PATH" - done -else - for arch in "amd64" "arm64"; do - zip -r "$nPath/build/nekoray_$arch.zip" "$nPath/build/nekoray_$arch.app" - done -fi - -echo "Build finished and output files are in $nPath/build" -cd "$nPath" -open "$nPath/build" diff --git a/packaging_nekory.sh b/packaging_nekory.sh new file mode 100644 index 0000000..2b6e40d --- /dev/null +++ b/packaging_nekory.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +# set environment variables from sh file +source config_environment.sh + +cd "$nPath/build" +cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DNKR_PACKAGE_MACOS=1 .. +ninja + +cd $nPath + +# Deploy frameworks using macdeployqt +macdeployqt "$nApp" -verbose=3 + +# Download data files for both amd64 and arm64 +curl -fLso $nApp/Contents/MacOS/geoip.dat "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat" +curl -fLso $nApp/Contents/MacOS/geosite.dat "https://github.com/v2fly/domain-list-community/releases/latest/download/dlc.dat" +curl -fLso $nApp/Contents/MacOS/geoip.db "https://github.com/SagerNet/sing-geoip/releases/latest/download/geoip.db" +curl -fLso $nApp/Contents/MacOS/geosite.db "https://github.com/SagerNet/sing-geosite/releases/latest/download/geosite.db" + +# copy fa_IR.qm and zh_CN.qm to nekoray.app/Contents/MacOS +for file in "fa_IR.qm" "zh_CN.qm"; do + cp "$nPath/build/$file" "$nApp/Contents/MacOS" +done + +# remove updater shortcut with check if exist +cd $nApp/Contents/MacOS/ +if [ -f "updater" ]; then + rm updater +fi +cd $nPath + +# Build nekoray for both amd64 and arm64 +for arch in "amd64" "arm64"; do + rm -rf "$nPath/build/nekoray_$arch.app" + cp -r $nApp "$nPath/build/nekoray_$arch.app" +done + +rm -rf $nApp \ No newline at end of file diff --git a/readme.md b/readme.md index 1ff7157..6cd2ba2 100644 --- a/readme.md +++ b/readme.md @@ -15,7 +15,7 @@ Each version is based on the latest version released in the main repository for ### How to use ```bash -bash nekoray_macos_builder.sh +bash builder.sh ``` diff --git a/sing-box b/sing-box deleted file mode 160000 index ab23e11..0000000 --- a/sing-box +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ab23e111dda5f9ee66fca2d49cb28f39d41192bb diff --git a/sing-box-extra b/sing-box-extra deleted file mode 160000 index e7c37b1..0000000 --- a/sing-box-extra +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e7c37b1587c38841f4eb687249a43dab421d8eff diff --git a/v2ray-core b/v2ray-core deleted file mode 160000 index 8134d3c..0000000 --- a/v2ray-core +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 8134d3cc23aa6b8e2a056887addf22d7d22bd969