Esempio n. 1
0
        public static Linux DetectAndCreate(Context context)
        {
            string name;
            string release;
            string codeName;
            string progPath;

            if (Directory.Exists("/app"))
            {
                name     = "Flatpak";
                release  = GetFlatpakRelease();
                codeName = String.Empty;
            }
            else
            {
                if (File.Exists(DefaultLsbReleasePath))
                {
                    progPath = DefaultLsbReleasePath;
                }
                else
                {
                    progPath = FindProgram("lsb_release", GetPathDirectories());
                }

                if (String.IsNullOrEmpty(progPath) || !IsExecutable(progPath, true))
                {
                    throw new InvalidOperationException("Your Linux distribution lacks a working `lsb_release` command");
                }

                name     = Utilities.GetStringFromStdout(progPath, "-is");
                release  = Utilities.GetStringFromStdout(progPath, "-rs");
                codeName = Utilities.GetStringFromStdout(progPath, "-cs");
            }

            Func <Context, Linux> creator;

            if (!distroMap.TryGetValue(name, out creator))
            {
                throw new InvalidOperationException($"Your Linux distribution ({name} {release}) is not supported at this time.");
            }

            Linux linux = creator(context);

            linux.Name       = name;
            linux.Release    = release;
            linux.warnBinFmt = ShouldWarnAboutBinfmt();
            linux.codeName   = codeName;

            Log.Instance.Todo("Check Mono version and error out if not the required minimum version");
            return(linux);
        }
Esempio n. 2
0
        public static Linux DetectAndCreate(Context context)
        {
            string name     = String.Empty;
            string release  = String.Empty;
            string codeName = String.Empty;
            string idLike   = String.Empty;
            string id       = String.Empty;
            bool   detected = DetectFlatpak(ref name, ref release, ref codeName, ref idLike, ref id);

            if (!detected)
            {
                detected = DetectOsRelease(ref name, ref release, ref codeName, ref idLike, ref id);
            }
            ;
            if (!detected)
            {
                detected = DetectLsbRelease(ref name, ref release, ref codeName, ref idLike, ref id);
            }

            if (!detected)
            {
                throw new InvalidOperationException("Unable to detect your Linux distribution");
            }

            bool   usingBaseDistro = false;
            string distro          = String.Empty;

            detected = MapDistro(id, ref distro);
            if (!detected)
            {
                usingBaseDistro = detected = MapDistro(idLike, ref distro);
            }

            if (!detected)
            {
                var list = new List <string> ();

                if (!String.IsNullOrEmpty(name))
                {
                    list.Add($"name: ${name}");
                }
                if (!String.IsNullOrEmpty(release))
                {
                    list.Add($"release: ${release}");
                }
                if (!String.IsNullOrEmpty(codeName))
                {
                    list.Add($"codename: ${codeName}");
                }
                if (!String.IsNullOrEmpty(id))
                {
                    list.Add($"id: ${id}");
                }
                if (!String.IsNullOrEmpty(idLike))
                {
                    list.Add($"id like: ${idLike}");
                }

                string info;
                if (list.Count > 0)
                {
                    string infoText = String.Join("; ", list);
                    info = $" Additional info: {infoText}";
                }
                else
                {
                    info = String.Empty;
                }

                throw new InvalidOperationException($"Failed to detect your Linux distribution.{info}");
            }

            if (usingBaseDistro)
            {
                Log.Instance.InfoLine($"Distribution supported via its base distribution: {idLike}");
            }

            Func <Context, Linux> creator;

            if (!distroMap.TryGetValue(distro, out creator))
            {
                throw new InvalidOperationException($"Your Linux distribution ({name} {release}) is not supported at this time.");
            }

            Linux linux = creator(context);

            linux.Name       = name;
            linux.Release    = release;
            linux.warnBinFmt = ShouldWarnAboutBinfmt();
            linux.codeName   = codeName;
            linux.derived    = usingBaseDistro;

            return(linux);
        }