Changeset 1256 in MondoRescue


Ignore:
Timestamp:
Mar 21, 2007, 12:48:32 PM (17 years ago)
Author:
Bruno Cornec
Message:

Begining of work on conf file introduction in mondo

  • create a new struct mr_ar_conf to store conf info
  • adds a static mr_ar_store_conf function to store conf file info in that struc
  • mondo.conf is now the .dist version
  • md5 not done yet

Not tested may not work at all nor compile

Location:
branches/stable/mondo
Files:
1 added
6 edited
1 moved

Legend:

Unmodified
Added
Removed
  • branches/stable/mondo/distributions/conf/mondo.conf.dist

    r1249 r1256  
    8383
    8484#
    85 # deplist file used
     85# deplist file used (either fill path or relative to
     86# mondo's configuration dir
    8687#
    87 mondo_deplist_file="/etc/mondo/deplist.txt"
     88mondo_deplist_file="deplist.txt"
    8889
    8990#
     
    128129# Default compression level
    129130#
    130 mondo_compression_level=5
     131mondo_compression_level=6
    131132
    132133#
     
    134135# (white space separated list of paths)
    135136#
    136 mondo_exclude_files=""
     137mondo_exclude_paths=""
    137138
    138139#
     
    140141# (white space separated list of paths)
    141142#
    142 mondo_include_files=""
     143mondo_include_paths=""
    143144
    144145#
    145 # Activate semi-graphical mode by default (yes|no)
     146# Which mode should be activated by default (cli|newt|x11|web)
     147# TBC
    146148#
    147 mondo_text_mode=no
     149mondo_ui_mode=newt
    148150
    149151#
     
    156158# Scratch directory
    157159#
    158 mondo_scratch_dir=""
    159 #scratch_dir="/tmp/mondo/scratch"
     160mondo_scratch_dir="/var/spool/mondo"
     161#scratch_dir="/var/cache/mondo/scratch"
    160162
    161163#
    162 # Temporary directory
     164# Temporary directory main path
     165# A subdirectory will be created below to host mondo's temp files
    163166#
    164 mondo_tmp_dir=""
    165 #tmp_dir="/tmp/mondo/tmp"
     167mondo_tmp_dir="/tmp"
     168#tmp_dir="/var/cache/mondo/tmp"
    166169
    167170#
  • branches/stable/mondo/src/common/libmondo-archive.c

    r1213 r1256  
    1919#include "my-stuff.h"
    2020#include "mondostructures.h"
     21
    2122#include "mr_conf.h"
    2223#include "mr_mem.h"
     
    39003901    char *tmp = NULL;
    39013902    char *p = NULL;
    3902     char *path_min = "/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin";
     3903    char *path_min = "/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin";
    39033904
    39043905    mr_setenv("MONDO_SHARE",MONDO_SHARE);
    39053906    mr_setenv("MONDORESTORECFG",MONDORESTORECFG);
    39063907    mr_setenv("MONDO_CACHE",MONDO_CACHE);
     3908    /* Add the ARCH environment variable for ia64 purposes */
     3909    mr_setenv("ARCH", get_architecture());
     3910
    39073911
    39083912    if ((p = getenv("PATH")) == NULL) {
  • branches/stable/mondo/src/include/mr_conf.h

    r1064 r1256  
    1515#define MR_CONF_H
    1616
     17/* mondoarchive structure storing conf info
     18 * each field of the configuration file should have an entry here
     19 */
     20struct mr_ar_conf {
     21    /* ISO image CLI command to use */
     22    char *iso_creation_cmd;
     23    /* ISO image common creation options */
     24    char *iso_creation_options;
     25    /* ISO Burning CLI command to use */
     26    char *iso_burning_cmd;
     27    /* ISO Burning CLI command options */
     28    char *iso_burning_options;
     29    /* ISO Burning Speed */
     30    int iso_burning_speed;
     31    /* Default size of media */
     32    int media_size;
     33    /* Default device of media */
     34    char *media_device;
     35    /* Is the CD tray manual ? */
     36    bool manual_tray;
     37    /* Default log level */
     38    int log_level;
     39    /* default prefix for ISO names */
     40    char *prefix;
     41    /* External tape blocksize */
     42    int external_tape_blocksize;
     43    /* Internal tape blocksize */
     44    int internal_tape_blocksize;
     45    /* Size in MB of the slices for biggiefiles */
     46    int slice_size;
     47    /* deplist file used */
     48    char *deplist_file;
     49    /* Write boot floppies ? */
     50    bool write_boot_floppy;
     51    /* Create mindi CD ? */
     52    bool create_mindi_cd;
     53    /* Kernel to use */
     54    char *kernel;
     55    /* Additional modules to support */
     56    char *additional_modules;
     57    /* Boot loader to use */
     58    char *boot_loader;
     59    /* Differential backup ? */
     60    bool differential;
     61    /* Default compression tool */
     62    char *compression_tool;
     63    /* Default compression level */
     64    int compression_level;
     65    /* Paths to exclude from backup */
     66    char *exclude_paths;
     67    /* Paths to include onto the backup */
     68    char *include_paths;
     69    /* Which mode should be activated by default*/
     70    char *ui_mode;
     71    /* Activate automatic restore ? */
     72    bool automatic_restore;
     73    /* Scratch directory */
     74    char *scratch_dir;
     75    /* Temporary directory main path */
     76    char *tmp_dir;
     77    /* Images creation dir */
     78    char *images_dir;
     79};
     80
    1781/* functions (public methods) */
    1882
     
    2791extern double mr_conf_fread(const char *field_name);
    2892
     93/*read boolean after string str in the current file*/
     94extern bool mr_conf_bread(const char *field_name);
     95
    2996/*
    3097 * read string after string str in the current file.
  • branches/stable/mondo/src/lib/mr_conf.c

    r1227 r1256  
    207207}
    208208
     209
    209210/*
    210211  reads string outstr after string str in the current file (between
     
    256257    mr_free(q);
    257258
     259    return ret;
     260}
     261
     262/*read boolean after string str in the current file*/
     263bool mr_conf_bread(const char *field_name) {
     264    char *p = NULL;             /*pointer to the field */
     265    bool ret = FALSE;
     266   
     267    p = mr_conf_sread(field_name);
     268    if (p != NULL) {
     269        /* match if yes/true/1 */
     270        if ((strncasecmp(p, "y" , (size_t)1) == 0) ||
     271            (strncasecmp(p, "t" , (size_t)1) == 0) ||
     272            (strncasecmp(p, "1" , (size_t)1) == 0)) {
     273            ret = TRUE;
     274        }
     275    }
    258276    return ret;
    259277}
  • branches/stable/mondo/src/lib/mr_err.c

    r1104 r1256  
    3636
    3737    mr_cleanup();
    38     fprintf(stderr,"%s\n",message);
     38    if (message != NULL) {
     39        fprintf(stderr,"%s\n",message);
     40    }
    3941    exit(errorcode);
    4042}
  • branches/stable/mondo/src/mondoarchive/Makefile.am

    r1187 r1256  
    44## Process with Automake to generate Makefile.in
    55##
    6 AM_CPPFLAGS = -DMONDO_CONF_DIR=\"$(sysconfdir)\" -I${top_builddir}/src/include -I${top_builddir}/src/common
     6AM_CPPFLAGS = -DMONDO_CONF_DIR=\"$(sysconfdir)\" -I${top_builddir}/src/include -I${top_builddir}/src/common -I${top_builddir}/src/mondoarchive
    77
    88## Headers
    9 noinst_HEADERS       = mondo-cli-EXT.h mondo-cli.h
     9noinst_HEADERS       = mondo-cli-EXT.h mondo-cli.h mondoarchive.h
    1010
    1111## The program
  • branches/stable/mondo/src/mondoarchive/mondoarchive.c

    r1245 r1256  
    2222#include "mondo-cli-EXT.h"
    2323
     24#include "mondoarchive.h"
    2425#include "mr_mem.h"
    2526#include "mr_str.h"
    2627#include "mr_msg.h"
    2728#include "mr_file.h"
     29#include "mr_conf.h"
    2830
    2931// for CVS
     
    4143extern char *g_erase_tmpdir_and_scratchdir;
    4244extern char *g_cdrw_drive_is_here;
     45extern double g_kernel_version;
     46extern char *g_magicdev_command;
     47extern t_bkptype g_backup_media_type;
     48extern int g_loglevel;
     49
    4350static char *g_cdrom_drive_is_here = NULL;
    4451static char *g_dvd_drive_is_here = NULL;
    45 extern double g_kernel_version;
    46 
    47 /***************** global vars, used only by main.c ******************/
     52
     53struct mr_ar_conf mr_conf;
     54
     55/***************** global vars ******************/
    4856bool g_skip_floppies;
    4957long diffs;
     
    5159char *ps_proc_id = "$2";
    5260
    53 extern t_bkptype g_backup_media_type;
    54 extern int g_loglevel;
    55 
    56 /****************** subroutines used only by main.c ******************/
     61/****************** subroutines used only here ******************/
    5762
    5863
     
    6065 * Print a "don't panic" message to the log and a message about the logfile to the screen.
    6166 */
    62 void welcome_to_mondoarchive(void)
     67static void welcome_to_mondoarchive(void)
    6368{
    64     mr_msg(0, "Mondo Archive v%s --- http://www.mondorescue.org",
    65             PACKAGE_VERSION);
     69    mr_msg(0, "Mondo Archive v%s --- http://www.mondorescue.org", PACKAGE_VERSION);
    6670    mr_msg(0, "running on %s architecture", get_architecture());
    67     mr_msg(0,
    68             "-----------------------------------------------------------");
    69     mr_msg(0,
    70             "NB: Mondo logs almost everything, so don't panic if you see");
    71     mr_msg(0,
    72             "some error messages.  Please read them carefully before you");
    73     mr_msg(0,
    74             "decide to break out in a cold sweat.    Despite (or perhaps");
    75     mr_msg(0,
    76             "because of) the wealth of messages. some users are inclined");
    77     mr_msg(0,
    78             "to stop reading this log. If Mondo stopped for some reason,");
    79     mr_msg(0,
    80             "chances are it's detailed here.  More than likely there's a");
    81     mr_msg(0,
    82             "message at the very end of this log that will tell you what");
    83     mr_msg(0,
    84             "is wrong. Please read it!                          -Devteam");
    85     mr_msg(0,
    86             "-----------------------------------------------------------");
     71    mr_msg(0, "-----------------------------------------------------------");
     72    mr_msg(0, "NB: Mondo logs almost everything, so don't panic if you see");
     73    mr_msg(0, "some error messages.  Please read them carefully before you");
     74    mr_msg(0, "decide to break out in a cold sweat.    Despite (or perhaps");
     75    mr_msg(0, "because of) the wealth of messages. some users are inclined");
     76    mr_msg(0, "to stop reading this log. If Mondo stopped for some reason,");
     77    mr_msg(0, "chances are it's detailed here.  More than likely there's a");
     78    mr_msg(0, "message at the very end of this log that will tell you what");
     79    mr_msg(0, "is wrong. Please read it!                          -Devteam");
     80    mr_msg(0, "-----------------------------------------------------------");
    8781
    8882    mr_msg(0, "Zero...");
     
    9892}
    9993
    100 
    101 extern char *g_magicdev_command;
    102 
    10394/**
    10495 * Do whatever is necessary to insure a successful backup on the Linux distribution
    10596 * of the day.
    10697 */
    107 void distro_specific_kludges_at_start_of_mondoarchive(void)
     98static void distro_specific_kludges_at_start_of_mondoarchive(void)
    10899{
    109100    mr_msg(2, "Unmounting old ramdisks if necessary");
     
    120111 * Undo whatever was done by distro_specific_kludges_at_start_of_mondoarchive().
    121112 */
    122 void distro_specific_kludges_at_end_of_mondoarchive(void)
     113static void distro_specific_kludges_at_end_of_mondoarchive(void)
    123114{
    124115    mr_msg(2, "Restarting magicdev if necessary");
     
    133124    sync();
    134125    unmount_boot_if_necessary();    // for Gentoo users
     126}
     127
     128/* create the mr_ar_conf structure from mondo's conf file */
     129static void mr_ar_store_conf(struct mr_ar_conf *mr_conf) {
     130   
     131    mr_asprintf(mr_conf->iso_creation_cmd, mr_conf_sread("mondo_iso_creation_cmd"));
     132    mr_asprintf(mr_conf->iso_creation_options, mr_conf_sread("mondo_iso_creation_options"));
     133    mr_asprintf(mr_conf->iso_burning_cmd, mr_conf_sread("mondo_iso_burning_cmd"));
     134    mr_asprintf(mr_conf->iso_burning_options, mr_conf_sread("mondo_iso_burning_options"));
     135    iso_burning_speed = mr_conf_iread("mondo_iso_burning_speed");
     136    media_size = mr_conf_iread("mondo_media_size");
     137    mr_asprintf(mr_conf->media_device, mr_conf_sread("mondo_media_device"));
     138    manual_tray = mr_conf_bread("mondo_manual_tray");
     139    log_level = mr_conf_iread("mondo_log_level");
     140    mr_asprintf(mr_conf->prefix, mr_conf_sread("mondo_prefix"));
     141    external_tape_blocksize = mr_conf_iread("mondo_external_tape_blocksize");
     142    internal_tape_blocksize = mr_conf_iread("mondo_internal_tape_blocksize");
     143    slice_size = mr_conf_iread("mondo_slice_size");
     144    mr_asprintf(mr_conf->deplist_file, mr_conf_sread("mondo_deplist_file"));
     145    write_boot_floppy = mr_conf_bread("mondo_write_boot_floppy");
     146    create_mindi_cd = mr_conf_bread("mondo_create_mindi_cd");
     147    mr_asprintf(mr_conf->kernel, mr_conf_sread("mondo_kernel"));
     148    mr_asprintf(mr_conf->additional_modules, mr_conf_sread("mondo_additional_modules"));
     149    mr_asprintf(mr_conf->boot_loader, mr_conf_sread("mondo_boot_loader"));
     150    differential = mr_conf_bread("mondo_differential");
     151    mr_asprintf(mr_conf->compression_tool, mr_conf_sread("mondo_compression_tool"));
     152    compression_level = mr_conf_iread("mondo_compression_level");
     153    mr_asprintf(mr_conf->exclude_paths, mr_conf_sread("mondo_exclude_paths"));
     154    mr_asprintf(mr_conf->include_paths, mr_conf_sread("mondo_include_paths"));
     155    mr_asprintf(mr_conf->ui_mode, mr_conf_sread("mondo_ui_mode"));
     156    automatic_restore = mr_conf_bread("mondo_automatic_restore");
     157    mr_asprintf(mr_conf->scratch_dir, mr_conf_sread("mondo_scratch_dir"));
     158    mr_asprintf(mr_conf->tmp_dir, mr_conf_sread("mondo_tmp_dir"));
     159    mr_asprintf(mr_conf->images_dir, mr_conf_sread("mondo_images_dir"));
    135160}
    136161
     
    145170int main(int argc, char *argv[])
    146171{
    147     struct s_bkpinfo *bkpinfo;
     172    struct s_bkpinfo *bkpinfo = NULL;
    148173    struct stat stbuf;
    149174    char *tmp = NULL;
     
    157182    (void) textdomain("mondo");
    158183#endif
    159 /* Make sure I'm root; abort if not */
     184    printf(_("Initializing..."));
     185
     186    /* initialize log file with time stamp */
     187    /* We start with a loglevel of 4 - Adapted later on */
     188    /* It's mandatory to set this up first as all mr_ functions rely on it */
     189    unlink(MONDO_LOGFILE);
     190    mr_msg_init(MONDO_LOGFILE,4);
     191    mr_msg(0, _("Time started: %s"), mr_date());
     192
     193    /* Make sure I'm root; abort if not */
    160194    if (getuid() != 0) {
    161         fprintf(stderr, _("Please run as root.\n"));
    162         exit(127);
     195        mr_log_exit(127, _("Please run as root."));
    163196    }
    164197
     
    168201            || !strcmp(argv[argc - 1], "--version"))) {
    169202        printf(_("mondoarchive v%s\nSee man page for help\n"), PACKAGE_VERSION);
    170         exit(0);
    171     }
     203        mr_exit(0, NULL);
     204    }
     205
     206    /* Conf file management */
     207    /* Check md5 sum before */
     208    /* Get content */
     209    if (mr_conf_open(MONDO_CONF_DIR"/mondo.conf.dist") != 0) {
     210            mr_log_exit(-1, "Unable to open "MONDO_CONF_DIR"/mondo.conf.dist");
     211    }
     212    mr_ar_store_conf(&mr_conf);
     213    mr_conf_close();
     214
     215    /* Add MONDO_SHARE + other environment variables for mindi */
     216    setenv_mondo_var();
    172217
    173218    /* Initialize variables */
    174219    malloc_libmondo_global_strings();
    175 
    176     res = 0;
    177     retval = 0;
    178220    diffs = 0;
    179 
    180     /* initialize log file with time stamp */
    181     unlink(MONDO_LOGFILE);
    182     mr_msg_init(MONDO_LOGFILE,4);
    183     mr_msg(0, _("Initializing...\n"));
    184     mr_msg(0, _("Time started: %s"), mr_date());
    185 
    186221    bkpinfo = mr_malloc(sizeof(struct s_bkpinfo));
    187 
    188     /* Add the ARCH environment variable for ia64 purposes */
    189     setenv("ARCH", get_architecture(), 1);
    190 
    191     /* Add MONDO_SHARE + other environment variables for mindi */
    192     setenv_mondo_var();
    193 
    194222    if (stat(MONDO_CACHE, &stbuf) != 0) {
    195223        mr_mkdir(MONDO_CACHE,0x755);
Note: See TracChangeset for help on using the changeset viewer.