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.
21 #include <sys/cdefs.h>
22 __FBSDID("$FreeBSD$");
30 * Try and fetch a file by URL, returning the directory name for where
31 * it's unpacked, if successful.
34 fileGetURL(const char *base, const char *spec)
37 char fname[FILENAME_MAX];
38 char pen[FILENAME_MAX];
42 int pfd[2], pstat, r, w = 0;
47 /* Special tip that sysinstall left for us */
48 hint = getenv("PKG_ADD_BASE");
53 * We've been given an existing URL (that's known-good) and now we need
54 * to construct a composite one out of that and the basename we were
55 * handed as a dependency.
60 * Advance back two slashes to get to the root of the package
63 cp = strrchr(fname, '/');
65 *cp = '\0'; /* chop name */
66 cp = strrchr(fname, '/');
72 #if defined(__FreeBSD_version) && __FreeBSD_version >= 500039
83 * Otherwise, we've been given an environment variable hinting
84 * at the right location from sysinstall
88 #if defined(__FreeBSD_version) && __FreeBSD_version >= 500039
89 strcat(fname, ".tbz");
91 strcat(fname, ".tgz");
98 if ((ftp = fetchGetURL(fname, Verbose ? "v" : NULL)) == NULL) {
99 printf("Error: FTP Unable to get %s: %s\n",
100 fname, fetchLastErrString);
104 if (isatty(0) || Verbose)
105 printf("Fetching %s...", fname), fflush(stdout);
107 if ((rp = make_playpen(pen, 0)) == NULL) {
108 printf("Error: Unable to construct a new playpen for FTP!\n");
112 if (pipe(pfd) == -1) {
117 if ((tpid = fork()) == -1) {
124 for (fd = getdtablesize() - 1; fd >= 3; --fd)
126 execl("/usr/bin/tar", "tar",
127 #if defined(__FreeBSD_version) && __FreeBSD_version >= 500039
128 Verbose ? "-xjvf" : "-xjf",
130 Verbose ? "-xzvf" : "-xzf",
137 if ((r = fread(buf, 1, sizeof buf, ftp)) < 1)
139 if ((w = write(pfd[1], buf, r)) != r)
143 warn("warning: error reading from server");
147 warn("warning: error writing to tar");
148 tpid = waitpid(tpid, &pstat, 0);
150 printf("tar command returns %d status\n", WEXITSTATUS(pstat));
151 if (rp && (isatty(0) || Verbose))