This commit is contained in:
unknown
2026-02-04 20:27:13 +08:00
commit 3b042d1dad
9410 changed files with 1488147 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
edge-instance-installer*
prepare.sh

View File

@@ -0,0 +1,45 @@
#!/usr/bin/env bash
function build() {
ROOT=$(dirname "$0")
OS="${1}"
ARCH="${2}"
TAG="${3}"
if [ -z "$OS" ]; then
echo "usage: build.sh OS ARCH"
exit
fi
if [ -z "$ARCH" ]; then
echo "usage: build.sh OS ARCH"
exit
fi
VERSION=$(lookup_version "${ROOT}/../../internal/const/const.go")
TARGET_NAME="edge-instance-installer-${OS}-${ARCH}-v${VERSION}"
env GOOS=linux GOARCH="${ARCH}" go build -tags="${TAG}" -trimpath -ldflags="-s -w" -o "${TARGET_NAME}" main.go
if [ -f "${TARGET_NAME}" ]; then
cp "${TARGET_NAME}" "${ROOT}/../../../EdgeAdmin/docker/instance/edge-instance/assets"
fi
echo "[done]"
}
function lookup_version() {
FILE=$1
VERSION_DATA=$(cat "$FILE")
re="Version[ ]+=[ ]+\"([0-9.]+)\""
if [[ $VERSION_DATA =~ $re ]]; then
VERSION=${BASH_REMATCH[1]}
echo "$VERSION"
else
echo "could not match version"
exit
fi
}
build "$1" "$2" "$3"

View File

@@ -0,0 +1,97 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
package main
import (
"fmt"
"github.com/TeaOSLab/EdgeAPI/internal/instances"
_ "github.com/iwind/TeaGo/bootstrap"
"github.com/iwind/TeaGo/lists"
"log"
"os"
)
func main() {
var verbose = lists.ContainsString(os.Args, "-v")
var dbHost = "127.0.0.1"
var dbPassword = "123456"
var dbName = "edges"
envDBHost, _ := os.LookupEnv("EDGE_DB_HOST")
if len(envDBHost) > 0 {
dbHost = envDBHost
if verbose {
log.Println("env EDGE_DB_HOST=" + envDBHost)
}
}
envDBPassword, _ := os.LookupEnv("EDGE_DB_PASSWORD")
if len(envDBPassword) > 0 {
dbPassword = envDBPassword
if verbose {
log.Println("env EDGE_DB_PASSWORD=" + envDBPassword)
}
}
envDBName, _ := os.LookupEnv("EDGE_DB_NAME")
if len(envDBName) > 0 {
dbName = envDBName
if verbose {
log.Println("env EDGE_DB_NAME=" + envDBName)
}
}
var isTesting = lists.ContainsString(os.Args, "-test") || lists.ContainsString(os.Args, "--test")
if isTesting {
fmt.Println("testing mode ...")
}
var instance = instances.NewInstance(instances.Options{
IsTesting: isTesting,
Verbose: verbose,
Cacheable: false,
WorkDir: "",
SrcDir: "/usr/local/goedge/src",
DB: struct {
Host string
Port int
Username string
Password string
Name string
}{
Host: dbHost,
Port: 3306,
Username: "root",
Password: dbPassword,
Name: dbName,
},
AdminNode: struct {
Port int
}{
Port: 7788,
},
APINode: struct {
HTTPPort int
RestHTTPPort int
}{
HTTPPort: 8001,
RestHTTPPort: 8002,
},
Node: struct{ HTTPPort int }{
HTTPPort: 80,
},
UserNode: struct {
HTTPPort int
}{
HTTPPort: 7799,
},
})
err := instance.SetupAll()
if err != nil {
fmt.Println("[ERROR]setup failed: " + err.Error())
return
}
fmt.Println("ok")
}

View File

