specific support for Linux, notably Ubuntu/Debian;
authorwenzelm
Tue, 29 Oct 2019 18:08:24 +0100
changeset 70965 fe9496df6298
parent 70964 99eec58dc551
child 70966 acc3bac0d7c5
specific support for Linux, notably Ubuntu/Debian;
src/Pure/System/linux.scala
src/Pure/build-jars
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Pure/System/linux.scala	Tue Oct 29 18:08:24 2019 +0100
@@ -0,0 +1,49 @@
+/*  Title:      Pure/System/linux.scala
+    Author:     Makarius
+
+Specific support for Linux, notably Ubuntu/Debian.
+*/
+
+package isabelle
+
+
+import scala.util.matching.Regex
+
+
+object Linux
+{
+  /* check system */
+
+  def check_system(): Unit =
+    if (!Platform.is_linux) error("Not a Linux system")
+
+  def check_system_root(): Unit =
+  {
+    check_system()
+    if (Isabelle_System.bash("id -u").check.out != "0") error("Not running as superuser (root)")
+  }
+
+
+  /* release */
+
+  object Release
+  {
+    private val ID = """^Distributor ID:\s*(\S.*)$""".r
+    private val RELEASE = """^Release:\s*(\S.*)$""".r
+    private val DESCRIPTION = """^Description:\s*(\S.*)$""".r
+
+    def apply(): Release =
+    {
+      val lines = Isabelle_System.bash("lsb_release -a").check.out_lines
+      def find(R: Regex): String = lines.collectFirst({ case R(a) => a }).getOrElse("Unknown")
+      new Release(find(ID), find(RELEASE), find(DESCRIPTION))
+    }
+  }
+
+  final class Release private(val id: String, val release: String, val description: String)
+  {
+    override def toString: String = description
+
+    def is_ubuntu: Boolean = id == "Ubuntu"
+  }
+}
--- a/src/Pure/build-jars	Mon Oct 28 20:51:38 2019 +0100
+++ b/src/Pure/build-jars	Tue Oct 29 18:08:24 2019 +0100
@@ -125,6 +125,7 @@
   System/isabelle_process.scala
   System/isabelle_system.scala
   System/isabelle_tool.scala
+  System/linux.scala
   System/numa.scala
   System/options.scala
   System/platform.scala