summaryrefslogtreecommitdiff
path: root/nautilus-installer
diff options
context:
space:
mode:
authorRobey Pointer <robey@src.gnome.org>2000-09-21 23:42:20 +0000
committerRobey Pointer <robey@src.gnome.org>2000-09-21 23:42:20 +0000
commit81952cfbc769cacc05270760e09c33746f7962ed (patch)
tree226252ed41dd6db5324a37d233148d08d87b3e67 /nautilus-installer
parent38839aa81a7ded0a27eb8efadab1325a4c83bce6 (diff)
downloadnautilus-81952cfbc769cacc05270760e09c33746f7962ed.tar.gz
Add proxy autodetect from the nautilus first-time druid, and support for
* components/services/install/lib/eazel-install-rpm-glue.c: * nautilus-installer/src/Makefile.am: * nautilus-installer/src/installer.c: (eazel_install_get_depends), (eazel_installer_initialize): * nautilus-installer/src/link.sh: * nautilus-installer/src/prescript: * nautilus-installer/src/proxy.c: * nautilus-installer/src/proxy.h: Add proxy autodetect from the nautilus first-time druid, and support for the install lib to use proxies. Clean up some of the temp dir stuff for security reasons.
Diffstat (limited to 'nautilus-installer')
-rw-r--r--nautilus-installer/src/Makefile.am1
-rw-r--r--nautilus-installer/src/installer.c61
-rwxr-xr-xnautilus-installer/src/link.sh16
-rw-r--r--nautilus-installer/src/prescript9
-rw-r--r--nautilus-installer/src/proxy.c224
-rw-r--r--nautilus-installer/src/proxy.h37
6 files changed, 324 insertions, 24 deletions
diff --git a/nautilus-installer/src/Makefile.am b/nautilus-installer/src/Makefile.am
index 6264da815..d797f7333 100644
--- a/nautilus-installer/src/Makefile.am
+++ b/nautilus-installer/src/Makefile.am
@@ -26,6 +26,7 @@ nautilus_installer_SOURCES = \
main.c \
support.c support.h \
callbacks.c callbacks.h \
+ proxy.c proxy.h \
installer.c installer.h
nautilus_installer_LDFLAGS = -static
diff --git a/nautilus-installer/src/installer.c b/nautilus-installer/src/installer.c
index 76de0c6d9..4bfb0287a 100644
--- a/nautilus-installer/src/installer.c
+++ b/nautilus-installer/src/installer.c
@@ -44,6 +44,7 @@
#include "callbacks.h"
#include "installer.h"
#include "support.h"
+#include "proxy.h"
/* Include the pixmaps */
@@ -66,6 +67,15 @@
#define REMOTE_RPM_DIR "/RPMS"
#define CATEGORY_DEPENDS_LIST "package-list-depends.xml"
+#define DIALOG_NEED_TO_SET_PROXY _("I can't reach the Eazel servers. This could be\n" \
+ "because the Eazel servers are down, or more likely,\n" \
+ "because you need to use a web proxy to access external\n" \
+ "web servers, and I couldn't figure out your proxy\n" \
+ "configuration.\n\n" \
+ "If you know you have a web proxy, you can try again by\n" \
+ "setting the environment variable 'http_proxy' to your\n" \
+ "proxy server, and restarting the Nautilus install.")
+
int installer_debug = 0;
int installer_output = 0;
int installer_test = 0;
@@ -1162,7 +1172,7 @@ eazel_installer_class_initialize (EazelInstallerClass *klass)
}
static void
-eazel_install_get_depends (EazelInstaller *installer)
+eazel_install_get_depends (EazelInstaller *installer, const char *dest_dir)
{
char *url;
char *destination;
@@ -1173,12 +1183,22 @@ eazel_install_get_depends (EazelInstaller *installer)
eazel_install_get_server_port (installer->service),
CATEGORY_DEPENDS_LIST);
- destination = g_strdup (CATEGORY_DEPENDS_LIST);
-
- retval = eazel_install_fetch_file (installer->service,
- url,
- "package list",
- destination);
+ destination = g_strdup_printf ("%s/%s", dest_dir, CATEGORY_DEPENDS_LIST);
+
+ if (! eazel_install_fetch_file (installer->service, url, "package list", destination)) {
+ /* try again with proxy config */
+ unlink (destination);
+ if (! attempt_http_proxy_autoconfigure () ||
+ ! eazel_install_fetch_file (installer->service, url, "package list", destination)) {
+ GnomeDialog *d;
+
+ d = GNOME_DIALOG (gnome_warning_dialog_parented (DIALOG_NEED_TO_SET_PROXY,
+ GTK_WINDOW (installer->window)));
+ gnome_dialog_run_and_close (d);
+ exit (1);
+ }
+ }
+
eazel_installer_load_dependencies (installer, destination);
if (retval == FALSE) {
g_warning (_("Unable to retrieve dependency xml!\n"));
@@ -1186,7 +1206,6 @@ eazel_install_get_depends (EazelInstaller *installer)
g_free (destination);
g_free (url);
-
}
static void
@@ -1195,18 +1214,27 @@ eazel_installer_initialize (EazelInstaller *object) {
GList *iterator;
char *tmpdir;
char *package_destination;
+ int tries;
g_assert (object != NULL);
g_assert (IS_EAZEL_INSTALLER (object));
installer = EAZEL_INSTALLER (object);
- /* The manpage says not to use this, but I can't be arsed */
- tmpdir = g_strdup ("/tmp/eazel-installer.XXXXXX");
- mktemp (tmpdir);
-
- if (!tmpdir || mkdir (tmpdir, 0700) != 0) {
- g_error (_("Cannot create %s"), tmpdir);
+ /* attempt to create a directory we can use */
+#define RANDCHAR ('@' + (rand () % 31))
+ srand (time (NULL));
+ for (tries = 0; tries < 50; tries++) {
+ tmpdir = g_strdup_printf ("/tmp/eazel-installer.%c%c%c%c%c%c%d",
+ RANDCHAR, RANDCHAR, RANDCHAR, RANDCHAR,
+ RANDCHAR, RANDCHAR, (rand () % 1000));
+ if (mkdir (tmpdir, 0700) == 0) {
+ break;
+ }
+ g_free (tmpdir);
+ }
+ if (tries == 50) {
+ g_error (_("Cannot create temporary directory"));
}
package_destination = g_strdup_printf ("%s/package-list.xml", tmpdir);
@@ -1289,11 +1317,12 @@ eazel_installer_initialize (EazelInstaller *object) {
g_free (log);
}
+ /* do this first, so we can check for proxies, etc */
+ eazel_install_get_depends (installer, tmpdir);
+
eazel_install_fetch_remote_package_list (installer->service);
installer->categories = parse_local_xml_package_list (package_destination);
- eazel_install_get_depends (installer);
-
if (!installer->categories) {
CategoryData *cat = categorydata_new ();
PackageData *pack = packagedata_new ();
diff --git a/nautilus-installer/src/link.sh b/nautilus-installer/src/link.sh
index 5210e6f64..ffb945ca8 100755
--- a/nautilus-installer/src/link.sh
+++ b/nautilus-installer/src/link.sh
@@ -5,8 +5,8 @@ GNOME=/gnome
pushd `pwd`
cd ../../components/services/install/lib
make -f makefile.staticlib clean && \
- make CFLAGS="-g -Werror" DEFINES="-DEAZEL_INSTALL_NO_CORBA -DEAZEL_INSTALL_SLIM -DEAZEL_INSTALL_PROTOCOL_USE_OLD_CGI" -f makefile.staticlib && \
- #make CFLAGS="-g -Werror" DEFINES="-DEAZEL_INSTALL_NO_CORBA -DEAZEL_INSTALL_SLIM" -f makefile.staticlib && \
+ #make CFLAGS="-g -Werror" DEFINES="-DEAZEL_INSTALL_NO_CORBA -DEAZEL_INSTALL_SLIM -DEAZEL_INSTALL_PROTOCOL_USE_OLD_CGI" -f makefile.staticlib && \
+ make CFLAGS="-g -Werror" DEFINES="-DEAZEL_INSTALL_NO_CORBA -DEAZEL_INSTALL_SLIM" -f makefile.staticlib && \
#make CFLAGS="-O -Werror" DEFINES="-DEAZEL_INSTALL_NO_CORBA -DEAZEL_INSTALL_SLIM -DEAZEL_INSTALL_PROTOCOL_USE_OLD_CGI" -f makefile.staticlib && \
cd ../../trilobite/libtrilobite && \
make -f makefile.staticlib clean && \
@@ -14,11 +14,13 @@ cd ../../components/services/install/lib
popd && \
make clean && \
-make CFLAGS="-O -Werror -DNO_TEXT_BOX $*" LDFLAGS="-static" DEFINES="-DNAUTILUS_INSTALLER_RELEASE" && \
-gcc -static -O -Werror -o nautilus-installer main.o support.o callbacks.o installer.o \
+#make CFLAGS="-O -Werror -DNO_TEXT_BOX $*" LDFLAGS="-static" DEFINES="-DNAUTILUS_INSTALLER_RELEASE" && \
+#gcc -static -O -Werror -o nautilus-installer main.o support.o callbacks.o installer.o proxy.o \
+make CFLAGS="-g -Werror -DNO_TEXT_BOX $*" LDFLAGS="-static" DEFINES="-DNAUTILUS_INSTALLER_RELEASE" && \
+gcc -static -g -Werror -o nautilus-installer main.o support.o callbacks.o installer.o proxy.o \
../../components/services/install/lib/libeazelinstall_minimal.a \
../../components/services/trilobite/libtrilobite/libtrilobite_minimal.a \
-../..//libnautilus-extensions/nautilus-druid.o \
+../../libnautilus-extensions/nautilus-druid.o \
../../libnautilus-extensions/nautilus-druid-page-eazel.o \
-L$GNOME/lib -lgnomecanvaspixbuf -lgdk_pixbuf \
-lgnomeui -lgnome -lart_lgpl \
@@ -29,8 +31,8 @@ gcc -static -O -Werror -o nautilus-installer main.o support.o callbacks.o instal
cp nautilus-installer nautilus-installer-prezip
-echo Stripping...
-strip nautilus-installer
+#echo Stripping...
+#strip nautilus-installer
echo Packing...
gzexe nautilus-installer
diff --git a/nautilus-installer/src/prescript b/nautilus-installer/src/prescript
index f97dcd887..6e2ee7f63 100644
--- a/nautilus-installer/src/prescript
+++ b/nautilus-installer/src/prescript
@@ -1,5 +1,12 @@
if test x$DISPLAY = x; then
echo "The Nautilus-Installer requires X"
+ exit
+fi
+params="DISPLAY=$DISPLAY"
+if test x$http_proxy = x; then
+ params="$params"
+else
+ params="$params http_proxy=$http_proxy"
fi
if test $UID -ne 0; then
echo ""
@@ -16,7 +23,7 @@ if test $UID -ne 0; then
echo ""
echo "Please enter root password at the prompt"
xhost + localhost
- su - -c "export DISPLAY=$DISPLAY && cd $PWD && echo Uncompressing... && sh $0 $* $USER"
+ su - -c "export $params && cd $PWD && echo Uncompressing... && sh $0 $* $USER"
xhost - localhost
exit
fi
diff --git a/nautilus-installer/src/proxy.c b/nautilus-installer/src/proxy.c
new file mode 100644
index 000000000..ef8e08ebb
--- /dev/null
+++ b/nautilus-installer/src/proxy.c
@@ -0,0 +1,224 @@
+/* -*- 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: Mike Fleming <mfleming@eazel.com>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <glib.h>
+#include "proxy.h"
+
+/**
+ * set_http_proxy
+ *
+ * just sets "http_proxy" environment variable, since that's all the bootstrap
+ * installer needs.
+ */
+static gboolean
+set_http_proxy (const char *proxy_url)
+{
+ /* set the "http_proxy" environment variable */
+ trilobite_setenv ("http_proxy", proxy_url, 1);
+ return TRUE;
+}
+
+/**
+ * getline_dup
+ *
+ * reads newline or EOF terminated line from stream, allocating the return
+ * buffer as appropriate
+ */
+#define GETLINE_INITIAL 256
+static char *
+getline_dup (FILE* stream)
+{
+ char *ret;
+ size_t ret_size;
+ size_t ret_used;
+ int char_read;
+ gboolean done;
+
+ ret = g_malloc( GETLINE_INITIAL * sizeof(char) );
+ ret_size = GETLINE_INITIAL;
+
+ for ( ret_used = 0, done = FALSE ;
+ !done && (EOF != (char_read = fgetc (stream))) ;
+ ret_used++
+ ) {
+ if (ret_size == (ret_used + 1)) {
+ ret_size *= 2;
+ ret = g_realloc (ret, ret_size);
+ }
+ if ('\n' == char_read || '\r' == char_read ) {
+ done = TRUE;
+ ret [ret_used] = '\0';
+ } else {
+ ret [ret_used] = char_read;
+ }
+ }
+
+ if ( 0 == ret_used ) {
+ g_free (ret);
+ ret = NULL;
+ } else {
+ ret [ret_used] = '\0';
+ }
+
+ return ret;
+}
+
+#define NETSCAPE_PREFS_PATH "/.netscape/preferences.js"
+
+/* user_pref("network.proxy.http", "localhost");
+ * user_pref("network.proxy.http_port", 8080);
+ * user_pref("network.proxy.type", 1);
+ */
+static char *
+load_nscp_proxy_settings ()
+{
+ char * user_directory = NULL;
+ char * prefs_path = NULL;
+ char * ret = NULL;
+ char * proxy_host = NULL;
+ guint32 proxy_port = 8080;
+ gboolean has_proxy_type = FALSE;
+
+ char * line;
+ char * current, *end;
+ FILE * prefs_file;
+
+ user_directory = g_get_home_dir ();
+
+ prefs_path = g_strconcat (user_directory, NETSCAPE_PREFS_PATH, NULL);
+ g_free (user_directory);
+ user_directory = NULL;
+
+ prefs_file = fopen (prefs_path, "r");
+
+ if ( NULL == prefs_file ) {
+ goto error;
+ }
+
+ /* Normally I wouldn't be caught dead doing it this way...*/
+ for ( ; NULL != (line = getline_dup (prefs_file)) ; g_free (line) ) {
+ if ( NULL != (current = strstr (line, "\"network.proxy.http\"")) ) {
+ current += strlen ("\"network.proxy.http\"");
+
+ current = strchr (current, '"');
+
+ if (NULL == current) {
+ continue;
+ }
+ current++;
+
+ end = strchr (current, '"');
+ if (NULL == end) {
+ continue;
+ }
+
+ proxy_host = g_strndup (current, end-current);
+ } else if ( NULL != (current = strstr (line, "\"network.proxy.http_port\""))) {
+ current += strlen ("\"network.proxy.http_port\"");
+
+ while ( *current && !isdigit(*current)) {
+ current++;
+ }
+
+ if ( '\0' == *current ) {
+ continue;
+ }
+
+ proxy_port = strtoul (current, &end, 10);
+
+ } else if ( NULL != (current = strstr (line, "\"network.proxy.type\""))) {
+ /* Proxy type must equal '1' */
+ current += strlen ("\"network.proxy.type\"");
+
+ while ( *current && !isdigit(*current)) {
+ current++;
+ }
+
+ has_proxy_type = ('1' == *current);
+ }
+ }
+
+ if (has_proxy_type && NULL != proxy_host) {
+ ret = g_strdup_printf ("http://%s:%u", proxy_host, proxy_port);
+ }
+
+error:
+ g_free (proxy_host);
+ g_free (prefs_path);
+ prefs_path = NULL;
+
+ return ret;
+}
+
+/**
+ * attempt_http_proxy_autoconfigure
+ *
+ * Attempt to discover HTTP proxy settings from environment variables
+ * and Netscape 4.x configuation files
+ */
+gboolean
+attempt_http_proxy_autoconfigure (void)
+{
+ static gboolean autoconfigure_attempted = FALSE;
+ gboolean success = FALSE;
+ char * proxy_url;
+
+ /* If we've already failed once, we're not going to try again */
+ if (autoconfigure_attempted) {
+ return FALSE;
+ }
+
+ /* The "http_proxy" environment variable is used by libwww */
+
+ /* Note that g_getenv returns a pointer to a static buffer */
+ proxy_url = g_getenv ("http_proxy");
+
+ if (NULL != proxy_url) {
+ success = TRUE;
+ set_http_proxy (proxy_url);
+ g_free (proxy_url);
+ proxy_url = NULL;
+ }
+
+ /* Check Netscape 4.x settings */
+
+ proxy_url = load_nscp_proxy_settings ();
+
+ if (NULL != proxy_url) {
+ success = TRUE;
+ set_http_proxy (proxy_url);
+ g_free (proxy_url);
+ proxy_url = NULL;
+ }
+
+ autoconfigure_attempted = TRUE;
+ return success;
+}
+
diff --git a/nautilus-installer/src/proxy.h b/nautilus-installer/src/proxy.h
new file mode 100644
index 000000000..7bd22ca65
--- /dev/null
+++ b/nautilus-installer/src/proxy.h
@@ -0,0 +1,37 @@
+/* -*- 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 Library 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 Library 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: Mike Fleming <mfleming@eazel.com>
+ *
+ */
+
+#ifndef EAZEL_INSTALLER_PROXY_H
+#define EAZEL_INSTALLER_PROXY_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+gboolean attempt_http_proxy_autoconfigure (void);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* EAZEL_INSTALLER_PROXY_H */