2003-06-13 11:26:41 +04:00
|
|
|
/* $NetBSD: functions.c,v 1.7 2003/06/13 07:26:41 itojun Exp $ */
|
Initial import of sushi.
Sushi is an interactive, menu-based program that is designed to aid
the user or administrator with administrative and complex tasks on thier
machines.
Sushi provides a menu of various functions that the user can perform on
his or her machine. Once the user selects a desired function, the
function is either performed outright, or in most cases, the user is
asked to fill in a simple form with required and option information,
which is then processed by sushi, and the action occurs.
The programming interface for sushi is very simple. There are
directories containing various files, such as menu indexes, or forms for
the user to fill out. These files are interpreted by sushi to generate
the menus the user sees on his/her screen. When the form is filled out
by the user, the entries are passed as command-line arguments to a
program, or script contained in one of the subdirectories. In this way,
it is possible to add new entries to the sushi menu structure, by simply
adding a new menu item, form and script, the binary does not need to be
recompiled to take advantage of this new menu.
2001-01-05 04:28:33 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2000 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2000 Tim Rightnour <garbled@netbsd.org>
|
|
|
|
* Copyright (c) 2000 Hubert Feyrer <hubertf@netbsd.org>
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <err.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/utsname.h>
|
|
|
|
|
|
|
|
#include "sushi.h"
|
|
|
|
#include "functions.h"
|
|
|
|
|
|
|
|
#ifndef NETBSD_PKG_BASE
|
|
|
|
#define NETBSD_PKG_BASE "ftp://ftp.netbsd.org/pub/NetBSD/packages"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern int scripting;
|
|
|
|
extern int logging;
|
|
|
|
extern FILE *logfile;
|
|
|
|
extern FILE *script;
|
|
|
|
extern int errno;
|
|
|
|
extern nl_catd catalog;
|
|
|
|
|
|
|
|
char *ftp_base(int truename);
|
|
|
|
void cleanup(void);
|
|
|
|
|
|
|
|
/* Required by libinstall */
|
|
|
|
void cleanup(void){ ; }
|
|
|
|
int ftp_cmd(const char *cmd, const char *expectstr);
|
|
|
|
void ftp_stop(void);
|
|
|
|
|
|
|
|
func_record func_map[] =
|
|
|
|
{
|
|
|
|
{ "ftp_pkglist", ftp_pkglist },
|
2001-01-24 12:30:30 +03:00
|
|
|
{ "ftp_pkgcats", ftp_pkgcats },
|
Initial import of sushi.
Sushi is an interactive, menu-based program that is designed to aid
the user or administrator with administrative and complex tasks on thier
machines.
Sushi provides a menu of various functions that the user can perform on
his or her machine. Once the user selects a desired function, the
function is either performed outright, or in most cases, the user is
asked to fill in a simple form with required and option information,
which is then processed by sushi, and the action occurs.
The programming interface for sushi is very simple. There are
directories containing various files, such as menu indexes, or forms for
the user to fill out. These files are interpreted by sushi to generate
the menus the user sees on his/her screen. When the form is filled out
by the user, the entries are passed as command-line arguments to a
program, or script contained in one of the subdirectories. In this way,
it is possible to add new entries to the sushi menu structure, by simply
adding a new menu item, form and script, the binary does not need to be
recompiled to take advantage of this new menu.
2001-01-05 04:28:33 +03:00
|
|
|
{ "script_do", script_do },
|
|
|
|
{ "log_do", log_do },
|
|
|
|
{(char *)NULL, (char **(*)(char *))NULL},
|
|
|
|
};
|
|
|
|
|
2001-03-03 16:54:22 +03:00
|
|
|
/*ARGSUSED*/
|
Initial import of sushi.
Sushi is an interactive, menu-based program that is designed to aid
the user or administrator with administrative and complex tasks on thier
machines.
Sushi provides a menu of various functions that the user can perform on
his or her machine. Once the user selects a desired function, the
function is either performed outright, or in most cases, the user is
asked to fill in a simple form with required and option information,
which is then processed by sushi, and the action occurs.
The programming interface for sushi is very simple. There are
directories containing various files, such as menu indexes, or forms for
the user to fill out. These files are interpreted by sushi to generate
the menus the user sees on his/her screen. When the form is filled out
by the user, the entries are passed as command-line arguments to a
program, or script contained in one of the subdirectories. In this way,
it is possible to add new entries to the sushi menu structure, by simply
adding a new menu item, form and script, the binary does not need to be
recompiled to take advantage of this new menu.
2001-01-05 04:28:33 +03:00
|
|
|
char **
|
|
|
|
log_do(char *what)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
time_t tloc;
|
|
|
|
|
|
|
|
i = logging;
|
|
|
|
|
2001-03-03 16:54:22 +03:00
|
|
|
if (logging == 1)
|
Initial import of sushi.
Sushi is an interactive, menu-based program that is designed to aid
the user or administrator with administrative and complex tasks on thier
machines.
Sushi provides a menu of various functions that the user can perform on
his or her machine. Once the user selects a desired function, the
function is either performed outright, or in most cases, the user is
asked to fill in a simple form with required and option information,
which is then processed by sushi, and the action occurs.
The programming interface for sushi is very simple. There are
directories containing various files, such as menu indexes, or forms for
the user to fill out. These files are interpreted by sushi to generate
the menus the user sees on his/her screen. When the form is filled out
by the user, the entries are passed as command-line arguments to a
program, or script contained in one of the subdirectories. In this way,
it is possible to add new entries to the sushi menu structure, by simply
adding a new menu item, form and script, the binary does not need to be
recompiled to take advantage of this new menu.
2001-01-05 04:28:33 +03:00
|
|
|
logging = 0;
|
2001-03-03 16:54:22 +03:00
|
|
|
else if (logging == 0)
|
Initial import of sushi.
Sushi is an interactive, menu-based program that is designed to aid
the user or administrator with administrative and complex tasks on thier
machines.
Sushi provides a menu of various functions that the user can perform on
his or her machine. Once the user selects a desired function, the
function is either performed outright, or in most cases, the user is
asked to fill in a simple form with required and option information,
which is then processed by sushi, and the action occurs.
The programming interface for sushi is very simple. There are
directories containing various files, such as menu indexes, or forms for
the user to fill out. These files are interpreted by sushi to generate
the menus the user sees on his/her screen. When the form is filled out
by the user, the entries are passed as command-line arguments to a
program, or script contained in one of the subdirectories. In this way,
it is possible to add new entries to the sushi menu structure, by simply
adding a new menu item, form and script, the binary does not need to be
recompiled to take advantage of this new menu.
2001-01-05 04:28:33 +03:00
|
|
|
logging = 1;
|
|
|
|
|
2001-03-03 16:54:22 +03:00
|
|
|
time(&tloc);
|
|
|
|
|
|
|
|
if (logging && i == 0) { /* open */
|
Initial import of sushi.
Sushi is an interactive, menu-based program that is designed to aid
the user or administrator with administrative and complex tasks on thier
machines.
Sushi provides a menu of various functions that the user can perform on
his or her machine. Once the user selects a desired function, the
function is either performed outright, or in most cases, the user is
asked to fill in a simple form with required and option information,
which is then processed by sushi, and the action occurs.
The programming interface for sushi is very simple. There are
directories containing various files, such as menu indexes, or forms for
the user to fill out. These files are interpreted by sushi to generate
the menus the user sees on his/her screen. When the form is filled out
by the user, the entries are passed as command-line arguments to a
program, or script contained in one of the subdirectories. In this way,
it is possible to add new entries to the sushi menu structure, by simply
adding a new menu item, form and script, the binary does not need to be
recompiled to take advantage of this new menu.
2001-01-05 04:28:33 +03:00
|
|
|
logfile = fopen(LOGFILE_NAME, "w");
|
|
|
|
if (logfile == NULL)
|
|
|
|
bailout("fopen %s: %s", LOGFILE_NAME, strerror(errno));
|
|
|
|
fprintf(logfile, "%s: %s\n",
|
|
|
|
catgets(catalog, 4, 3, "Log started at"),
|
|
|
|
asctime(localtime(&tloc)));
|
|
|
|
fflush(logfile);
|
2001-03-03 16:54:22 +03:00
|
|
|
} else { /* close */
|
|
|
|
if (logfile == NULL)
|
|
|
|
bailout("fopen %s: %s", LOGFILE_NAME, strerror(errno));
|
|
|
|
fprintf(logfile, "%s: %s\n",
|
|
|
|
catgets(catalog, 4, 10, "Log ended at"),
|
|
|
|
asctime(localtime(&tloc)));
|
|
|
|
fflush(logfile);
|
|
|
|
fclose(logfile);
|
Initial import of sushi.
Sushi is an interactive, menu-based program that is designed to aid
the user or administrator with administrative and complex tasks on thier
machines.
Sushi provides a menu of various functions that the user can perform on
his or her machine. Once the user selects a desired function, the
function is either performed outright, or in most cases, the user is
asked to fill in a simple form with required and option information,
which is then processed by sushi, and the action occurs.
The programming interface for sushi is very simple. There are
directories containing various files, such as menu indexes, or forms for
the user to fill out. These files are interpreted by sushi to generate
the menus the user sees on his/her screen. When the form is filled out
by the user, the entries are passed as command-line arguments to a
program, or script contained in one of the subdirectories. In this way,
it is possible to add new entries to the sushi menu structure, by simply
adding a new menu item, form and script, the binary does not need to be
recompiled to take advantage of this new menu.
2001-01-05 04:28:33 +03:00
|
|
|
}
|
|
|
|
return(NULL); /* XXX */
|
|
|
|
}
|
|
|
|
|
2001-03-03 16:54:22 +03:00
|
|
|
/*ARGSUSED*/
|
Initial import of sushi.
Sushi is an interactive, menu-based program that is designed to aid
the user or administrator with administrative and complex tasks on thier
machines.
Sushi provides a menu of various functions that the user can perform on
his or her machine. Once the user selects a desired function, the
function is either performed outright, or in most cases, the user is
asked to fill in a simple form with required and option information,
which is then processed by sushi, and the action occurs.
The programming interface for sushi is very simple. There are
directories containing various files, such as menu indexes, or forms for
the user to fill out. These files are interpreted by sushi to generate
the menus the user sees on his/her screen. When the form is filled out
by the user, the entries are passed as command-line arguments to a
program, or script contained in one of the subdirectories. In this way,
it is possible to add new entries to the sushi menu structure, by simply
adding a new menu item, form and script, the binary does not need to be
recompiled to take advantage of this new menu.
2001-01-05 04:28:33 +03:00
|
|
|
char **
|
|
|
|
script_do(char *what)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
time_t tloc;
|
|
|
|
|
|
|
|
i = scripting;
|
|
|
|
|
2001-03-03 16:54:22 +03:00
|
|
|
if (scripting == 0)
|
Initial import of sushi.
Sushi is an interactive, menu-based program that is designed to aid
the user or administrator with administrative and complex tasks on thier
machines.
Sushi provides a menu of various functions that the user can perform on
his or her machine. Once the user selects a desired function, the
function is either performed outright, or in most cases, the user is
asked to fill in a simple form with required and option information,
which is then processed by sushi, and the action occurs.
The programming interface for sushi is very simple. There are
directories containing various files, such as menu indexes, or forms for
the user to fill out. These files are interpreted by sushi to generate
the menus the user sees on his/her screen. When the form is filled out
by the user, the entries are passed as command-line arguments to a
program, or script contained in one of the subdirectories. In this way,
it is possible to add new entries to the sushi menu structure, by simply
adding a new menu item, form and script, the binary does not need to be
recompiled to take advantage of this new menu.
2001-01-05 04:28:33 +03:00
|
|
|
scripting = 1;
|
2001-03-03 16:54:22 +03:00
|
|
|
else if (scripting == 1)
|
Initial import of sushi.
Sushi is an interactive, menu-based program that is designed to aid
the user or administrator with administrative and complex tasks on thier
machines.
Sushi provides a menu of various functions that the user can perform on
his or her machine. Once the user selects a desired function, the
function is either performed outright, or in most cases, the user is
asked to fill in a simple form with required and option information,
which is then processed by sushi, and the action occurs.
The programming interface for sushi is very simple. There are
directories containing various files, such as menu indexes, or forms for
the user to fill out. These files are interpreted by sushi to generate
the menus the user sees on his/her screen. When the form is filled out
by the user, the entries are passed as command-line arguments to a
program, or script contained in one of the subdirectories. In this way,
it is possible to add new entries to the sushi menu structure, by simply
adding a new menu item, form and script, the binary does not need to be
recompiled to take advantage of this new menu.
2001-01-05 04:28:33 +03:00
|
|
|
scripting = 0;
|
|
|
|
|
2001-03-03 16:54:22 +03:00
|
|
|
time(&tloc);
|
|
|
|
|
|
|
|
if (scripting && i == 0) { /* open */
|
Initial import of sushi.
Sushi is an interactive, menu-based program that is designed to aid
the user or administrator with administrative and complex tasks on thier
machines.
Sushi provides a menu of various functions that the user can perform on
his or her machine. Once the user selects a desired function, the
function is either performed outright, or in most cases, the user is
asked to fill in a simple form with required and option information,
which is then processed by sushi, and the action occurs.
The programming interface for sushi is very simple. There are
directories containing various files, such as menu indexes, or forms for
the user to fill out. These files are interpreted by sushi to generate
the menus the user sees on his/her screen. When the form is filled out
by the user, the entries are passed as command-line arguments to a
program, or script contained in one of the subdirectories. In this way,
it is possible to add new entries to the sushi menu structure, by simply
adding a new menu item, form and script, the binary does not need to be
recompiled to take advantage of this new menu.
2001-01-05 04:28:33 +03:00
|
|
|
script = fopen(SCRIPTFILE_NAME, "w");
|
|
|
|
if (script == NULL)
|
|
|
|
bailout("fopen %s: %s", SCRIPTFILE_NAME,
|
|
|
|
strerror(errno));
|
|
|
|
fprintf(script, "#!/bin/sh\n");
|
|
|
|
fprintf(script, "# %s: %s\n",
|
|
|
|
catgets(catalog, 4, 4, "Script started at"),
|
|
|
|
asctime(localtime(&tloc)));
|
|
|
|
fflush(script);
|
2001-03-03 16:54:22 +03:00
|
|
|
} else { /* close */
|
|
|
|
if (script == NULL)
|
|
|
|
bailout("fopen %s: %s", SCRIPTFILE_NAME,
|
|
|
|
strerror(errno));
|
|
|
|
fprintf(script, "# %s: %s\n",
|
|
|
|
catgets(catalog, 4, 11, "Script ended at"),
|
|
|
|
asctime(localtime(&tloc)));
|
|
|
|
fflush(script);
|
|
|
|
fclose(script);
|
Initial import of sushi.
Sushi is an interactive, menu-based program that is designed to aid
the user or administrator with administrative and complex tasks on thier
machines.
Sushi provides a menu of various functions that the user can perform on
his or her machine. Once the user selects a desired function, the
function is either performed outright, or in most cases, the user is
asked to fill in a simple form with required and option information,
which is then processed by sushi, and the action occurs.
The programming interface for sushi is very simple. There are
directories containing various files, such as menu indexes, or forms for
the user to fill out. These files are interpreted by sushi to generate
the menus the user sees on his/her screen. When the form is filled out
by the user, the entries are passed as command-line arguments to a
program, or script contained in one of the subdirectories. In this way,
it is possible to add new entries to the sushi menu structure, by simply
adding a new menu item, form and script, the binary does not need to be
recompiled to take advantage of this new menu.
2001-01-05 04:28:33 +03:00
|
|
|
}
|
|
|
|
return(NULL); /* XXX */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-05-14 18:30:59 +04:00
|
|
|
* Return list of packages available at the given URL
|
Initial import of sushi.
Sushi is an interactive, menu-based program that is designed to aid
the user or administrator with administrative and complex tasks on thier
machines.
Sushi provides a menu of various functions that the user can perform on
his or her machine. Once the user selects a desired function, the
function is either performed outright, or in most cases, the user is
asked to fill in a simple form with required and option information,
which is then processed by sushi, and the action occurs.
The programming interface for sushi is very simple. There are
directories containing various files, such as menu indexes, or forms for
the user to fill out. These files are interpreted by sushi to generate
the menus the user sees on his/her screen. When the form is filled out
by the user, the entries are passed as command-line arguments to a
program, or script contained in one of the subdirectories. In this way,
it is possible to add new entries to the sushi menu structure, by simply
adding a new menu item, form and script, the binary does not need to be
recompiled to take advantage of this new menu.
2001-01-05 04:28:33 +03:00
|
|
|
* or NULL on error. Returned pointer can be free(3)d
|
|
|
|
* later.
|
|
|
|
*/
|
|
|
|
char **
|
|
|
|
ftp_pkglist(char *subdir)
|
|
|
|
{
|
|
|
|
int rc, tfd;
|
|
|
|
char tmpname[FILENAME_MAX];
|
|
|
|
char buf[FILENAME_MAX];
|
|
|
|
char url[FILENAME_MAX];
|
|
|
|
char **list;
|
|
|
|
FILE *f;
|
|
|
|
int nlines;
|
|
|
|
|
|
|
|
extern int ftp_start(char *url); /* pkg_install/lib stuff */
|
|
|
|
extern int Verbose; /* pkg_install/lib stuff */
|
|
|
|
Verbose=0; /* debugging */
|
|
|
|
|
|
|
|
/* ftp(1) must have a trailing '/' for directories */
|
|
|
|
snprintf(url, sizeof(url), "%s/%s/", ftp_base(0), subdir);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start FTP coprocess
|
|
|
|
*/
|
|
|
|
rc = ftp_start(url);
|
|
|
|
if (rc == -1)
|
|
|
|
bailout(catgets(catalog, 1, 3, "ftp_start failed"));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Generate tmp file
|
|
|
|
*/
|
2003-06-13 11:26:41 +04:00
|
|
|
strlcpy(tmpname, TMPFILE_NAME, sizeof(tmpname));
|
Initial import of sushi.
Sushi is an interactive, menu-based program that is designed to aid
the user or administrator with administrative and complex tasks on thier
machines.
Sushi provides a menu of various functions that the user can perform on
his or her machine. Once the user selects a desired function, the
function is either performed outright, or in most cases, the user is
asked to fill in a simple form with required and option information,
which is then processed by sushi, and the action occurs.
The programming interface for sushi is very simple. There are
directories containing various files, such as menu indexes, or forms for
the user to fill out. These files are interpreted by sushi to generate
the menus the user sees on his/her screen. When the form is filled out
by the user, the entries are passed as command-line arguments to a
program, or script contained in one of the subdirectories. In this way,
it is possible to add new entries to the sushi menu structure, by simply
adding a new menu item, form and script, the binary does not need to be
recompiled to take advantage of this new menu.
2001-01-05 04:28:33 +03:00
|
|
|
tfd=mkstemp(tmpname);
|
|
|
|
if (tfd == -1)
|
|
|
|
bailout("mkstemp: %s", strerror(errno));
|
|
|
|
|
|
|
|
close(tfd); /* We don't need the file descriptor, but will use
|
|
|
|
the file in a second */
|
|
|
|
/*
|
|
|
|
* Setup & run the command for ftp(1)
|
|
|
|
*/
|
|
|
|
(void) snprintf(buf, sizeof(buf), "nlist *.tgz %s\n",
|
|
|
|
tmpname);
|
|
|
|
rc = ftp_cmd(buf, "\n(550|226).*\n"); /* catch errors */
|
|
|
|
if (rc != 226) {
|
|
|
|
unlink(tmpname); /* remove clutter */
|
|
|
|
bailout(catgets(catalog, 1, 4, "nlist failed"));
|
|
|
|
}
|
|
|
|
|
|
|
|
f = fopen(tmpname, "r");
|
|
|
|
if (!f)
|
|
|
|
bailout("fopen: %s", strerror(errno));
|
|
|
|
|
|
|
|
/* Read through file once to find out how many lines it has */
|
|
|
|
nlines=0;
|
|
|
|
while(fgets(buf, sizeof(buf), f))
|
|
|
|
nlines++;
|
|
|
|
rewind(f);
|
|
|
|
|
|
|
|
list = malloc((nlines + 1) * sizeof(char *));
|
|
|
|
if (list == NULL)
|
|
|
|
bailout("malloc: %s", strerror(errno));
|
|
|
|
|
|
|
|
/* alloc space for each line now */
|
|
|
|
nlines = 0;
|
|
|
|
while(fgets(buf, sizeof(buf), f)) {
|
|
|
|
list[nlines] = strdup(buf);
|
|
|
|
/* XXX 5 to get .tgz */
|
|
|
|
list[nlines][strlen(list[nlines])-5] = '\0';
|
|
|
|
nlines++;
|
|
|
|
}
|
|
|
|
list[nlines] = NULL;
|
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
unlink(tmpname);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stop FTP coprocess
|
|
|
|
*/
|
|
|
|
ftp_stop();
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2001-01-24 12:30:30 +03:00
|
|
|
/*
|
2003-05-14 18:30:59 +04:00
|
|
|
* Return list of package categories available at the given URL
|
2001-01-24 12:30:30 +03:00
|
|
|
* or NULL on error. Returned pointer can be free(3)d
|
|
|
|
* later.
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
|
|
|
char **
|
|
|
|
ftp_pkgcats(char *subdir)
|
|
|
|
{
|
|
|
|
int rc, tfd;
|
|
|
|
char tmpname[FILENAME_MAX];
|
|
|
|
char buf[FILENAME_MAX];
|
|
|
|
char url[FILENAME_MAX];
|
|
|
|
char **list;
|
|
|
|
FILE *f;
|
|
|
|
int nlines;
|
|
|
|
|
|
|
|
extern int ftp_start(char *url); /* pkg_install/lib stuff */
|
|
|
|
extern int Verbose; /* pkg_install/lib stuff */
|
|
|
|
Verbose=0; /* debugging */
|
|
|
|
|
|
|
|
/* ftp(1) must have a trailing '/' for directories */
|
|
|
|
snprintf(url, sizeof(url), "%s/", ftp_base(0));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start FTP coprocess
|
|
|
|
*/
|
|
|
|
rc = ftp_start(url);
|
|
|
|
if (rc == -1)
|
|
|
|
bailout(catgets(catalog, 1, 3, "ftp_start failed"));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Generate tmp file
|
|
|
|
*/
|
2003-06-13 11:26:41 +04:00
|
|
|
strlcpy(tmpname, TMPFILE_NAME, sizeof(tmpname));
|
2001-01-24 12:30:30 +03:00
|
|
|
tfd=mkstemp(tmpname);
|
|
|
|
if (tfd == -1)
|
|
|
|
bailout("mkstemp: %s", strerror(errno));
|
|
|
|
|
|
|
|
close(tfd); /* We don't need the file descriptor, but will use
|
|
|
|
the file in a second */
|
|
|
|
/*
|
|
|
|
* Setup & run the command for ftp(1)
|
|
|
|
*/
|
|
|
|
(void) snprintf(buf, sizeof(buf), "ls -1F %s\n",
|
|
|
|
tmpname);
|
|
|
|
rc = ftp_cmd(buf, "\n(550|226).*\n"); /* catch errors */
|
|
|
|
if (rc != 226) {
|
|
|
|
unlink(tmpname); /* remove clutter */
|
|
|
|
bailout(catgets(catalog, 1, 4, "nlist failed"));
|
|
|
|
}
|
|
|
|
|
|
|
|
f = fopen(tmpname, "r");
|
|
|
|
if (!f)
|
|
|
|
bailout("fopen: %s", strerror(errno));
|
|
|
|
|
|
|
|
/* Read through file once to find out how many lines it has */
|
|
|
|
nlines=0;
|
|
|
|
while(fgets(buf, sizeof(buf), f))
|
|
|
|
nlines++;
|
|
|
|
rewind(f);
|
|
|
|
|
|
|
|
list = malloc((nlines + 1) * sizeof(char *));
|
|
|
|
if (list == NULL)
|
|
|
|
bailout("malloc: %s", strerror(errno));
|
|
|
|
|
|
|
|
/* alloc space for each line now */
|
|
|
|
nlines = 0;
|
|
|
|
while(fgets(buf, sizeof(buf), f)) {
|
|
|
|
list[nlines] = strdup(buf);
|
2002-07-25 16:20:56 +04:00
|
|
|
/* XXX jdolecek: is this right? strdup() and conditional
|
|
|
|
* nlines++?
|
|
|
|
*/
|
2001-01-24 12:30:30 +03:00
|
|
|
if (list[nlines][strlen(list[nlines])-2] == '/') {
|
|
|
|
list[nlines][strlen(list[nlines])-2] = '\0';
|
|
|
|
nlines++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
list[nlines] = NULL;
|
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
unlink(tmpname);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stop FTP coprocess
|
|
|
|
*/
|
|
|
|
ftp_stop();
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
Initial import of sushi.
Sushi is an interactive, menu-based program that is designed to aid
the user or administrator with administrative and complex tasks on thier
machines.
Sushi provides a menu of various functions that the user can perform on
his or her machine. Once the user selects a desired function, the
function is either performed outright, or in most cases, the user is
asked to fill in a simple form with required and option information,
which is then processed by sushi, and the action occurs.
The programming interface for sushi is very simple. There are
directories containing various files, such as menu indexes, or forms for
the user to fill out. These files are interpreted by sushi to generate
the menus the user sees on his/her screen. When the form is filled out
by the user, the entries are passed as command-line arguments to a
program, or script contained in one of the subdirectories. In this way,
it is possible to add new entries to the sushi menu structure, by simply
adding a new menu item, form and script, the binary does not need to be
recompiled to take advantage of this new menu.
2001-01-05 04:28:33 +03:00
|
|
|
/*
|
|
|
|
* Return patch where binary packages for this OS version/arch
|
|
|
|
* are expected. If mirror is NULL, ftp.netbsd.org is used.
|
|
|
|
* If it's set, it's assumed to be the URL where the the
|
|
|
|
* OS version dirs are, e.g. ftp://ftp.netbsd.org/pub/NetBSD/packages.
|
|
|
|
* If $PKG_PATH is set, is returned unchanged, overriding everything.
|
|
|
|
* In any case, a trailing '/' is *not* passed.
|
|
|
|
* See also Appendix B of /usr/pkgsrc/Packages.txt.
|
|
|
|
*
|
|
|
|
* The returned pointer will be overwritten on next call of
|
|
|
|
* this function.
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
ftp_base(int truename)
|
|
|
|
{
|
|
|
|
char *pkg_path;
|
|
|
|
struct utsname un;
|
|
|
|
static char buf[256];
|
|
|
|
int rc, i, founddot;
|
|
|
|
|
|
|
|
founddot = 0;
|
|
|
|
pkg_path = getenv("PKG_PATH");
|
|
|
|
if (pkg_path)
|
|
|
|
return strdup(pkg_path);
|
|
|
|
|
2003-06-13 11:26:41 +04:00
|
|
|
strlcpy(buf, NETBSD_PKG_BASE, sizeof(buf));
|
Initial import of sushi.
Sushi is an interactive, menu-based program that is designed to aid
the user or administrator with administrative and complex tasks on thier
machines.
Sushi provides a menu of various functions that the user can perform on
his or her machine. Once the user selects a desired function, the
function is either performed outright, or in most cases, the user is
asked to fill in a simple form with required and option information,
which is then processed by sushi, and the action occurs.
The programming interface for sushi is very simple. There are
directories containing various files, such as menu indexes, or forms for
the user to fill out. These files are interpreted by sushi to generate
the menus the user sees on his/her screen. When the form is filled out
by the user, the entries are passed as command-line arguments to a
program, or script contained in one of the subdirectories. In this way,
it is possible to add new entries to the sushi menu structure, by simply
adding a new menu item, form and script, the binary does not need to be
recompiled to take advantage of this new menu.
2001-01-05 04:28:33 +03:00
|
|
|
|
|
|
|
rc = uname(&un);
|
|
|
|
if (rc == -1)
|
|
|
|
bailout("uname: %s", strerror(errno));
|
|
|
|
|
2003-06-13 11:26:41 +04:00
|
|
|
strlcat(buf, "/", sizeof(buf));
|
Initial import of sushi.
Sushi is an interactive, menu-based program that is designed to aid
the user or administrator with administrative and complex tasks on thier
machines.
Sushi provides a menu of various functions that the user can perform on
his or her machine. Once the user selects a desired function, the
function is either performed outright, or in most cases, the user is
asked to fill in a simple form with required and option information,
which is then processed by sushi, and the action occurs.
The programming interface for sushi is very simple. There are
directories containing various files, such as menu indexes, or forms for
the user to fill out. These files are interpreted by sushi to generate
the menus the user sees on his/her screen. When the form is filled out
by the user, the entries are passed as command-line arguments to a
program, or script contained in one of the subdirectories. In this way,
it is possible to add new entries to the sushi menu structure, by simply
adding a new menu item, form and script, the binary does not need to be
recompiled to take advantage of this new menu.
2001-01-05 04:28:33 +03:00
|
|
|
if (!truename)
|
|
|
|
for (i = 0; i < _SYS_NMLN; i++) {
|
|
|
|
if ((un.release[i] == '_') ||
|
|
|
|
(un.release[i] >= 'A' && un.release[i] <= 'Z'))
|
|
|
|
un.release[i] = '\0';
|
|
|
|
if (un.release[i] == '.') {
|
|
|
|
if (founddot)
|
|
|
|
un.release[i] = '\0';
|
|
|
|
else
|
|
|
|
founddot++;
|
|
|
|
}
|
|
|
|
if (un.release[i] == '\0')
|
|
|
|
break;
|
|
|
|
}
|
2003-06-13 11:26:41 +04:00
|
|
|
strlcat(buf, un.release, sizeof(buf));
|
|
|
|
strlcat(buf, "/", sizeof(buf));
|
|
|
|
strlcat(buf, un.machine, sizeof(buf)); /* sysctl hw.machine_arch? */
|
Initial import of sushi.
Sushi is an interactive, menu-based program that is designed to aid
the user or administrator with administrative and complex tasks on thier
machines.
Sushi provides a menu of various functions that the user can perform on
his or her machine. Once the user selects a desired function, the
function is either performed outright, or in most cases, the user is
asked to fill in a simple form with required and option information,
which is then processed by sushi, and the action occurs.
The programming interface for sushi is very simple. There are
directories containing various files, such as menu indexes, or forms for
the user to fill out. These files are interpreted by sushi to generate
the menus the user sees on his/her screen. When the form is filled out
by the user, the entries are passed as command-line arguments to a
program, or script contained in one of the subdirectories. In this way,
it is possible to add new entries to the sushi menu structure, by simply
adding a new menu item, form and script, the binary does not need to be
recompiled to take advantage of this new menu.
2001-01-05 04:28:33 +03:00
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|