Example #1
0
        public void Update(int attemptNumber)
        {
            Console.WriteLine("");
            Console.WriteLine("Performing apt-get update...");

            Starter.WriteOutputToConsole = false;

            Starter.StartBash("sudo apt-get update");

            if (Starter.Output.ToLower().IndexOf("permission denied") > -1)
            {
                throw new Exception("Error: Permission denied. Do you need to run with sudo?");
            }

            if (Starter.Output.IndexOf("Resource temporarily unavailable") > -1)
            {
                if (attemptNumber <= MaximumAttempts)
                {
                    Console.WriteLine("Resource temporarily unavailable. Retrying after waiting...");
                    Thread.Sleep(2000);
                    Update(attemptNumber + 1);
                }
                else
                {
                    throw new Exception("Error: Resource temporarily unavailable.");
                }
            }

            Starter.WriteOutputToConsole = true;
        }
Example #2
0
        public void Stop()
        {
            Console.WriteLine("Stopping GrowSense system services...");

            Starter.StartBash("bash stop-garden.sh");

            Console.WriteLine("Finished stopping GrowSense system services.");
        }
Example #3
0
        public string Logs(string containerName)
        {
            Starter.OutputBuilder.Clear();
            Starter.StartBash("docker logs " + containerName);
            var output = Starter.Output;

            Starter.OutputBuilder.Clear();
            return(output);
        }
Example #4
0
        public bool IsPackageInstalled(string packageName)
        {
            var starter = new ProcessStarter();

            starter.WriteOutputToConsole  = false;
            starter.ThrowExceptionOnError = false;
            starter.StartBash("dpkg -s " + packageName);

            if (starter.Output.IndexOf("is not installed") > -1)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Example #5
0
        public CLISettings LoadSettings()//CLIContext context)
        {
            Console.WriteLine("Loading settings...");

            var settingsFile = GetSettingsFilePath();

            Console.WriteLine("  Path: " + settingsFile);

            if (File.Exists(settingsFile))
            {
                Console.WriteLine("  Settings file exists.");
                var settingsJson = File.ReadAllText(settingsFile);
                var settings     = JsonConvert.DeserializeObject <CLISettings>(settingsJson);

                var starter = new ProcessStarter(WorkingDirectory);
                starter.StartBash("hostname");
                settings.HostName = starter.Output.Trim();

                return(settings);
            }
            else
            {
                Console.WriteLine("  Settings file doesn't exist. Loading from legacy settings files...");
                var settings = new CLISettings();


                // Load settings from legacy files if they exist
                if (File.Exists(WorkingDirectory + "/mqtt-host.security"))
                {
                    settings.MqttHost = File.ReadAllText(WorkingDirectory + "/mqtt-host.security").Trim();
                }
                if (File.Exists(WorkingDirectory + "/mqtt-username.security"))
                {
                    settings.MqttUsername = File.ReadAllText(WorkingDirectory + "/mqtt-username.security").Trim();
                }
                if (File.Exists(WorkingDirectory + "/mqtt-password.security"))
                {
                    settings.MqttPassword = File.ReadAllText(WorkingDirectory + "/mqtt-password.security").Trim();
                }
                if (File.Exists(WorkingDirectory + "/mqtt-port.security"))
                {
                    settings.MqttPort = Convert.ToInt32(File.ReadAllText(WorkingDirectory + "/mqtt-port.security").Trim());
                }

                if (File.Exists(WorkingDirectory + "/wifi-name.security"))
                {
                    settings.WiFiName = File.ReadAllText(WorkingDirectory + "/wifi-name.security").Trim();
                }
                if (File.Exists(WorkingDirectory + "/wifi-password.security"))
                {
                    settings.WiFiPassword = File.ReadAllText(WorkingDirectory + "/wifi-password.security").Trim();
                }

                if (File.Exists(WorkingDirectory + "/smtp-server.security"))
                {
                    settings.SmtpServer = File.ReadAllText(WorkingDirectory + "/smtp-server.security").Trim();
                }
                if (File.Exists(WorkingDirectory + "/smtp-username.security"))
                {
                    settings.SmtpUsername = File.ReadAllText(WorkingDirectory + "/smtp-username.security").Trim();
                }
                if (File.Exists(WorkingDirectory + "/smtp-password.security"))
                {
                    settings.SmtpPassword = File.ReadAllText(WorkingDirectory + "/smtp-password.security").Trim();
                }
                if (File.Exists(WorkingDirectory + "/smtp-port.security"))
                {
                    settings.SmtpPort = Convert.ToInt32(File.ReadAllText(WorkingDirectory + "/smtp-port.security").Trim());
                }
                if (File.Exists(WorkingDirectory + "/admin-email.security"))
                {
                    settings.Email = File.ReadAllText(WorkingDirectory + "/admin-email.security").Trim();
                }

                return(settings);
            }
        }