| 1 |
/*
|
| 2 |
Magpie - reference librarian for Debian systems
|
| 3 |
Copyright (C) 2000 Bear Giles <bgiles@coyotesong.com>
|
| 4 |
|
| 5 |
This program is free software; you may redistribute it and/or
|
| 6 |
modify it under the terms of the GNU General Public License
|
| 7 |
as published by the Free Software Foundation; either version 2
|
| 8 |
of the license, or (at your option) any later version.
|
| 9 |
|
| 10 |
This program is distributed in the hope that it will be useful,
|
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
GNU General Public License for more details.
|
| 14 |
|
| 15 |
You should have received a copy of the GNU General Public License
|
| 16 |
along with this program; if not, write to the Free Software
|
| 17 |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
| 18 |
*/
|
| 19 |
|
| 20 |
static const char rcsid[] = "$Id: magpie.c,v 1.4 2003/08/31 16:00:34 djpig-guest Exp $";
|
| 21 |
|
| 22 |
/*****
|
| 23 |
This program generates a series of cross-referenced HTML pages
|
| 24 |
based on the content of the apt and dpkg caches.
|
| 25 |
|
| 26 |
This software contains tags recognized by cxref(1).
|
| 27 |
*****/
|
| 28 |
#include <assert.h>
|
| 29 |
#include <stdio.h>
|
| 30 |
#include <string.h>
|
| 31 |
#include <unistd.h>
|
| 32 |
#include <stdlib.h>
|
| 33 |
#include <locale.h>
|
| 34 |
#include <time.h>
|
| 35 |
#include <errno.h>
|
| 36 |
#include <sys/types.h>
|
| 37 |
#include <sys/wait.h>
|
| 38 |
#include <pwd.h>
|
| 39 |
#include <grp.h>
|
| 40 |
#include "magpie.h"
|
| 41 |
|
| 42 |
char timestamp[30];
|
| 43 |
char *compress_ext = ".gz";
|
| 44 |
tOptions magpieOptions;
|
| 45 |
|
| 46 |
extern int mkdir (const char *, mode_t);
|
| 47 |
|
| 48 |
/*+
|
| 49 |
For now, we hard-link our modules.
|
| 50 |
+*/
|
| 51 |
extern struct magpie_module mod_html;
|
| 52 |
extern struct magpie_module mod_debian;
|
| 53 |
extern struct magpie_module mod_core;
|
| 54 |
extern struct magpie_module mod_xml;
|
| 55 |
extern struct magpie_module mod_docbook;
|
| 56 |
extern struct magpie_module mod_debiandoc;
|
| 57 |
extern struct magpie_module mod_texinfo;
|
| 58 |
|
| 59 |
extern struct magpie_module mod_sections;
|
| 60 |
extern struct magpie_module mod_priorities;
|
| 61 |
extern struct magpie_module mod_keywords;
|
| 62 |
extern struct magpie_module mod_installed;
|
| 63 |
extern struct magpie_module mod_tasks;
|
| 64 |
extern struct magpie_module mod_names;
|
| 65 |
extern struct magpie_module mod_maintainers;
|
| 66 |
extern struct magpie_module mod_sources;
|
| 67 |
extern struct magpie_module mod_sizes;
|
| 68 |
extern struct magpie_module mod_installed_sizes;
|
| 69 |
extern struct magpie_module mod_md5sums;
|
| 70 |
extern struct magpie_module mod_conffiles;
|
| 71 |
|
| 72 |
struct magpie_module *modules[] = {
|
| 73 |
|
| 74 |
&mod_html, /* produce HTML output */
|
| 75 |
&mod_debian, /* read Debian database files */
|
| 76 |
&mod_core, /* generate reference material, 'current' format */
|
| 77 |
// &mod_xml, /* generate reference material, XML format */
|
| 78 |
&mod_docbook, /* generate reference material, docbook format */
|
| 79 |
// &mod_debiandoc, /* generate reference material, debiandoc format */
|
| 80 |
// &mod_texinfo, /* generate reference material, texinfo format */
|
| 81 |
|
| 82 |
#if 1
|
| 83 |
&mod_sections,
|
| 84 |
&mod_priorities,
|
| 85 |
&mod_keywords,
|
| 86 |
&mod_installed,
|
| 87 |
&mod_tasks, /* TODO: task packages are obsolete */
|
| 88 |
&mod_names,
|
| 89 |
&mod_maintainers,
|
| 90 |
&mod_sources,
|
| 91 |
&mod_sizes,
|
| 92 |
&mod_installed_sizes,
|
| 93 |
&mod_md5sums,
|
| 94 |
&mod_conffiles,
|
| 95 |
#endif
|
| 96 |
NULL
|
| 97 |
};
|
| 98 |
|
| 99 |
extern int rmrf (const char *);
|
| 100 |
|
| 101 |
#define ARGC_MIN 0
|
| 102 |
#define ARGC_MAX 0
|
| 103 |
/*+
|
| 104 |
The main procedure.
|
| 105 |
+*/
|
| 106 |
int main (int argc, char *argv[])
|
| 107 |
{
|
| 108 |
FILE *fp;
|
| 109 |
char pathname[256], buffer[256];
|
| 110 |
static const char prefix[] = "/var/cache/magpie";
|
| 111 |
time_t now;
|
| 112 |
char user[] = "magpie";
|
| 113 |
char group[] = "magpie";
|
| 114 |
uid_t uid;
|
| 115 |
// gid_t gid;
|
| 116 |
struct passwd *pw;
|
| 117 |
struct group *gr;
|
| 118 |
struct magpie_module **m;
|
| 119 |
|
| 120 |
{
|
| 121 |
int arg_ct = optionProcess( &magpieOptions, argc, argv );
|
| 122 |
argc -= arg_ct;
|
| 123 |
if ((argc < ARGC_MIN) || (argc > ARGC_MAX)) {
|
| 124 |
fprintf( stderr, "%s ERROR: remaining args (%d) "
|
| 125 |
"out of range\n", magpieOptions.pzProgName,
|
| 126 |
argc );
|
| 127 |
|
| 128 |
USAGE( EXIT_FAILURE );
|
| 129 |
}
|
| 130 |
argv += arg_ct;
|
| 131 |
if (!ENABLED_OPT( COMPRESS_GZIP )) {
|
| 132 |
compress_ext = "";
|
| 133 |
}
|
| 134 |
}
|
| 135 |
|
| 136 |
|
| 137 |
if (mkdir (prefix, 0755) == -1 && errno != EEXIST) {
|
| 138 |
sprintf (buffer, "mkdir (%s)", prefix);
|
| 139 |
perror (buffer);
|
| 140 |
exit (0);
|
| 141 |
}
|
| 142 |
|
| 143 |
if (chdir (prefix) == -1) {
|
| 144 |
sprintf (buffer, "chdir (%s)", prefix);
|
| 145 |
perror (buffer);
|
| 146 |
exit (0);
|
| 147 |
}
|
| 148 |
|
| 149 |
/* change effective uid to 'magpie' here, if we're running
|
| 150 |
* as root and that user is known. We don't surrender root
|
| 151 |
* privileges since we can use them later.
|
| 152 |
*/
|
| 153 |
uid = getuid();
|
| 154 |
if (uid == 0 && (pw = getpwnam (user)) != NULL) {
|
| 155 |
gr = getgrnam (group);
|
| 156 |
if (gr) {
|
| 157 |
chown (prefix, pw->pw_uid, gr->gr_gid);
|
| 158 |
setgid (gr->gr_gid);
|
| 159 |
}
|
| 160 |
else {
|
| 161 |
chown (prefix, pw->pw_uid, -1);
|
| 162 |
}
|
| 163 |
seteuid (pw->pw_uid);
|
| 164 |
}
|
| 165 |
|
| 166 |
setlocale (LC_ALL, NULL);
|
| 167 |
|
| 168 |
time (&now);
|
| 169 |
strcpy (timestamp, ctime (&now));
|
| 170 |
|
| 171 |
rmrf (prefix);
|
| 172 |
|
| 173 |
printf ("Reading databases..\n");
|
| 174 |
/* read the database(s) */
|
| 175 |
for (m = modules; *m; m++) {
|
| 176 |
printf ("..for %s\n",(*m)->description);
|
| 177 |
if ((*m)->database)
|
| 178 |
(*m)->database ();
|
| 179 |
}
|
| 180 |
|
| 181 |
printf ("Generating reference material..\n");
|
| 182 |
/* generate 'reference' material */
|
| 183 |
for (m = modules; *m; m++) {
|
| 184 |
printf ("..for %s\n",(*m)->description);
|
| 185 |
if ((*m)->init)
|
| 186 |
(*m)->init ();
|
| 187 |
}
|
| 188 |
|
| 189 |
printf ("Creating index.html\n");
|
| 190 |
sprintf (pathname, "./index.html");
|
| 191 |
fp = fopen (pathname, "w");
|
| 192 |
if (fp == NULL) {
|
| 193 |
perror ("fopen (./index.html)");
|
| 194 |
}
|
| 195 |
else {
|
| 196 |
mp_doc_open (fp, "");
|
| 197 |
|
| 198 |
mp_abstract (fp, "\
|
| 199 |
These pages contain information on all packages known to either\n\
|
| 200 |
apt(8) or dpkg(8), with extensive cross-referencing.\n");
|
| 201 |
|
| 202 |
mp_title (fp, 2, "Annotated Indexes, All Packages");
|
| 203 |
for (m = modules; *m; m++) {
|
| 204 |
if ((*m)->annotated_index)
|
| 205 |
(*m)->annotated_index (fp, MAGPIE_ALL_PACKAGES);
|
| 206 |
}
|
| 207 |
|
| 208 |
mp_title (fp, 2, "Annotated Indexes, Installed Packages");
|
| 209 |
for (m = modules; *m; m++) {
|
| 210 |
if ((*m)->annotated_index)
|
| 211 |
(*m)->annotated_index (fp, MAGPIE_INSTALLED_PACKAGES);
|
| 212 |
}
|
| 213 |
|
| 214 |
mp_title (fp, 2, "Unannotated Indexes, All Packages");
|
| 215 |
mp_list_open (fp);
|
| 216 |
for (m = modules; *m; m++) {
|
| 217 |
if ((*m)->unannotated_index)
|
| 218 |
(*m)->unannotated_index (fp, MAGPIE_ALL_PACKAGES);
|
| 219 |
}
|
| 220 |
mp_list_close (fp);
|
| 221 |
|
| 222 |
mp_title (fp, 2, "Unannotated Indexes, Installed Packages");
|
| 223 |
mp_list_open (fp);
|
| 224 |
for (m = modules; *m; m++) {
|
| 225 |
if ((*m)->unannotated_index)
|
| 226 |
(*m)->unannotated_index (fp, MAGPIE_INSTALLED_PACKAGES);
|
| 227 |
}
|
| 228 |
mp_list_close (fp);
|
| 229 |
|
| 230 |
mp_title (fp, 2, "Miscellaneous Material");
|
| 231 |
mp_list_open (fp);
|
| 232 |
for (m = modules; *m; m++) {
|
| 233 |
if ((*m)->miscellaneous)
|
| 234 |
(*m)->miscellaneous (fp);
|
| 235 |
}
|
| 236 |
mp_list_close (fp);
|
| 237 |
|
| 238 |
mp_doc_close (fp);
|
| 239 |
fclose (fp);
|
| 240 |
}
|
| 241 |
|
| 242 |
for (m = modules; *m; m++) {
|
| 243 |
if ((*m)->cleanup)
|
| 244 |
(*m)->cleanup ();
|
| 245 |
}
|
| 246 |
printf ("Finished. Check %s/index.html\n", prefix);
|
| 247 |
|
| 248 |
return 0;
|
| 249 |
}
|