Hi,
I wrote this function It's not beauty!!! but it can work on most conditions, of course not all. Add it or improve it please. Hope that we can write something useful, other can use and enjoy
( I categorized Linux distributions (as my need) in: REDHAT, SUSE and DEBIAN based )
Code:
int DistroName()
{
//0 redhat, 1 suse, 2 debian, 3 NONE
system("cat /etc/issue > .distro");
FILE* fp=NULL;
fp=fopen(".distro","r");
char distro[100];
fscanf(fp,"%s",distro);
int i=0;
for(i=0;distro[i]!='\0';i++)
distro[i]=tolower(distro[i]);
fclose(fp);
if( access("/etc/redhat-release",F_OK)==0 || strcmp(distro,"redhat")==0 || strcmp(distro,"centos")==0
|| strcmp(distro,"fedora")==0 ) return 0;
else if( access("/etc/suse_release",F_OK)==0 || strcmp(distro,"opensuse")==0 || strcmp(distro,"suse")==0 )
return 1;
else if( access("/etc/debian_version",F_OK)==0 || strcmp(distro,"ubuntu")==0 || strcmp(distro,"debian")==0 )
return 2;
system("lsb_release -si > .distro");
fp=fopen(".distro","r");
fscanf(fp,"%s",distro);
for(i=0;distro[i]!='\0';i++)
distro[i]=tolower(distro[i]);
fclose(fp);
unlink(".distro");
if( strcmp(distro,"centos")==0 || strcmp(distro,"redhat")==0 || strcmp(distro,"fedora")==0 )
return 0;
else if( strcmp(distro,"opensuse")==0 || strcmp(distro,"suse")==0 )
return 1;
else if( strcmp(distro,"ubuntu")==0 || strcmp(distro,"debian")==0 )
return 2;
return 3;
}