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
|
|
|
)
|
|
|
|
|
2022-04-19 05:19:26 +08:00
|
|
|
// LINUX_APP_DATA_PATH - linux path
|
|
|
|
const LINUX_APP_DATA_PATH = "/etc/netmaker"
|
|
|
|
|
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
|
2021-05-30 23:26:10 +08:00
|
|
|
func SetDNSDir() error {
|
2021-10-09 03:07:12 +08:00
|
|
|
dir, err := os.Getwd()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-01-28 11:07:56 +08:00
|
|
|
|
2021-10-09 03:07:12 +08:00
|
|
|
_, err = os.Stat(dir + "/config/dnsconfig")
|
|
|
|
if os.IsNotExist(err) {
|
2022-01-28 11:07:56 +08:00
|
|
|
err = os.MkdirAll(dir+"/config/dnsconfig", 0744)
|
|
|
|
}
|
|
|
|
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
|
|
|
|
}
|
2022-01-28 11:07:56 +08:00
|
|
|
|
2021-10-09 03:07:12 +08:00
|
|
|
_, 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
|
|
|
}
|
2022-01-28 11:07:56 +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
|
|
|
}
|
|
|
|
}
|
2021-05-30 23:26:10 +08:00
|
|
|
return nil
|
|
|
|
}
|
2022-04-19 05:19:26 +08:00
|
|
|
|
|
|
|
// GetNetmakerPath - gets netmaker path locally
|
|
|
|
func GetNetmakerPath() string {
|
|
|
|
return LINUX_APP_DATA_PATH
|
|
|
|
}
|