void exit_setup(int ret) { /* Cleanup afterwards */ if ( info ) delete_install(info); FreePlugins(); free_corrupt_files(); unmount_filesystems(); log_exit(); exit(ret); }
int main(int argc, char **argv) { char *cds[SETUP_MAX_DRIVES]; int nb_drives, i; argv0 = argv[0]; log_init(LOG_DEBUG); nb_drives = detect_and_mount_cdrom(cds); printf("%d drives detected.\n", nb_drives); for(i = 0; i < nb_drives; ++i ) { printf("Detected CDROM on %s\n", cds[i]); } free_mounted_cdrom(nb_drives, cds); unmount_filesystems(); return 0; }
void DoMediaCheck(const char *Dir) { carbon_debug("DoMediaCheck()\n"); char path[PATH_MAX], root[PATH_MAX]; install_info *install; //if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radio)) ) { // If path was specified if(Dir) { /* We ignore the CDROM prefix in that case */ snprintf(path, sizeof(path), "%s/setup.data/setup.xml", Dir); if ( access( path, R_OK) ) { /* Doesn't look like a setup archive */ carbon_SetLabelText(Res, CHECK_STATUS_LABEL_ID, _("Unable to identify an installation media.")); return; } strncpy(root, Dir, sizeof(root)); } // Else, assume they selected CDROM drive else { /* Go through all CDROM devices and look for setup.xml files */ char *cds[SETUP_MAX_DRIVES]; int nb_drives = detect_and_mount_cdrom(cds), i; for(i = 0; i < nb_drives; ++i ) { snprintf(path, sizeof(path), "%s/%s/setup.data/setup.xml", cds[i], info->prefix); if ( !access( path, R_OK) ) { snprintf(root, sizeof(root), "%s/%s", cds[i], info->prefix); break; /* FIXME: What if there are many setup CDs ? */ } } free_mounted_cdrom(nb_drives, cds); } /* Verify that the package is the same (product name and version) */ if(!check_xml_setup(path, info->name)) { carbon_SetLabelText(Res, CHECK_STATUS_LABEL_ID, _("Installation media doesn't match the product.")); return; } carbon_SetLabelText(Res, CHECK_STATUS_LABEL_ID, _("Restoring files...")); /* Fetch the files to be refreshed, i.e install with a restricted set of files */ install = create_install(path, info->root, NULL, info->prefix); if ( install ) { const char *f; if ( chdir(root) < 0 ) { fprintf(stderr, _("Unable to change to directory %s\n"), root); } else { /* Update the setup path */ strncpy(install->setup_path, root, sizeof(install->setup_path)); } /* Check if we need to create a default component entry */ if ( GetProductNumComponents(install) == 0 ) { current_component = add_component_entry(install, "Default", install->version, 1, NULL, NULL); } /* Restore any environment */ loki_put_envvars_component(loki_find_component(product, current_component->name)); /* Enable the relevant options */ select_corrupt_options(install); copy_tree(install, install->config->root->childs, install->install_path, NULL); /* Menu items are currently not being restored - maybe they should be tagged in setupdb ? */ /* Install the optional README and EULA files Warning: those are always installed in the root of the installation directory! */ f = GetProductREADME(install); if ( f && ! GetProductIsMeta(install) ) { copy_path(install, f, install->install_path, NULL, 1, NULL, NULL); } f = GetProductEULA(install); if ( f && ! GetProductIsMeta(install) ) { copy_path(install, f, install->install_path, NULL, 1, NULL, NULL); } } /* Print end message and disable the "Rescue" button */ carbon_SetLabelText(Res, CHECK_STATUS_LABEL_ID, _("Files successfully restored !")); carbon_DisableControl(Res, CHECK_RESCUE_BUTTON_ID); carbon_Prompt(Res, PromptType_OK, _("Files successfully restored !"), NULL, 0); /* Unmount filesystems that may have been mounted */ unmount_filesystems(); }
/* Get a mount point for the specified CDROM, and return its path. If the CDROM is not mounted, prompt the user to mount it */ const char *get_cdrom(install_info *info, const char *id) { const char *mounted = NULL, *desc = info->desc; struct cdrom_elem *cd; while ( ! mounted ) { detect_cdrom(info); for ( cd = info->cdroms_list; cd; cd = cd->next ) { if ( !strcmp(id, cd->id) ) { desc = cd->name; if ( cd->mounted ) { mounted = cd->mounted; break; } } } if ( ! mounted ) { yesno_answer response; char buf[1024]; char *prompt; #if defined(darwin) // !!! TODO: do this right. I just hacked this in. --ryan. char *discs[SETUP_MAX_DRIVES]; // This only detects mounted discs and doesn't mount itself on OSX. int discCount = detect_and_mount_cdrom(discs); if (discCount > 0) { char cmd[128]; strcpy(cmd, "/usr/sbin/disktool -e "); strcat(cmd, darwinEjectThisCDDevice); strcat(cmd, " &"); system(cmd); for (discCount--; discCount >= 0; discCount--) free(discs[discCount]); } // end ryan's hack. prompt = _("\nPlease insert the %s CDROM.\n" "Choose Yes to retry, No to cancel"); #else if ( mounted_filesystems() ) { /* We were able to mount at least one CDROM */ prompt = _("\nPlease insert the %s CDROM.\n" "Choose Yes to retry, No to cancel"); } else { prompt = _("\nPlease mount the %s CDROM.\n" "Choose Yes to retry, No to cancel"); } #endif unmount_filesystems(); snprintf(buf, sizeof(buf), prompt, desc); response = UI.prompt(buf, RESPONSE_NO); if ( response == RESPONSE_NO ) { abort_install(); return NULL; } } } return mounted; }
void on_media_ok_clicked (GtkButton *button, gpointer user_data) { GtkWidget *diag = glade_xml_get_widget(check_glade, "diagnostic_label"), *radio; char path[PATH_MAX], root[PATH_MAX]; install_info *install; radio = glade_xml_get_widget(rescue_glade, "dir_radio"); if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radio)) ) { /* Directory */ const gchar *str = gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(rescue_glade, "dir_entry"))); /* We ignore the CDROM prefix in that case */ snprintf(path, sizeof(path), "%s/setup.data/setup.xml", str); if ( access( path, R_OK) ) { /* Doesn't look like a setup archive */ gtk_label_set_text(GTK_LABEL(diag), _("Unable to identify an installation media.")); gtk_widget_hide(glade_xml_get_widget(rescue_glade, "media_select")); return; } strncpy(root, str, sizeof(root)); } else { /* Go through all CDROM devices and look for setup.xml files */ char *cds[SETUP_MAX_DRIVES]; int nb_drives = detect_and_mount_cdrom(cds), i; for(i = 0; i < nb_drives; ++i ) { snprintf(path, sizeof(path), "%s/%s/setup.data/setup.xml", cds[i], info->prefix); if ( !access( path, R_OK) ) { snprintf(root, sizeof(root), "%s/%s", cds[i], info->prefix); break; /* FIXME: What if there are many setup CDs ? */ } } free_mounted_cdrom(nb_drives, cds); } /* Verify that the package is the same (product name and version) */ if ( ! check_xml_setup(path, info->name) ) { gtk_label_set_text(GTK_LABEL(diag), _("Installation media doesn't match the product.")); gtk_widget_hide(glade_xml_get_widget(rescue_glade, "media_select")); return; } gtk_label_set_text(GTK_LABEL(diag), _("Restoring files...")); gtk_widget_realize(diag); /* Fetch the files to be refreshed, i.e install with a restricted set of files */ install = create_install(path, info->root, NULL, info->prefix); if ( install ) { const char *f; if ( chdir(root) < 0 ) { fprintf(stderr, _("Unable to change to directory %s\n"), root); } else { /* Update the setup path */ strncpy(install->setup_path, root, sizeof(install->setup_path)); } /* Check if we need to create a default component entry */ if ( GetProductNumComponents(install) == 0 ) { current_component = add_component_entry(install, "Default", install->version, 1, NULL, NULL); } /* Restore any environment */ loki_put_envvars_component(loki_find_component(product, current_component->name)); /* Enable the relevant options */ select_corrupt_options(install); copy_tree(install, install->config->root->childs, install->install_path, NULL); /* Menu items are currently not being restored - maybe they should be tagged in setupdb ? */ /* Install the optional README and EULA files Warning: those are always installed in the root of the installation directory! */ f = GetProductREADME(install, NULL); if ( f && ! GetProductIsMeta(install) ) { copy_path(install, f, install->install_path, NULL, 1, NULL, NULL); } f = GetProductEULA(install, NULL); if ( f && ! GetProductIsMeta(install) ) { copy_path(install, f, install->install_path, NULL, 1, NULL, NULL); } } /* Print end message and disable the "Rescue" button */ gtk_label_set_text(GTK_LABEL(diag), _("Files successfully restored !")); gtk_widget_set_sensitive(glade_xml_get_widget(check_glade, "rescue_button"), FALSE); gtk_widget_hide(glade_xml_get_widget(rescue_glade, "media_select")); message_dialog(_("Files successfully restored !"), _("Success")); /* Unmount filesystems that may have been mounted */ unmount_filesystems(); }