Browse Source

update: `disable` option for asset

v1.x.x
dnomd343 2 years ago
parent
commit
c9b917663b
  1. 11
      cmd/asset/update.go
  2. 17
      cmd/config/decode.go
  3. 3
      cmd/config/default.go
  4. 2
      cmd/config/main.go
  5. 12
      cmd/controller.go

11
cmd/asset/update.go

@ -8,9 +8,12 @@ import (
)
type Config struct {
Disable bool `yaml:"disable" json:"disable"`
Update struct {
Proxy string `yaml:"proxy" json:"proxy"`
Cron string `yaml:"cron" json:"cron"`
Url map[string]string `yaml:"url" json:"url"`
}
}
func updateAsset(urls map[string]string, assetDir string, updateProxy string) { // download new assets
@ -27,11 +30,11 @@ func updateAsset(urls map[string]string, assetDir string, updateProxy string) {
}
}
func AutoUpdate(update *Config, assetDir string) { // set cron task for auto update
if update.Cron != "" {
func AutoUpdate(config *Config, assetDir string) { // set cron task for auto update
if config.Update.Cron != "" {
autoUpdate := cron.New()
_ = autoUpdate.AddFunc(update.Cron, func() { // cron function
updateAsset(update.Url, assetDir, update.Proxy)
_ = autoUpdate.AddFunc(config.Update.Cron, func() { // cron function
updateAsset(config.Update.Url, assetDir, config.Update.Proxy)
})
autoUpdate.Start()
}

17
cmd/config/decode.go

@ -18,7 +18,7 @@ type NetConfig struct {
}
type RawConfig struct {
Update asset.Config `yaml:"update" json:"update"`
Asset asset.Config `yaml:"asset" json:"asset"`
Radvd radvd.Config `yaml:"radvd" json:"radvd"`
Proxy proxy.Config `yaml:"proxy" json:"proxy"`
Custom custom.Config `yaml:"custom" json:"custom"`
@ -164,16 +164,17 @@ func decodeRadvd(rawConfig *RawConfig, config *Config) {
}
func decodeUpdate(rawConfig *RawConfig, config *Config) {
config.Update = rawConfig.Update
if config.Update.Proxy != "" {
_, err := url.Parse(config.Update.Proxy) // check proxy info
config.Asset = rawConfig.Asset
if config.Asset.Update.Proxy != "" {
_, err := url.Parse(config.Asset.Update.Proxy) // check proxy info
if err != nil {
log.Panicf("Invalid update proxy -> %s", config.Update.Proxy)
log.Panicf("Invalid asset update proxy -> %s", config.Asset.Update.Proxy)
}
}
log.Debugf("Update proxy -> %s", config.Update.Proxy)
log.Debugf("Update cron -> %s", config.Update.Cron)
log.Debugf("Update urls -> %v", config.Update.Url)
log.Debugf("Asset disable -> %t", config.Asset.Disable)
log.Debugf("Asset update proxy -> %s", config.Asset.Update.Proxy)
log.Debugf("Asset update cron -> %s", config.Asset.Update.Cron)
log.Debugf("Asset update urls -> %v", config.Asset.Update.Url)
}
func decodeCustom(rawConfig *RawConfig, config *Config) {

3
cmd/config/default.go

@ -13,7 +13,8 @@ network:
- fe80::/10
- ff00::/8
update:
asset:
update:
cron: "0 0 4 * * *"
url:
geoip.dat: "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat"

2
cmd/config/main.go

@ -18,7 +18,7 @@ type Config struct {
IPv4 network.Config
IPv6 network.Config
Proxy proxy.Config
Update asset.Config
Asset asset.Config
Radvd radvd.Config
Custom custom.Config
}

12
cmd/controller.go

@ -29,12 +29,20 @@ func blockWait() {
}
func loadRadvd(settings *config.Config) {
if settings.Radvd.Enable {
radvd.Load(&settings.Radvd)
} else {
log.Infof("Skip loading radvd")
}
}
func loadAsset(settings *config.Config) {
if settings.Asset.Disable {
log.Infof("Skip loading asset")
} else {
asset.Load(assetFile, assetDir)
asset.AutoUpdate(&settings.Update, assetDir)
asset.AutoUpdate(&settings.Asset, assetDir)
}
}
func loadNetwork(settings *config.Config) {
@ -72,5 +80,7 @@ func runRadvd(settings *config.Config) {
radvdCmd = append(radvdCmd, "--debug", strconv.Itoa(settings.Radvd.Log))
}
runProcess(nil, radvdCmd...)
} else {
log.Infof("Skip running radvd")
}
}

Loading…
Cancel
Save