summaryrefslogtreecommitdiff
path: root/libyelp/yelp-settings.c
diff options
context:
space:
mode:
authorShaun McCance <shaunm@redhat.com>2015-05-06 20:06:12 -0400
committerShaun McCance <shaunm@redhat.com>2015-05-06 20:07:29 -0400
commit176c25f6d7ab44df3a683c330857a396f2da89d0 (patch)
treeb995a924d87a6f512034652be96fae38b25e224d /libyelp/yelp-settings.c
parent00831188f1f2f7d6763f298992185e3953775ef3 (diff)
downloadyelp-176c25f6d7ab44df3a683c330857a396f2da89d0.tar.gz
yelp-settings: Set platform conditional tokens from os-release
Diffstat (limited to 'libyelp/yelp-settings.c')
-rw-r--r--libyelp/yelp-settings.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/libyelp/yelp-settings.c b/libyelp/yelp-settings.c
index 866cb1d7..adb45c11 100644
--- a/libyelp/yelp-settings.c
+++ b/libyelp/yelp-settings.c
@@ -243,6 +243,7 @@ yelp_settings_constructed (GObject *object)
GVariantIter iter;
gchar *name;
gboolean env_shell, env_classic, env_panel, env_unity, env_xfce;
+ gchar *os_release = NULL;
GError *error = NULL;
connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
@@ -324,6 +325,65 @@ yelp_settings_constructed (GObject *object)
else if (env_panel)
yelp_settings_set_if_token (settings, "platform:gnome-panel");
+ g_file_get_contents ("/etc/os-release", &os_release, NULL, NULL);
+ if (os_release == NULL)
+ g_file_get_contents ("/usr/lib/os-release", &os_release, NULL, NULL);
+
+ if (os_release != NULL) {
+ gint i;
+ gchar **lines = g_strsplit(os_release, "\n", -1);
+ gchar *osid = NULL, *osversion = NULL, *end;
+ g_free (os_release);
+
+ for (i = 0; lines[i] != NULL; i++) {
+ if (g_str_has_prefix (lines[i], "ID=")) {
+ if (lines[i][3] == '"') {
+ end = strchr (lines[i] + 4, '"');
+ if (end != NULL)
+ osid = g_strndup (lines[i] + 4, end - lines[i] - 4);
+ }
+ else if (lines[i][3] == '\'') {
+ end = strchr (lines[i] + 4, '\'');
+ if (end != NULL)
+ osid = g_strndup (lines[i] + 4, end - lines[i] - 4);
+ }
+ else {
+ osid = g_strdup (lines[i] + 3);
+ }
+ }
+ else if (g_str_has_prefix (lines[i], "VERSION_ID=")) {
+ if (lines[i][11] == '"') {
+ end = strchr (lines[i] + 12, '"');
+ if (end != NULL)
+ osversion = g_strndup (lines[i] + 12, end - lines[i] - 12);
+ }
+ else if (lines[i][11] == '\'') {
+ end = strchr (lines[i] + 12, '\'');
+ if (end != NULL)
+ osversion = g_strndup (lines[i] + 12, end - lines[i] - 12);
+ }
+ else {
+ osversion = g_strdup (lines[i] + 11);
+ }
+ }
+ }
+
+ if (osid) {
+ gchar *token = g_strconcat("platform:", osid, NULL);
+ yelp_settings_set_if_token (settings, token);
+ g_free (token);
+ if (osversion) {
+ token = g_strconcat("platform:", osid, "-", osversion, NULL);
+ yelp_settings_set_if_token (settings, token);
+ g_free (token);
+ g_free (osversion);
+ }
+ g_free (osid);
+ }
+
+ g_strfreev(lines);
+ }
+
yelp_settings_set_if_token (settings, "action:install");
}