Exemplo n.º 1
0
        public IEnumerable <SystemComponentModel> GetSystemComponentModels()
        {
            var repoSystem = Parameter.RepoSystem;
            var actives    = Directory.EnumerateFileSystemEntries(repoSystem).Where(_ => _.Contains("active-")).ToList();
            var repoKernel = Parameter.RepoKernel;

            actives.AddRange(Directory.EnumerateFileSystemEntries(repoKernel).Where(_ => _.Contains("active-")).ToList());
            var components = new List <SystemComponentModel>();
            var losetup    = GetLosetup().ToList();

            foreach (var file in actives)
            {
                var alias    = file.SplitToList("-").LastOrDefault();
                var dir      = file.SplitToList("active-").LastOrDefault();
                var active   = Bash.Execute($"file {file}").SplitToList("symbolic link to ").LastOrDefault();
                var recovery = Bash.Execute($"file {file.Replace("active", "recovery")}").SplitToList(":").LastOrDefault()?.Replace("symbolic link to", "");
                var hash     = File.Exists(dir + "/" + active) ? GetFileHash(dir + "/" + active) : "";
                var running  = losetup.Any(_ => _.Hash == hash && _.Backfile == dir + "/" + active) ? "1" : "0";
                var comp     = new SystemComponentModel {
                    Alias    = alias,
                    Active   = active,
                    Recovery = recovery,
                    Running  = running
                };
                components.Add(comp);
            }
            return(components);
        }
Exemplo n.º 2
0
        private static IEnumerable <SystemComponentModel> GetActiveSystemComponents()
        {
            var list           = new List <SystemComponentModel>();
            var activeLinkData = Terminal.Terminal.Execute($"find {Parameter.Repo} -type l | grep active");

            ConsoleLogger.Warn(activeLinkData);
            var activeLinks = activeLinkData.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries).ToArray();

            foreach (var link in activeLinks)
            {
                ConsoleLogger.Warn(link);
                var linkInfoData = Terminal.Terminal.Execute($"file {link}");
                ConsoleLogger.Warn(linkInfoData);
                var linkInfos = linkInfoData.Split(new[] { ":" }, StringSplitOptions.RemoveEmptyEntries).ToArray();
                var sc        = new SystemComponentModel()
                {
                    active = linkInfos[0].Replace(":", "").Trim(),
                    link   = linkInfos[1].Replace("symbolic link to", "").Trim()
                };
                list.Add(sc);
            }
            return(list);
        }