2015-10-17 18:50:51 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2015-12-08 06:41:20 -05:00
|
|
|
func copyConfigFile(src, dest string, goOS GoOS, format bool) error {
|
2015-10-17 18:50:51 -04:00
|
|
|
content, err := ioutil.ReadFile(src)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-12-08 06:41:20 -05:00
|
|
|
if format {
|
2015-12-08 11:31:31 -05: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 18:50:51 -04:00
|
|
|
}
|
2015-12-08 06:41:20 -05:00
|
|
|
return ioutil.WriteFile(dest, content, 0777)
|
2015-10-17 18:50:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func copyConfigFiles(dir string, goOS GoOS) error {
|
|
|
|
GOPATH := os.Getenv("GOPATH")
|
|
|
|
srcDir := filepath.Join(GOPATH, "src", "github.com", "v2ray", "v2ray-core", "release", "config")
|
|
|
|
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")
|
|
|
|
}
|
2015-12-08 06:41:20 -05:00
|
|
|
if err := copyConfigFile(src, dest, goOS, true); err != nil {
|
2015-10-17 18:50:51 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if goOS == Windows || goOS == MacOS {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
src = filepath.Join(srcDir, "vpoint_vmess_freedom.json")
|
|
|
|
dest = filepath.Join(dir, "vpoint_vmess_freedom.json")
|
2015-12-08 06:41:20 -05:00
|
|
|
|
|
|
|
if err := copyConfigFile(src, dest, goOS, true); err != nil {
|
2015-12-08 11:31:31 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2015-12-08 06:41:20 -05:00
|
|
|
}
|
|
|
|
|
2015-12-08 11:31:31 -05:00
|
|
|
return nil
|
2015-10-17 18:50:51 -04:00
|
|
|
}
|