Ignore:
Timestamp:
Aug 26, 2007, 12:26:06 PM (17 years ago)
Author:
Bruno Cornec
Message:

Use of conf file entries (iso_burning_*, media_device, media_size)
and adapatation of the rest of the code to that (including bkpinfo)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/stable/mondo/src/common/libmondo-devices.c

    r1581 r1594  
    2222#include "mr_str.h"
    2323#include "mr_gettext.h"
     24#include "mr_conf.h"
    2425
    2526#include <sys/ioctl.h>
     
    4748extern char *g_selfmounted_isodir;
    4849extern char *MONDO_LOGFILE;
     50extern struct mr_ar_conf *mr_conf;
    4951
    5052static char g_cdrw_drive_is_here[MAX_STR_LEN / 4] = "";
     
    14431445    char *prompt = NULL;
    14441446    int i = 0;
    1445     int res = 0;
    14461447    FILE *fin = NULL;
    14471448
     
    14661467        sensibly_set_tmpdir_and_scratchdir(bkpinfo);
    14671468    }
    1468     bkpinfo->cdrw_speed = (bkpinfo->backup_media_type == cdstream) ? 2 : 4;
    14691469    bkpinfo->compression_level =
    14701470        (bkpinfo->backup_media_type == cdstream) ? 1 : 5;
     
    14941494            mr_asprintf(&comment, _("What speed is your %s (re)writer?"),
    14951495                    bkpinfo->backup_media_string);
    1496             if (bkpinfo->backup_media_type == dvd) {
    1497                 find_dvd_device(bkpinfo->media_device, FALSE);
    1498                 mr_asprintf(&tmp, "1");
    1499                 mr_asprintf(&sz_size, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4482 MB
    1500                 mr_msg(1, "Setting to DVD defaults");
    1501             } else if (bkpinfo->backup_media_type == usb) {
    1502                 strcpy(bkpinfo->media_device, VANILLA_USB_DEVICE);
    1503                 asprintf(&sz_size, "512");
    1504             } else {
    1505                 strcpy(bkpinfo->media_device, VANILLA_SCSI_CDROM);
    1506                 mr_asprintf(&tmp, "4");
    1507                 mr_asprintf(&sz_size, "650");
    1508                 mr_msg(1, "Setting to CD defaults");
    1509             }
    1510             if ((bkpinfo->backup_media_type != dvd) && (bkpinfo->backup_media_type != usb)) {
     1496            mr_asprintf(&tmp, "%d", mr_conf->iso_burning_speed);
     1497            if (bkpinfo->backup_media_type != usb) {
     1498                /* BERLIOS: NOW that tmp isn't static anymore it does NOT work */
    15111499                if (!popup_and_get_string(_("Speed"), comment, tmp, 4)) {
    15121500                    log_to_screen(_("User has chosen not to backup the PC"));
     
    15161504            mr_free(comment);
    15171505
    1518             bkpinfo->cdrw_speed = atoi(tmp);    // if DVD then this shouldn't ever be used anyway :)
     1506            bkpinfo->writer_speed = atoi(tmp);
    15191507            mr_free(tmp);
    15201508
    1521             mr_asprintf(&comment,
    1522                     _("How much data (in Megabytes) will each %s store?"),
    1523                     bkpinfo->backup_media_string);
    1524 
    1525             if (!popup_and_get_string("Size", comment, sz_size, 5)) {
     1509            mr_asprintf(&comment, _("What is your media device ?"));
     1510            mr_asprintf(&tmp, mr_conf->media_device);
     1511
     1512            if (!popup_and_get_string("Device", comment, tmp, 5)) {
    15261513                log_to_screen(_("User has chosen not to backup the PC"));
    15271514                finish(1);
     
    15291516            mr_free(comment);
    15301517
    1531             bkpinfo->media_size = atol(sz_size);
    1532             mr_free(sz_size);
    1533 
    1534             if (bkpinfo->media_size <= 0L) {
    1535                 log_to_screen(_("User has chosen not to backup the PC"));
    1536                 finish(1);
    1537             }
    1538         }
    1539     case cdstream:
    1540         if (bkpinfo->disaster_recovery) {
    1541             strcpy(bkpinfo->media_device, "/dev/cdrom");
    1542             mr_msg(2, "CD-ROM device assumed to be at %s",
    1543                     bkpinfo->media_device);
    1544         } else if (bkpinfo->restore_data
    1545                    || bkpinfo->backup_media_type == dvd) {
    1546             if (!bkpinfo->media_device[0]) {
    1547                 strcpy(bkpinfo->media_device, "/dev/cdrom");
    1548             }                   // just for the heck of it :)
    1549             mr_msg(1, "bkpinfo->media_device = %s",
    1550                     bkpinfo->media_device);
    1551             if (bkpinfo->backup_media_type == dvd
    1552                 || find_cdrom_device(bkpinfo->media_device, FALSE)) {
    1553                 mr_msg(1, "bkpinfo->media_device = %s",
    1554                         bkpinfo->media_device);
    1555                 mr_asprintf(&comment,
    1556                         _("Please specify your %s drive's /dev entry"),
    1557                         bkpinfo->backup_media_string);
    1558                 if (!popup_and_get_string
    1559                     (_("Device?"), comment, bkpinfo->media_device, MAX_STR_LEN / 4)) {
     1518            mr_free(bkpinfo->media_device);
     1519            bkpinfo->media_device = tmp;
     1520
     1521            /* Also adapt the burning device if needed */
     1522            if ((strcmp(bkpinfo->media_device, mr_conf->media_device) != 0) &&
     1523                (strcmp(mr_conf->media_device,mr_conf->iso_burning_dev) != 0)) {
     1524                mr_asprintf(&comment, _("What is your burning media device then ?"));
     1525                mr_asprintf(&tmp, mr_conf->iso_burning_dev);
     1526   
     1527                if (!popup_and_get_string("Device", comment, tmp, 5)) {
    15601528                    log_to_screen(_("User has chosen not to backup the PC"));
    15611529                    finish(1);
    15621530                }
    15631531                mr_free(comment);
    1564             }
     1532   
     1533                /* BCO: We change the mr_conf struct. Check that it doesn't create pb */
     1534                mr_free(bkpinfo->iso_burning_dev);
     1535                bkpinfo->iso_burning_dev = tmp;
     1536            }
     1537
     1538            mr_asprintf(&comment,
     1539                    _("How much data (in Megabytes) will each %s store?"),
     1540                    bkpinfo->backup_media_string);
     1541            mr_asprintf(&sz_size, "%d", mr_conf->media_size);
     1542
     1543            if (!popup_and_get_string("Size", comment, sz_size, 5)) {
     1544                log_to_screen(_("User has chosen not to backup the PC"));
     1545                finish(1);
     1546            }
     1547            mr_free(comment);
     1548
     1549            bkpinfo->media_size = atol(sz_size);
     1550            mr_free(sz_size);
     1551
     1552            if (bkpinfo->media_size <= 0L) {
     1553                log_to_screen(_("User has chosen not to backup the PC"));
     1554                finish(1);
     1555            }
     1556        }
     1557
     1558    case cdstream:
     1559        if (bkpinfo->disaster_recovery) {
     1560            mr_allocstr(bkpinfo->media_device, "/dev/cdrom");
     1561            mr_msg(2, "CD-ROM device assumed to be at %s", bkpinfo->media_device);
     1562        } else if (bkpinfo->restore_data || bkpinfo->backup_media_type == dvd) {
     1563            if (!bkpinfo->media_device) {
     1564                mr_allocstr(bkpinfo->media_device, "/dev/cdrom");
     1565            }                   // just for the heck of it :)
     1566            mr_msg(1, "bkpinfo->media_device = %s", bkpinfo->media_device);
     1567            mr_asprintf(&comment,
     1568                _("Please specify your %s drive's /dev entry"), bkpinfo->backup_media_string);
     1569            mr_asprintf(&tmp,"/dev/cdrom");
     1570            if (!popup_and_get_string
     1571                (_("Device?"), comment, tmp, MAX_STR_LEN / 4)) {
     1572                    log_to_screen(_("User has chosen not to backup the PC"));
     1573                    finish(1);
     1574                }
     1575            mr_free(comment);
     1576            mr_free(bkpinfo->media_device);
     1577            bkpinfo->media_device=tmp;
     1578
    15651579            mr_msg(2, "%s device found at %s",
    15661580                    bkpinfo->backup_media_string,
    15671581                    bkpinfo->media_device);
    15681582        } else {
    1569             if (find_cdrw_device(bkpinfo->media_device)) {
    1570                 bkpinfo->media_device[0] = '\0';
    1571             }
    1572             if (bkpinfo->media_device[0]) {
    1573                 mr_asprintf(&tmp,
    1574                         _("I think I've found your %s burner at SCSI node %s; Is this correct ? (say no if you have an IDE burner and you are running a 2.6 kernel. You will then be prompted for further details."),
    1575                         bkpinfo->backup_media_string,
    1576                         bkpinfo->media_device);
    1577                 if (!ask_me_yes_or_no(tmp)) {
    1578                     bkpinfo->media_device[0] = '\0';
    1579                 }
    1580                 mr_free(tmp);
    1581             } else {
    1582                 if (g_kernel_version < 2.6) {
    1583                     i = popup_and_get_string("Device node?",
    1584                                              "What is the SCSI node of your CD (re)writer, please?",
    1585                                              bkpinfo->media_device,
    1586                                              MAX_STR_LEN / 4);
    1587                 } else {
    1588                     i = popup_and_get_string("/dev entry?",
    1589                                              "What is the /dev entry of your CD (re)writer, please?",
    1590                                              bkpinfo->media_device,
    1591                                              MAX_STR_LEN / 4);
    1592                 }
    1593                 if (!i) {
     1583            mr_asprintf(&comment, _("What is your media device ?"));
     1584            mr_asprintf(&tmp, mr_conf->media_device);
     1585
     1586            if (!popup_and_get_string("Device", comment, tmp, 5)) {
     1587                log_to_screen(_("User has chosen not to backup the PC"));
     1588                finish(1);
     1589            }
     1590            mr_free(comment);
     1591
     1592            mr_free(bkpinfo->media_device);
     1593            bkpinfo->media_device = tmp;
     1594
     1595            /* Also adapt the burning device if needed */
     1596            if ((strcmp(bkpinfo->media_device, mr_conf->media_device) != 0) &&
     1597                (strcmp(mr_conf->media_device,mr_conf->iso_burning_dev) != 0)) {
     1598                mr_asprintf(&comment, _("What is your burning media device then ?"));
     1599                mr_asprintf(&tmp, mr_conf->iso_burning_dev);
     1600   
     1601                if (!popup_and_get_string("Device", comment, tmp, 5)) {
    15941602                    log_to_screen(_("User has chosen not to backup the PC"));
    15951603                    finish(1);
    15961604                }
    1597             }
    1598         }
    1599         if (bkpinfo->backup_media_type == cdstream) {
    1600             bkpinfo->media_size = (long)650;
    1601         }
     1605                mr_free(comment);
     1606   
     1607                /* BCO: We change the mr_conf struct. Check that it doesn't create pb */
     1608                mr_free(bkpinfo->iso_burning_dev);
     1609                bkpinfo->iso_burning_dev = tmp;
     1610            }
     1611
     1612        }
     1613        /* BERLIOS: Is it useful ?? */
     1614        bkpinfo->media_size = (long)650;
    16021615        break;
     1616
    16031617    case udev:
    16041618        if (!ask_me_yes_or_no
     
    16071621            finish(1);
    16081622        }
     1623
    16091624    case tape:
    1610 
    1611         res = find_tape_device_and_size(bkpinfo->media_device, sz_size);
    1612         if ((res != 0) && (! bkpinfo->media_device[0])) {
    1613             mr_msg(3, "Ok, using vanilla scsi tape.");
    1614             strcpy(bkpinfo->media_device, VANILLA_SCSI_TAPE);
    1615             if ((fin = fopen(bkpinfo->media_device, "r"))) {
    1616                 paranoid_fclose(fin);
    1617             } else {
    1618                 mr_msg(2, "Don't know what your tape device is :-(");
    1619             }
    1620         }
    1621         if (bkpinfo->media_device[0]) {
     1625        if (bkpinfo->media_device) {
    16221626            if ((fin = fopen(bkpinfo->media_device, "r"))) {
    16231627                paranoid_fclose(fin);
    16241628            } else {
    16251629                if (does_file_exist("/tmp/mondo-restore.cfg")) {
     1630                    /* BERLIOS: NOW that bkpinfo->media_device isn't static anymore it does NOT work */
    16261631                    read_cfg_var("/tmp/mondo-restore.cfg", "media-dev",
    16271632                                 bkpinfo->media_device);
    16281633                }
    16291634            }
    1630             mr_asprintf(&tmp,
     1635            mr_asprintf(&comment,
    16311636                    _("I think I've found your tape streamer at %s; am I right on the money?"),
    16321637                    bkpinfo->media_device);
    1633             if (!ask_me_yes_or_no(tmp)) {
     1638            if (!ask_me_yes_or_no(comment)) {
     1639                mr_asprintf(&tmp,bkpinfo->media_device);
    16341640                if (!popup_and_get_string
    1635                     ("Device name?",
    1636                     "What is the /dev entry of your tape streamer?",
    1637                     bkpinfo->media_device, MAX_STR_LEN / 4)) {
     1641                    (_("Device name?"),
     1642                    _("What is the /dev entry of your tape streamer?"),
     1643                    tmp, MAX_STR_LEN / 4)) {
    16381644                    log_to_screen("User has chosen not to backup the PC");
    16391645                    finish(1);
    16401646                }
    1641             }
    1642             mr_free(tmp);
     1647                mr_free(bkpinfo->media_device);
     1648                bkpinfo->media_device = tmp;
     1649            }
     1650            mr_free(comment);
    16431651        } else {
     1652            mr_asprintf(&tmp,bkpinfo->media_device);
    16441653            if (!popup_and_get_string
    1645                 ("Device name?",
    1646                  "What is the /dev entry of your tape streamer?",
    1647                  bkpinfo->media_device, MAX_STR_LEN / 4)) {
     1654                (_("Device name?"),
     1655                 _("What is the /dev entry of your tape streamer?"),
     1656                 tmp, MAX_STR_LEN / 4)) {
    16481657                log_to_screen("User has chosen not to backup the PC");
    16491658                finish(1);
    16501659            }
     1660            mr_free(bkpinfo->media_device);
     1661            bkpinfo->media_device = tmp;
    16511662        }
    16521663        mr_asprintf(&tmp, "ls -l %s", bkpinfo->media_device);
     
    16561667        }
    16571668        mr_free(tmp);
    1658         mr_msg(4, "sz_size = %s", sz_size);
    1659         mr_free(sz_size);
    16601669        bkpinfo->media_size = 0L;
    16611670        mr_msg(4, "media_size = %ld", bkpinfo->media_size);
    1662         if (bkpinfo->media_size <= 0L) {
    1663             bkpinfo->media_size = 0L;
    1664         }
    16651671        if (archiving_to_media) {
    16661672            if ((bkpinfo->compression_level =
     
    17971803        mr_msg(3, "prefix set to %s", bkpinfo->prefix);
    17981804
    1799         bkpinfo->media_size = (long)650;
     1805        if (archiving_to_media) {
     1806            if (!popup_and_get_string
     1807                ("Size.",
     1808                "Please enter how big you want each NFS image to be (in megabytes).",
     1809                sz_size, 16)) {
     1810                log_to_screen("User has chosen not to backup the PC");
     1811                finish(1);
     1812            }
     1813            bkpinfo->media_size = atol(sz_size);
     1814            if (bkpinfo->media_size <= 0L) {
     1815                log_to_screen(_("User has chosen not to backup the PC"));
     1816                finish(1);
     1817            }
     1818        }
    18001819        mr_msg(3, "Just set nfs_remote_dir to %s",
    18011820                bkpinfo->nfs_remote_dir);
     
    18261845                }
    18271846                bkpinfo->media_size = atol(sz_size);
     1847            /* BERLIOS: this should be useless
     1848            */
    18281849            } else {
    18291850                bkpinfo->media_size = (long)650;
     
    19741995        g_ISO_restore_mode = TRUE;
    19751996    }
    1976 #ifdef __FreeSD__
     1997#ifdef __FreeBSD__
    19771998// skip
    19781999#else
     
    21562177
    21572178    mr_asprintf(&mountdev, bkpinfo->media_device);
    2158     if (!mountdev[0]) {
    2159         log_it
    2160             ("(what_number_cd_is_this) Warning - media_device unknown. Finding out...");
    2161         find_cdrom_device(bkpinfo->media_device, FALSE);
    2162     }
    21632179    if (!is_this_device_mounted(MNT_CDROM)) {
    21642180        mount_CDROM_here(mountdev, MNT_CDROM);
Note: See TracChangeset for help on using the changeset viewer.