1/*
2 * The new sysinstall program.
3 *
4 * This is probably the last attempt in the `sysinstall' line, the next
5 * generation being slated for what's essentially a complete rewrite.
6 *
7 * Copyright (c) 1995
8 *	Jordan Hubbard.  All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer,
15 *    verbatim and that no modifications are made prior to this
16 *    point in the file.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 *    notice, this list of conditions and the following disclaimer in the
19 *    documentation and/or other materials provided with the distribution.
20 *
21 * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED.  IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * $FreeBSD$
34 */
35
36#include "sysinstall.h"
37
38/*
39 * This is called from the main menu.  Try to find a copy of Lynx from somewhere
40 * and fire it up on the first copy of the handbook we can find.
41 */
42int
43docBrowser(dialogMenuItem *self)
44{
45    int ret;
46    char *browser = variable_get(VAR_BROWSER_PACKAGE);
47
48    if (RunningAsInit && !strstr(variable_get(SYSTEM_STATE), "install")) {
49	msgConfirm("This option may only be used after the system is installed, sorry!");
50	return DITEM_FAILURE;
51    }
52
53    /* First, make sure we have whatever browser we've chosen is here */
54    if (!package_installed(browser)) {
55	ret = package_add(browser);
56    	if (DITEM_STATUS(ret) != DITEM_SUCCESS) {
57	    msgConfirm("Unable to install the %s HTML browser package.  You may\n"
58		       "wish to verify that your media is configured correctly and\n"
59		       "try again.", browser);
60	    return ret;
61	}
62    }
63
64    if (!file_executable(variable_get(VAR_BROWSER_BINARY))) {
65	if (!msgYesNo("Hmmm.  The %s package claims to have installed, but I can't\n"
66		      "find its binary in %s!  You may wish to try a different\n"
67		      "location to load the package from (go to Media menu) and see if that\n"
68		      "makes a difference.\n\n"
69		      "I suggest that we remove the version that was extracted since it does\n"
70		      "not appear to be correct.   Would you like me to do that now?",
71		      browser, variable_get(VAR_BROWSER_BINARY)))
72	    vsystem("pkg_delete %s %s", !strcmp(variable_get(VAR_CPIO_VERBOSITY), "high") ? "-v" : "", browser);
73	return DITEM_FAILURE;
74    }
75
76    /* Run browser on the appropriate doc */
77    if (dmenuOpenSimple(&MenuHTMLDoc, FALSE))
78	return DITEM_SUCCESS;
79    else
80	return DITEM_FAILURE;
81}
82
83/* Try to show one of the documents requested from the HTML doc menu */
84int
85docShowDocument(dialogMenuItem *self)
86{
87    char tmp[512], target[512];
88    char *where, *browser = variable_get(VAR_BROWSER_BINARY);
89    char *str = self->prompt;
90
91    if (!file_executable(browser)) {
92	msgConfirm("Can't find the browser in %s!  Please ensure that it's\n"
93		   "properly set in the Options editor.", browser);
94	return DITEM_FAILURE;
95    }
96    /* Default to Home */
97    where = strcpy(target, "http://www.freebsd.org");
98    if (strstr(str, "Other")) {
99	where = msgGetInput("http://www.freebsd.org", "Please enter the URL of the location you wish to visit.");
100	if (where)
101	    strcpy(target, where);
102    }
103    else if (strstr(str, "FAQ")) {
104	where = strcpy(target, "/usr/local/share/doc/freebsd/faq/index.html");
105	if (!file_readable(target))
106	    where = strcpy(target, "http://www.freebsd.org/doc/en_US.ISO8859-1/books/faq");
107    }
108    else if (strstr(str, "Handbook")) {
109	where = strcpy(target, "/usr/local/share/doc/freebsd/handbook/index.html");
110	if (!file_readable(target))
111	    where = strcpy(target, "http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook");
112    }
113    if (where) {
114	sprintf(tmp, "%s %s", browser, target);
115	systemExecute(tmp);
116	return DITEM_SUCCESS;
117    }
118    else {
119	msgConfirm("Hmmmmm!  I can't seem to access the documentation you selected!\n"
120		   "Have you installed the english documentation?  Is your network connected?");
121	return DITEM_FAILURE;
122    }
123}
124