summaryrefslogtreecommitdiff
path: root/components/services/install/command-line/eazel-alt-install-corba.c
blob: 2b4d363e641d22e99e1bc4775b657cc5ee8d95b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* 
 * Copyright (C) 2000 Eazel, Inc
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * Authors: Eskil Heyn Olsen <eskil@eazel.com>
 *
 */

#include <config.h>
#include <gnome.h>
#include <liboaf/liboaf.h>
#include <bonobo.h>
#include <sys/utsname.h>

#include <eazel-install-types.h>
#include <eazel-install-corba-types.h>
#include <eazel-install-corba-callback.h>

#include <libtrilobite/libtrilobite.h>
#include <trilobite-eazel-install.h>

#include <unistd.h>

#define PACKAGE_FILE_NAME "package-list.xml"

#define DEFAULT_PROTOCOL PROTOCOL_HTTP
#define DEFAULT_RPMRC "/usr/lib/rpm/rpmrc"
#define DEFAULT_REMOTE_PACKAGE_LIST "/package-list.xml"
#define DEFAULT_REMOTE_RPM_DIR "/RPMS"
#define DEFAULT_LOG_FILE "/tmp/eazel-install/log"

/* This ensure that if the arch is detected as i[3-9]86, the
   requested archtype will be set to i386 */
#define ASSUME_ix86_IS_i386 

#define OAF_ID "OAFIID:trilobite_eazel_install_service:8ff6e815-1992-437c-9771-d932db3b4a17"

/* Popt stuff */
int     arg_dry_run,
	arg_http,
	arg_ftp,
	arg_local,
	arg_debug,
	arg_port,
	arg_delay,
	arg_file,
	arg_force,
	arg_upgrade,
	arg_downgrade,
	arg_erase,
	arg_query,
	arg_revert,
	arg_verbose;
char    *arg_server,
	*arg_config_file,
	*arg_package_list,
	*arg_tmp_dir,
	*arg_root;

CORBA_ORB orb;
CORBA_Environment ev;

static const struct poptOption options[] = {
	{"debug", '0', POPT_ARG_NONE, &arg_debug, 0 , N_("Show debug output"), NULL},
	{"delay", '\0', POPT_ARG_NONE, &arg_delay, 0 , N_("10 sec delay after starting service"), NULL},
	{"downgrade", 'd', POPT_ARG_NONE, &arg_downgrade, 0, N_("Allow downgrades"), NULL},
	{"erase", 'e', POPT_ARG_NONE, &arg_erase, 0, N_("Erase packages"), NULL},
	{"file",'\0', POPT_ARG_NONE, &arg_file, 0, N_("RPM args are filename"), NULL},
	{"force", 'F', POPT_ARG_NONE, &arg_force, 0, N_("Force install"), NULL},
	{"ftp", 'f', POPT_ARG_NONE, &arg_ftp, 0, N_("Use ftp"), NULL},
	{"local", 'l', POPT_ARG_NONE, &arg_local, 0, N_("Use local"), NULL},
	{"http", 'h', POPT_ARG_NONE, &arg_http, 0, N_("Use http"), NULL},
	{"packagefile", '\0', POPT_ARG_STRING, &arg_package_list, 0, N_("Specify package file"), NULL},
	{"port", '\0', POPT_ARG_INT, &arg_port, 0 , N_("Set port numer (80)"), NULL},
	{"query", 'q', POPT_ARG_NONE, &arg_query, 0, N_("Run Query"), NULL},
	{"revert", 'r', POPT_ARG_NONE, &arg_revert, 0, N_("Revert"), NULL},
	{"root", '\0', POPT_ARG_STRING, &arg_root, 0, N_("Set root"), NULL},
	{"server", '\0', POPT_ARG_STRING, &arg_server, 0, N_("Specify server"), NULL},
	{"test", 't', POPT_ARG_NONE, &arg_dry_run, 0, N_("Test run"), NULL},
	{"tmp", '\0', POPT_ARG_STRING, &arg_tmp_dir, 0, N_("Set tmp dir (/tmp/eazel-install)"), NULL},
	{"upgrade", 'u', POPT_ARG_NONE, &arg_upgrade, 0, N_("Allow upgrades"), NULL},
	{"verbose", 'v', POPT_ARG_NONE, &arg_verbose, 0, N_("Verbose output"), NULL},
	{NULL, '\0', 0, NULL, 0}
};

