2 * FreeBSD install - a package for the installation and maintainance
3 * of non-core utilities.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
17 * URL file access utilities.
19 * $FreeBSD: src/usr.sbin/pkg_install/lib/url.c,v 1.4 2004/06/29 19:06:42 eik Exp $
20 * $DragonFly: src/usr.sbin/pkg_install/lib/Attic/url.c,v 1.1 2004/07/30 04:46:13 dillon Exp $
29 * Try and fetch a file by URL, returning the directory name for where
30 * it's unpacked, if successful.
33 fileGetURL(const char *base, const char *spec)
36 char fname[FILENAME_MAX];
37 char pen[FILENAME_MAX];
41 int pfd[2], pstat, r, w = 0;
46 /* Special tip that sysinstall left for us */
47 hint = getenv("PKG_ADD_BASE");
52 * We've been given an existing URL (that's known-good) and now we need
53 * to construct a composite one out of that and the basename we were
54 * handed as a dependency.
59 * Advance back two slashes to get to the root of the package
62 cp = strrchr(fname, '/');
64 *cp = '\0'; /* chop name */
65 cp = strrchr(fname, '/');
71 #if defined(__FreeBSD_version) && __FreeBSD_version >= 500039
82 * Otherwise, we've been given an environment variable hinting
83 * at the right location from sysinstall
87 #if defined(__FreeBSD_version) && __FreeBSD_version >= 500039
88 strcat(fname, ".tbz");
90 strcat(fname, ".tgz");
97 if ((ftp = fetchGetURL(fname, Verbose ? "v" : NULL)) == NULL) {
98 printf("Error: FTP Unable to get %s: %s\n",
99 fname, fetchLastErrString);
103 if (isatty(0) || Verbose)
104 printf("Fetching %s...", fname), fflush(stdout);
106 if ((rp = make_playpen(pen, 0)) == NULL) {
107 printf("Error: Unable to construct a new playpen for FTP!\n");
111 if (pipe(pfd) == -1) {
116 if ((tpid = fork()) == -1) {
123 for (fd = getdtablesize() - 1; fd >= 3; --fd)
125 execl("/usr/bin/tar", "tar",
126 #if defined(__FreeBSD_version) && __FreeBSD_version >= 500039
127 Verbose ? "-xjvf" : "-xjf",
129 Verbose ? "-xzvf" : "-xzf",
136 if ((r = fread(buf, 1, sizeof buf, ftp)) < 1)
138 if ((w = write(pfd[1], buf, r)) != r)
142 warn("warning: error reading from server");
146 warn("warning: error writing to tar");
147 tpid = waitpid(tpid, &pstat, 0);
149 printf("tar command returns %d status\n", WEXITSTATUS(pstat));
150 if (rp && (isatty(0) || Verbose))