2024-04-18 01:52:23 +09:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"archive/zip"
|
|
|
|
"bytes"
|
|
|
|
_ "embed"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
)
|
|
|
|
|
2024-04-19 00:29:30 +09:00
|
|
|
type config struct {
|
|
|
|
BaseURL string `yaml:"BaseURL"`
|
|
|
|
Targets []targets `yaml:"Targets"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type targets struct {
|
|
|
|
Refer string `yaml:"Refer"`
|
|
|
|
Folder string `yaml:"Folder"`
|
|
|
|
Copy []string `yaml:"Copy"`
|
|
|
|
OS string `yaml:"OS"`
|
|
|
|
Arch string `yaml:"Arch"`
|
|
|
|
}
|
|
|
|
|
2024-04-18 01:52:23 +09:00
|
|
|
//go:embed cfg.zip
|
|
|
|
var cfgdata []byte
|
|
|
|
|
|
|
|
var cfg = func() *zip.Reader {
|
|
|
|
r, err := zip.NewReader(bytes.NewReader(cfgdata), int64(len(cfgdata)))
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
for _, f := range r.File {
|
|
|
|
cmdlst = append(cmdlst, f.Name)
|
|
|
|
}
|
|
|
|
return r
|
|
|
|
}()
|
|
|
|
|
2024-04-18 18:21:01 +09:00
|
|
|
func readconfig(path string, usecust bool) (c config, err error) {
|
2024-04-18 01:52:23 +09:00
|
|
|
fname := path + ".yaml"
|
|
|
|
f, err := cfg.Open(fname)
|
2024-04-18 18:21:01 +09:00
|
|
|
if usecust && err != nil {
|
|
|
|
f, err = os.Open(fname)
|
|
|
|
}
|
2024-04-18 01:52:23 +09:00
|
|
|
if err != nil {
|
|
|
|
err = errors.Wrap(err, "invalid path")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
err = yaml.NewDecoder(f).Decode(&c)
|
|
|
|
if err != nil {
|
|
|
|
err = errors.Wrap(err, "invalid config")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|