static void tree_helper (EazelInstallCallback *service,
			 const PackageData *pd,		
			 gchar *indent,
			 gchar *indent_type,
			 int indent_level,
			 char *title);

#define check_ev(s) if (ev._major!=CORBA_NO_EXCEPTION) { g_warning ("%s: Caught exception %s", s, CORBA_exception_id (&ev)); }

static void
set_parameters_from_command_line (Trilobite_Eazel_Install service)
{
	if (!arg_debug) {
		Trilobite_Eazel_Install__set_log_file (service, DEFAULT_LOG_FILE, &ev);
		check_ev ("set_log_file");
	}

	/* We only want 1 protocol type */
	if (arg_http + arg_ftp + arg_local > 1) {
			fprintf (stderr, "*** You cannot specify more then one protocol type.\n");
			exit (1);
	}
	if (arg_http) {
		Trilobite_Eazel_Install__set_protocol (service, Trilobite_Eazel_PROTOCOL_HTTP, &ev);
		check_ev ("set_protocol");
	} else if (arg_ftp) {
		Trilobite_Eazel_Install__set_protocol (service, Trilobite_Eazel_PROTOCOL_FTP, &ev);
		check_ev ("set_protocol");
	} else if (arg_local) {
		Trilobite_Eazel_Install__set_protocol (service, Trilobite_Eazel_PROTOCOL_LOCAL, &ev);
		check_ev ("set_protocol");
	} else {
		Trilobite_Eazel_Install__set_protocol (service, Trilobite_Eazel_PROTOCOL_HTTP, &ev);
		check_ev ("set_protocol");
	}
	if (arg_downgrade + arg_upgrade + arg_erase +arg_revert > 1) {
			fprintf (stderr, "*** Upgrade, downgrade, revert and erase ? This is not a all-in-one tool");
			exit (1);
	}
	if (arg_upgrade) {
		Trilobite_Eazel_Install__set_update (service, TRUE, &ev);
		check_ev ("update");
	}
	if (arg_downgrade) {
		Trilobite_Eazel_Install__set_downgrade (service, TRUE, &ev);
		check_ev ("downgrade");
	}
	if (arg_server) {
		Trilobite_Eazel_Install__set_server (service, arg_server, &ev);
		check_ev ("set_server");
	}
	if (arg_tmp_dir) {
		Trilobite_Eazel_Install__set_tmp_dir (service, arg_tmp_dir, &ev);
		check_ev ("set_tmp_dir");
	}
	if (arg_port) {
		Trilobite_Eazel_Install__set_server_port (service, arg_port, &ev);
		check_ev ("set_server_port");
	}
	if (arg_dry_run) {
		Trilobite_Eazel_Install__set_test_mode (service, TRUE, &ev);
	}
	if (arg_force) {
		Trilobite_Eazel_Install__set_force (service, TRUE, &ev);
	}
	if (arg_package_list) {
		Trilobite_Eazel_Install__set_package_list (service, arg_package_list, &ev);
		check_ev ("packagelist");
	}

	if (arg_root) {
		if (arg_root[0]=='~') {
			char *tmp = g_strdup_printf ("%s/%s", g_get_home_dir (), 
						     arg_root+1);
			free (arg_root);
			arg_root = strdup (tmp);
			g_free (tmp);
		} else if (arg_root[0]!='/' || arg_root[0]=='.') {
			char *tmp = g_strdup_printf ("%s%s%s", g_get_current_dir (), 
						     arg_root[0]=='.' ? "" : "/",
						     arg_root+1);
			free (arg_root);
			arg_root = strdup (tmp);
			g_free (tmp);
		}
		g_message ("DB root = %s", arg_root);
	}
}

