111580Sjkh/*
211580Sjkh * The new sysinstall program.
311580Sjkh *
415242Sjkh * This is probably the last attempt in the `sysinstall' line, the next
515242Sjkh * generation being slated for what's essentially a complete rewrite.
611580Sjkh *
715242Sjkh * Copyright (c) 1995
815242Sjkh *	Jordan Hubbard.  All rights reserved.
911580Sjkh *
1015242Sjkh * Redistribution and use in source and binary forms, with or without
1115242Sjkh * modification, are permitted provided that the following conditions
1215242Sjkh * are met:
1315242Sjkh * 1. Redistributions of source code must retain the above copyright
1415242Sjkh *    notice, this list of conditions and the following disclaimer,
1515242Sjkh *    verbatim and that no modifications are made prior to this
1615242Sjkh *    point in the file.
1715242Sjkh * 2. Redistributions in binary form must reproduce the above copyright
1815242Sjkh *    notice, this list of conditions and the following disclaimer in the
1915242Sjkh *    documentation and/or other materials provided with the distribution.
2011580Sjkh *
2115242Sjkh * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND
2215242Sjkh * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2315242Sjkh * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2415242Sjkh * ARE DISCLAIMED.  IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
2515242Sjkh * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2615242Sjkh * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2715242Sjkh * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
2815242Sjkh * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2915242Sjkh * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3015242Sjkh * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3115242Sjkh * SUCH DAMAGE.
3215242Sjkh *
33124068Sobrien * $FreeBSD$
3411580Sjkh */
3511580Sjkh
3611580Sjkh#include "sysinstall.h"
3711580Sjkh
3811580Sjkh/*
3911580Sjkh * This is called from the main menu.  Try to find a copy of Lynx from somewhere
4011580Sjkh * and fire it up on the first copy of the handbook we can find.
4111580Sjkh */
4211580Sjkhint
4315091SjkhdocBrowser(dialogMenuItem *self)
4411580Sjkh{
4515419Sjkh    int ret;
4611640Sjkh    char *browser = variable_get(VAR_BROWSER_PACKAGE);
4712055Sjkh
4812129Sjkh    if (RunningAsInit && !strstr(variable_get(SYSTEM_STATE), "install")) {
4912055Sjkh	msgConfirm("This option may only be used after the system is installed, sorry!");
5015242Sjkh	return DITEM_FAILURE;
5112055Sjkh    }
5212055Sjkh
5311580Sjkh    /* First, make sure we have whatever browser we've chosen is here */
54124068Sobrien    if (!package_installed(browser)) {
5515788Sjkh	ret = package_add(browser);
5615788Sjkh    	if (DITEM_STATUS(ret) != DITEM_SUCCESS) {
5715788Sjkh	    msgConfirm("Unable to install the %s HTML browser package.  You may\n"
5815788Sjkh		       "wish to verify that your media is configured correctly and\n"
5915788Sjkh		       "try again.", browser);
6015788Sjkh	    return ret;
6115788Sjkh	}
6211580Sjkh    }
6315419Sjkh
6411640Sjkh    if (!file_executable(variable_get(VAR_BROWSER_BINARY))) {
6511580Sjkh	if (!msgYesNo("Hmmm.  The %s package claims to have installed, but I can't\n"
6611580Sjkh		      "find its binary in %s!  You may wish to try a different\n"
6711580Sjkh		      "location to load the package from (go to Media menu) and see if that\n"
6811580Sjkh		      "makes a difference.\n\n"
6911580Sjkh		      "I suggest that we remove the version that was extracted since it does\n"
7022746Sjkh		      "not appear to be correct.   Would you like me to do that now?",
7122746Sjkh		      browser, variable_get(VAR_BROWSER_BINARY)))
7211640Sjkh	    vsystem("pkg_delete %s %s", !strcmp(variable_get(VAR_CPIO_VERBOSITY), "high") ? "-v" : "", browser);
7354587Sjkh	return DITEM_FAILURE;
7411580Sjkh    }
7511580Sjkh
7611580Sjkh    /* Run browser on the appropriate doc */
7716887Sjkh    if (dmenuOpenSimple(&MenuHTMLDoc, FALSE))
7854587Sjkh	return DITEM_SUCCESS;
7915091Sjkh    else
8054587Sjkh	return DITEM_FAILURE;
8111580Sjkh}
8211580Sjkh
8311580Sjkh/* Try to show one of the documents requested from the HTML doc menu */
8411580Sjkhint
8515091SjkhdocShowDocument(dialogMenuItem *self)
8611580Sjkh{
8757507Sjkh    char tmp[512], target[512];
8857367Sjkh    char *where, *browser = variable_get(VAR_BROWSER_BINARY);
8915091Sjkh    char *str = self->prompt;
9011580Sjkh
9111580Sjkh    if (!file_executable(browser)) {
9211580Sjkh	msgConfirm("Can't find the browser in %s!  Please ensure that it's\n"
9311580Sjkh		   "properly set in the Options editor.", browser);
9415242Sjkh	return DITEM_FAILURE;
9511580Sjkh    }
9657367Sjkh    /* Default to Home */
9757367Sjkh    where = strcpy(target, "http://www.freebsd.org");
9857367Sjkh    if (strstr(str, "Other")) {
9911804Sjkh	where = msgGetInput("http://www.freebsd.org", "Please enter the URL of the location you wish to visit.");
10057367Sjkh	if (where)
10157367Sjkh	    strcpy(target, where);
10257367Sjkh    }
10357367Sjkh    else if (strstr(str, "FAQ")) {
104195132Sblackend	where = strcpy(target, "/usr/local/share/doc/freebsd/faq/index.html");
10511804Sjkh	if (!file_readable(target))
106101142Sblackend	    where = strcpy(target, "http://www.freebsd.org/doc/en_US.ISO8859-1/books/faq");
10711580Sjkh    }
10857367Sjkh    else if (strstr(str, "Handbook")) {
109195132Sblackend	where = strcpy(target, "/usr/local/share/doc/freebsd/handbook/index.html");
11011832Sjkh	if (!file_readable(target))
111101142Sblackend	    where = strcpy(target, "http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook");
11211832Sjkh    }
11311832Sjkh    if (where) {
11457367Sjkh	sprintf(tmp, "%s %s", browser, target);
11511832Sjkh	systemExecute(tmp);
11654587Sjkh	return DITEM_SUCCESS;
11711832Sjkh    }
11811832Sjkh    else {
11911832Sjkh	msgConfirm("Hmmmmm!  I can't seem to access the documentation you selected!\n"
120195132Sblackend		   "Have you installed the english documentation?  Is your network connected?");
12115242Sjkh	return DITEM_FAILURE;
12211832Sjkh    }
12311580Sjkh}
124