Restructure repo around sing-box-rr package layout

This commit is contained in:
2026-05-14 10:04:14 +03:00
parent 3bd162ed6f
commit 473952f620
1388 changed files with 1092 additions and 137 deletions
+102
View File
@@ -0,0 +1,102 @@
#!/usr/bin/env bash
set -e -o pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)"
BINARY_NAME="sing-box"
INSTALL_BIN_PATH="/usr/local/bin"
INSTALL_CONFIG_PATH="/usr/local/etc/sing-box"
INSTALL_DATA_PATH="/var/lib/sing-box"
SYSTEMD_SERVICE_PATH="/etc/systemd/system"
DEFAULT_BUILD_TAGS="$(cat "$PROJECT_DIR/release/DEFAULT_BUILD_TAGS_OTHERS")"
setup_environment() {
if [ -d /usr/local/go ]; then
export PATH="$PATH:/usr/local/go/bin"
fi
if ! command -v go &> /dev/null; then
echo "Error: Go is not installed or not in PATH"
echo "Run install_go.sh to install Go"
exit 1
fi
}
get_build_tags() {
local extra_tags="$1"
if [ -n "$extra_tags" ]; then
echo "${DEFAULT_BUILD_TAGS},${extra_tags}"
else
echo "${DEFAULT_BUILD_TAGS}"
fi
}
get_version() {
cd "$PROJECT_DIR"
GOHOSTOS=$(go env GOHOSTOS)
GOHOSTARCH=$(go env GOHOSTARCH)
CGO_ENABLED=0 GOOS=$GOHOSTOS GOARCH=$GOHOSTARCH go run github.com/sagernet/sing-box/cmd/internal/read_tag@latest
}
get_ldflags() {
local version
version=$(get_version)
local shared_ldflags
shared_ldflags=$(cat "$PROJECT_DIR/release/LDFLAGS")
echo "-X 'github.com/sagernet/sing-box/constant.Version=${version}' ${shared_ldflags} -s -w -buildid="
}
build_sing_box() {
local tags="$1"
local ldflags
ldflags=$(get_ldflags)
echo "Building sing-box with tags: $tags"
cd "$PROJECT_DIR"
export GOTOOLCHAIN=local
go install -v -trimpath -ldflags "$ldflags" -tags "$tags" ./cmd/sing-box
}
install_binary() {
local gopath
gopath=$(go env GOPATH)
echo "Installing binary to $INSTALL_BIN_PATH/$BINARY_NAME"
sudo cp "${gopath}/bin/${BINARY_NAME}" "${INSTALL_BIN_PATH}/"
}
setup_config() {
echo "Setting up configuration"
sudo mkdir -p "$INSTALL_CONFIG_PATH"
if [ ! -f "$INSTALL_CONFIG_PATH/config.json" ]; then
sudo cp "$PROJECT_DIR/release/config/config.json" "$INSTALL_CONFIG_PATH/config.json"
echo "Default config installed to $INSTALL_CONFIG_PATH/config.json"
else
echo "Config already exists at $INSTALL_CONFIG_PATH/config.json (not overwriting)"
fi
}
setup_systemd() {
echo "Setting up systemd service"
sudo cp "$SCRIPT_DIR/sing-box.service" "$SYSTEMD_SERVICE_PATH/"
sudo systemctl daemon-reload
}
stop_service() {
if systemctl is-active --quiet sing-box; then
echo "Stopping sing-box service"
sudo systemctl stop sing-box
fi
}
start_service() {
echo "Starting sing-box service"
sudo systemctl start sing-box
}
restart_service() {
echo "Restarting sing-box service"
sudo systemctl restart sing-box
}
+26
View File
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
set -e -o pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "$SCRIPT_DIR/common.sh"
setup_environment
echo "Updating sing-box from git repository..."
cd "$PROJECT_DIR"
git fetch
git reset FETCH_HEAD --hard
git clean -fdx
BUILD_TAGS=$(get_build_tags "debug")
build_sing_box "$BUILD_TAGS"
stop_service
install_binary
start_service
echo ""
echo "Following service logs (Ctrl+C to exit)..."
sudo journalctl -u sing-box --output cat -f
+7
View File
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -e -o pipefail
sudo systemctl enable sing-box
sudo systemctl start sing-box
sudo journalctl -u sing-box --output cat -f
+19
View File
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -e -o pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "$SCRIPT_DIR/common.sh"
setup_environment
BUILD_TAGS=$(get_build_tags)
build_sing_box "$BUILD_TAGS"
install_binary
setup_config
setup_systemd
echo ""
echo "Installation complete!"
echo "To enable and start the service, run: $SCRIPT_DIR/enable.sh"
+9
View File
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -e -o pipefail
go_version=$(curl -s https://raw.githubusercontent.com/actions/go-versions/main/versions-manifest.json | grep -oE '"version": "[0-9]{1}.[0-9]{1,}(.[0-9]{1,})?"' | head -1 | cut -d':' -f2 | sed 's/ //g; s/"//g')
curl -Lo go.tar.gz "https://go.dev/dl/go$go_version.linux-amd64.tar.gz"
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf go.tar.gz
rm go.tar.gz
+19
View File
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -e -o pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "$SCRIPT_DIR/common.sh"
setup_environment
BUILD_TAGS=$(get_build_tags)
build_sing_box "$BUILD_TAGS"
stop_service
install_binary
start_service
echo ""
echo "Reinstallation complete!"
@@ -0,0 +1,16 @@
[Unit]
Description=sing-box service
Documentation=https://sing-box.sagernet.org
After=network.target nss-lookup.target network-online.target
[Service]
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_RAW CAP_NET_BIND_SERVICE CAP_SYS_PTRACE CAP_DAC_READ_SEARCH
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_RAW CAP_NET_BIND_SERVICE CAP_SYS_PTRACE CAP_DAC_READ_SEARCH
ExecStart=/usr/local/bin/sing-box -D /var/lib/sing-box -C /usr/local/etc/sing-box run
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartSec=10s
LimitNOFILE=infinity
[Install]
WantedBy=multi-user.target
+30
View File
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
set -e -o pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "$SCRIPT_DIR/common.sh"
echo "Uninstalling sing-box..."
if systemctl is-active --quiet sing-box 2>/dev/null; then
echo "Stopping sing-box service..."
sudo systemctl stop sing-box
fi
if systemctl is-enabled --quiet sing-box 2>/dev/null; then
echo "Disabling sing-box service..."
sudo systemctl disable sing-box
fi
echo "Removing files..."
sudo rm -rf "$INSTALL_DATA_PATH"
sudo rm -rf "$INSTALL_BIN_PATH/$BINARY_NAME"
sudo rm -rf "$INSTALL_CONFIG_PATH"
sudo rm -rf "$SYSTEMD_SERVICE_PATH/sing-box.service"
echo "Reloading systemd..."
sudo systemctl daemon-reload
echo ""
echo "Uninstallation complete!"
+16
View File
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -e -o pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "$SCRIPT_DIR/common.sh"
echo "Updating sing-box from git repository..."
cd "$PROJECT_DIR"
git fetch
git reset FETCH_HEAD --hard
git clean -fdx
echo ""
echo "Running reinstall..."
exec "$SCRIPT_DIR/reinstall.sh"