static void 
eazel_download_progress_signal (EazelInstallCallback *service, 
				const char *name,
				int amount, 
				int total,
				char *title) 
{
	if (amount==0) {
		fprintf (stdout, "Downloading %s...\n", name);
	} else if (amount != total ) {
		fprintf (stdout, "(%d/%d) %% %f\r", 
			 amount, total,
			 (float) (((float) amount * 100.0) / total));
		fflush (stdout);
	} else if (amount == total && total!=0) {
		fprintf (stdout, "(%d/%d) %% %f\r",
			 amount, total, 100.0);
		fprintf (stdout, "\nDone\n");
		fflush (stdout);
	}
}

static void 
eazel_install_progress_signal (EazelInstallCallback *service, 
			       const PackageData *pack,
			       int package_num, int num_packages, 
			       int amount, int total,
			       int total_size_completed, int total_size, 
			       char *title)
{
	if (amount==0) {
		fprintf (stdout, "%s %s: \"%20.20s\"...\n", title, pack->name, pack->description);
	} else if (amount != total ) {
		fprintf (stdout, "(%d/%d), (%d/%d)b - (%d/%d) %% %f\r", 
			 package_num, num_packages,
			 total_size_completed, total_size,
			 amount, total,
			 (float) (((float) amount * 100.0) / total));
		fflush (stdout);
	}
	if (amount == total && total!=0) {
		fprintf (stdout, "(%d/%d), (%d/%d)b - (%d/%d) %% %f\r",
			 package_num, num_packages,
			 total_size_completed, total_size,
			 amount, total, 100.0);
		fprintf (stdout, "\nDone\n");
		fflush (stdout);
	}
}

static void
download_failed (EazelInstallCallback *service, 
		 const char *name,
		 gpointer unused)
{
	fprintf (stdout, "Download of %s FAILED\n", name);
}

/* This is ridiculous... */
static void
tree_helper_helper(EazelInstallCallback *service,
		   gchar *indent,
		   gchar *indent_type,
		   int indent_level,
		   GList *iterator,
		   GList *next_list) 
{
	PackageData *pack = (PackageData*)iterator->data;
	char *indent2;
	char indenter;
	gchar *extra_space=NULL;
	int indent_level_cnt;

	if (indent_level>0) {
		extra_space = g_new0 (char, indent_level+1);
		for (indent_level_cnt = 0; indent_level_cnt < indent_level; indent_level_cnt++) {
			extra_space [indent_level_cnt] = ' ';
		}
	}

	if (iterator->next || next_list) {
		indenter = '|';
	} else {
		indenter = ' ';
		*indent_type = '\\';
	}
	
	indent2 = g_strdup_printf ("%s%s%c", indent, extra_space ? extra_space : "", indenter);
	tree_helper (service, pack, indent2, indent_type, indent_level, NULL);
	g_free (indent2);
	g_free (extra_space);	
}


static void
tree_helper (EazelInstallCallback *service,
	     const PackageData *pd,		
	     gchar *indent,
	     gchar *indent_type,
	     int indent_level,
	     char *title)
{
	GList *iterator;

	if (title && pd->toplevel) {
		fprintf (stdout, title);
	}

	switch (pd->status) {
	case PACKAGE_DEPENDENCY_FAIL:
		fprintf (stdout, "%s%s%s, which FAILED\n", 
			 indent,  indent_type, 
			 rpmfilename_from_packagedata (pd));
		break;
	case PACKAGE_CANNOT_OPEN:
		fprintf (stdout, "%s%s%s,which was NOT FOUND\n", 
			 indent,  indent_type,
			 rpmfilename_from_packagedata (pd));
		break;		
	case PACKAGE_SOURCE_NOT_SUPPORTED:
		fprintf (stdout, "%s%s%s, which is a source package\n", 
			 indent,  indent_type,
			 rpmfilename_from_packagedata (pd));
		break;
	case PACKAGE_BREAKS_DEPENDENCY:
		fprintf (stdout, "%s%s%s, which breaks deps\n", 
			 indent,  indent_type,
			 rpmfilename_from_packagedata (pd));
		break;
	case PACKAGE_FILE_CONFLICT:
		fprintf (stdout, "%s%s%s, which has file conflict\n", 
			 indent,  indent_type,
			 rpmfilename_from_packagedata (pd));
		break;
	default:
		fprintf (stdout, "%s%s%s %s (status %d)\n", 
			 indent,  indent_type,
			 pd->name, 
			 pd->status==PACKAGE_ALREADY_INSTALLED ? "already installed" : "",
			 pd->status);
		break;
	}
	for (iterator = pd->soft_depends; iterator; iterator = iterator->next) {		
		char *tmp;
		tmp = g_strdup ("-d-");
		tree_helper_helper (service, indent, tmp, indent_level, iterator, 
				    pd->breaks ? pd->breaks : pd->modifies);
		g_free (tmp);
	}
	for (iterator = pd->breaks; iterator; iterator = iterator->next) {			
		char *tmp;
		tmp = g_strdup ("-b-");
		tree_helper_helper (service, indent, tmp, indent_level, iterator, pd->modifies);
		g_free (tmp);
	}
	for (iterator = pd->modifies; iterator; iterator = iterator->next) {			
		char *tmp;
		tmp = g_strdup ("-m-");
		tree_helper_helper (service, indent, tmp, indent_level, iterator, NULL);
		g_free (tmp);
	}
}

