70965
|
1 |
/* Title: Pure/System/linux.scala
|
|
2 |
Author: Makarius
|
|
3 |
|
|
4 |
Specific support for Linux, notably Ubuntu/Debian.
|
|
5 |
*/
|
|
6 |
|
|
7 |
package isabelle
|
|
8 |
|
|
9 |
|
|
10 |
import scala.util.matching.Regex
|
|
11 |
|
|
12 |
|
|
13 |
object Linux
|
|
14 |
{
|
|
15 |
/* check system */
|
|
16 |
|
|
17 |
def check_system(): Unit =
|
|
18 |
if (!Platform.is_linux) error("Not a Linux system")
|
|
19 |
|
|
20 |
def check_system_root(): Unit =
|
|
21 |
{
|
|
22 |
check_system()
|
|
23 |
if (Isabelle_System.bash("id -u").check.out != "0") error("Not running as superuser (root)")
|
|
24 |
}
|
|
25 |
|
|
26 |
|
|
27 |
/* release */
|
|
28 |
|
|
29 |
object Release
|
|
30 |
{
|
|
31 |
private val ID = """^Distributor ID:\s*(\S.*)$""".r
|
|
32 |
private val RELEASE = """^Release:\s*(\S.*)$""".r
|
|
33 |
private val DESCRIPTION = """^Description:\s*(\S.*)$""".r
|
|
34 |
|
|
35 |
def apply(): Release =
|
|
36 |
{
|
|
37 |
val lines = Isabelle_System.bash("lsb_release -a").check.out_lines
|
|
38 |
def find(R: Regex): String = lines.collectFirst({ case R(a) => a }).getOrElse("Unknown")
|
|
39 |
new Release(find(ID), find(RELEASE), find(DESCRIPTION))
|
|
40 |
}
|
|
41 |
}
|
|
42 |
|
|
43 |
final class Release private(val id: String, val release: String, val description: String)
|
|
44 |
{
|
|
45 |
override def toString: String = description
|
|
46 |
|
|
47 |
def is_ubuntu: Boolean = id == "Ubuntu"
|
|
48 |
}
|
|
49 |
}
|