1 /* bug-buddy bug submitting program
3 * Copyright (C) Jacob Berkman
5 * Author: Jacob Berkman <jberkman@andrew.cmu.edu>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of version 2 of the GNU General Public
9 * License as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
25 #include <libxml/tree.h>
26 #include <libxml/parser.h>
27 #include "bug-buddy.h"
28 #include "distribution.h"
30 typedef struct _Package Package
;
31 typedef struct _Phylum Phylum
;
32 typedef struct _Distribution Distribution
;
34 typedef char *(*DistroVersionFunc
) (Distribution
*distro
);
37 DistroVersionFunc version
;
41 struct _Distribution
{
47 static char *get_lsb_version (Distribution
*distro
);
48 static char *get_redhat_version (Distribution
*distro
);
49 static char *get_turbolinux_version (Distribution
*distro
);
50 static char *get_debian_version (Distribution
*distro
);
51 static char *get_irix_version (Distribution
*distro
);
61 Phylum turbolinux_phy
= {
62 get_turbolinux_version
73 DistroVersionFunc lsb_ver
= get_lsb_version
;
74 DistroVersionFunc redhat_ver
= get_redhat_version
;
75 DistroVersionFunc turbolinux_ver
= get_turbolinux_version
;
76 DistroVersionFunc debian_ver
= get_debian_version
;
77 DistroVersionFunc irix_ver
= get_irix_version
;
79 static Distribution distros
[] = {
80 { "Slackware", "/etc/slackware-version", &debian_phy
},
81 { "Mandrake", "/etc/mandrake-release", &redhat_phy
},
82 { "TurboLinux", "/etc/turbolinux-release", &turbolinux_phy
},
83 { "SuSE", "/etc/SuSE-release", &redhat_phy
},
84 { "Red Hat", "/etc/redhat-release", &redhat_phy
},
85 { "Frugalware", "/etc/frugalware-release", &redhat_phy
},
86 { "Fedora", "/etc/fedora-release", &redhat_phy
},
87 { "Gentoo", "/etc/gentoo-release", &redhat_phy
},
88 { "Solaris", "/etc/release", &redhat_phy
},
89 { "PLD Linux", "/etc/pld-release", &redhat_phy
},
90 { "LSB Linux", "/etc/lsb-release", &lsb_phy
},
91 { "Debian", "/etc/debian_version", &debian_phy
},
92 { "IRIX Freeware", "/bin/hinv", &irix_phy
},
98 get_lines_from_file (const char *filename
)
103 GError
*error
= NULL
;
105 if (!g_file_get_contents (filename
, &contents
, &length
, &error
)) {
106 g_error_free (error
);
110 lines
= g_strsplit (contents
, "\n", 0);
118 get_lsb_version (Distribution
*distro
)
122 char *release
= NULL
;
123 char *codename
= NULL
;
127 g_return_val_if_fail (distro
, NULL
);
128 g_return_val_if_fail (distro
->version_file
, NULL
);
130 lines
= get_lines_from_file (distro
->version_file
);
131 while (lines
&& lines
[i
]) {
132 if (g_str_has_prefix (lines
[i
], "DISTRIB_ID="))
134 else if (g_str_has_prefix (lines
[i
], "DISTRIB_RELEASE="))
135 release
= lines
[i
] + 16;
136 else if (g_str_has_prefix (lines
[i
], "DISTRIB_CODENAME="))
137 codename
= lines
[i
] + 17;
140 if (id
!= NULL
&& release
!= NULL
&& codename
!= NULL
)
141 name
= g_strdup_printf ("%s %s (%s)", id
, release
, codename
);
151 get_redhat_version (Distribution
*distro
)
156 g_return_val_if_fail (distro
, NULL
);
157 g_return_val_if_fail (distro
->version_file
, NULL
);
159 lines
= get_lines_from_file (distro
->version_file
);
160 if (lines
!= NULL
&& lines
[0] != NULL
)
161 name
= g_strdup (lines
[0]);
169 get_turbolinux_version (Distribution
*distro
)
173 g_return_val_if_fail (distro
, NULL
);
174 g_return_val_if_fail (distro
->version_file
, NULL
);
176 lines
= get_lines_from_file (distro
->version_file
);
177 if (lines
!= NULL
&& lines
[0] != NULL
)
178 name
= g_strdup_printf ("TurboLinux %s", lines
[0]);
187 get_debian_version (Distribution
*distro
)
192 g_return_val_if_fail (distro
, NULL
);
193 g_return_val_if_fail (distro
->version_file
, NULL
);
194 g_return_val_if_fail (distro
->name
, NULL
);
196 lines
= get_lines_from_file (distro
->version_file
);
197 if (lines
!= NULL
&& lines
[0] != NULL
)
198 name
= g_strdup_printf ("%s %s", distro
->name
, lines
[0]);
207 get_irix_version (Distribution
*distro
)
209 g_return_val_if_fail (distro
, NULL
);
210 g_return_val_if_fail (distro
->version_file
, NULL
);
213 return get_line_from_command ("/usr/bin/echo -n SGI `/sbin/uname -Rs | /bin/cut -d' ' -f1,3-`; "
214 "versions -b fw_common | awk 'NR >= 4 { print \", Freeware\",$3 }'");*/
218 get_distro_name_from_file (void)
221 for (i
= 0; distros
[i
].name
; i
++) {
222 if (!g_file_test (distros
[i
].version_file
, G_FILE_TEST_EXISTS
))
224 return distros
[i
].phylum
->version (&distros
[i
]);
230 get_distro_name (void)
234 name
= get_distro_name_from_file ();
236 return g_strdup ("Unknown");