@@ -0,0 +1,73 @@
package main
import (
"flag"
"github.com/TeaOSLab/EdgeAPI/internal/installers/helpers"
"github.com/iwind/gosock/pkg/gosock"
"os"
"os/exec"
)
func main() {
cmd := ""
flag.StringVar(&cmd, "cmd", "", "command name: [unzip]")
// unzip
zipPath := ""
targetPath := ""
flag.StringVar(&zipPath, "zip", "", "zip path")
flag.StringVar(&targetPath, "target", "", "target dir")
// parse
flag.Parse()
if len(cmd) == 0 {
stderr("need '-cmd=COMMAND' argument")
} else if cmd == "test" {
// 检查是否正在运行
var sock = gosock.NewTmpSock("edge-dns")
if sock.IsListening() {
// 从systemd中停止
systemctl, _ := exec.LookPath("systemctl")
if len(systemctl) > 0 {
systemctlCmd := exec.Command(systemctl, "stop", "edge-dns")
_ = systemctlCmd.Run()
}
// 从进程中停止
if sock.IsListening() {
_, _ = sock.Send(&gosock.Command{
Code: "stop",
})
}
}
} else if cmd == "unzip" { // 解压
if len(zipPath) == 0 {
stderr("ERROR: need '-zip=PATH' argument")
return
}
if len(targetPath) == 0 {
stderr("ERROR: need '-target=TARGET' argument")
return
}
unzip := helpers.NewUnzip(zipPath, targetPath)
err := unzip.Run()
if err != nil {
stderr("ERROR: " + err.Error())
return
}
stdout("ok")
} else {
stderr("ERROR: not recognized command '" + cmd + "'")
}
}
func stdout(s string) {
_, _ = os.Stdout.WriteString(s + "\n")
}
func stderr(s string) {
_, _ = os.Stderr.WriteString(s + "\n")
}

View File

@@ -0,0 +1,74 @@
package main
// 注意这里的依赖文件应该最小化,从而使编译后的文件最小化
import (
"flag"
"github.com/TeaOSLab/EdgeAPI/internal/installers/helpers"
"github.com/iwind/gosock/pkg/gosock"
"os"
"os/exec"
)
func main() {
cmd := ""
flag.StringVar(&cmd, "cmd", "", "command name: [unzip]")
// unzip
zipPath := ""
targetPath := ""
flag.StringVar(&zipPath, "zip", "", "zip path")
flag.StringVar(&targetPath, "target", "", "target dir")
// parse
flag.Parse()
if len(cmd) == 0 {
stderr("need '-cmd=COMMAND' argument")
} else if cmd == "test" {
// 检查是否正在运行
var sock = gosock.NewTmpSock("edge-node")
if sock.IsListening() {
// 从systemd中停止
systemctl, _ := exec.LookPath("systemctl")
if len(systemctl) > 0 {
systemctlCmd := exec.Command(systemctl, "stop", "edge-node")
_ = systemctlCmd.Run()
}
// 从进程中停止
if sock.IsListening() {
_, _ = sock.Send(&gosock.Command{
Code: "stop",
})
}
}
} else if cmd == "unzip" { // 解压
if len(zipPath) == 0 {
stderr("ERROR: need '-zip=PATH' argument")
return
}
if len(targetPath) == 0 {
stderr("ERROR: need '-target=TARGET' argument")
return
}
var unzip = helpers.NewUnzip(zipPath, targetPath)
err := unzip.Run()
if err != nil {
stderr("ERROR: " + err.Error())
return
}
stdout("ok")
} else {
stderr("ERROR: not recognized command '" + cmd + "'")
}
}
func stdout(s string) {
_, _ = os.Stdout.WriteString(s + "\n")
}
func stderr(s string) {
_, _ = os.Stderr.WriteString(s + "\n")
}

View File

