using syncconf for freebsd

This commit is contained in:
afeiszli 2021-11-12 13:03:31 -05:00
parent 5b3b6119ae
commit eb770163f8

View file

@ -2,6 +2,7 @@ package wireguard
import (
"io/ioutil"
"os"
"github.com/gravitl/netmaker/models"
"github.com/gravitl/netmaker/netclient/config"
@ -57,7 +58,25 @@ func ApplyWGQuickConf(confPath string) error {
// ApplyWGQuickConf - applies wg-quick commands if os supports
func SyncWGQuickConf(confPath string) error {
_, err := ncutils.RunCmd("wg-quick down "+confPath, false)
var tmpConf = confPath + ".sync.tmp"
conf, err := ncutils.RunCmd("wg-quick strip "+confPath, false)
if err != nil {
return err
}
err = ioutil.WriteFile(tmpConf, []byte(conf), 0644)
if err != nil {
return err
}
_, err = ncutils.RunCmd("wg sync "+confPath, false)
if err != nil {
ncutils.Log("error syncing conf, resetting")
err = ApplyWGQuickConf(confPath)
}
errN := os.Remove(tmpConf)
if errN != nil {
ncutils.Log(errN.Error())
}
return err
}