Skip to content

Commit 90de28f

Browse files
author
AMIR ABBAS
committed
first category source codes
1 parent 9bc14b7 commit 90de28f

14 files changed

+224
-182
lines changed

.github/workflows/blank.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333

3434
- name: Build Nekoray
3535
run: |
36-
bash nekoray_macos_builder.sh
36+
bash builder.sh
3737
- name: Upload Artifact for amd64
3838
uses: actions/upload-artifact@v2
3939
with:

builder.sh

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# set environment variables from sh file
6+
echo "Setting environment variables"
7+
source config_environment.sh
8+
init_script_variable
9+
10+
# get dependencies and first configure
11+
echo "Getting dependencies"
12+
bash get_dependencies.sh
13+
14+
# clone or update source codes
15+
echo "Cloning or updating source codes"
16+
bash get_sources.sh
17+
18+
# Create or clean build directory
19+
if [ ! -d "$nPath/build" ]; then
20+
mkdir -p "$nPath/build"
21+
else
22+
23+
read -p "Do you want to clean 'build' and 'libs/deps' directories ? [y/n] " -n 1 -r
24+
echo
25+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
26+
exit 1
27+
fi
28+
29+
rm -rf "$nPath/libs/deps"
30+
rm -rf "$nPath/build"
31+
mkdir -p "$nPath/build"
32+
fi
33+
34+
# get dependencies (official source)
35+
echo "Getting dependencies (official source)"
36+
bash build_deps_all.sh
37+
38+
# package nekoray
39+
echo "Packaging nekoray"
40+
bash packaging_nekoray.sh
41+
42+
# Build nekobox_core and nekoray_core
43+
echo "Building nekobox_core and nekoray_core"
44+
bash core_builder.sh
45+
46+
#zip nekoray by arch
47+
echo "Zipping nekoray"
48+
if [ -n "$GITHUB_ACTIONS" ]; then
49+
for arch in "amd64" "arm64"; do
50+
TEMP_PATH=$(pwd)
51+
cd "$nPath/build"
52+
zip -r "nekoray_$arch.zip" "nekoray_$arch.app"
53+
cd "$TEMP_PATH"
54+
done
55+
else
56+
for arch in "amd64" "arm64"; do
57+
zip -r "$nPath/build/nekoray_$arch.zip" "$nPath/build/nekoray_$arch.app"
58+
done
59+
fi
60+
61+
echo "Build finished and output files are in $nPath/build"
62+
cd "$nPath"
63+
open "$nPath/build"

config_environment.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
# first config environment variables
4+
export MACOSX_DEPLOYMENT_TARGET="10.13"
5+
6+
init_script_variable() {
7+
nRoot="$(pwd)"
8+
nPath="$(pwd)/temp/nekoray"
9+
nApp=$nPath/build/nekoray.app
10+
}
11+
12+
init_nekoray_local() {
13+
neko_common="github.com/matsuridayo/libneko/neko_common"
14+
cd $nRoot/v2ray-core
15+
version_v2ray=$(git log --pretty=format:'%h' -n 1)
16+
cd $nPath
17+
version_standalone="nekoray-"$(cat $nPath/nekoray_version.txt)
18+
}

core_builder.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
# set environment variables from sh file
4+
source config_environment.sh
5+
6+
# Build nekobox_core and nekoray_core for both amd64 and arm64
7+
for cmd in "nekobox_core" "nekoray_core"; do
8+
for arch in "amd64" "arm64"; do
9+
cd "$nPath/go/cmd/$cmd"
10+
GOARCH="$arch"
11+
12+
if [ "$cmd" = "nekoray_core" ]; then
13+
go build -o "${cmd}_${arch}" -v -trimpath -ldflags "-w -s -X $neko_common.Version_v2ray=$version_v2ray -X $neko_common.Version_neko=$version_standalone"
14+
else
15+
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"
16+
fi
17+
18+
cp "${cmd}_${arch}" "$nPath/build/nekoray_$arch.app/Contents/MacOS/$cmd"
19+
done
20+
done

get_dependencies.sh

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
# set environment variables from sh file
4+
source config_environment.sh
5+
6+
# Install dependencies if they are not already installed
7+
8+
command -v "brew" >/dev/null 2>&1 || {
9+
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
10+
}
11+
12+
check_and_install() {
13+
local cmd="$1"
14+
local package="$2"
15+
command -v "$cmd" >/dev/null 2>&1 || {
16+
echo "$cmd could not be found, installing $package"
17+
brew install "$package"
18+
}
19+
}
20+
21+
check_and_install "cmake" "cmake"
22+
check_and_install "ninja" "ninja"
23+
check_and_install "go" "go"
24+
check_and_install "curl" "curl"
25+
26+
# Set environment variables
27+
export PATH="/usr/local/opt/qt@5/bin:$PATH"
28+
export LDFLAGS="-L/usr/local/opt/qt@5/lib"
29+
export CPPFLAGS="-I/usr/local/opt/qt@5/include"
30+
export PKG_CONFIG_PATH="/usr/local/opt/qt@5/lib/pkgconfig"
31+
32+
check_and_install "macdeployqt" "qt@5"
33+
34+
# golang dependencies
35+
go get github.com/sagernet/sing-box/experimental/clashapi/trafficontrol@v1.0.0

get_sources.sh

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
3+
# set environment variables from sh file
4+
source config_environment.sh
5+
6+
# if this script running in github action then
7+
# remove unessary directories with check if exist (nekoray, v2ray-core, sing-box-extra, sing-box, libneko)
8+
9+
if [ -n "$GITHUB_ACTIONS" ]; then
10+
if [ -d "nekoray" ]; then
11+
rm -rf nekoray
12+
fi
13+
if [ -d "v2ray-core" ]; then
14+
rm -rf v2ray-core
15+
fi
16+
if [ -d "sing-box-extra" ]; then
17+
rm -rf sing-box-extra
18+
fi
19+
if [ -d "sing-box" ]; then
20+
rm -rf sing-box
21+
fi
22+
if [ -d "libneko" ]; then
23+
rm -rf libneko
24+
fi
25+
fi
26+
27+
# Clone or update repositories
28+
29+
clone_last_valid_source() {
30+
local repo="$1"
31+
local url="$2"
32+
if [ -d "$repo" ]; then
33+
git -C "$repo" reset --hard
34+
git -C "$repo" fetch --all --tags --prune
35+
else
36+
git clone --recursive "$url" "$repo"
37+
fi
38+
if [ -n "$(git -C "$repo" tag --list)" ]; then
39+
git -C "$repo" checkout "$(git -C "$repo" describe --tags $(git -C "$repo" rev-list --tags --max-count=1))"
40+
fi
41+
}
42+
43+
clone_last_valid_source "nekoray" "https://github.com/MatsuriDayo/nekoray.git"
44+
clone_last_valid_source "v2ray-core" "https://github.com/MatsuriDayo/v2ray-core.git"
45+
clone_last_valid_source "sing-box-extra" "https://github.com/MatsuriDayo/sing-box-extra.git"
46+
clone_last_valid_source "sing-box" "https://github.com/MatsuriDayo/sing-box.git"
47+
clone_last_valid_source "libneko" "https://github.com/MatsuriDayo/libneko.git"

libneko

-1
This file was deleted.

nekoray

-1
This file was deleted.

nekoray_macos_builder.sh

-175
This file was deleted.

0 commit comments

Comments
 (0)