/// <summary>
        /// Crea archivo /etc/netplan/50-cloud-init.yam"
        /// </summary>
        /// <param name="networkInterfaceName"></param>
        /// <param name="ip"></param>
        /// <param name="mask"></param>
        /// <param name="gateway"></param>
        /// <param name="nameServersAddresses"></param>
        /// <returns></returns>
        public static async Task <CommandResult> CreateYamlAsync(string networkInterfaceName, string ip, string mask, string gateway, string nameServersAddresses, string password, bool backup = true)
        {
            var content = GetYamlTemplate(networkInterfaceName, ip, mask, gateway, nameServersAddresses);

            var outputfile = YAML_FILE;

            var currentdir = Directory.GetCurrentDirectory();
            var tmpfile    = Path.Combine(currentdir, System.IO.Path.GetFileName(outputfile));

            await tmpfile.WriteAllTextAsync(content);

            await Bash.ExecuteAsync($"chmod 640 {tmpfile}");

            if (backup && File.Exists(YAML_FILE))
            {
                var backupfilename = $"{YAML_FILE}-{DateTimeExtensions.NowToFilenameString()}.backup";
                await Bash.ExecuteAsync($"cp {YAML_FILE} {backupfilename}", password : password);
            }

            var result = await Bash.ExecuteAsync($"mv {tmpfile} {outputfile}", password : password);

            await Bash.ExecuteAsync($"chmod 640 {outputfile}");

            return(result);
        }
        public static CommandResult Execute(string command, string password = "", string workingDirectory = "")
        {
            var bash = new Bash(command, password, workingDirectory);

            bash.Start();
            return(bash.WaitForExit());
        }
        public static async Task <CommandResult> ExecuteAsync(string command, string password = "", string workingDirectory = "")
        {
            var bash = new Bash(command, password, workingDirectory);

            bash.Start();
            return(await bash.WaitForExitAsync());
        }
Example #4
0
        public static async Task <List <NetworkInteface> > GetNetworkInterfacesAsync()
        {
            var cards = await GetNetworkCardsAsync();

            var interfaces = (await Bash.ExecuteAsync("ifconfig -a")).OutputList;

            return(ExtractNetworkInterfaces(cards, interfaces));
        }
Example #5
0
        public static List <NetworkInteface> GetNetworkInterfaces()
        {
            var cards = GetNetworkCards();

            var interfaces = (Bash.Execute("ifconfig -a")).OutputList;

            return(ExtractNetworkInterfaces(cards, interfaces));
        }
        public static string WhoAmI()
        {
            var bash = new Bash("whoami");

            bash.Start();
            var result = bash.WaitForExit();

            return(result.LastOutput);
        }
        public static async Task <string> WhoAmIAsync()
        {
            var bash = new Bash("whoami");

            bash.Start();
            var result = await bash.WaitForExitAsync();

            return(result.LastOutput);
        }
        public static async Task <bool> IsSudoPasswordAsync(string password)
        {
            await ExecuteAsync("sudo -k");

            var bash = new Bash("whoami", password: password);

            bash.Start();
            var result = await bash.WaitForExitAsync();

            return(result.LastOutput == "root");
        }
        public static bool IsSudoPassword(string password)
        {
            Execute("sudo -k");

            var bash = new Bash("whoami", password: password);

            bash.Start();
            var result = bash.WaitForExit();

            return(result.LastOutput == "root");
        }
 public static async Task <CommandResult> ApplyAsync(string password)
 {
     return(await Bash.ExecuteAsync("netplan apply", password));
 }
Example #11
0
        /// <summary>
        /// ls /sys/class/net -1"
        /// </summary>
        /// <returns></returns>
        ///
        public static List <string> GetNetworkCards()
        {
            var result = Bash.Execute("ls /sys/class/net -1");

            return(result.OutputList);
        }
Example #12
0
        /// <summary>
        /// ls /sys/class/net -1"
        /// </summary>
        /// <returns></returns>
        ///
        public static async Task <List <string> > GetNetworkCardsAsync()
        {
            var result = await Bash.ExecuteAsync("ls /sys/class/net -1");

            return(result.OutputList);
        }