~hamo/ubuntu/precise/grub2/grub2.hi_res

« back to all changes in this revision

Viewing changes to util/grub-editenv.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Robert Millan, Updated translations
  • Date: 2010-11-22 12:24:56 UTC
  • mfrom: (1.26.4 upstream) (17.3.36 sid)
  • mto: (17.3.43 sid)
  • mto: This revision was merged to the branch mainline in revision 89.
  • Revision ID: james.westby@ubuntu.com-20101122122456-y82z3sfb7k4zfdcc
Tags: 1.99~20101122-1
[ Colin Watson ]
* New Bazaar snapshot.  Too many changes to list in full, but some of the
  more user-visible ones are as follows:
  - GRUB script:
    + Function parameters, "break", "continue", "shift", "setparams",
      "return", and "!".
    + "export" command supports multiple variable names.
    + Multi-line quoted strings support.
    + Wildcard expansion.
  - sendkey support.
  - USB hotunplugging and USB serial support.
  - Rename CD-ROM to cd on BIOS.
  - Add new --boot-directory option to grub-install, grub-reboot, and
    grub-set-default; the old --root-directory option is still accepted
    but was often confusing.
  - Basic btrfs detection/UUID support (but no file reading yet).
  - bash-completion for utilities.
  - If a device is listed in device.map, always assume that it is
    BIOS-visible rather than using extra layers such as LVM or RAID.
  - Add grub-mknetdir script (closes: #550658).
  - Remove deprecated "root" command.
  - Handle RAID devices containing virtio components.
  - GRUB Legacy configuration file support (via grub-menulst2cfg).
  - Keyboard layout support (via grub-mklayout and grub-kbdcomp).
  - Check generated grub.cfg for syntax errors before saving.
  - Pause execution for at most ten seconds if any errors are displayed,
    so that the user has a chance to see them.
  - Support submenus.
  - Write embedding zone using Reed-Solomon, so that it's robust against
    being partially overwritten (closes: #550702, #591416, #593347).
  - GRUB_DISABLE_LINUX_RECOVERY and GRUB_DISABLE_NETBSD_RECOVERY merged
    into a single GRUB_DISABLE_RECOVERY variable.
  - Fix loader memory allocation failure (closes: #551627).
  - Don't call savedefault on recovery entries (closes: #589325).
  - Support triple-indirect blocks on ext2 (closes: #543924).
  - Recognise DDF1 fake RAID (closes: #603354).

[ Robert Millan ]
* Use dpkg architecture wildcards.

[ Updated translations ]
* Slovenian (Vanja Cvelbar).  Closes: #604003
* Dzongkha (dawa pemo via Tenzin Dendup).  Closes: #604102

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
#include <config.h>
21
21
#include <grub/types.h>
 
22
#include <grub/emu/misc.h>
22
23
#include <grub/util/misc.h>
23
24
#include <grub/lib/envblk.h>
24
 
#include <grub/handler.h>
25
25
#include <grub/i18n.h>
26
26
 
27
27
#include <stdio.h>
28
28
#include <unistd.h>
29
29
#include <string.h>
30
30
#include <stdlib.h>
31
 
#include <getopt.h>
 
31
#include <argp.h>
32
32
 
33
33
#include "progname.h"
34
34
 
35
35
#define DEFAULT_ENVBLK_SIZE     1024
36
 
 
37
 
void
38
 
grub_putchar (int c)
39
 
{
40
 
  putchar (c);
41
 
}
42
 
 
43
 
void
44
 
grub_refresh (void)
45
 
{
46
 
  fflush (stdout);
47
 
}
48
 
 
49
 
int
50
 
grub_getkey (void)
51
 
{
 
36
#define DEFAULT_ENVBLK_PATH DEFAULT_DIRECTORY "/" GRUB_ENVBLK_DEFCFG
 
37
 
 
38
static struct argp_option options[] = {
 
39
  {0,        0, 0, OPTION_DOC, N_("Commands:"), 1},
 
40
  {"create", 0, 0, OPTION_DOC|OPTION_NO_USAGE,
 
41
   N_("Create a blank environment block file."), 0},
 
42
  {"list",   0, 0, OPTION_DOC|OPTION_NO_USAGE,
 
43
   N_("List the current variables."), 0},
 
44
  {"set [name=value ...]", 0, 0, OPTION_DOC|OPTION_NO_USAGE,
 
45
   N_("Set variables."), 0},
 
46
  {"unset [name ....]",    0, 0, OPTION_DOC|OPTION_NO_USAGE,
 
47
   N_("Delete variables."), 0},
 
48
 
 
49
  {0,         0, 0, OPTION_DOC, N_("Options:"), -1},
 
50
  {"verbose", 'v', 0, 0, N_("Print verbose messages."), 0},
 
51
 
 
52
  { 0, 0, 0, 0, 0, 0 }
 
53
};
 
54
 
 
55
/* Print the version information.  */
 
56
static void
 
57
print_version (FILE *stream, struct argp_state *state)
 
58
{
 
59
  fprintf (stream, "%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION);
 
60
}
 
61
void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version;
 
62
 
 
63
/* Set the bug report address */
 
64
const char *argp_program_bug_address = "<"PACKAGE_BUGREPORT">";
 
65
 
 
66
error_t argp_parser (int key, char *arg, struct argp_state *state)
 
67
{
 
68
  switch (key)
 
69
    {
 
70
      case 'v':
 
71
        verbosity++;
 
72
        break;
 
73
 
 
74
      case ARGP_KEY_NO_ARGS:
 
75
        fprintf (stderr, "%s",
 
76
                 _("You need to specify at least one command.\n"));
 
77
        argp_usage (state);
 
78
        break;
 
79
 
 
80
      default:
 
81
        return ARGP_ERR_UNKNOWN;
 
82
    }
 
83
 
52
84
  return 0;
53
85
}
54
86
 
55
 
char *
56
 
grub_env_get (const char *name __attribute__ ((unused)))
 
87
static char *
 
88
help_filter (int key, const char *text, void *input __attribute__ ((unused)))
57
89
{
58
 
  return NULL;
 
90
  switch (key)
 
91
    {
 
92
      case ARGP_KEY_HELP_POST_DOC:
 
93
        return xasprintf(text, DEFAULT_ENVBLK_PATH);
 
94
 
 
95
      default:
 
96
        return (char *) text;
 
97
    }
59
98
}
60
99
 
61
 
static struct option options[] = {
62
 
  {"help", no_argument, 0, 'h'},
63
 
  {"version", no_argument, 0, 'V'},
64
 
  {"verbose", no_argument, 0, 'v'},
65
 
  {0, 0, 0, 0}
 
100
struct argp argp = {
 
101
  options, argp_parser, N_("FILENAME COMMAND"),
 
102
  "\n"N_("\
 
103
Tool to edit environment block.")
 
104
"\v"N_("\
 
105
If FILENAME is '-', the default value %s is used."),
 
106
  NULL, help_filter, NULL
66
107
};
67
108
 
68
109
static void
69
 
usage (int status)
70
 
{
71
 
  if (status)
72
 
    fprintf (stderr, "Try `%s --help' for more information.\n", program_name);
73
 
  else
74
 
    printf ("\
75
 
Usage: %s [OPTIONS] [FILENAME] COMMAND\n\
76
 
\n\
77
 
Tool to edit environment block.\n\
78
 
\nCommands:\n\
79
 
  create                    create a blank environment block file\n\
80
 
  list                      list the current variables\n\
81
 
  set [name=value ...]      set variables\n\
82
 
  unset [name ....]         delete variables\n\
83
 
\nOptions:\n\
84
 
  -h, --help                display this message and exit\n\
85
 
  -V, --version             print version information and exit\n\
86
 
  -v, --verbose             print verbose messages\n\
87
 
\n\
88
 
If not given explicitly, FILENAME defaults to %s.\n\
89
 
\n\
90
 
Report bugs to <%s>.\n",
91
 
program_name, DEFAULT_DIRECTORY "/" GRUB_ENVBLK_DEFCFG, PACKAGE_BUGREPORT);
92
 
 
93
 
  exit (status);
94
 
}
95
 
 
96
 
static void
97
110
create_envblk_file (const char *name)
98
111
{
99
112
  FILE *fp;
251
264
{
252
265
  char *filename;
253
266
  char *command;
 
267
  int index, arg_count;
254
268
 
255
269
  set_program_name (argv[0]);
256
270
 
257
271
  grub_util_init_nls ();
258
272
 
259
 
  /* Check for options.  */
260
 
  while (1)
261
 
    {
262
 
      int c = getopt_long (argc, argv, "hVv", options, 0);
263
 
 
264
 
      if (c == -1)
265
 
        break;
266
 
      else
267
 
        switch (c)
268
 
          {
269
 
          case 'h':
270
 
            usage (0);
271
 
            break;
272
 
 
273
 
          case 'V':
274
 
            printf ("%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION);
275
 
            return 0;
276
 
 
277
 
          case 'v':
278
 
            verbosity++;
279
 
            break;
280
 
 
281
 
          default:
282
 
            usage (1);
283
 
            break;
284
 
          }
285
 
    }
286
 
 
287
 
  /* Obtain the filename.  */
288
 
  if (optind >= argc)
289
 
    {
290
 
      fprintf (stderr, "no filename specified\n");
291
 
      usage (1);
292
 
    }
293
 
 
294
 
  if (optind + 1 >= argc)
295
 
    {
296
 
      filename = DEFAULT_DIRECTORY "/" GRUB_ENVBLK_DEFCFG;
297
 
      command = argv[optind];
 
273
  /* Parse our arguments */
 
274
  if (argp_parse (&argp, argc, argv, 0, &index, 0) != 0)
 
275
    {
 
276
      fprintf (stderr, "%s", _("Error in parsing command line arguments\n"));
 
277
      exit(1);
 
278
    }
 
279
 
 
280
  arg_count = argc - index;
 
281
 
 
282
  if (arg_count == 1)
 
283
    {
 
284
      filename = DEFAULT_ENVBLK_PATH;
 
285
      command  = argv[index++];
298
286
    }
299
287
  else
300
288
    {
301
 
      filename = argv[optind];
302
 
      command = argv[optind + 1];
 
289
      filename = argv[index++];
 
290
      if (strcmp (filename, "-") == 0)
 
291
        filename = DEFAULT_ENVBLK_PATH;
 
292
      command  = argv[index++];
303
293
    }
304
294
 
305
295
  if (strcmp (command, "create") == 0)
307
297
  else if (strcmp (command, "list") == 0)
308
298
    list_variables (filename);
309
299
  else if (strcmp (command, "set") == 0)
310
 
    set_variables (filename, argc - optind - 2, argv + optind + 2);
 
300
    set_variables (filename, argc - index, argv + index);
311
301
  else if (strcmp (command, "unset") == 0)
312
 
    unset_variables (filename, argc - optind - 2, argv + optind + 2);
 
302
    unset_variables (filename, argc - index, argv + index);
313
303
  else
314
304
    {
315
 
      fprintf (stderr, "unknown command %s\n", command);
316
 
      usage (1);
 
305
      char *program = xstrdup(program_name);
 
306
      fprintf (stderr, _("Unknown command `%s'.\n"), command);
 
307
      argp_help (&argp, stderr, ARGP_HELP_STD_USAGE, program);
 
308
      free(program);
 
309
      exit(1);
317
310
    }
318
311
 
319
312
  return 0;