/*
  This dumps the entire tree for the failed package.
 */
static void
install_failed (EazelInstallCallback *service,
		const PackageData *pd,		
		gpointer unused)
{
	char *title;
	title = g_strdup_printf ("\nPackage %s failed to install. Here's the tree...\n", pd->name);
	tree_helper (service, pd, "", "", 4, title);
	g_free (title);
}

static void
uninstall_failed (EazelInstallCallback *service,
		  const PackageData *pd,		
		  gpointer unused)
{
	char *title;
	title = g_strdup_printf ("\nPackage %s failed to uninstall. Here's the tree...\n", pd->name);
	tree_helper (service, pd, "", "", 4, title);
	g_free (title);
}

static gboolean
eazel_preflight_check_signal (EazelInstallCallback *service, 
			      const GList *packages,
			      int total_bytes,
			      int total_packages,
			      gpointer unused) 
{	
	const GList *iterator;

	fprintf (stdout, "About to %s a total of %d packages, %dKb\n", 
		 arg_erase ? "uninstall" : "install",
		 total_packages, total_bytes/1024);
	for (iterator = packages; iterator; iterator = iterator->next) {
		PackageData *pack = (PackageData*)iterator->data;
		tree_helper (service, pack, "", "", 4, NULL);
	}

	return TRUE;
}

static void
dep_check (EazelInstallCallback *service,
	   const PackageData *package,
	   const PackageData *needs,
	   gpointer unused) 
{
	fprintf (stdout, "Doing dependency check for %s-%s - need %s-%s\n", 
		 package->name, package->version,
		 needs->name, needs->version);
}

static void
md5_check_failed (EazelInstallCallback *service,
		  const PackageData *package,
		  const char *actual_md5,
		  gpointer unused) 
{
	fprintf (stdout, "Package %s failed md5 check!\n", package->name);
	fprintf (stdout, "MD5 checksum is  %s\n", package->md5);
	fprintf (stdout, "should have been %s\n", actual_md5);
}

static PackageData*
create_package (char *name) 
{
	struct utsname buf;
	PackageData *pack;

	uname (&buf);
	pack = packagedata_new ();
	if (arg_file) {
		/* If file starts with /, use filename,
		   if it starts with ~, insert g_get_home_dir,
		   otherwise, insert g_get_current_dir */
		pack->filename = 
			name[0]=='/' ? 
			g_strdup (name) : 
			name[0]=='~' ?
			g_strdup_printf ("%s/%s", g_get_home_dir (), name+1) :
			g_strdup_printf ("%s/%s", g_get_current_dir (), name);
	} else {
		pack->name = g_strdup (name);
	}
	pack->archtype = g_strdup (buf.machine);
#ifdef ASSUME_ix86_IS_i386
	if (strlen (pack->archtype)==4 && pack->archtype[0]=='i' &&
	    pack->archtype[1]>='3' && pack->archtype[1]<='9' &&
	    pack->archtype[2]=='8' && pack->archtype[3]=='6') {
		g_free (pack->archtype);
		pack->archtype = g_strdup ("i386");
	}
#endif
	pack->distribution = trilobite_get_distribution ();
	pack->toplevel = TRUE;
	
	return pack;
}

