2018-06-10 14:50:03 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2018-11-14 12:58:10 +00:00
|
|
|
"flag"
|
2019-03-23 11:24:26 +00:00
|
|
|
"fmt"
|
2018-06-10 14:50:03 +00:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
2018-11-14 12:58:10 +00:00
|
|
|
"path/filepath"
|
2019-03-23 11:24:26 +00:00
|
|
|
"runtime"
|
2018-06-10 14:50:03 +00:00
|
|
|
"syscall"
|
|
|
|
|
2018-07-25 16:04:59 +00:00
|
|
|
"github.com/Dreamacro/clash/config"
|
2018-11-14 12:58:10 +00:00
|
|
|
C "github.com/Dreamacro/clash/constant"
|
2018-06-18 03:31:49 +00:00
|
|
|
"github.com/Dreamacro/clash/hub"
|
2018-06-10 14:50:03 +00:00
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
2018-10-16 05:12:36 +00:00
|
|
|
var (
|
2019-03-23 11:24:26 +00:00
|
|
|
version bool
|
2018-10-16 05:12:36 +00:00
|
|
|
homedir string
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
flag.StringVar(&homedir, "d", "", "set configuration directory")
|
2019-03-23 11:24:26 +00:00
|
|
|
flag.BoolVar(&version, "v", false, "show current version of clash")
|
2018-10-16 05:12:36 +00:00
|
|
|
flag.Parse()
|
|
|
|
}
|
|
|
|
|
2018-06-10 14:50:03 +00:00
|
|
|
func main() {
|
2019-03-23 11:24:26 +00:00
|
|
|
if version {
|
|
|
|
fmt.Printf("Clash %s %s %s %s\n", C.Version, runtime.GOOS, runtime.GOARCH, C.BuildTime)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-02-26 17:02:43 +00:00
|
|
|
// enable tls 1.3 and remove when go 1.13
|
|
|
|
os.Setenv("GODEBUG", os.Getenv("GODEBUG")+",tls13=1")
|
|
|
|
|
2018-11-14 12:58:10 +00:00
|
|
|
if homedir != "" {
|
|
|
|
if !filepath.IsAbs(homedir) {
|
2018-10-16 05:12:36 +00:00
|
|
|
currentDir, _ := os.Getwd()
|
2018-11-14 12:58:10 +00:00
|
|
|
homedir = filepath.Join(currentDir, homedir)
|
2018-10-16 05:12:36 +00:00
|
|
|
}
|
|
|
|
C.SetHomeDir(homedir)
|
|
|
|
}
|
|
|
|
|
2018-11-21 05:47:46 +00:00
|
|
|
if err := config.Init(C.Path.HomeDir()); err != nil {
|
|
|
|
log.Fatalf("Initial configuration directory error: %s", err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := hub.Parse(); err != nil {
|
2018-07-25 16:04:59 +00:00
|
|
|
log.Fatalf("Parse config error: %s", err.Error())
|
2018-06-18 03:31:49 +00:00
|
|
|
}
|
|
|
|
|
2018-06-10 14:50:03 +00:00
|
|
|
sigCh := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
|
|
|
|
<-sigCh
|
|
|
|
}
|