5
* Copyright 2016 Tony George <teejee2008@gmail.com>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26
using TeeJee.FileSystem;
27
using TeeJee.ProcessHelper;
29
public class LinuxDistro : GLib.Object{
31
/* Class for storing information about Linux distribution */
33
public string dist_id = "";
34
public string description = "";
35
public string release = "";
36
public string codename = "";
45
public string full_name(){
52
val += (release.length > 0) ? " " + release : "";
53
val += (codename.length > 0) ? " (" + codename + ")" : "";
58
public static LinuxDistro get_dist_info(string root_path){
60
/* Returns information about the Linux distribution
61
* installed at the given root path */
63
LinuxDistro info = new LinuxDistro();
65
string dist_file = root_path + "/etc/lsb-release";
66
var f = File.new_for_path(dist_file);
67
if (f.query_exists()){
72
DISTRIB_CODENAME=raring
73
DISTRIB_DESCRIPTION="Ubuntu 13.04"
76
foreach(string line in file_read(dist_file).split("\n")){
78
if (line.split("=").length != 2){ continue; }
80
string key = line.split("=")[0].strip();
81
string val = line.split("=")[1].strip();
83
if (val.has_prefix("\"")){
84
val = val[1:val.length];
87
if (val.has_suffix("\"")){
88
val = val[0:val.length-1];
95
case "DISTRIB_RELEASE":
98
case "DISTRIB_CODENAME":
101
case "DISTRIB_DESCRIPTION":
102
info.description = val;
109
dist_file = root_path + "/etc/os-release";
110
f = File.new_for_path(dist_file);
111
if (f.query_exists()){
115
VERSION="13.04, Raring Ringtail"
118
PRETTY_NAME="Ubuntu 13.04"
120
HOME_URL="http://www.ubuntu.com/"
121
SUPPORT_URL="http://help.ubuntu.com/"
122
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
125
foreach(string line in file_read(dist_file).split("\n")){
127
if (line.split("=").length != 2){ continue; }
129
string key = line.split("=")[0].strip();
130
string val = line.split("=")[1].strip();
139
//case "DISTRIB_CODENAME":
140
//info.codename = val;
143
info.description = val;
153
public static string get_running_desktop_name(){
155
/* Return the names of the current Desktop environment */
159
pid = get_pid_by_name("cinnamon");
164
pid = get_pid_by_name("xfdesktop");
169
pid = get_pid_by_name("lxsession");
174
pid = get_pid_by_name("gnome-shell");
179
pid = get_pid_by_name("wingpanel");
184
pid = get_pid_by_name("unity-panel-service");
189
pid = get_pid_by_name("plasma-desktop");