mirror of
https://github.com/vivier/EMILE.git
synced 2025-08-07 15:25:04 +00:00
add config file
This commit is contained in:
@@ -14,6 +14,8 @@
|
|||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
|
||||||
#include "libemile.h"
|
#include "libemile.h"
|
||||||
|
#include "libconfig.h"
|
||||||
|
#include "emile_config.h"
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
ARG_NONE = 0,
|
ARG_NONE = 0,
|
||||||
@@ -24,6 +26,7 @@ enum {
|
|||||||
ARG_KERNEL = 'k',
|
ARG_KERNEL = 'k',
|
||||||
ARG_RAMDISK = 'r',
|
ARG_RAMDISK = 'r',
|
||||||
ARG_GETINFO = 'g',
|
ARG_GETINFO = 'g',
|
||||||
|
ARG_CONFIG = 'c',
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct option long_options[] =
|
static struct option long_options[] =
|
||||||
@@ -35,6 +38,7 @@ static struct option long_options[] =
|
|||||||
{"kernel", 1, NULL, ARG_KERNEL },
|
{"kernel", 1, NULL, ARG_KERNEL },
|
||||||
{"ramdisk", 1, NULL, ARG_RAMDISK },
|
{"ramdisk", 1, NULL, ARG_RAMDISK },
|
||||||
{"getinfo", 1, NULL, ARG_GETINFO },
|
{"getinfo", 1, NULL, ARG_GETINFO },
|
||||||
|
{"config", 1, NULL, ARG_CONFIG },
|
||||||
{NULL, 0, NULL, 0 },
|
{NULL, 0, NULL, 0 },
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -49,7 +53,8 @@ static void usage(int argc, char** argv)
|
|||||||
fprintf(stderr, " -s, --second second level to copy to floppy\n");
|
fprintf(stderr, " -s, --second second level to copy to floppy\n");
|
||||||
fprintf(stderr, " -k, --kernel kernel to copy to floppy\n");
|
fprintf(stderr, " -k, --kernel kernel to copy to floppy\n");
|
||||||
fprintf(stderr, " -r, --ramdisk ramdisk to copy to floppy\n");
|
fprintf(stderr, " -r, --ramdisk ramdisk to copy to floppy\n");
|
||||||
fprintf(stderr, " -g, --getinfo get information from >image>\n");
|
fprintf(stderr, " -g, --getinfo get information from <image>\n");
|
||||||
|
fprintf(stderr, " -c, --config set configuration according to a config file\n");
|
||||||
fprintf(stderr, "\nbuild: \n%s\n", SIGNATURE);
|
fprintf(stderr, "\nbuild: \n%s\n", SIGNATURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,13 +67,14 @@ int main(int argc, char** argv)
|
|||||||
char* kernel_image = NULL;
|
char* kernel_image = NULL;
|
||||||
char* ramdisk = NULL;
|
char* ramdisk = NULL;
|
||||||
char* image = NULL;
|
char* image = NULL;
|
||||||
|
char* config_path = NULL;
|
||||||
int action_getinfo = 0;
|
int action_getinfo = 0;
|
||||||
int c;
|
int c;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
c = getopt_long(argc, argv, "hvf:s:k:r:g", long_options,
|
c = getopt_long(argc, argv, "hvf:s:k:r:gc:", long_options,
|
||||||
&option_index);
|
&option_index);
|
||||||
if (c == -1)
|
if (c == -1)
|
||||||
break;
|
break;
|
||||||
@@ -95,6 +101,9 @@ int main(int argc, char** argv)
|
|||||||
case ARG_GETINFO:
|
case ARG_GETINFO:
|
||||||
action_getinfo = 1;
|
action_getinfo = 1;
|
||||||
break;
|
break;
|
||||||
|
case ARG_CONFIG:
|
||||||
|
config_path = optarg;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,6 +166,120 @@ int main(int argc, char** argv)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (config_path != NULL)
|
||||||
|
{
|
||||||
|
emile_config* config;
|
||||||
|
char *configuration;
|
||||||
|
int timeout;
|
||||||
|
int gestaltid;
|
||||||
|
int default_entry;
|
||||||
|
char *title, *args;
|
||||||
|
char buf[64];
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
if (kernel_image || ramdisk)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ERROR: don't use --kernel or --ramdisk with --config\n");
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
config = emile_config_open(config_path);
|
||||||
|
if (config == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ERROR: cannot open %s\n", config_path);
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((first_level == NULL) &&
|
||||||
|
(emile_config_get(config, CONFIG_FIRST_LEVEL, &first_level)))
|
||||||
|
first_level = PREFIX "/lib/emile/first_floppy";
|
||||||
|
|
||||||
|
if ((second_level == NULL) &&
|
||||||
|
emile_config_get(config, CONFIG_SECOND_LEVEL, &second_level))
|
||||||
|
second_level = PREFIX "/lib/emile/second_floppy";
|
||||||
|
|
||||||
|
fd = emile_floppy_create(image, first_level, second_level);
|
||||||
|
if (fd < 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ERROR: cannot create %s\n", image);
|
||||||
|
return 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
configuration = emile_second_get_configuration(fd);
|
||||||
|
if (configuration == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ERROR: cannot initalize configuration\n");
|
||||||
|
return 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
config_set_property(configuration, "vga", "default");
|
||||||
|
|
||||||
|
if (!emile_config_get(config, CONFIG_GESTALTID, &gestaltid))
|
||||||
|
{
|
||||||
|
sprintf(buf, "%d", gestaltid);
|
||||||
|
config_set_property(configuration, "gestaltID", buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!emile_config_get(config, CONFIG_DEFAULT, &default_entry))
|
||||||
|
{
|
||||||
|
sprintf(buf, "%d", default_entry);
|
||||||
|
config_set_property(configuration, "default", buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!emile_config_get(config, CONFIG_TIMEOUT, &timeout))
|
||||||
|
{
|
||||||
|
sprintf(buf, "%d", timeout);
|
||||||
|
config_set_property(configuration, "timeout", buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
emile_config_read_first_entry(config);
|
||||||
|
do {
|
||||||
|
if (!emile_config_get(config, CONFIG_TITLE, &title))
|
||||||
|
config_add_property(configuration, "title", title);
|
||||||
|
if (!emile_config_get(config, CONFIG_KERNEL, &kernel_image))
|
||||||
|
{
|
||||||
|
if (emile_is_url(kernel_image))
|
||||||
|
config_set_indexed_property(configuration,
|
||||||
|
"title", title,
|
||||||
|
"kernel", kernel_image);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
kernel_image = emile_floppy_add(fd, kernel_image);
|
||||||
|
config_set_indexed_property(configuration,
|
||||||
|
"title", title,
|
||||||
|
"kernel", kernel_image);
|
||||||
|
free(kernel_image);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!emile_config_get(config, CONFIG_INITRD, &ramdisk))
|
||||||
|
{
|
||||||
|
if (emile_is_url(ramdisk))
|
||||||
|
config_set_indexed_property(configuration,
|
||||||
|
"title", title,
|
||||||
|
"initrd", ramdisk);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ramdisk = emile_floppy_add(fd, ramdisk);
|
||||||
|
config_set_indexed_property(configuration,
|
||||||
|
"title", title,
|
||||||
|
"initrd", ramdisk);
|
||||||
|
free(ramdisk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!emile_config_get(config, CONFIG_ARGS, &args))
|
||||||
|
config_set_indexed_property(configuration,
|
||||||
|
"title", title,
|
||||||
|
"parameters", args);
|
||||||
|
} while (!emile_config_read_next(config));
|
||||||
|
emile_config_close(config);
|
||||||
|
|
||||||
|
emile_second_set_configuration(fd, configuration);
|
||||||
|
emile_floppy_close(fd);
|
||||||
|
|
||||||
|
free(configuration);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (first_level == NULL)
|
if (first_level == NULL)
|
||||||
first_level = PREFIX "/lib/emile/first_floppy";
|
first_level = PREFIX "/lib/emile/first_floppy";
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user