static gboolean
delete_files (EazelInstallCallback *service, gpointer unused)
{
	char answer[10];

	printf ("should i delete the RPM files? (y/n) ");
	fflush (stdout);

	fgets (answer, 10, stdin);
	if (answer[0] == 'y' || answer[0] == 'Y') {
		printf ("you said: YES\n");
		fflush (stdout);
		return TRUE;
	}
	printf ("you said: NO\n");
	fflush (stdout);
	return FALSE;
}

static void
done (EazelInstallCallback *service,
      gboolean result,
      gpointer unused)
{
	fprintf (stderr, "Operation %s\n", result ? "ok" : "failed");
	gtk_main_quit ();
}

static char *
get_password_dude (TrilobiteRootClient *root_client, const char *prompt, void *user_data)
{
	char * real_prompt;
	char * passwd;

	real_prompt = g_strdup_printf ("%s: ", prompt);
	passwd = getpass (real_prompt);
	g_free (real_prompt);

	return g_strdup (passwd);
}

static TrilobiteRootClient *
set_root_client (BonoboObjectClient *service)
{
	TrilobiteRootClient *root_client;

	if (bonobo_object_client_has_interface (service, "IDL:Trilobite/PasswordQuery:1.0", &ev)) {
		root_client = trilobite_root_client_new ();
		gtk_signal_connect (GTK_OBJECT (root_client), "need_password", GTK_SIGNAL_FUNC (get_password_dude),
				    NULL);

		if (! trilobite_root_client_attach (root_client, service)) {
			g_warning ("unable to attach root client to Trilobite/PasswordQuery!");
		}

		return root_client;
	} else {
		g_warning ("Object does not support IDL:Trilobite/PasswordQuery:1.0");
		return NULL;
	}
}

