2024-01-29 21:55:01 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/hiddify/libcore/config"
|
|
|
|
|
"github.com/hiddify/libcore/global"
|
|
|
|
|
"github.com/sagernet/sing-box/log"
|
2024-01-30 00:42:52 +01:00
|
|
|
"github.com/sagernet/sing-box/option"
|
2024-01-29 21:55:01 +01:00
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var commandRunInputPath string
|
|
|
|
|
|
|
|
|
|
var commandRun = &cobra.Command{
|
|
|
|
|
Use: "run",
|
|
|
|
|
Short: "run",
|
|
|
|
|
Args: cobra.ExactArgs(0),
|
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
|
err := runSingbox(commandRunInputPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
commandRun.Flags().StringVarP(&commandRunInputPath, "config", "c", "", "read config")
|
|
|
|
|
mainCommand.AddCommand(commandRun)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func runSingbox(configPath string) error {
|
|
|
|
|
options, err := readConfigAt(configPath)
|
2024-01-30 00:42:52 +01:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
options.Log = &option.LogOptions{}
|
2024-01-29 21:55:01 +01:00
|
|
|
options.Log.Disabled = false
|
|
|
|
|
options.Log.Level = "trace"
|
|
|
|
|
options.Log.Output = ""
|
|
|
|
|
options.Log.DisableColor = false
|
|
|
|
|
|
|
|
|
|
err = global.SetupC("./", "./", "./tmp", false)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
configStr, err := config.ToJson(*options)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
go global.StartServiceC(false, configStr)
|
|
|
|
|
fmt.Printf("Waiting for 30 seconds\n")
|
|
|
|
|
<-time.After(time.Second * 30)
|
|
|
|
|
return err
|
|
|
|
|
}
|