From a703315d000f91e774e74b474118102dcb839261 Mon Sep 17 00:00:00 2001 From: CN-JS-HuiBai Date: Fri, 17 Apr 2026 22:37:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=9E=84=E5=BB=BA=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/build_install.sh | 67 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/scripts/build_install.sh b/scripts/build_install.sh index 3b9f55b..216203f 100644 --- a/scripts/build_install.sh +++ b/scripts/build_install.sh @@ -10,6 +10,9 @@ OUTPUT_PATH="${ROOT_DIR}/api" TOOLS_DIR="${ROOT_DIR}/.build-tools" CACHE_DIR="${ROOT_DIR}/.build-cache" CLEAN_GO="false" +INSTALL_SERVICE="false" +SERVICE_NAME="singbox-gopanel" +RUN_USER="${SUDO_USER:-${USER:-root}}" usage() { cat < Toolchain directory, default: ${TOOLS_DIR} --cache-dir Go cache directory, default: ${CACHE_DIR} --clean-go Re-download the Go toolchain even if it exists + --install-service Install and start the systemd service + --service-name Systemd service name, default: ${SERVICE_NAME} + --run-user Runtime user, default: ${RUN_USER} -h, --help Show this help Examples: bash scripts/build_install.sh bash scripts/build_install.sh --output ./package/api + sudo bash scripts/build_install.sh --install-service EOF } @@ -52,6 +59,18 @@ parse_args() { CLEAN_GO="true" shift ;; + --install-service) + INSTALL_SERVICE="true" + shift + ;; + --service-name) + SERVICE_NAME="$2" + shift 2 + ;; + --run-user) + RUN_USER="$2" + shift 2 + ;; -h|--help) usage exit 0 @@ -154,6 +173,49 @@ build_binary() { chmod +x "${OUTPUT_PATH}" || true } +install_systemd_service() { + if [[ "${INSTALL_SERVICE}" != "true" ]]; then + return + fi + + if [[ "${EUID}" -ne 0 ]]; then + echo "error: systemd service installation requires root/sudo" >&2 + exit 1 + fi + + if ! command -v systemctl >/dev/null 2>&1; then + echo "systemctl not found, skipping service installation" + return + fi + + echo "installing systemd service: ${SERVICE_NAME}..." + + cat >"/etc/systemd/system/${SERVICE_NAME}.service" <