summaryrefslogtreecommitdiffstats
path: root/mdk-stage1
diff options
context:
space:
mode:
authorGuillaume Cottenceau <gc@mandriva.com>2000-12-17 23:32:50 +0000
committerGuillaume Cottenceau <gc@mandriva.com>2000-12-17 23:32:50 +0000
commite5b4ea994b4cf66d418494d33abd89300d291c6d (patch)
tree7d8c840ea0a27814b53fa0a94c0a0d3fa92ae5c6 /mdk-stage1
parent2766c6bb69ced7c4f33ec9d8bda56ba5b66e2915 (diff)
downloaddrakx-e5b4ea994b4cf66d418494d33abd89300d291c6d.tar
drakx-e5b4ea994b4cf66d418494d33abd89300d291c6d.tar.gz
drakx-e5b4ea994b4cf66d418494d33abd89300d291c6d.tar.bz2
drakx-e5b4ea994b4cf66d418494d33abd89300d291c6d.tar.xz
drakx-e5b4ea994b4cf66d418494d33abd89300d291c6d.zip
automatic mode added (a.k.a get rid of redhat kickstart)
Diffstat (limited to 'mdk-stage1')
-rw-r--r--mdk-stage1/Makefile2
-rw-r--r--mdk-stage1/automatic.c123
-rw-r--r--mdk-stage1/automatic.h31
-rw-r--r--mdk-stage1/network.c67
-rw-r--r--mdk-stage1/newt-frontend.c6
-rw-r--r--mdk-stage1/stage1.c36
-rw-r--r--mdk-stage1/stage1.h6
-rw-r--r--mdk-stage1/stdio-frontend.c6
-rw-r--r--mdk-stage1/tools.c39
-rw-r--r--mdk-stage1/tools.h7
10 files changed, 248 insertions, 75 deletions
diff --git a/mdk-stage1/Makefile b/mdk-stage1/Makefile
index 5df003dbd..ce3c04879 100644
--- a/mdk-stage1/Makefile
+++ b/mdk-stage1/Makefile
@@ -64,7 +64,7 @@ STAGE1_NETWORK_LIBS = /usr/lib/libresolv.a
#- stage1 itself
-STAGE1SRC = stage1.c log.c tools.c modules.c probing.c mount.c
+STAGE1SRC = stage1.c log.c tools.c modules.c probing.c mount.c automatic.c
CDROMSRC = cdrom.c
DISKSRC = disk.c
NETWORKSRC = network.c dns.c nfsmount.c
diff --git a/mdk-stage1/automatic.c b/mdk-stage1/automatic.c
new file mode 100644
index 000000000..3571614a0
--- /dev/null
+++ b/mdk-stage1/automatic.c
@@ -0,0 +1,123 @@
+/*
+ * Guillaume Cottenceau (gc@mandrakesoft.com)
+ *
+ * Copyright 2000 MandrakeSoft
+ *
+ * This software may be freely redistributed under the terms of the GNU
+ * public license.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+/*
+ * This is supposed to replace the redhat "kickstart", by name but
+ * also by design (less code pollution).
+ *
+ */
+
+
+#include <stdlib.h>
+#include <unistd.h>
+#include "tools.h"
+#include "stage1.h"
+#include "frontend.h"
+#include "log.h"
+
+#include "automatic.h"
+
+
+static struct param_elem * automatic_params;
+static char * value_not_bound = "";
+
+void grab_automatic_params(char * line)
+{
+ int i, p;
+ struct param_elem tmp_params[50];
+
+ i = 0; p = 0;
+ while (line[i] != '\0') {
+ char *name, *value;
+ int k;
+ int j = i;
+ while (line[i] != ':' && line[i] != '\0')
+ i++;
+ name = memdup(&line[j], i-j + 1);
+ name[i-j] = 0;
+
+ k = i+1;
+ i++;
+ while (line[i] != ',' && line[i] != '\0')
+ i++;
+ value = memdup(&line[k], i-k + 1);
+ value[i-k] = 0;
+
+ tmp_params[p].name = name;
+ tmp_params[p].value = value;
+ p++;
+ if (line[i] == '\0')
+ break;
+ i++;
+ }
+
+ tmp_params[p++].name = NULL;
+ automatic_params = memdup(tmp_params, sizeof(struct param_elem) * p);
+
+ log_message("AUTOMATIC MODE: got %d params", p-1);
+}
+
+
+char * get_auto_value(char * auto_param)
+{
+ struct param_elem * ptr = automatic_params;
+
+ while (ptr->name) {
+ if (!strcmp(ptr->name, auto_param))
+ return ptr->value;
+ ptr++;
+ }
+
+ return value_not_bound;
+}
+
+
+enum return_type ask_from_list_auto(char *msg, char ** elems, char ** choice, char * auto_param, char ** elems_auto)
+{
+ if (!IS_AUTOMATIC || IS_AUTOMATIC_ERROR_OCCURED)
+ return ask_from_list(msg, elems, choice);
+ else {
+ char * tmp = get_auto_value(auto_param);
+ while (elems && *elems) {
+ if (!strcmp(tmp, *elems_auto)) {
+ *choice = *elems;
+ log_message("AUTOMATIC: parameter %s for %s means returning %s", tmp, auto_param, *elems);
+ break;
+ }
+ elems++;
+ elems_auto++;
+ }
+ return RETURN_OK;
+ }
+}
+
+enum return_type ask_from_entries_auto(char *msg, char ** questions, char *** answers, int entry_size, char ** questions_auto)
+{
+ if (!IS_AUTOMATIC || IS_AUTOMATIC_ERROR_OCCURED)
+ return ask_from_entries(msg, questions, answers, entry_size);
+ else {
+ char * tmp_answers[50];
+ int i = 0;
+ while (questions && *questions) {
+ tmp_answers[i] = get_auto_value(*questions_auto);
+ log_message("AUTOMATIC: question %s answers %s because of param %s", *questions, tmp_answers[i], *questions_auto);
+ i++;
+ questions++;
+ questions_auto++;
+
+ }
+ *answers = memdup(tmp_answers, sizeof(char *) * i);
+ return RETURN_OK;
+ }
+}
diff --git a/mdk-stage1/automatic.h b/mdk-stage1/automatic.h
new file mode 100644
index 000000000..507876072
--- /dev/null
+++ b/mdk-stage1/automatic.h
@@ -0,0 +1,31 @@
+/*
+ * Guillaume Cottenceau (gc@mandrakesoft.com)
+ *
+ * Copyright 2000 MandrakeSoft
+ *
+ * This software may be freely redistributed under the terms of the GNU
+ * public license.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+/*
+ * This is supposed to replace the redhat "kickstart", by name but
+ * also by design (no code pollution).
+ *
+ */
+
+#ifndef _AUTOMATIC_H_
+#define _AUTOMATIC_H_
+
+#include "stage1.h"
+
+void grab_automatic_params(char * line);
+
+enum return_type ask_from_list_auto(char *msg, char ** elems, char ** choice, char * auto_param, char ** elems_auto);
+enum return_type ask_from_entries_auto(char *msg, char ** questions, char *** answers, int entry_size, char ** questions_auto);
+
+#endif
diff --git a/mdk-stage1/network.c b/mdk-stage1/network.c
index dbce28113..a2932863c 100644
--- a/mdk-stage1/network.c
+++ b/mdk-stage1/network.c
@@ -38,6 +38,7 @@
#include "log.h"
#include "dns.h"
#include "mount.h"
+#include "automatic.h"
#include "network.h"
@@ -268,18 +269,20 @@ static enum return_type setup_network_interface(struct interface_info * intf)
{
enum return_type results;
char * bootprotos[] = { "Static", "DHCP", NULL };
+ char * bootprotos_auto[] = { "static", "dhcp" };
char * choice;
- results = ask_from_list("Please choose the desired IP attribution.", bootprotos, &choice);
+ results = ask_from_list_auto("Please choose the desired IP attribution.", bootprotos, &choice, "network", bootprotos_auto);
if (results != RETURN_OK)
return results;
if (!strcmp(choice, "Static")) {
char * questions[] = { "IP of this machine", "IP of Domain Name Server", "IP of default gateway", NULL };
+ char * questions_auto[] = { "ip", "dns", "gateway" };
char ** answers;
struct in_addr addr;
- results = ask_from_entries("Please enter the network information.", questions, &answers, 16);
+ results = ask_from_entries_auto("Please enter the network information.", questions, &answers, 16, questions_auto);
if (results != RETURN_OK)
return setup_network_interface(intf);
@@ -331,6 +334,7 @@ static enum return_type setup_network_interface(struct interface_info * intf)
} else {
error_message("DHCP not implemented yet");
intf->boot_proto = BOOTPROTO_DHCP;
+ return RETURN_ERROR;
}
if (configure_net_device(intf))
@@ -352,15 +356,16 @@ static enum return_type configure_network(struct interface_info * intf)
if (!name) {
enum return_type results;
char * questions[] = { "Host name", "Domain name", NULL };
+ char * questions_auto[] = { "hostname", "domain" };
char ** answers;
char * boulet;
log_message("reverse name lookup on self failed");
- results = ask_from_entries("I could not guess hostname and domain name; please fill in this information. "
- "Valid answers are for example: `mybox' for hostname and `mynetwork.com' for domain name, "
- "for a machine called `mybox.mynetwork.com' on the Internet.",
- questions, &answers, 32);
+ results = ask_from_entries_auto("I could not guess hostname and domain name; please fill in this information. "
+ "Valid answers are for example: `mybox' for hostname and `mynetwork.com' for domain name, "
+ "for a machine called `mybox.mynetwork.com' on the Internet.",
+ questions, &answers, 32, questions_auto);
if (results != RETURN_OK)
return results;
@@ -475,32 +480,25 @@ static enum return_type intf_select_and_up(void)
{
static struct interface_info intf[20];
static int num_interfaces = 0;
- enum return_type results;
-
- do {
- struct interface_info * sel_intf = NULL;
- int i;
- char * iface = interface_select();
-
- if (iface == NULL)
- return RETURN_BACK;
-
- for (i = 0; i < num_interfaces ; i++)
- if (!strcmp(intf[i].device, iface))
- sel_intf = &(intf[i]);
-
- if (sel_intf == NULL) {
- sel_intf = &(intf[num_interfaces]);
- strcpy(sel_intf->device, iface);
- sel_intf->is_up = 0;
- num_interfaces++;
- }
-
- results = bringup_networking(sel_intf);
+ struct interface_info * sel_intf = NULL;
+ int i;
+ char * iface = interface_select();
+
+ if (iface == NULL)
+ return RETURN_BACK;
+
+ for (i = 0; i < num_interfaces ; i++)
+ if (!strcmp(intf[i].device, iface))
+ sel_intf = &(intf[i]);
+
+ if (sel_intf == NULL) {
+ sel_intf = &(intf[num_interfaces]);
+ strcpy(sel_intf->device, iface);
+ sel_intf->is_up = 0;
+ num_interfaces++;
}
- while (results == RETURN_BACK);
-
- return RETURN_OK;
+
+ return bringup_networking(sel_intf);
}
@@ -508,6 +506,7 @@ static enum return_type intf_select_and_up(void)
enum return_type nfs_prepare(void)
{
char * questions[] = { "NFS server name", "Linux-Mandrake directory", NULL };
+ char * questions_auto[] = { "server", "directory", NULL };
char ** answers;
char * nfsmount_location;
enum return_type results = intf_select_and_up();
@@ -516,9 +515,9 @@ enum return_type nfs_prepare(void)
return results;
do {
- results = ask_from_entries("Please enter the name or IP address of your NFS server, "
- "and the directory containing the Linux-Mandrake installation.",
- questions, &answers, 40);
+ results = ask_from_entries_auto("Please enter the name or IP address of your NFS server, "
+ "and the directory containing the Linux-Mandrake installation.",
+ questions, &answers, 40, questions_auto);
if (results != RETURN_OK)
return nfs_prepare();
diff --git a/mdk-stage1/newt-frontend.c b/mdk-stage1/newt-frontend.c
index 4f62f87f0..cae1c1c1a 100644
--- a/mdk-stage1/newt-frontend.c
+++ b/mdk-stage1/newt-frontend.c
@@ -60,6 +60,7 @@ void error_message(char *msg, ...)
va_start(args, msg);
va_end(args);
newtWinMessagev("Error", "Ok", msg, args);
+ set_param(MODE_AUTOMATIC_ERROR_OCCURED);
}
void info_message(char *msg, ...)
@@ -67,7 +68,10 @@ void info_message(char *msg, ...)
va_list args;
va_start(args, msg);
va_end(args);
- newtWinMessagev("Notice", "Ok", msg, args);
+ if (!IS_AUTOMATIC)
+ newtWinMessagev("Notice", "Ok", msg, args);
+ else
+ vlog_message(msg, args);
}
void wait_message(char *msg, ...)
diff --git a/mdk-stage1/stage1.c b/mdk-stage1/stage1.c
index 4f72ab9d1..528132ace 100644
--- a/mdk-stage1/stage1.c
+++ b/mdk-stage1/stage1.c
@@ -42,6 +42,7 @@
#include "frontend.h"
#include "modules.h"
#include "tools.h"
+#include "automatic.h"
#ifndef DISABLE_CDROM
#include "cdrom.h"
@@ -110,37 +111,38 @@ void spawn_shell(void)
enum return_type method_select_and_prepare(void)
{
+ enum return_type results;
+ char * choice;
+ char * means[10], * means_auto[10];
+ int i;
+
#ifndef DISABLE_DISK
- char * disk_install = "Hard disk";
+ char * disk_install = "Hard disk"; char * disk_install_auto = "disk";
#endif
#ifndef DISABLE_CDROM
- char * cdrom_install = "CDROM drive";
+ char * cdrom_install = "CDROM drive"; char * cdrom_install_auto = "cdrom";
#endif
#ifndef DISABLE_NETWORK
- char * network_nfs_install = "NFS server";
- char * network_ftp_install = "FTP server";
- char * network_http_install = "HTTP server";
+ char * network_nfs_install = "NFS server"; char * network_nfs_install_auto = "nfs";
+ char * network_ftp_install = "FTP server"; char * network_ftp_install_auto = "ftp";
+ char * network_http_install = "HTTP server"; char * network_http_install_auto = "http";
#endif
- enum return_type results;
- char * choice;
- char * means[10];
- int i;
i = 0;
#ifndef DISABLE_NETWORK
- means[i] = network_nfs_install; i++;
- means[i] = network_ftp_install; i++;
- means[i] = network_http_install; i++;
-#endif
-#ifndef DISABLE_DISK
- means[i] = disk_install; i++;
+ means[i] = network_nfs_install; means_auto[i++] = network_nfs_install_auto;
+ means[i] = network_ftp_install; means_auto[i++] = network_ftp_install_auto;
+ means[i] = network_http_install; means_auto[i++] = network_http_install_auto;
#endif
#ifndef DISABLE_CDROM
- means[i] = cdrom_install; i++;
+ means[i] = cdrom_install; means_auto[i++] = cdrom_install_auto;
+#endif
+#ifndef DISABLE_DISK
+ means[i] = disk_install; means_auto[i++] = disk_install_auto;
#endif
means[i] = NULL;
- results = ask_from_list("Please choose the mean of installation.", means, &choice);
+ results = ask_from_list_auto("Please choose the mean of installation.", means, &choice, "method", means_auto);
if (results != RETURN_OK)
return results;
diff --git a/mdk-stage1/stage1.h b/mdk-stage1/stage1.h
index d224babea..01620c266 100644
--- a/mdk-stage1/stage1.h
+++ b/mdk-stage1/stage1.h
@@ -36,18 +36,20 @@ extern char * method_name;
#define MODE_EXPERT (1 << 1)
#define MODE_TEXT (1 << 2)
#define MODE_RESCUE (1 << 3)
-#define MODE_KICKSTART (1 << 4)
+#define MODE_AUTOMATIC (1 << 4)
#define MODE_PCMCIA (1 << 5)
#define MODE_CDROM (1 << 6)
#define MODE_LIVE (1 << 7)
#define MODE_SPECIAL_STAGE2 (1 << 8)
#define MODE_RAMDISK (1 << 9)
+#define MODE_AUTOMATIC_ERROR_OCCURED (1 << 10)
#define IS_TESTING (get_param(MODE_TESTING))
#define IS_EXPERT (get_param(MODE_EXPERT))
#define IS_TEXT (get_param(MODE_TEXT))
#define IS_RESCUE (get_param(MODE_RESCUE))
-#define IS_KICKSTART (get_param(MODE_KICKSTART))
+#define IS_AUTOMATIC (get_param(MODE_AUTOMATIC))
+#define IS_AUTOMATIC_ERROR_OCCURED (get_param(MODE_AUTOMATIC_ERROR_OCCURED))
#define IS_PCMCIA (get_param(MODE_PCMCIA))
#define IS_CDROM (get_param(MODE_CDROM))
#define IS_LIVE (get_param(MODE_LIVE))
diff --git a/mdk-stage1/stdio-frontend.c b/mdk-stage1/stdio-frontend.c
index ae7a57af1..8f8b68c17 100644
--- a/mdk-stage1/stdio-frontend.c
+++ b/mdk-stage1/stdio-frontend.c
@@ -87,6 +87,7 @@ void error_message(char *msg, ...)
va_start(args, msg);
va_end(args);
blocking_msg("> Error! ", msg, args);
+ set_param(MODE_AUTOMATIC_ERROR_OCCURED);
}
void info_message(char *msg, ...)
@@ -94,7 +95,10 @@ void info_message(char *msg, ...)
va_list args;
va_start(args, msg);
va_end(args);
- blocking_msg("> Notice: ", msg, args);
+ if (!IS_AUTOMATIC)
+ blocking_msg("> Notice: ", msg, args);
+ else
+ vlog_message(msg, args);
}
void wait_message(char *msg, ...)
diff --git a/mdk-stage1/tools.c b/mdk-stage1/tools.c
index 9420ed1dd..f4da3b50b 100644
--- a/mdk-stage1/tools.c
+++ b/mdk-stage1/tools.c
@@ -31,23 +31,18 @@
#include "log.h"
#include "mount.h"
#include "frontend.h"
+#include "automatic.h"
#include "tools.h"
-struct cmdline_elem
-{
- char * name;
- char * value;
-};
-
-struct cmdline_elem * params;
+static struct param_elem * params;
void process_cmdline(void)
{
char buf[512];
int fd, size, i, p;
- struct cmdline_elem tmp_params[50];
+ struct param_elem tmp_params[50];
log_message("opening /proc/cmdline... ");
@@ -61,36 +56,42 @@ void process_cmdline(void)
log_message("\t%s", buf);
i = 0; p = 0;
- while (buf[i] != 0) {
+ while (buf[i] != '\0') {
char *name, *value = NULL;
int j = i;
- while (buf[i] != ' ' && buf[i] != '=' && buf[i] != 0)
+ while (buf[i] != ' ' && buf[i] != '=' && buf[i] != '\0')
i++;
if (i == j) {
i++;
continue;
}
name = memdup(&buf[j], i-j + 1);
- name[i-j] = 0;
+ name[i-j] = '\0';
if (buf[i] == '=') {
int k = i+1;
i++;
- while (buf[i] != ' ' && buf[i] != 0)
+ while (buf[i] != ' ' && buf[i] != '\0')
i++;
value = memdup(&buf[k], i-k + 1);
- value[i-k] = 0;
+ value[i-k] = '\0';
}
tmp_params[p].name = name;
tmp_params[p].value = value;
- p++;
- i++;
if (!strcmp(name, "expert")) set_param(MODE_EXPERT);
if (!strcmp(name, "rescue")) set_param(MODE_RESCUE);
if (!strcmp(name, "pcmcia")) set_param(MODE_PCMCIA);
if (!strcmp(name, "cdrom")) set_param(MODE_CDROM);
if (!strcmp(name, "special_stage2")) set_param(MODE_SPECIAL_STAGE2);
+ if (!strcmp(name, "automatic")) {
+ set_param(MODE_AUTOMATIC);
+ grab_automatic_params(value);
+ }
+ p++;
+ if (buf[i] == '\0')
+ break;
+ i++;
}
if (IS_RESCUE) {
@@ -102,9 +103,9 @@ void process_cmdline(void)
tmp_params[p++].name = NULL;
- params = memdup(tmp_params, sizeof(struct cmdline_elem) * p);
+ params = memdup(tmp_params, sizeof(struct param_elem) * p);
- log_message("\tgot %d args", p);
+ log_message("\tgot %d args", p-1);
}
@@ -117,7 +118,7 @@ int get_param(int i)
char * get_param_valued(char *param_name)
{
- struct cmdline_elem * ptr = params;
+ struct param_elem * ptr = params;
while (ptr->name) {
if (!strcmp(ptr->name, param_name))
@@ -179,7 +180,7 @@ int ramdisk_possible(void)
if (total_memory() > MEM_LIMIT_RAMDISK)
return 1;
else {
- log_message("Warning, ramdisk is not possible due to low mem!");
+ log_message("warning, ramdisk is not possible due to low mem!");
return 0;
}
}
diff --git a/mdk-stage1/tools.h b/mdk-stage1/tools.h
index a21615891..7f34c8c5d 100644
--- a/mdk-stage1/tools.h
+++ b/mdk-stage1/tools.h
@@ -22,6 +22,7 @@
#ifndef _TOOLS_H_
#define _TOOLS_H_
+#include <stdlib.h>
void process_cmdline(void);
int get_param(int i);
@@ -31,5 +32,11 @@ int ramdisk_possible(void);
enum return_type load_ramdisk(void);
void * memdup(void *src, size_t size);
+struct param_elem
+{
+ char * name;
+ char * value;
+};
+
#endif