Esempio n. 1
0
static int loadUrlImages(struct iurlinfo * ui) {
    char *buf, *path, *dest, *slash;
    int rc;

    /* Figure out the path where updates.img and product.img files are
     * kept.  Since ui->prefix points to a stage2 image file, we just need
     * to trim off the file name and look in the same directory.
     */
    if ((slash = strrchr(ui->prefix, '/')) == NULL)
        return 0;

    if ((path = strndup(ui->prefix, slash - ui->prefix)) == NULL)
        path = ui->prefix;

    /* grab the updates.img before install.img so that we minimize our
     * ramdisk usage */
    if (asprintf(&buf, "%s/%s", path, "updates.img") == -1) {
        logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
        abort();
    }

    if (!loadSingleUrlImage(ui, buf,
                            "/tmp/updates-disk.img", "/tmp/update-disk",
                            "/dev/loop7", 1)) {
        copyDirectory("/tmp/update-disk", "/tmp/updates", copyWarnFn,
                      copyErrorFn);
        umountLoopback("/tmp/update-disk", "/dev/loop7");
        unlink("/tmp/updates-disk.img");
        unlink("/tmp/update-disk");
    } else if (!access("/tmp/updates-disk.img", R_OK)) {
        unpackCpioBall("/tmp/updates-disk.img", "/tmp/updates");
        unlink("/tmp/updates-disk.img");
    }

    free(buf);

    /* grab the product.img before install.img so that we minimize our
     * ramdisk usage */
    if (asprintf(&buf, "%s/%s", path, "product.img") == -1) {
        logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
        abort();
    }

    if (!loadSingleUrlImage(ui, buf,
                            "/tmp/product-disk.img", "/tmp/product-disk",
                            "/dev/loop7", 1)) {
        copyDirectory("/tmp/product-disk", "/tmp/product", copyWarnFn,
                      copyErrorFn);
        umountLoopback("/tmp/product-disk", "/dev/loop7");
        unlink("/tmp/product-disk.img");
        unlink("/tmp/product-disk");
    }

    free(buf);

    if (asprintf(&dest, "/tmp/install.img") == -1) {
        logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
        abort();
    }

    rc = loadSingleUrlImage(ui, ui->prefix, dest, "/mnt/runtime", "/dev/loop0", 0);
    free(dest);

    if (rc) {
        if (rc != 2) 
            newtWinMessage(_("Error"), _("OK"),
                           _("Unable to retrieve the install image."));
        return 1;
    }

    return 0;
}
Esempio n. 2
0
/* given a partition device and directory, tries to mount hd install image */
static char * setupIsoImages(char * device, char * dirName, char * location) {
    int rc = 0;
    char *url = NULL, *dirspec, *updpath, *path;

    logMessage(INFO, "mounting device %s for hard drive install", device);

    if (doPwMount(device, "/mnt/isodir", "auto", "ro", NULL))
        return NULL;

    checked_asprintf(&dirspec, "/mnt/isodir%.*s",
                     (int) (strrchr(dirName, '/') - dirName), dirName);
    checked_asprintf(&path, "/mnt/isodir%s", dirName);

    if (path) {
        logMessage(INFO, "Path to stage2 image is %s", path);

        rc = copyFile(path, "/tmp/install.img");
        rc = mountStage2("/tmp/install.img");

        free(path);

        if (rc) {
            umountLoopback("/mnt/runtime", "/dev/loop0");
            umount("/mnt/isodir");
            goto err;
        }

        checked_asprintf(&updpath, "%s/updates.img", dirspec);

        logMessage(INFO, "Looking for updates for HD in %s", updpath);
        copyUpdatesImg(updpath);
        free(updpath);

        checked_asprintf(&updpath, "%s/product.img", dirspec);

        logMessage(INFO, "Looking for product for HD in %s", updpath);
        copyProductImg(updpath);

        free(updpath);
        free(dirspec);
        umount("/mnt/isodir");

        checked_asprintf(&url, "hd:%s:/%s", device,
                         dirName ? dirName : ".");

        return url;
    } else {
        free(dirspec);
        free(path);

        if (rc) {
            umount("/mnt/isodir");
            return NULL;
        }
    }

err:
    newtWinMessage(_("Error"), _("OK"),
                   _("An error occured finding the installation image "
                     "on your hard drive.  Please check your images and "
                     "try again."));
    return NULL;
}
Esempio n. 3
0
char * mountNfsImage(struct installMethod * method,
                     char * location, struct loaderData_s * loaderData,
                     moduleInfoSet modInfo, moduleList modLoaded,
                     moduleDeps * modDepsPtr) {
    char * host = NULL;
    char * directory = NULL;
    char * mountOpts = NULL;
    char * fullPath = NULL;
    char * path;
    char * url = NULL;

    enum { NFS_STAGE_NFS, NFS_STAGE_MOUNT, 
           NFS_STAGE_DONE } stage = NFS_STAGE_NFS;

    int rc;
    int dir = 1;

    /* JKFIXME: ASSERT -- we have a network device setup when we get here */
    while (stage != NFS_STAGE_DONE) {
        switch (stage) {
        case NFS_STAGE_NFS:
            logMessage(INFO, "going to do nfsGetSetup");
            if (loaderData->method == METHOD_NFS && loaderData->methodData) {
                host = ((struct nfsInstallData *)loaderData->methodData)->host;
                directory = ((struct nfsInstallData *)loaderData->methodData)->directory;
                mountOpts = ((struct nfsInstallData *)loaderData->methodData)->mountOpts;

                logMessage(INFO, "host is %s, dir is %s, opts are '%s'", host, directory, mountOpts);

                if (!host || !directory) {
                    logMessage(ERROR, "missing host or directory specification");
                    loaderData->method = -1;
                    break;
                } else {
                    host = strdup(host);
                    directory = strdup(directory);
                    if (mountOpts) {
                        mountOpts = strdup(mountOpts);
                    }
                }
            } else if (nfsGetSetup(&host, &directory, &mountOpts) == LOADER_BACK) {
                return NULL;
            }
             
            stage = NFS_STAGE_MOUNT;
            dir = 1;
            break;

        case NFS_STAGE_MOUNT: {
            int foundinvalid = 0;
            char * buf;
            struct in_addr ip;

            if (loaderData->noDns && !(inet_pton(AF_INET, host, &ip))) {
                newtWinMessage(_("Error"), _("OK"),
                               _("Hostname specified with no DNS configured"));
                if (loaderData->method >= 0) {
                    loaderData->method = -1;
                }
                break;
            }

            fullPath = alloca(strlen(host) + strlen(directory) + 2);
            sprintf(fullPath, "%s:%s", host, directory);

            logMessage(INFO, "mounting nfs path %s, options '%s'", fullPath, mountOpts);

            if (FL_TESTING(flags)) {
                stage = NFS_STAGE_DONE;
                dir = 1;
                break;
            }

            stage = NFS_STAGE_NFS;

            if (!doPwMount(fullPath, "/mnt/source", "nfs", 
                           IMOUNT_RDONLY, mountOpts)) {
                if (!access("/mnt/source/images/stage2.img", R_OK)) {
                    logMessage(INFO, "can access /mnt/source/images/stage2.img");
                    rc = mountStage2("/mnt/source/images/stage2.img");
                    logMessage(DEBUGLVL, "after mountStage2, rc is %d", rc);
                    if (rc) {
                        if (rc == -1) { 
                            foundinvalid = 1; 
                            logMessage(WARNING, "not the right one"); 
                        }
                    } else {
                        stage = NFS_STAGE_DONE;
                        url = "nfs://mnt/source/.";
                        break;
                    }
                } else {
                    logMessage(WARNING, "unable to access /mnt/source/images/stage2.img");
                }

                if ((path = validIsoImages("/mnt/source", &foundinvalid))) {
		    foundinvalid = 0;
		    logMessage(INFO, "Path to valid iso is %s", path);
                    copyUpdatesImg("/mnt/source/updates.img");

                    if (mountLoopback(path, "/mnt/source2", "loop1")) 
                        logMessage(WARNING, "failed to mount iso %s loopback", path);
                    else {
                        rc = mountStage2("/mnt/source2/images/stage2.img");
                        if (rc) {
                            umountLoopback("/mnt/source2", "loop1");
                            if (rc == -1)
				foundinvalid = 1;
                        } else {
                            /* JKFIXME: hack because /mnt/source is hard-coded
                             * in mountStage2() */
                            copyUpdatesImg("/mnt/source2/images/updates.img");
                            copyProductImg("/mnt/source2/images/product.img");

                            queryIsoMediaCheck(path);

                            stage = NFS_STAGE_DONE;
                            url = "nfsiso:/mnt/source";
                            break;
                        }
                    }
                }

		/* if we fell through to here we did not find a valid NFS */
		/* source for installation.                               */
		umount("/mnt/source");
                if (foundinvalid) 
                    buf = sdupprintf(_("The %s installation tree in that "
                                       "directory does not seem to match "
                                       "your boot media."), getProductName());
                else
                    buf = sdupprintf(_("That directory does not seem to "
                                       "contain a %s installation tree."),
                                     getProductName());
                newtWinMessage(_("Error"), _("OK"), buf);
                if (loaderData->method >= 0) {
                    loaderData->method = -1;
                }

		
                break;
            } else {
                newtWinMessage(_("Error"), _("OK"),
                               _("That directory could not be mounted from "
                                 "the server."));
                if (loaderData->method >= 0) {
                    loaderData->method = -1;
                }
                break;
            }
        }

        case NFS_STAGE_DONE:
            break;
        }
    }

    free(host);
    free(directory);
    free(mountOpts);

    return url;
}
Esempio n. 4
0
static int loadUrlImages(struct iurlinfo * ui) {
    char *stage2img;
    char tmpstr1[1024], tmpstr2[1024];
    int rc;

    /*    setupRamdisk();*/

    /* grab the updates.img before netstg1.img so that we minimize our
     * ramdisk usage */
    if (!loadSingleUrlImage(ui, "images/updates.img",
                            "/tmp/ramfs/updates-disk.img", "/tmp/update-disk",
                            "loop7", 1)) {
        copyDirectory("/tmp/update-disk", "/tmp/updates");
        umountLoopback("/tmp/update-disk", "loop7");
        unlink("/tmp/ramfs/updates-disk.img");
        unlink("/tmp/update-disk");
    }

    /* grab the product.img before netstg1.img so that we minimize our
     * ramdisk usage */
    if (!loadSingleUrlImage(ui, "images/product.img",
                            "/tmp/ramfs/product-disk.img", "/tmp/product-disk",
                            "loop7", 1)) {
        copyDirectory("/tmp/product-disk", "/tmp/product");
        umountLoopback("/tmp/product-disk", "loop7");
        unlink("/tmp/ramfs/product-disk.img");
        unlink("/tmp/product-disk");
    }

    /* require 128MB for use of graphical stage 2 due to size of image */
    if (totalMemory() < GUI_STAGE2_RAM) {
	stage2img = "minstg2.img";
	logMessage(WARNING, "URLINSTALL falling back to non-GUI stage2 "
                       "due to insufficient RAM");
    } else {
	stage2img = "stage2.img";
    }

    snprintf(tmpstr1, sizeof(tmpstr1), "images/%s", stage2img);
    snprintf(tmpstr2, sizeof(tmpstr2), "/tmp/ramfs/%s", stage2img);

#ifdef ROCKS
    rc = loadSingleUrlImage(ui, tmpstr1, tmpstr2, "/mnt/runtime", "loop2", 0);
#else
    rc = loadSingleUrlImage(ui, tmpstr1, tmpstr2,
                            "/mnt/runtime", "loop0", 0);
#endif /* ROCKS */

    if (rc) {
        if (rc != 2) 
            newtWinMessage(_("Error"), _("OK"),
                           _("Unable to retrieve the install image."));
        return 1;
    }

#ifndef ROCKS

    /*
     * ROCKS - we don't want to check the stamp since we routinely rebuild
     * the distribution.
     */

    /* now verify the stamp... */
    if (!verifyStamp("/mnt/runtime")) {
	char * buf;

	buf = sdupprintf(_("The %s installation tree in that directory does "
			   "not seem to match your boot media."), 
                         getProductName());

	newtWinMessage(_("Error"), _("OK"), buf);

	umountLoopback("/mnt/runtime", "loop0");
	return 1;
    }

#endif /* ROCKS */

    return 0;

}