]> andersk Git - moira.git/blobdiff - gen/boot.pc
Include CUPS-PRINT servers in generated tftp config files, too.
[moira.git] / gen / boot.pc
index 7c1fe116b6be3a63e7bcb7b28f7dc9c9c71edc46..79f12be66ada0df4459c992b10ce541aa22ed581 100644 (file)
@@ -33,6 +33,7 @@ int main(int argc, char **argv)
 {
   EXEC SQL BEGIN DECLARE SECTION;
   char name[MACHINE_NAME_SIZE], hwaddr[MACHINE_HWADDR_SIZE];
+  char ohwaddr[MACHINE_HWADDR_SIZE], hwtype[PRINTERS_HWTYPE_SIZE];
   char addr[MACHINE_ADDRESS_SIZE], location[PRINTERS_LOCATION_SIZE];
   char contact[PRINTERS_CONTACT_SIZE], logaddr[MACHINE_ADDRESS_SIZE];
   char modtime[PRINTERS_MODTIME_SIZE], type[PRINTERS_TYPE_SIZE];
@@ -57,13 +58,14 @@ int main(int argc, char **argv)
   EXEC SQL WHENEVER SQLERROR DO sqlerr();
 
   /* Get print spoolers for allow lists. */
-  EXEC SQL SELECT COUNT(service) INTO :alcount FROM serverhosts
-    WHERE service = 'PRINT';
+  EXEC SQL SELECT COUNT(service) INTO :alcount FROM serverhosts sh
+    WHERE sh.service = 'PRINT' or sh.service = 'CUPS-PRINT';
   allowlist = malloc(alcount * sizeof(*allowlist));
 
   EXEC SQL DECLARE csr_spool CURSOR FOR
     SELECT m.address, sh.value3 FROM machine m, serverhosts sh
-    WHERE m.mach_id = sh.mach_id AND sh.service = 'PRINT';
+    WHERE m.mach_id = sh.mach_id AND 
+    (sh.service = 'PRINT' OR sh.service = 'CUPS-PRINT');
   EXEC SQL OPEN csr_spool;
   for (i = 0; i < alcount; i++)
     {
@@ -83,30 +85,38 @@ int main(int argc, char **argv)
 
   out = tarfile_start(tf, "/var/boot/bootptab.print", 0755, 0, 0,
                      "root", "root", now);
+  ohwaddr[0] = '\0';
   EXEC SQL DECLARE csr_boot CURSOR FOR
     SELECT LOWER(m.name), m.hwaddr, m.address, m2.address,
-    pr.location, pr.contact
+    pr.location, pr.contact, pr.hwtype
     FROM printers pr, machine m, machine m2
-    WHERE pr.hwtype = 'HP' AND pr.mach_id != 0
+    WHERE pr.type != 'ALIAS' AND pr.mach_id != 0
     AND pr.mach_id = m.mach_id AND pr.loghost = m2.mach_id
-    AND pr.type != 'ALIAS';
+    ORDER BY m.hwaddr;
   EXEC SQL OPEN csr_boot;
   while (1)
     {
       EXEC SQL FETCH csr_boot INTO :name, :hwaddr, :addr, :logaddr,
-       :location, :contact;
+       :location, :contact, :hwtype;
       if (sqlca.sqlcode)
        break;
 
       strtrim(hwaddr);
       if (!*hwaddr || !strcasecmp(hwaddr, "unknown"))
        continue;
+      if (!strcmp(hwaddr, ohwaddr))
+       {
+         fprintf(stderr, "Ignoring duplicate hwaddr %s\n", hwaddr);
+         continue;
+       }
+      strcpy(ohwaddr, hwaddr);
 
       strtrim(name);
       strtrim(addr);
       strtrim(logaddr);
       strtrim(location);
       strtrim(contact);
+      strtrim(hwtype);
       strcpy(shortname, name);
       if ((p = strchr(shortname, '.')))
        *p = '\0';
@@ -121,9 +131,11 @@ int main(int argc, char **argv)
 
       fprintf(out, "# %s: %s\n# contact: %s\n%s:\\\n\t:tc=net%s.global:\\\n"
              "\t:ht=ethernet:\\\n\t:ha=%s:\\\n\t:ip=%s:\\\n"
-             "\t:lg=%s:\\\n\t:T144=\"/hp/%s\":\\\n\t:vm=rfc1048:\n\n",
-             shortname, location, contact, name, net, hwaddr, addr, logaddr,
-             shortname);
+             "\t:lg=%s:\\\n\t:vm=rfc1048:",
+             shortname, location, contact, name, net, hwaddr, addr, logaddr);
+      if (!strncmp(hwtype, "HP", 2))
+       fprintf(out, "\\\n\t:T144=\"/hp/%s\":", shortname);
+      fprintf(out, "\n\n");
     }
   EXEC SQL CLOSE csr_boot;
   tarfile_end(tf);
@@ -133,7 +145,7 @@ int main(int argc, char **argv)
     SELECT LOWER(m.name), m.hwaddr, m2.address, m3.address, pr.type,
     pr.location, pr.contact, TO_CHAR(pr.modtime, :unixtime_fmt)
     FROM printers pr, machine m, machine m2, machine m3
-    WHERE pr.hwtype = 'HP' AND pr.mach_id != 0
+    WHERE pr.hwtype LIKE 'HP%' AND pr.mach_id != 0
     AND pr.mach_id = m.mach_id AND pr.rm = m2.mach_id
     AND pr.loghost = m3.mach_id AND pr.type != 'ALIAS';
   EXEC SQL OPEN csr_boot2;
@@ -158,7 +170,10 @@ int main(int argc, char **argv)
       if ((p = strchr(shortname, '.')))
        *p = '\0';
 
-      sprintf(filename, "/var/boot/hp/%s", shortname);
+      /* We create it as foo.new so boot.sh can append the passwords
+       * and other data and rename it.
+       */
+      sprintf(filename, "/var/boot/hp/%s.new", shortname);
       out = tarfile_start(tf, filename, 0755, 0, 0, "root", "root",
                          unixtime(modtime));
 
This page took 2.031584 seconds and 4 git commands to generate.