200,128 → 200,6 |
zipfile[0] = 0; |
} |
|
#ifndef NOREPOS |
if (zipfile[0] == 0) { /* need to download the package from a repository */ |
char *instrepo; |
struct pkgdb *pkgnode, *lastnode; |
struct pkgrepo *pkgrepo; |
int repoid; |
unsigned long zipfilecrc, remotecrc; |
unsigned char *buff; |
int buffreadres; |
char *pkgext; /* zip or zib */ |
|
/* look into the db to find the package */ |
pkgnode = findpkg(pkgdb, pkgname, &lastnode); |
if (pkgnode == NULL) { /* no such package found in repositories */ |
kitten_printf(3, 1, "No package '%s' found in online repositories.", pkgname); |
puts(""); |
return(NULL); |
} |
|
/* if found - check the list of repositories */ |
if (pkgnode->repolist == NULL) { |
kitten_printf(3, 2, "Package '%s' is not available in repositories.", pkgname); |
puts(""); |
return(NULL); |
} |
|
if (pkgnode->repolist->nextrepo != NULL) { /* available from more than 1 repo.. */ |
char userchoicestr[8]; |
int userchoice, latestver_repoid = 1; |
struct pkgrepo *xrepo, *latestver = pkgnode->repolist; |
/* check out if we are able to find out the newest version */ |
repoid = 2; /* setting to 2, because we start iterating at the second repo entry */ |
for (xrepo = pkgnode->repolist->nextrepo; xrepo != NULL; xrepo = xrepo->nextrepo) { |
int versionnewerres = isversionnewer(latestver->version, xrepo->version); |
if (versionnewerres > 0) { |
latestver = xrepo; |
latestver_repoid = repoid; |
} else if (versionnewerres < 0) { /* unable to tell which version is newer */ |
latestver_repoid = -1; |
break; |
} |
repoid += 1; |
} |
if (latestver_repoid > 0) { |
repoid = latestver_repoid; |
} else { /* newest version could not be figured out, so let's ask the user to choose */ |
puts(""); |
kitten_printf(3, 3, "%s is available from several repositories. Choose which one to use:", pkgname); |
puts(""); |
repoid = 1; |
for (xrepo = pkgnode->repolist; xrepo != NULL; xrepo = xrepo->nextrepo) { |
printf(" %d) %s %s (%s)\n", repoid, pkgnode->name, xrepo->version, repolist[xrepo->repo]); |
repoid += 1; |
} |
for (;;) { |
kitten_printf(3, 4, "Your choice:"); |
printf(" "); |
fgets(userchoicestr, 6, stdin); |
userchoice = atoi(userchoicestr); |
if ((userchoice < 1) || (userchoice >= repoid)) { |
kitten_puts(3, 5, "Invalid choice!"); |
} else { |
break; |
} |
} |
repoid = userchoice; |
} |
} else { /* available only from one repository - get it there */ |
repoid = 1; |
} |
pkgrepo = pkgnode->repolist; |
for (; repoid > 1; repoid--) pkgrepo = pkgrepo->nextrepo; |
instrepo = repolist[pkgrepo->repo]; |
|
/* select the package extension: zip or zib */ |
if ((flags & PKGINST_NOSOURCE) && (pkgrepo->crc32zib != 0)) { /* use zib if available and if no sources needed */ |
pkgext = "zib"; /* zib is the same thing as zip, but binary-only (no sources) */ |
remotecrc = pkgrepo->crc32zib; |
} else { /* otherwise use the full-blown zip package */ |
pkgext = "zip"; |
remotecrc = pkgrepo->crc32zip; |
} |
|
/* if it's a network repo, download the package from repoid into the temp directory */ |
if (detect_localpath(instrepo) == 0) { |
sprintf(fname, "%s%s.%s", instrepo, pkgname, pkgext); |
sprintf(zipfile, "%s\\fdnpkg.tmp", tempdir); |
kitten_printf(3, 6, "Downloading package %s...", fname); |
puts(""); |
if (http_get(fname, zipfile, proxy, proxyport, downloadingstring) <= 0) { |
kitten_puts(3, 7, "Error downloading package. Aborted."); |
return(NULL); |
} |
} else { /* else it's an on-disk repo, so we can use the package right from there */ |
sprintf(zipfile, "%s%s.%s", instrepo, pkgname, pkgext); |
} |
/* check the CRC of the downloaded file */ |
buff = malloc(4096); /* use a 4K buffer to compute file's CRC */ |
if (buff == NULL) { |
kitten_puts(3, 15, "Error: Out of memory while computing the CRC of the package!"); |
return(NULL); |
} |
*zipfd = fopen(zipfile, "rb"); |
if (*zipfd == NULL) { |
kitten_puts(3, 14, "Error: Failed to open the downloaded package. Installation aborted."); |
free(buff); |
return(NULL); |
} |
zipfilecrc = crc32_init(); |
while ((buffreadres = read(fileno(*zipfd), buff, 4096)) > 0) { |
crc32_feed(&zipfilecrc, buff, buffreadres); |
} |
crc32_finish(&zipfilecrc); |
fclose(*zipfd); |
free(buff); |
if (zipfilecrc != remotecrc) { |
kitten_puts(3, 13, "Error: Downloaded package had wrong CRC. Installation aborted."); |
return(NULL); |
} |
} /* if (zipfile[0] == 0) */ |
#endif |
|
/* Now let's check the content of the zip file */ |
|
*zipfd = fopen(zipfile, "rb"); |