@@ -0,0 +1,41 @@
package main
import (
"encoding/json"
"fmt"
"github.com/TeaOSLab/EdgeAPI/internal/setup"
"github.com/iwind/TeaGo/Tea"
_ "github.com/iwind/TeaGo/bootstrap"
"github.com/iwind/TeaGo/dbs"
"os"
"path/filepath"
)
func main() {
db, err := dbs.Default()
if err != nil {
fmt.Println("[ERROR]" + err.Error())
return
}
results, err := setup.NewSQLDump().Dump(db, true)
if err != nil {
fmt.Println("[ERROR]" + err.Error())
return
}
prettyResultsJSON, err := json.MarshalIndent(results, "", " ")
if err != nil {
fmt.Println("[ERROR]" + err.Error())
return
}
// 写入到 sql.json 中
var dir = filepath.Dir(Tea.Root)
err = os.WriteFile(dir+"/internal/setup/sql.json", prettyResultsJSON, 0666)
if err != nil {
fmt.Println("[ERROR]" + err.Error())
return
}
fmt.Println("ok")
}

107
EdgeAPI/cmd/tt/main.go Normal file
View File

@@ -0,0 +1,107 @@
package main
import (
"bufio"
"bytes"
"fmt"
"github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/cmd"
_ "github.com/iwind/TeaGo/dbs/commands"
"github.com/iwind/TeaGo/lists"
"os"
"path/filepath"
"time"
)
// TeaTool工具
func main() {
r := bufio.NewReader(os.Stdin)
lastCommand := ""
for {
time.Sleep(200 * time.Millisecond)
fmt.Print("> ")
line, _, err := r.ReadLine()
if err != nil {
continue
}
command := string(bytes.TrimSpace(line))
// 命令帮助
if len(command) == 0 || command == "help" || command == "h" || command == "?" || command == "/?" {
lastCommand = command
fmt.Println("TeaTool commands:")
commands := cmd.AllCommands()
// 对命令代码进行排序
codes := []string{}
for code := range commands {
codes = append(codes, code)
}
lists.Sort(codes, func(i int, j int) bool {
code1 := codes[i]
code2 := codes[j]
return code1 < code2
})
//输出
for _, code := range codes {
ptr := commands[code]
fmt.Println(" ", code+"\n\t\t"+ptr.Name())
}
continue
}
if command == "retry" || command == "!!" /** csh like **/ || command == "!-1" /** csh like **/ {
command = lastCommand
fmt.Println("retry '" + command + "'")
}
lastCommand = command
found := cmd.Try(cmd.ParseArgs(command))
if !found {
fmt.Println("command '" + command + "' not found")
}
}
}
// 重置Root
func init() {
webIsSet := false
if !Tea.IsTesting() {
exePath, err := os.Executable()
if err != nil {
exePath = os.Args[0]
}
link, err := filepath.EvalSymlinks(exePath)
if err == nil {
exePath = link
}
fullPath, err := filepath.Abs(exePath)
if err == nil {
Tea.UpdateRoot(filepath.Dir(filepath.Dir(fullPath)))
}
} else {
pwd, ok := os.LookupEnv("PWD")
if ok {
webIsSet = true
Tea.SetPublicDir(pwd + Tea.DS + "web" + Tea.DS + "public")
Tea.SetViewsDir(pwd + Tea.DS + "web" + Tea.DS + "views")
Tea.SetTmpDir(pwd + Tea.DS + "web" + Tea.DS + "tmp")
Tea.Root = pwd + Tea.DS + "build"
}
}
if !webIsSet {
Tea.SetPublicDir(Tea.Root + Tea.DS + "web" + Tea.DS + "public")
Tea.SetViewsDir(Tea.Root + Tea.DS + "web" + Tea.DS + "views")
Tea.SetTmpDir(Tea.Root + Tea.DS + "web" + Tea.DS + "tmp")
}
Tea.SetConfigDir(Tea.Root + Tea.DS + "configs")
_ = os.Setenv("GOPATH", filepath.Dir(Tea.Root))
}