help-cfengine
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Mandrake support


From: Chip Seraphine
Subject: Mandrake support
Date: Mon, 14 Jun 2004 10:43:21 -0500
User-agent: KMail/1.5.4

Cfengine does not properly define Mandrake and Mandrake_Maj_Min classes
for Mandrake 9.2 and 10.0 (and possibly others, haven't tested).  This
patch corrects this.  (Did I make the cutoff for 2.1.7?)

--- /home/titan/chip/src/cfengine-2.1.6-pristine/src/prototypes.h       
2004-04-20 00:40:05.000000000 -0500
+++ /home/titan/chip/src/cfengine-2.1.6.Mandrake/src/prototypes.h       
2004-06-14 10:10:23.000000000 -0500
@@ -706,6 +706,7 @@

 int linux_fedora_version ARGLIST((void));
 int linux_redhat_version ARGLIST((void));
+int linux_mandrake_version ARGLIST((void));
 int linux_suse_version ARGLIST((void));
 int debian_version ARGLIST((void));
 char * UnQuote ARGLIST((char *name));


--- /home/titan/chip/src/cfengine-2.1.6-pristine/src/misc.c     2004-04-29 
16:35:59.000000000 -0500
+++ /home/titan/chip/src/cfengine-2.1.6.Mandrake/src/misc.c     2004-06-14 
10:34:01.000000000 -0500
@@ -811,7 +811,16 @@
       }
    }

-if (stat("/etc/redhat-release",&statbuf) != -1)
+if (stat("/etc/mandrake-release",&statbuf) != -1)
+   {
+   Verbose("This appears to be a mandrake system.\n");
+   AddClassToHeap("Mandrake");
+   linux_mandrake_version();
+   }
+/* Mandrake has a symlink at /etc/redhat-release pointing to
+ * /etc/mandrake-release, so we else-if around that
+ */
+else if (stat("/etc/redhat-release",&statbuf) != -1)
    {
    Verbose("This appears to be a redhat system.\n");
    AddClassToHeap("redhat");
@@ -981,7 +990,7 @@
  fgets(relstring, sizeof(relstring), fp);
  fclose(fp);

- Verbose("Looking for redhat linux info...\n");
+ Verbose("Looking for redhat linux info in \"%s\"\n",relstring);

  /* First, try to grok the vendor and the edition (if any) */
  if(!strncmp(relstring, REDHAT_ES_ID, strlen(REDHAT_ES_ID)))
@@ -1177,3 +1186,101 @@
 return 0;
 }

+/******************************************************************/
+
+int linux_mandrake_version(void)
+{
+
+/* We are looking for one of the following strings... */
+#define MANDRAKE_ID "Linux Mandrake"
+#define MANDRAKE_REV_ID "Mandrake Linux"
+
+#define RELEASE_FLAG "release "
+#define MANDRAKE_REL_FILENAME "/etc/mandrake-release"
+
+FILE *fp;
+
+/* The full string read in from mandrake-release */
+char relstring[CF_MAXVARSIZE];
+char classbuf[CF_MAXVARSIZE];
+
+/* I've never seen Mandrake-Move or the other 'editions', so
+   I'm not going to try and support them here.  Contributions welcome. */
+
+/* Where the numerical release will be found */
+char *release=NULL;
+char *vendor=NULL;
+int major = -1;
+char strmajor[CF_MAXVARSIZE];
+int minor = -1;
+char strminor[CF_MAXVARSIZE];
+
+/* Grab the first line from the file and then close it. */
+ if ((fp = fopen(MANDRAKE_REL_FILENAME,"r")) == NULL)
+    {
+    return 1;
+    }
+ fgets(relstring, sizeof(relstring), fp);
+ fclose(fp);
+
+ Verbose("Looking for Mandrake linux info in \"%s\"\n",relstring);
+
+  /* Older Mandrakes had the 'Mandrake Linux' string in reverse order */
+ if(!strncmp(relstring, MANDRAKE_ID, strlen(MANDRAKE_ID)))
+    {
+    vendor = "mandrake";
+    }
+ else if(!strncmp(relstring, MANDRAKE_REV_ID, strlen(MANDRAKE_REV_ID)))
+    {
+    vendor = "mandrake";
+    }
+ else
+    {
+    Verbose("Could not identify OS distro from %s\n", MANDRAKE_REL_FILENAME);
+    return 2;
+    }
+
+ /* Now, grok the release. We assume that all the strings will
+  * have the word 'release' before the numerical release.
+  */
+ release = strstr(relstring, RELEASE_FLAG);
+ if(release == NULL)
+    {
+    Verbose("Could not find a numeric OS release in %s\n",
+     MANDRAKE_REL_FILENAME);
+    return 2;
+    }
+ else
+    {
+    release += strlen(RELEASE_FLAG);
+    if (sscanf(release, "%d.%d", &major, &minor) == 2)
+       {
+       sprintf(strmajor, "%d", major);
+       sprintf(strminor, "%d", minor);
+       }
+    else
+       {
+       Verbose("Could not break down release version numbers in %s\n",
+       MANDRAKE_REL_FILENAME);
+       };
+    }
+
+ if (major != -1 && minor != -1 && vendor != "")
+    {
+    classbuf[0] = '\0';
+    strcat(classbuf, vendor);
+    AddClassToHeap(classbuf);
+    strcat(classbuf, "_");
+    strcat(classbuf, strmajor);
+    AddClassToHeap(classbuf);
+    if (minor != -2)
+       {
+       strcat(classbuf, "_");
+       strcat(classbuf, strminor);
+       AddClassToHeap(classbuf);
+       }
+    }
+ return 0;
+}
+
+/******************************************************************/





-- 

Chip Seraphine
Unix Administrator
TradeLink, LLC
312-264-2048
address@hidden





reply via email to

[Prev in Thread] Current Thread [Next in Thread]