v2ray-core/tools/build/config.go

82 lines
2.0 KiB
Go
Raw Normal View History

2015-10-17 22:50:51 +00:00
package main
import (
"io/ioutil"
"os"
"path/filepath"
"strings"
)
func copyConfigFile(src, dest string, goOS GoOS, format bool) error {
2015-10-17 22:50:51 +00:00
content, err := ioutil.ReadFile(src)
if err != nil {
return err
}
if format {
2015-12-08 16:31:31 +00:00
str := string(content)
str = strings.Replace(str, "\r\n", "\n", -1)
if goOS == Windows {
str = strings.Replace(str, "\n", "\r\n", -1)
}
content = []byte(str)
2015-10-17 22:50:51 +00:00
}
return ioutil.WriteFile(dest, content, 0777)
2015-10-17 22:50:51 +00:00
}
func copyConfigFiles(dir string, goOS GoOS) error {
GOPATH := os.Getenv("GOPATH")
2016-08-20 19:03:50 +00:00
srcDir := filepath.Join(GOPATH, "src", "v2ray.com", "core", "tools", "release", "config")
2015-10-17 22:50:51 +00:00
src := filepath.Join(srcDir, "vpoint_socks_vmess.json")
dest := filepath.Join(dir, "vpoint_socks_vmess.json")
if goOS == Windows || goOS == MacOS {
dest = filepath.Join(dir, "config.json")
}
if err := copyConfigFile(src, dest, goOS, true); err != nil {
2015-10-17 22:50:51 +00:00
return err
}
2017-02-24 12:35:52 +00:00
src = filepath.Join(GOPATH, "src", "v2ray.com", "core", "tools", "release", "doc", "readme.md")
dest = filepath.Join(dir, "readme.md")
if err := copyConfigFile(src, dest, goOS, true); err != nil {
return err
}
2015-10-17 22:50:51 +00:00
if goOS == Windows || goOS == MacOS {
return nil
}
src = filepath.Join(srcDir, "vpoint_vmess_freedom.json")
dest = filepath.Join(dir, "vpoint_vmess_freedom.json")
if err := copyConfigFile(src, dest, goOS, true); err != nil {
2015-12-08 16:31:31 +00:00
return err
}
2017-02-24 12:35:52 +00:00
if err := copyConfigFile(src, dest, goOS, true); err != nil {
return err
}
2015-12-08 16:31:31 +00:00
if goOS == Linux {
if err := os.MkdirAll(filepath.Join(dir, "systemv"), os.ModeDir|0777); err != nil {
return err
}
src = filepath.Join(srcDir, "systemv", "v2ray")
dest = filepath.Join(dir, "systemv", "v2ray")
if err := copyConfigFile(src, dest, goOS, false); err != nil {
return err
}
2016-01-12 22:35:45 +00:00
if err := os.MkdirAll(filepath.Join(dir, "systemd"), os.ModeDir|0777); err != nil {
return err
}
src = filepath.Join(srcDir, "systemd", "v2ray.service")
dest = filepath.Join(dir, "systemd", "v2ray.service")
if err := copyConfigFile(src, dest, goOS, false); err != nil {
return err
}
}
2015-12-08 16:31:31 +00:00
return nil
2015-10-17 22:50:51 +00:00
}