int main(int argc, char *argv[]) {
	poptContext ctxt;
	GList *packages;
	GList *categories;
	char *str;
	GList *strs;
	EazelInstallCallback *cb;		

	CORBA_exception_init (&ev);

	strs = NULL;

	/* Seems that bonobo_main doens't like
	   not having gnome_init called, dies in a
	   X call, yech */
#if 1
	gnome_init_with_popt_table ("Eazel Install", "1.0", argc, argv, options, 0, &ctxt);
#else
	gtk_type_init ();
	gnomelib_init ("Eazel Install", "1.0");
	gnomelib_register_popt_table (options, "Eazel Install");
	ctxt = gnomelib_parse_args (argc, argv, 0);
#endif
	
	packages = NULL;
	categories = NULL;
	/* If there are more args, get them and parse them as packages */
	while ((str = poptGetArg (ctxt)) != NULL) {
		packages = g_list_prepend (packages, create_package (str));
		strs = g_list_prepend (strs, g_strdup (str));
	}
	if (packages) {
		CategoryData *category;
		category = categorydata_new ();
		category->name = g_strdup ("files from commandline");
		category->packages = packages;
		categories = g_list_prepend (NULL, category);		
	} else {
		g_message ("Using remote list ");
	}

	/* Check that we're root and on a redhat system */
	if (!check_for_redhat ()) {
		fprintf (stderr, "*** This tool can only be used on RedHat.\n");
		exit (1);
	}

	orb = oaf_init (argc, argv);
	
	if (!bonobo_init (NULL, NULL, NULL)) {
		g_error ("Could not init bonobo");
	}
	bonobo_activate ();
	
	cb = eazel_install_callback_new ();

	if (arg_delay) {
		sleep (10);
	}

	set_parameters_from_command_line (eazel_install_callback_corba_objref (cb));
	set_root_client (eazel_install_callback_bonobo (cb));
	
	/* Set up signal connections */
	gtk_signal_connect (GTK_OBJECT (cb), "download_progress", 
			    GTK_SIGNAL_FUNC (eazel_download_progress_signal), 
			    "Download progress");
	gtk_signal_connect (GTK_OBJECT (cb), "preflight_check", 
			    GTK_SIGNAL_FUNC (eazel_preflight_check_signal), 
			    NULL);
	gtk_signal_connect (GTK_OBJECT (cb), "install_progress", 
			    GTK_SIGNAL_FUNC (eazel_install_progress_signal), 
			    "Installing");
	gtk_signal_connect (GTK_OBJECT (cb), "md5_check_failed", 
			    GTK_SIGNAL_FUNC (md5_check_failed), 
			    "");
	gtk_signal_connect (GTK_OBJECT (cb), "install_failed", 
			    GTK_SIGNAL_FUNC (install_failed), 
			    NULL);
	gtk_signal_connect (GTK_OBJECT (cb), "uninstall_progress", 
			    GTK_SIGNAL_FUNC (eazel_install_progress_signal), 
			    "Uninstalling");
	gtk_signal_connect (GTK_OBJECT (cb), "uninstall_failed", 
			    GTK_SIGNAL_FUNC (uninstall_failed), 
			    NULL);
	gtk_signal_connect (GTK_OBJECT (cb), "download_failed", 
			    GTK_SIGNAL_FUNC (download_failed), 
			    NULL);
	gtk_signal_connect (GTK_OBJECT (cb), "dependency_check", 
			    GTK_SIGNAL_FUNC (dep_check), 
			    NULL);
	gtk_signal_connect (GTK_OBJECT (cb), "delete_files", 
			    GTK_SIGNAL_FUNC (delete_files), 
			    NULL);
	gtk_signal_connect (GTK_OBJECT (cb), "done", 
			    GTK_SIGNAL_FUNC (done), 
			    NULL);

	if (arg_erase + arg_query + arg_downgrade + arg_upgrade + arg_revert > 1) {
		g_error ("Only one operation at a time please.");
	}

	if (arg_erase) {
		eazel_install_callback_uninstall_packages (cb, categories, arg_root, &ev);
	} else if (arg_query) {
		GList *iterator;
		for (iterator = strs; iterator; iterator = iterator->next) {
			GList *matched_packages;
			GList *match_it;
			matched_packages = eazel_install_callback_simple_query (cb, 
										(char*)iterator->data, 
										NULL, 
										&ev);
			for (match_it = matched_packages; match_it; match_it = match_it->next) {
				PackageData *p;
				p = (PackageData*)match_it->data;
				if (arg_verbose) {
					char *tmp;
					tmp = trilobite_get_distribution_name (p->distribution, TRUE, FALSE);
					fprintf (stdout, "Name         : %s\n", p->name?p->name:"?"); 
					fprintf (stdout, "Version      : %s\n", p->version?p->version:"?");
					fprintf (stdout, "Minor        : %s\n", p->minor?p->minor:"?");

					fprintf (stdout, "Size         : %d\n", p->bytesize);
					fprintf (stdout, "Arch         : %s\n", p->archtype?p->archtype:"?");
					fprintf (stdout, "Distribution : %s\n", tmp?tmp:"?");
					fprintf (stdout, "Description  : %s\n", 
						 p->description?p->description:"?");
					fprintf (stdout, "Install root : %s\n", 
						 p->install_root?p->install_root:"?");
				} else {
					fprintf (stdout, "%s %s %50.50s\n", p->name, p->version, p->description);
				}
			}
		}
	} else if (arg_revert) {
		GList *iterator;
		for (iterator = strs; iterator; iterator = iterator->next) {
			eazel_install_callback_revert_transaction (cb, (char*)iterator->data, arg_root, &ev);
		}
	} else {
		eazel_install_callback_install_packages (cb, categories, arg_root, &ev);
	}

	g_list_foreach (categories, (GFunc)categorydata_destroy_foreach, NULL);
	
	if (!arg_query) {
		gtk_main ();
	}

	eazel_install_callback_unref (GTK_OBJECT (cb));

	/* Corba cleanup */
	CORBA_exception_free (&ev);
       
	return 0;
};