Skip to content
API Documentation
BastionGuard™
LinuxDistro Class Reference
Inheritance diagram for LinuxDistro:

Public Member Functions

 LinuxDistro ()
string full_name ()

Static Public Member Functions

static LinuxDistro get_dist_info (string root_path)

Public Attributes

string dist_id = ""
string description = ""
string release = ""
string codename = ""

Properties

string dist_type [get]

Static Private Member Functions

static ? LinuxDistro read_info_file (string file_path)

Detailed Description

Definition at line 29 of file LinuxDistro.vala.

Constructor & Destructor Documentation

◆ LinuxDistro()

LinuxDistro.LinuxDistro ( )
inline

Definition at line 38 of file LinuxDistro.vala.

38 {
39 dist_id = "";
40 description = "";
41 release = "";
42 codename = "";
43 }
string codename
string description

References codename, description, dist_id, and release.

Referenced by get_dist_info(), and read_info_file().

Member Function Documentation

◆ full_name()

string LinuxDistro.full_name ( )
inline

Definition at line 45 of file LinuxDistro.vala.

45 {
46
47 if (dist_id == ""){
48 return "";
49 }
50 else{
51 string val = "";
52 val += dist_id;
53 val += (release.length > 0) ? " " + release : "";
54 val += (codename.length > 0) ? " (" + codename + ")" : "";
55 return val;
56 }
57 }

References codename, dist_id, and release.

Referenced by Main.create_snapshot_with_btrfs(), Main.create_snapshot_with_rsync(), and Main.Main().

◆ get_dist_info()

LinuxDistro LinuxDistro.get_dist_info ( string root_path)
inlinestatic

Definition at line 59 of file LinuxDistro.vala.

59 {
60
61 /* Returns information about the Linux distribution
62 * installed at the given root path */
63
64
65 /*
66 try to read from /etc/lsb-release
67 example content:
68
69 DISTRIB_ID=Ubuntu
70 DISTRIB_RELEASE=13.04
71 DISTRIB_CODENAME=raring
72 DISTRIB_DESCRIPTION="Ubuntu 13.04"
73 */
74 LinuxDistro? info = read_info_file(root_path + "/etc/lsb-release");
75 if(info != null) {
76 return info;
77 }
78
79 /*
80 fallback to /etc/os-release
81 example content:
82
83 NAME="Ubuntu"
84 VERSION="13.04, Raring Ringtail"
85 ID=ubuntu
86 ID_LIKE=debian
87 PRETTY_NAME="Ubuntu 13.04"
88 VERSION_ID="13.04"
89 HOME_URL="http://www.ubuntu.com/"
90 SUPPORT_URL="http://help.ubuntu.com/"
91 BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
92 */
93 return read_info_file(root_path + "/etc/os-release") ?? new LinuxDistro();
94 }
static ? LinuxDistro read_info_file(string file_path)

References LinuxDistro(), and read_info_file().

Referenced by Main.create_pre_restore_snapshot_btrfs(), Main.create_restore_scripts(), Main.Main(), and Snapshot.read_control_file().

◆ read_info_file()

? LinuxDistro LinuxDistro.read_info_file ( string file_path)
inlinestaticprivate

Definition at line 97 of file LinuxDistro.vala.

97 {
98 string dist_file_cont;
99 try {
100 GLib.FileUtils.get_contents(file_path, out dist_file_cont);
101 } catch (Error e) {
102 return null;
103 }
104
105 if(dist_file_cont.length == 0) {
106 return null;
107 }
108
109 LinuxDistro info = new LinuxDistro();
110 string[] lines = dist_file_cont.split("\n");
111
112 foreach(string line in lines){
113 // split for 3 to detect if there are to many
114 string[] linesplit = line.split("=", 3);
115
116 if (linesplit.length != 2){ continue; }
117
118 string key = linesplit[0].strip();
119 string val = linesplit[1].strip();
120
121 // removing leading "
122 if (val.has_prefix("\"")) {
123 val = val[1:val.length];
124 }
125
126 // remove trailing "
127 if (val.has_suffix("\"")) {
128 val = val[0:val.length-1];
129 }
130
131 switch (key) {
132 case "ID":
133 case "DISTRIB_ID":
134 info.dist_id = val;
135 break;
136 case "VERSION_ID":
137 case "DISTRIB_RELEASE":
138 info.release = val;
139 break;
140 case "VERSION_CODENAME":
141 case "DISTRIB_CODENAME":
142 info.codename = val;
143 break;
144 case "PRETTY_NAME":
145 case "DISTRIB_DESCRIPTION":
146 info.description = val;
147 break;
148 }
149 }
150 return info;
151 }

References Error, and LinuxDistro().

Referenced by get_dist_info().

Member Data Documentation

◆ codename

string LinuxDistro.codename = ""

Definition at line 36 of file LinuxDistro.vala.

Referenced by full_name(), and LinuxDistro().

◆ description

string LinuxDistro.description = ""

Definition at line 34 of file LinuxDistro.vala.

Referenced by LinuxDistro().

◆ dist_id

string LinuxDistro.dist_id = ""

◆ release

string LinuxDistro.release = ""

Definition at line 35 of file LinuxDistro.vala.

Referenced by full_name(), and LinuxDistro().

Property Documentation

◆ dist_type

string LinuxDistro.dist_type
get

Definition at line 153 of file LinuxDistro.vala.

153 {
154
155 owned get{
156
157 if (dist_id.down() in "fedora rhel rocky centos almalinux"){
158 return "redhat";
159 }
160 else if (dist_id.down().contains("manjaro") || dist_id.down().contains("arch")){
161 return "arch";
162 }
163 else if (dist_id.down().contains("ubuntu") || dist_id.down().contains("debian")){
164 return "debian";
165 }
166 else{
167 return "";
168 }
169
170 }
171 }

The documentation for this class was generated from the following file: