diff --git a/internal/system/system.go b/internal/system/system.go index c39ecad..a694403 100644 --- a/internal/system/system.go +++ b/internal/system/system.go @@ -8,6 +8,8 @@ import ( "github.com/edgebox-iot/edgeboxctl/internal/utils" "github.com/shirou/gopsutil/host" + "github.com/joho/godotenv" + ) func GetUptimeInSeconds() string { @@ -54,3 +56,29 @@ func GetIP() string { func GetHostname() string { return utils.Exec("/", "hostname", []string{}) } + +func SetupCloudOptions() { + + var cloudEnv map[string]string + cloudEnv, err := godotenv.Read(utils.GetPath("cloudEnvFileLocation")) + + if err != nil { + fmt.Println("Error loading .env file for cloud version setup") + } + + if cloudEnv["NAME"] != "" { + utils.WriteOption("NAME", cloudEnv["NAME"]) + } + + if cloudEnv["EMAIL"] != "" { + utils.WriteOption("EMAIL", cloudEnv["EMAIL"]) + } + + if cloudEnv["EDGEBOXIO_API_TOKEN"] != "" { + utils.WriteOption("EDGEBOXIO_API_TOKEN", cloudEnv["EDGEBOXIO_API_TOKEN"]) + } + + // In the end of this operation takes place, remove the env file as to not overwrite any options once they are set. + utils.Exec("/", "rm", []string{utils.GetPath("cloudEnvFileLocation")}) + +} diff --git a/internal/tasks/tasks.go b/internal/tasks/tasks.go index 0d5987e..82fe537 100644 --- a/internal/tasks/tasks.go +++ b/internal/tasks/tasks.go @@ -281,11 +281,17 @@ func ExecuteSchedules(tick int) { hostname := taskGetHostname() log.Println("Hostname is " + hostname) - if diagnostics.Version == "cloud" && !edgeapps.IsPublicDashboard() { - taskEnablePublicDashboard(taskEnablePublicDashboardArgs{ - InternetURL: hostname + ".myedge.app", - }) + // if diagnostics.Version == "cloud" && !edgeapps.IsPublicDashboard() { + // taskEnablePublicDashboard(taskEnablePublicDashboardArgs{ + // InternetURL: hostname + ".myedge.app", + // }) + // } + + if diagnostics.Version == "cloud" { + log.Println("Setting up cloud version options (name, email, api token)") + taskSetupCloudOptions() } + // Executing on startup (first tick). Schedules run before tasks in the SystemIterator uptime := taskGetSystemUptime() @@ -467,3 +473,8 @@ func taskGetHostname() string { utils.WriteOption("HOSTNAME", hostname) return hostname } + +func taskSetupCloudOptions() { + fmt.Println("Executing taskSetupCloudOptions") + system.SetupCloudOptions() +} diff --git a/internal/utils/utils.go b/internal/utils/utils.go index 719b73d..3726bf2 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -113,6 +113,14 @@ func GetPath(pathKey string) string { } switch pathKey { + case "cloudEnvFileLocation": + + if env["CLOUD_ENV_FILE_LOCATION"] != "" { + targetPath = env["CLOUD_ENV_FILE_LOCATION"] + } else { + targetPath = "/home/system/components/edgeboxctl/cloud.env" + } + case "apiEnvFileLocation": if env["API_ENV_FILE_LOCATION"] != "" {