Commit b5f746e0 authored by J Shane Culpepper's avatar J Shane Culpepper
Browse files

Big time clean up of the overall flow of installs. Now, all packages

        are downloaded before install.  Tried to setup as many of the print
        functions as possible to support internationalization.  Removed old
        gnet http groks of the package list and now grab the package list with
        the async ghttp fetch functionality.  Did alot of cleanups in the
        rpm glue functions to make them more managable.  Removed the prune_xml
        function i swipped from helixcode since it is no longer needed.
parent be62a451
2000-05-25 J Shane Culpepper <pepper@eazel.com>
* components/services/install/command-line/eazel-install.c:
(generate_new_package_list), (create_temporary_directory),
(fetch_remote_package_list), (main):
* components/services/install/lib/eazel-install-metadata.c:
(create_default_metadata), (create_default_configuration_metafile),
(xml_doc_sanity_checks), (get_urltype_from_string):
* components/services/install/lib/eazel-install-protocols.c:
* components/services/install/lib/eazel-install-protocols.h:
* components/services/install/lib/eazel-install-rpm-glue.c:
(install_new_packages), (download_a_package),
(download_all_packages), (install_all_packages),
(uninstall_packages), (uninstall_a_package), (do_rpm_install):
* components/services/install/lib/eazel-install-tests.c:
(dump_package_list):
* components/services/install/lib/eazel-install-xml-package-list.c:
(parse_category), (parse_local_xml_package_list),
(generate_xml_package_list), (parse_pkg_template):
* components/services/trilobite/libtrilobite/helixcode-utils.c:
* components/services/trilobite/libtrilobite/helixcode-utils.h:
Big time clean up of the overall flow of installs. Now, all packages
are downloaded before install. Tried to setup as many of the print
functions as possible to support internationalization. Removed old
gnet http groks of the package list and now grab the package list with
the async ghttp fetch functionality. Did alot of cleanups in the
rpm glue functions to make them more managable. Removed the prune_xml
function i swipped from helixcode since it is no longer needed.
2000-05-24 Ramiro Estrugo <ramiro@eazel.com>
* components/mozilla/nautilus-mozilla-content-view.c:
......
......@@ -109,11 +109,10 @@ generate_new_package_list (const char* popt_genpkg_file,
retval = generate_xml_package_list (popt_genpkg_file, config_file);
if (retval == FALSE) {
fprintf (stderr, "***Could not generate xml package list !***\n");
exit (1);
g_error (_("*** Could not generate xml package list! ***\n"));
}
g_print ("XML package list successfully generated ...\n");
g_print (_("XML package list successfully generated ...\n"));
exit (1);
} /* end generate_new_package_list */
......@@ -122,13 +121,12 @@ create_temporary_directory (const char* tmpdir) {
int retval;
g_print("Creating temporary download directory ...\n");
g_print (_("Creating temporary download directory ...\n"));
retval = mkdir (tmpdir, 0755);
if (retval < 0) {
if (errno != EEXIST) {
fprintf (stderr, "***Could not create temporary directory !***\n");
exit (1);
g_error (_("*** Could not create temporary directory! ***\n"));
}
}
} /* end create_temporary_directory */
......@@ -137,17 +135,20 @@ static void
fetch_remote_package_list (const char* pkg_list, TransferOptions* topts) {
gboolean retval;
char* url;
g_print (_("Getting package-list.xml from remote server ...\n"));
g_print ("Getting package-list.xml from remote server ...\n");
url = g_strdup_printf ("http://%s%s", topts->hostname,
topts->pkg_list_storage_path);
retval = http_fetch_remote_file (url, pkg_list);
retval = http_fetch_xml_package_list (topts->hostname,
topts->port_number,
topts->pkg_list_storage_path,
pkg_list);
if (retval == FALSE) {
fprintf (stderr, "***Unable to retrieve package-list.xml !***\n");
exit (1);
g_free (url);
g_error ("*** Unable to retrieve package-list.xml! ***\n");
}
g_free (url);
} /* end fetch_remote_package_list */
int
......@@ -261,23 +262,20 @@ main (int argc, char* argv[]) {
retval = check_for_root_user ();
if (retval == FALSE) {
fprintf (stderr, "***You must run eazel-install as root!***\n");
exit (1);
g_error (_("*** You must run eazel-install as root! ***\n"));
}
retval = check_for_redhat ();
if (retval == FALSE) {
fprintf (stderr, "***eazel-install can only be used on RedHat!***\n");
exit (1);
g_error (_("*** eazel-install can only be used on RedHat! ***\n"));
}
if ( DOWNGRADE_MODE == TRUE ) {
fprintf (stderr, "***Downgrade Mode not supported yet !***\n");
exit (1);
g_error (_("*** Downgrade Mode not supported yet! ***\n"));
}
/* Initialize iopts and topts with defaults from the configuration file */
g_print ("Reading the eazel services configuration ...\n");
g_print (_("Reading the eazel services configuration ...\n"));
iopts = init_default_install_configuration (config_file);
topts = init_default_transfer_configuration (config_file);
......@@ -286,12 +284,12 @@ main (int argc, char* argv[]) {
}
if ( LOGGING_MODE == TRUE ) {
fprintf (stderr, "***Logging not currently supported !***\n");
g_error (_("*** Logging not currently supported! ***\n"));
exit (1);
}
if ( USE_FTP == TRUE ) {
fprintf (stderr, "***FTP installs are not currently supported !***\n");
g_error (_("*** FTP installs are not currently supported! ***\n"));
exit (1);
}
else if (USE_HTTP == TRUE) {
......@@ -334,19 +332,17 @@ main (int argc, char* argv[]) {
retval = uninstall_packages (iopts, topts);
if (retval == FALSE) {
fprintf (stderr, "***The uninstall failed !***\n");
exit (1);
g_error (_("*** The uninstall failed! ***\n"));
}
}
else {
retval = install_new_packages (iopts, topts);
if (retval == FALSE) {
fprintf (stderr, "***The install failed !***\n");
exit (1);
g_error (_("*** The install failed! ***\n"));
}
}
g_print ("Transaction completed normally...\n");
g_print (_("Transaction completed normally...\n"));
g_free (config_file);
g_free (iopts);
g_free (topts);
......
......@@ -40,19 +40,17 @@ create_default_metadata (const char* config_file) {
gboolean rv;
int retval;
g_print("Creating default configuration file ...\n");
g_print (_("Creating default configuration file ...\n"));
retval = mkdir ("/var/eazel/services", 0755);
if (retval < 0) {
if (errno != EEXIST) {
fprintf (stderr, "***Could not create services directory !***\n");
exit (1);
g_error (_("*** Could not create services directory! ***\n"));
}
}
rv = create_default_configuration_metafile(config_file);
rv = create_default_configuration_metafile (config_file);
if (rv == FALSE) {
fprintf(stderr, "***Could not create the default configuration file !***\n");
exit (1);
g_error (_("*** Could not create the default configuration file! ***\n"));
}
} /* end create_default_metadata */
......@@ -83,9 +81,8 @@ create_default_configuration_metafile (const char* target_file) {
tree = xmlNewChild (doc->root, NULL, "RPMRC_FILE", "/usr/lib/rpm/rpmrc");
if (doc == NULL) {
fprintf (stderr, "***Error generating default configuration file !***\n");
xmlFreeDoc (doc);
exit (1);
g_error (_("*** Error generating default configuration file! ***\n"));
}
xmlSaveFile (target_file, doc);
......@@ -101,22 +98,20 @@ xml_doc_sanity_checks (xmlDocPtr doc) {
xmlNodePtr base;
if (doc == NULL) {
fprintf (stderr, "***Unable to open config file!***\n");
xmlFreeDoc (doc);
g_assert (doc != NULL);
g_error (_("*** Unable to open config file! ***\n"));
}
base = doc->root;
if (base == NULL) {
fprintf (stderr, "***The config file contains no data!***\n");
xmlFreeDoc (doc);
g_assert (base != NULL);
g_error (_("*** The config file contains no data! ***\n"));
}
if (g_strcasecmp (base->name, "EAZEL_INSTALLER")) {
fprintf (stderr, "***Cannot find the EAZEL_INSTALLER xmlnode!***\n");
g_print (_("*** Cannot find the EAZEL_INSTALLER xmlnode! ***\n"));
xmlFreeDoc (doc);
g_error ("***Bailing from xmlparse!***\n");
g_error (_("*** Bailing from xmlparse! ***\n"));
}
} /* end xml_doc_sanity_checks */
......@@ -136,7 +131,7 @@ get_urltype_from_string (char* tmpbuf) {
rv = PROTOCOL_FTP;
}
else {
g_warning ("Could not set URLType from config file!");
g_warning (_("Could not set URLType from config file!"));
}
return rv;
} /* end get_urltype_from_string */
......
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/*
* Copyright (C) 2000 Eazel, Inc
* Copyright (C) 2000 Helix Code, Inc
* Copyright (C) 1998-1999 James Henstridge
*
* This program is free software; you can redistribute it and/or
......@@ -30,90 +29,6 @@
#include "eazel-install-protocols.h"
#include <config.h>
gboolean
http_fetch_xml_package_list (const char* hostname,
int port,
const char* path,
const char* pkg_list_file) {
GInetAddr* addr;
GTcpSocket* socket;
GIOChannel* iochannel;
char* request;
char* xmlbuf;
GIOError error;
guint bytes;
xmlDocPtr doc;
xmlbuf = "";
/* Create the socket address */
addr = gnet_inetaddr_new (hostname, port);
g_assert (addr != NULL);
/* Create the socket */
socket = gnet_tcp_socket_new (addr);
g_assert (socket != NULL);
/* Get an IOChannel */
iochannel = gnet_tcp_socket_get_iochannel (socket);
g_assert (iochannel != NULL);
/* Make the request */
request = g_strdup_printf ("GET %s HTTP/1.0\r\n\r\n", path);
error = gnet_io_channel_writen (iochannel, request, strlen(request), &bytes);
g_free(request);
if (error != G_IO_ERROR_NONE) {
g_warning("Unable to connect to host: %d\n", error);
}
/* Read the returned info */
while (1) {
char* buffer;
buffer = g_new0(char, 1024);
error = g_io_channel_read(iochannel, buffer, sizeof(buffer), &bytes);
if (error != G_IO_ERROR_NONE) {
g_warning ("Read Error: %d\n", error);
break;
}
if (bytes == 0) {
break;
}
xmlbuf = g_strconcat (xmlbuf, buffer, NULL);
g_free (buffer);
}
g_io_channel_unref (iochannel);
gnet_tcp_socket_delete (socket);
if (strstr (xmlbuf, "HTTP1.0 404") || strstr (xmlbuf, "HTTP/1.1 404")) {
fprintf (stderr, "***File %s not found !***\n", path);
return FALSE;
}
if (strstr (xmlbuf, "HTTP1.0 403") || strstr (xmlbuf, "HTTP/1.1 403")) {
fprintf (stderr, "***Server denied access !***\n");
return FALSE;
}
if (strstr (xmlbuf, "HTTP1.0 400") || strstr (xmlbuf, "HTTP/1.1 400")) {
fprintf (stderr, "***Server could not understand the request !***\n");
return FALSE;
}
doc = prune_xml (xmlbuf);
if (!doc) {
fprintf (stderr, "***Unable to read package file !***\n");
return FALSE;
}
xmlSaveFile (pkg_list_file, doc);
xmlFreeDoc (doc);
return TRUE;
} /* end http_fetch_xml_package_list */
gboolean
http_fetch_remote_file (char* url, const char* target_file) {
......
......@@ -29,18 +29,10 @@
#define __EAZEL_SERVICES_PROTOCOLS_H__
#include "eazel-install-types.h"
#include "helixcode-utils.h"
#include <ghttp.h>
#include <gnet/gnet.h>
#include <gnome-xml/parser.h>
#define USER_AGENT_STRING "eazel-install/"
gboolean http_fetch_xml_package_list (const char* hostname,
int port,
const char* path,
const char* pkg_list_file);
gboolean http_fetch_remote_file (char* url, const char* target_file);
#endif /* __EAZEL_SERVICES_PROTOCOLS_H__ */
......@@ -33,7 +33,6 @@
#include <rpm/rpmlib.h>
#include <rpm/rpmmacro.h>
#include <rpm/dbindex.h>
#include <rpm/rpmurl.h>
#include <string.h>
#include <time.h>
......@@ -41,6 +40,33 @@
typedef void (*rpm_install_cb)(char* name, char* group, void* user_data);
static void download_a_package (URLType protocol,
TransferOptions* topts,
PackageData* package);
static gboolean download_all_packages (URLType protocol,
TransferOptions* topts,
GList* categories);
static gboolean install_all_packages (const char* tmp_dir,
int install_flags,
int problem_filters,
int interface_flags,
GList* categories);
static gboolean uninstall_a_package (PackageData* package,
int uninstall_flags,
int problem_filters,
int interface_flags);
static void* rpm_show_progress (const Header h,
const rpmCallbackType callback_type,
const unsigned long amount,
const unsigned long total,
const void* pkgKey,
void* data);
static int rpm_install (char* root_dir,
char* file_name,
char* location,
......@@ -71,28 +97,21 @@ static int do_rpm_uninstall (char* root_dir,
int problem_filters,
int interface_flags);
static void* rpm_show_progress (const Header h,
const rpmCallbackType callback_type,
const unsigned long amount,
const unsigned long total,
const void* pkgKey,
void* data);
gboolean
install_new_packages (InstallOptions* iopts, TransferOptions* topts) {
GList* categories;
gboolean rv;
int install_flags, interface_flags, problem_filter;
int install_flags, interface_flags, problem_filters;
categories = NULL;
install_flags = 0;
interface_flags = 0;
problem_filter = 0;
problem_filters = 0;
if (iopts->mode_test == TRUE) {
g_print ("Dry Run Mode Activated. Packages will not actually be installed ...\n");
g_print (_("Dry Run Mode Activated. Packages will not actually be installed ...\n"));
install_flags |= RPMTRANS_FLAG_TEST;
}
......@@ -108,83 +127,138 @@ install_new_packages (InstallOptions* iopts, TransferOptions* topts) {
}
if (iopts->mode_force == TRUE) {
problem_filter |= RPMPROB_FILTER_REPLACEPKG |
RPMPROB_FILTER_REPLACEOLDFILES |
RPMPROB_FILTER_REPLACENEWFILES |
RPMPROB_FILTER_OLDPACKAGE;
problem_filters |= RPMPROB_FILTER_REPLACEPKG |
RPMPROB_FILTER_REPLACEOLDFILES |
RPMPROB_FILTER_REPLACENEWFILES |
RPMPROB_FILTER_OLDPACKAGE;
}
rpmReadConfigFiles (topts->rpmrc_file, NULL);
g_print ("Reading the install package list ...\n");
g_print (_("Reading the install package list ...\n"));
categories = parse_local_xml_package_list (iopts->pkg_list);
rv = download_all_packages (iopts->protocol, topts, categories);
rv = install_all_packages (topts->tmp_dir,
install_flags,
problem_filters,
interface_flags,
categories);
return rv;
} /* end install_new_packages */
static void
download_a_package (URLType protocol, TransferOptions* topts, PackageData* package) {
if (protocol == PROTOCOL_HTTP) {
char* rpmname;
char* targetname;
char* url;
gboolean rv;
rpmname = g_strdup_printf ("%s-%s-%s.%s.rpm",
package->name,
package->version,
package->minor,
package->archtype);
targetname = g_strdup_printf ("%s/%s",
topts->tmp_dir,
rpmname);
url = g_strdup_printf ("http://%s%s/%s",
topts->hostname,
topts->rpm_storage_path,
rpmname);
g_print ("Downloading %s...\n", rpmname);
rv = http_fetch_remote_file (url, targetname);
if (rv != TRUE) {
g_error ("*** Failed to retreive %s! ***\n", url);
}
g_free (rpmname);
g_free (targetname);
g_free (url);
}
} /* end download_a_package */
static gboolean
download_all_packages (URLType protocol,
TransferOptions* topts,
GList* categories) {
while (categories) {
CategoryData* cat;
GList* pkgs;
cat = categories->data;
pkgs = cat->packages;
g_print ("Category = %s\n", cat->name);
while (pkgs) {
PackageData* package;
package = pkgs->data;
download_a_package (protocol, topts, package);
pkgs = pkgs->next;
}
categories = categories->next;
}
free_categories (categories);
return TRUE;
} /* end download_all_packages */
static gboolean
install_all_packages (const char* tmp_dir,
int install_flags,
int problem_filters,
int interface_flags,
GList* categories) {
gboolean rv;
while (categories) {
CategoryData* c = categories->data;
GList* t = c->packages;
CategoryData* cat = categories->data;
GList* pkgs = cat->packages;
g_print ("Install Category - %s\n", c->name);
while (t) {
PackageData* pack = t->data;
g_print ("Category = %s\n", cat->name);
while (pkgs) {
PackageData* pack;
char* pkg;
int retval;
pack = pkgs->data;
retval = 0;
pkg = g_strdup_printf ("%s/%s-%s-%s.%s.rpm",
topts->tmp_dir,
tmp_dir,
pack->name,
pack->version,
pack->minor,
pack->archtype);
if (iopts->protocol == PROTOCOL_HTTP) {
gboolean rv;
char* rpmname;
char* targetname;
char* url;
rpmname = g_strdup_printf ("%s-%s-%s.%s.rpm",
pack->name,
pack->version,
pack->minor,
pack->archtype);
targetname = g_strdup_printf ("%s/%s",
topts->tmp_dir,
rpmname);
url = g_strdup_printf ("http://%s%s/%s",
topts->hostname,
topts->rpm_storage_path,
rpmname);
g_print ("Downloading %s...\n", rpmname);
rv = http_fetch_remote_file (url, targetname);
if (rv != TRUE) {
g_error ("*** Failed to retreive %s! ***\n", url);
}
g_free (rpmname);
g_free (targetname);
g_free (url);
}
g_print ("Installing %s\n", pkg);
retval = rpm_install ("/", pkg, NULL, install_flags,
problem_filter, interface_flags,
problem_filters, interface_flags,
NULL, NULL);
if (retval == 0) {
g_print ("Package install successful !\n");
g_print (_("Package install successful !\n"));
rv = TRUE;
}
else {
g_print ("Package install failed !\n");
<