one-api [分享]免费的本地构建者Bash

0pizxfdo  于 2个月前  发布在  其他
关注(0)|答案(1)|浏览(28)

代码:

#!/bin/bash

# Author: H0llyW00dzZ
# Script: One-Api Local Builder
# License: MIT

# Exit script if any command fails
set -e

# Function to handle errors
error_exit()
{
    echo "Error: $1" 1>&2
    exit 1
}

# Export the SQL DSN environment variable
# Changed this for SQL Server
export SQL_DSN="root:password@tcp(k8s.clusters.example.com:port)/dbname"

# Build the frontend
echo "Building the frontend..."
cd web || error_exit "Unable to enter 'web' directory."

# Check if npm is installed
if ! command -v npm &> /dev/null; then
    error_exit "npm could not be found. Please install it to continue."
fi

npm install || error_exit "npm install failed."
npm run build || error_exit "npm run build failed."

# Build the backend
echo "Building the backend..."
cd .. || error_exit "Unable to return to the project root directory."

# Check if Go is installed
if ! command -v go &> /dev/null; then
    error_exit "Go could not be found. Please install it to continue."
fi

go mod download || error_exit "go mod download failed."
go build -ldflags "-s -w" -o one-api || error_exit "go build failed."

# Set execute permission on the binary and run it
chmod u+x one-api
./one-api --port 3000 --log-dir ./logs || error_exit "Failed to start one-api."

echo "Build and launch process completed successfully."

b5buobof

b5buobof1#

注意:
这个bash脚本包含自动运行功能,所以当按下CTRL+C(退出命令)时,它也会关闭本地服务器。

相关问题