aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/pkg
diff options
context:
space:
mode:
authorBaptiste Daroussin <bapt@FreeBSD.org>2012-05-01 10:16:12 +0000
committerBaptiste Daroussin <bapt@FreeBSD.org>2012-05-01 10:16:12 +0000
commit2fe3761e69734dad8cecda8a3a4c8074cc29e1a6 (patch)
tree8af6d48b192b605d8a9f06d6cb64478ceffc7789 /usr.sbin/pkg
parent2b9c925ff0fcc2730b7bfb06af52660211d250c6 (diff)
downloadsrc-2fe3761e69734dad8cecda8a3a4c8074cc29e1a6.tar.gz
src-2fe3761e69734dad8cecda8a3a4c8074cc29e1a6.zip
- close the open file after fetching
- create a default /usr/local/etc/pkg.conf Approved by: des (mentor)
Notes
Notes: svn path=/head/; revision=234870
Diffstat (limited to 'usr.sbin/pkg')
-rw-r--r--usr.sbin/pkg/pkg.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/usr.sbin/pkg/pkg.c b/usr.sbin/pkg/pkg.c
index a4730afc18ac..e0bc4b3b5d44 100644
--- a/usr.sbin/pkg/pkg.c
+++ b/usr.sbin/pkg/pkg.c
@@ -282,7 +282,10 @@ static int
bootstrap_pkg(void)
{
FILE *remote;
+ FILE *config;
+ char *site;
char url[MAXPATHLEN];
+ char conf[MAXPATHLEN];
char abi[BUFSIZ];
char tmppkg[MAXPATHLEN];
char buf[10240];
@@ -290,7 +293,6 @@ bootstrap_pkg(void)
int fd, retry, ret;
struct url_stat st;
off_t done, r;
- time_t begin_dl;
time_t now;
time_t last;
@@ -298,6 +300,7 @@ bootstrap_pkg(void)
last = 0;
ret = -1;
remote = NULL;
+ config = NULL;
printf("Bootstrapping pkg please wait\n");
@@ -307,7 +310,7 @@ bootstrap_pkg(void)
}
if (getenv("PACKAGESITE") != NULL)
- snprintf(url, MAXPATHLEN, "%s/pkg.txz", getenv("PACKAGESITE"));
+ snprintf(url, MAXPATHLEN, "%s/Latest/pkg.txz", getenv("PACKAGESITE"));
else
snprintf(url, MAXPATHLEN, "%s/%s/latest/Latest/pkg.txz",
getenv("PACKAGEROOT") ? getenv("PACKAGEROOT") : _PKGS_URL,
@@ -331,7 +334,6 @@ bootstrap_pkg(void)
if (remote == NULL)
goto fetchfail;
- begin_dl = time(NULL);
while (done < st.size) {
if ((r = fread(buf, 1, sizeof(buf), remote)) < 1)
break;
@@ -353,12 +355,34 @@ bootstrap_pkg(void)
if ((ret = extract_pkg_static(fd, pkgstatic, MAXPATHLEN)) == 0)
ret = install_pkg_static(pkgstatic, tmppkg);
+ snprintf(conf, MAXPATHLEN, "%s/etc/pkg.conf",
+ getenv("LOCALBASE") ? getenv("LOCALBASE") : _LOCALBASE);
+
+ if (access(conf, R_OK) == -1) {
+ site = strrchr(url, '/');
+ if (site == NULL)
+ goto cleanup;
+ site[0] = '\0';
+ site = strrchr(url, '/');
+ if (site == NULL)
+ goto cleanup;
+ site[0] = '\0';
+
+ config = fopen(conf, "w+");
+ if (config == NULL)
+ goto cleanup;
+ fprintf(config, "packagesite: %s", url);
+ fclose(config);
+ }
+
goto cleanup;
fetchfail:
warnx("Error fetching %s: %s", url, fetchLastErrString);
cleanup:
+ if (remote != NULL)
+ fclose(remote);
close(fd);
unlink(tmppkg);