Subversion Repositories SvarDOS

Rev

Rev 223 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 223 Rev 224
Line 198... Line 198...
198
    strcpy(zipfile, localfile);
198
    strcpy(zipfile, localfile);
199
  } else {
199
  } else {
200
    zipfile[0] = 0;
200
    zipfile[0] = 0;
201
  }
201
  }
202
 
202
 
203
#ifndef NOREPOS
-
 
204
  if (zipfile[0] == 0) { /* need to download the package from a repository */
-
 
205
    char *instrepo;
-
 
206
    struct pkgdb *pkgnode, *lastnode;
-
 
207
    struct pkgrepo *pkgrepo;
-
 
208
    int repoid;
-
 
209
    unsigned long zipfilecrc, remotecrc;
-
 
210
    unsigned char *buff;
-
 
211
    int buffreadres;
-
 
212
    char *pkgext; /* zip or zib */
-
 
213
 
-
 
214
    /* look into the db to find the package */
-
 
215
    pkgnode = findpkg(pkgdb, pkgname, &lastnode);
-
 
216
    if (pkgnode == NULL) { /* no such package found in repositories */
-
 
217
      kitten_printf(3, 1, "No package '%s' found in online repositories.", pkgname);
-
 
218
      puts("");
-
 
219
      return(NULL);
-
 
220
    }
-
 
221
 
-
 
222
    /* if found - check the list of repositories */
-
 
223
    if (pkgnode->repolist == NULL) {
-
 
224
      kitten_printf(3, 2, "Package '%s' is not available in repositories.", pkgname);
-
 
225
      puts("");
-
 
226
      return(NULL);
-
 
227
    }
-
 
228
 
-
 
229
    if (pkgnode->repolist->nextrepo != NULL) { /* available from more than 1 repo.. */
-
 
230
      char userchoicestr[8];
-
 
231
      int userchoice, latestver_repoid = 1;
-
 
232
      struct pkgrepo *xrepo, *latestver = pkgnode->repolist;
-
 
233
      /* check out if we are able to find out the newest version */
-
 
234
      repoid = 2; /* setting to 2, because we start iterating at the second repo entry */
-
 
235
      for (xrepo = pkgnode->repolist->nextrepo; xrepo != NULL; xrepo = xrepo->nextrepo) {
-
 
236
        int versionnewerres = isversionnewer(latestver->version, xrepo->version);
-
 
237
        if (versionnewerres > 0) {
-
 
238
          latestver = xrepo;
-
 
239
          latestver_repoid = repoid;
-
 
240
        } else if (versionnewerres < 0) {  /* unable to tell which version is newer */
-
 
241
          latestver_repoid = -1;
-
 
242
          break;
-
 
243
        }
-
 
244
        repoid += 1;
-
 
245
      }
-
 
246
      if (latestver_repoid > 0) {
-
 
247
        repoid = latestver_repoid;
-
 
248
      } else { /* newest version could not be figured out, so let's ask the user to choose */
-
 
249
        puts("");
-
 
250
        kitten_printf(3, 3, "%s is available from several repositories. Choose which one to use:", pkgname);
-
 
251
        puts("");
-
 
252
        repoid = 1;
-
 
253
        for (xrepo = pkgnode->repolist; xrepo != NULL; xrepo = xrepo->nextrepo) {
-
 
254
          printf(" %d) %s %s (%s)\n", repoid, pkgnode->name, xrepo->version, repolist[xrepo->repo]);
-
 
255
          repoid += 1;
-
 
256
        }
-
 
257
        for (;;) {
-
 
258
          kitten_printf(3, 4, "Your choice:");
-
 
259
          printf(" ");
-
 
260
          fgets(userchoicestr, 6, stdin);
-
 
261
          userchoice = atoi(userchoicestr);
-
 
262
          if ((userchoice < 1) || (userchoice >= repoid)) {
-
 
263
            kitten_puts(3, 5, "Invalid choice!");
-
 
264
          } else {
-
 
265
            break;
-
 
266
          }
-
 
267
        }
-
 
268
        repoid = userchoice;
-
 
269
      }
-
 
270
    } else { /* available only from one repository - get it there */
-
 
271
      repoid = 1;
-
 
272
    }
-
 
273
    pkgrepo = pkgnode->repolist;
-
 
274
    for (; repoid > 1; repoid--) pkgrepo = pkgrepo->nextrepo;
-
 
275
    instrepo = repolist[pkgrepo->repo];
-
 
276
 
-
 
277
    /* select the package extension: zip or zib */
-
 
278
    if ((flags & PKGINST_NOSOURCE) && (pkgrepo->crc32zib != 0)) { /* use zib if available and if no sources needed */
-
 
279
      pkgext = "zib"; /* zib is the same thing as zip, but binary-only (no sources) */
-
 
280
      remotecrc = pkgrepo->crc32zib;
-
 
281
    } else { /* otherwise use the full-blown zip package */
-
 
282
      pkgext = "zip";
-
 
283
      remotecrc = pkgrepo->crc32zip;
-
 
284
    }
-
 
285
 
-
 
286
    /* if it's a network repo, download the package from repoid into the temp directory */
-
 
287
    if (detect_localpath(instrepo) == 0) {
-
 
288
      sprintf(fname, "%s%s.%s", instrepo, pkgname, pkgext);
-
 
289
      sprintf(zipfile, "%s\\fdnpkg.tmp", tempdir);
-
 
290
      kitten_printf(3, 6, "Downloading package %s...", fname);
-
 
291
      puts("");
-
 
292
      if (http_get(fname, zipfile, proxy, proxyport, downloadingstring) <= 0) {
-
 
293
        kitten_puts(3, 7, "Error downloading package. Aborted.");
-
 
294
        return(NULL);
-
 
295
      }
-
 
296
    } else { /* else it's an on-disk repo, so we can use the package right from there */
-
 
297
      sprintf(zipfile, "%s%s.%s", instrepo, pkgname, pkgext);
-
 
298
    }
-
 
299
    /* check the CRC of the downloaded file */
-
 
300
    buff = malloc(4096);  /* use a 4K buffer to compute file's CRC */
-
 
301
    if (buff == NULL) {
-
 
302
      kitten_puts(3, 15, "Error: Out of memory while computing the CRC of the package!");
-
 
303
      return(NULL);
-
 
304
    }
-
 
305
    *zipfd = fopen(zipfile, "rb");
-
 
306
    if (*zipfd == NULL) {
-
 
307
      kitten_puts(3, 14, "Error: Failed to open the downloaded package. Installation aborted.");
-
 
308
      free(buff);
-
 
309
      return(NULL);
-
 
310
    }
-
 
311
    zipfilecrc = crc32_init();
-
 
312
    while ((buffreadres = read(fileno(*zipfd), buff, 4096)) > 0) {
-
 
313
      crc32_feed(&zipfilecrc, buff, buffreadres);
-
 
314
    }
-
 
315
    crc32_finish(&zipfilecrc);
-
 
316
    fclose(*zipfd);
-
 
317
    free(buff);
-
 
318
    if (zipfilecrc != remotecrc) {
-
 
319
      kitten_puts(3, 13, "Error: Downloaded package had wrong CRC. Installation aborted.");
-
 
320
      return(NULL);
-
 
321
    }
-
 
322
  } /* if (zipfile[0] == 0) */
-
 
323
#endif
-
 
324
 
-
 
325
  /* Now let's check the content of the zip file */
203
  /* Now let's check the content of the zip file */
326
 
204
 
327
  *zipfd = fopen(zipfile, "rb");
205
  *zipfd = fopen(zipfile, "rb");
328
  if (*zipfd == NULL) {
206
  if (*zipfd == NULL) {
329
    kitten_puts(3, 8, "Error: Invalid zip archive! Package not installed.");
207
    kitten_puts(3, 8, "Error: Invalid zip archive! Package not installed.");