netmaker/functions/local.go

48 lines
1,005 B
Go
Raw Normal View History

2021-05-05 05:36:55 +08:00
package functions
import (
2021-05-10 01:31:50 +08:00
"os"
2021-10-27 00:27:29 +08:00
2021-12-07 04:31:08 +08:00
"github.com/gravitl/netmaker/logger"
2021-10-27 00:27:29 +08:00
"github.com/gravitl/netmaker/logic"
2021-05-05 05:36:55 +08:00
)
2021-10-27 00:27:29 +08:00
// FileExists - checks if file exists
2021-05-05 05:36:55 +08:00
func FileExists(f string) bool {
2021-05-10 01:31:50 +08:00
info, err := os.Stat(f)
if os.IsNotExist(err) {
return false
}
return !info.IsDir()
2021-05-05 05:36:55 +08:00
}
2021-10-27 00:27:29 +08:00
// SetDNSDir - sets the dns directory of the system
func SetDNSDir() error {
2021-10-09 03:07:12 +08:00
dir, err := os.Getwd()
if err != nil {
return err
}
_, err = os.Stat(dir + "/config/dnsconfig")
if os.IsNotExist(err) {
os.Mkdir(dir+"/config/dnsconfig", 0744)
} else if err != nil {
2021-12-07 04:31:08 +08:00
logger.Log(0, "couldnt find or create /config/dnsconfig")
2021-10-09 03:07:12 +08:00
return err
}
_, err = os.Stat(dir + "/config/dnsconfig/Corefile")
if os.IsNotExist(err) {
2021-10-27 00:27:29 +08:00
err = logic.SetCorefile(".")
2021-10-09 03:07:12 +08:00
if err != nil {
2021-12-07 04:31:08 +08:00
logger.Log(0, err.Error())
2021-08-19 02:55:41 +08:00
}
2021-10-09 03:07:12 +08:00
}
_, err = os.Stat(dir + "/config/dnsconfig/netmaker.hosts")
if os.IsNotExist(err) {
_, err = os.Create(dir + "/config/dnsconfig/netmaker.hosts")
if err != nil {
2021-12-07 04:31:08 +08:00
logger.Log(0, err.Error())
2021-10-09 03:07:12 +08:00
}
}
return nil
}