Bootstrap of 'captive-install-acquire' for W32 modules acquiration process.
[captive.git] / src / install / acquire / main.c
1 /* $Id$
2  * Drivers acquiring installation utility
3  * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
4  * 
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; exactly version 2 of June 1991 is required
8  * 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  * 
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19
20 #include "config.h"
21
22 #include <glib/gmessages.h>
23 #include <popt.h>
24 #include <locale.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <mntent.h>
28 #include <glib/ghash.h>
29 #include <glib/gstrfuncs.h>
30 #include <sys/stat.h>
31 #include <errno.h>
32 #include <unistd.h>
33 #include <libgnomevfs/gnome-vfs-init.h>
34
35 #include <captive/macros.h>
36
37
38 #include "captivemodid.h"
39 #include <glib/glist.h>
40 #include "moduriload.h"
41 #include "diskscan.h"
42
43
44 int optarg_verbose;
45 static int optarg_scan_disks;
46 static GList *optarg_scan_path_list;    /* of (char *) */
47
48 static void acquire_popt_callback
49                 (poptContext con,enum poptCallbackReason reason,const struct poptOption *opt,const char *arg,const void *data);
50
51 static const struct poptOption popt_table[]={
52                 { argInfo:POPT_ARG_CALLBACK,arg:(void *)acquire_popt_callback },
53
54 #define BUG_ACQUIRE_POPT(shortname,longname,argInfoP,argP,valP,descripP,argDescripP) \
55                 { \
56                         longName: (longname), \
57                         shortName: (shortname), \
58                         argInfo: (argInfoP)|(!(valP) ? 0 : POPT_ARG_VAL), \
59                         arg: (void *)argP, \
60                         val: (valP), \
61                         descrip: (descripP), \
62                         argDescrip: (argDescripP), \
63                 }
64
65                 BUG_ACQUIRE_POPT('v',"verbose"   ,POPT_ARG_NONE  ,&optarg_verbose   ,0,N_("Display additional debug information"),NULL),
66                 BUG_ACQUIRE_POPT(0  ,"scan-disks",POPT_ARG_NONE  ,&optarg_scan_disks,0,N_("Scan all local disks"),NULL),
67                 BUG_ACQUIRE_POPT(0  ,"scan-path" ,POPT_ARG_STRING,NULL              ,0,N_("Scan specified disk path"),N_("path/URI")),
68
69 #undef BUG_ACQUIRE_POPT
70                 POPT_AUTOHELP
71                 POPT_TABLEEND
72                 };
73
74
75 /* poptCallbackType captive_popt_callback */
76 static void acquire_popt_callback
77                 (poptContext con,enum poptCallbackReason reason,const struct poptOption *opt,const char *arg,const void *data)
78 {
79         g_return_if_fail(reason==POPT_CALLBACK_REASON_OPTION);
80
81         if (opt->longName && !strcmp(opt->longName,"scan-path")) {
82                 optarg_scan_path_list=g_list_append(optarg_scan_path_list,gnome_vfs_uri_new(arg));
83                 }
84 }
85
86
87 int main(int argc,char **argv)
88 {
89 poptContext context;
90 int errint;
91 GList *scan_uri_list;
92
93 #ifdef MAINTAINER_MODE
94         g_log_set_always_fatal(~(0
95                         |G_LOG_LEVEL_MESSAGE
96                         |G_LOG_LEVEL_INFO
97                         |G_LOG_LEVEL_DEBUG
98                         ));
99 #endif
100
101         /* Initialize the i18n stuff */
102         setlocale(LC_ALL,"");
103         bindtextdomain(PACKAGE,LOCALEDIR);
104         textdomain(PACKAGE);
105
106         if (!gnome_vfs_init())
107                 g_error(_("GnomeVFS failed to initialize"));
108
109         context=poptGetContext(
110                         PACKAGE,        /* name */
111                         argc,(/*en-const*/const char **)argv,   /* argc,argv */
112                         popt_table,     /* options */
113                         POPT_CONTEXT_POSIXMEHARDER);    /* flags; && !POPT_CONTEXT_KEEP_FIRST */
114         if (context==NULL) {
115                 g_assert_not_reached(); /* argument recognization args_error */
116                 return EXIT_FAILURE;
117                 }
118         errint=poptReadDefaultConfig(context,
119                         TRUE);  /* useEnv */
120         if (errint!=0) {
121                 g_assert_not_reached(); /* argument recognization args_error */
122                 return EXIT_FAILURE;
123                 }
124         errint=poptGetNextOpt(context);
125         if (errint!=-1) {
126                 g_assert_not_reached(); /* some non-callbacked argument reached */
127                 return EXIT_FAILURE;
128                 }
129         if (poptPeekArg(context)) {
130                 g_error(_("No arguments expected"));
131                 return EXIT_FAILURE;
132                 }
133
134         scan_uri_list=NULL;
135         scan_uri_list=g_list_concat(scan_uri_list,gnome_vfs_uri_list_copy(optarg_scan_path_list));
136         if (optarg_scan_disks)
137                 scan_uri_list=g_list_concat(scan_uri_list,mod_uri_list());
138
139         captivemodid_load("./w32-mod-id.captivemodid.xml");
140         g_list_foreach(scan_uri_list,(GFunc)mod_uri_load,NULL);
141
142         gnome_vfs_shutdown();
143
144         return EXIT_SUCCESS;
145 }