Add claude code multiplexer service

This commit is contained in:
世界
2025-10-21 10:34:05 +08:00
parent b5f62c1b88
commit 517e1503e9
30 changed files with 1807 additions and 369 deletions

100
release/local/common.sh Executable file
View File

@@ -0,0 +1,100 @@
#!/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="with_gvisor,with_quic,with_dhcp,with_wireguard,with_utls,with_acme,with_clash_api,with_tailscale,with_ccm,badlinkname,tfogo_checklinkname0"
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)
echo "-X 'github.com/sagernet/sing-box/constant.Version=${version}' -s -w -buildid= -checklinkname=0"
}
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
}

View File

@@ -2,21 +2,25 @@
set -e -o pipefail
if [ -d /usr/local/go ]; then
export PATH="$PATH:/usr/local/go/bin"
fi
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "$SCRIPT_DIR/common.sh"
DIR=$(dirname "$0")
PROJECT=$DIR/../..
setup_environment
pushd $PROJECT
echo "Updating sing-box from git repository..."
cd "$PROJECT_DIR"
git fetch
git reset FETCH_HEAD --hard
git clean -fdx
go install -v -trimpath -ldflags "-s -w -buildid=" -tags with_quic,with_acme,debug ./cmd/sing-box
popd
sudo systemctl stop sing-box
sudo cp $(go env GOPATH)/bin/sing-box /usr/local/bin/
sudo systemctl start sing-box
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

View File

@@ -2,19 +2,18 @@
set -e -o pipefail
if [ -d /usr/local/go ]; then
export PATH="$PATH:/usr/local/go/bin"
fi
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "$SCRIPT_DIR/common.sh"
DIR=$(dirname "$0")
PROJECT=$DIR/../..
setup_environment
pushd $PROJECT
go install -v -trimpath -ldflags "-s -w -buildid=" -tags with_quic,with_wireguard,with_acme ./cmd/sing-box
popd
BUILD_TAGS=$(get_build_tags)
sudo cp $(go env GOPATH)/bin/sing-box /usr/local/bin/
sudo mkdir -p /usr/local/etc/sing-box
sudo cp $PROJECT/release/config/config.json /usr/local/etc/sing-box/config.json
sudo cp $DIR/sing-box.service /etc/systemd/system
sudo systemctl daemon-reload
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"

View File

@@ -2,17 +2,18 @@
set -e -o pipefail
if [ -d /usr/local/go ]; then
export PATH="$PATH:/usr/local/go/bin"
fi
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "$SCRIPT_DIR/common.sh"
DIR=$(dirname "$0")
PROJECT=$DIR/../..
setup_environment
pushd $PROJECT
go install -v -trimpath -ldflags "-s -w -buildid=" -tags with_quic,with_wireguard,with_acme ./cmd/sing-box
popd
BUILD_TAGS=$(get_build_tags)
sudo systemctl stop sing-box
sudo cp $(go env GOPATH)/bin/sing-box /usr/local/bin/
sudo systemctl start sing-box
build_sing_box "$BUILD_TAGS"
stop_service
install_binary
start_service
echo ""
echo "Reinstallation complete!"

View File

@@ -1,8 +1,30 @@
#!/usr/bin/env bash
sudo systemctl stop sing-box
sudo rm -rf /var/lib/sing-box
sudo rm -rf /usr/local/bin/sing-box
sudo rm -rf /usr/local/etc/sing-box
sudo rm -rf /etc/systemd/system/sing-box.service
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!"

View File

@@ -2,13 +2,15 @@
set -e -o pipefail
DIR=$(dirname "$0")
PROJECT=$DIR/../..
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "$SCRIPT_DIR/common.sh"
pushd $PROJECT
echo "Updating sing-box from git repository..."
cd "$PROJECT_DIR"
git fetch
git reset FETCH_HEAD --hard
git clean -fdx
popd
$DIR/reinstall.sh
echo ""
echo "Running reinstall..."
exec "$SCRIPT_DIR/reinstall.sh"