summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mdk-stage1/config-stage1.h4
-rw-r--r--mdk-stage1/frontend-common.c19
-rw-r--r--mdk-stage1/frontend.h1
-rw-r--r--mdk-stage1/network.c200
-rw-r--r--mdk-stage1/newt-frontend.c58
-rw-r--r--mdk-stage1/stdio-frontend.c10
-rw-r--r--mdk-stage1/tools.c9
-rw-r--r--mdk-stage1/tools.h1
8 files changed, 137 insertions, 165 deletions
diff --git a/mdk-stage1/config-stage1.h b/mdk-stage1/config-stage1.h
index 616783abc..f668a465b 100644
--- a/mdk-stage1/config-stage1.h
+++ b/mdk-stage1/config-stage1.h
@@ -75,8 +75,8 @@
/* path to mirror list for net install */
#ifndef DISABLE_NETWORK
-#define MIRRORLIST_HOST "www.mandrivalinux.com"
-#define MIRRORLIST_PATH "/mirrorsfull.list"
+#define MIRRORLIST_HOST "api.mandriva.com"
+#define MIRRORLIST_PATH "/mirrors"
#endif
#endif
diff --git a/mdk-stage1/frontend-common.c b/mdk-stage1/frontend-common.c
index a66db457a..6ea2984cd 100644
--- a/mdk-stage1/frontend-common.c
+++ b/mdk-stage1/frontend-common.c
@@ -14,6 +14,7 @@
#include <stdlib.h>
#include <stdarg.h>
+#include <string.h>
#include <probing.h>
@@ -43,3 +44,21 @@ void error_message(char *msg, ...)
verror_message(msg, args);
va_end(args);
}
+
+enum return_type ask_from_list_comments(char *msg, char ** elems, char ** elems_comments, char ** choice)
+{
+ int answer = 0;
+ enum return_type results;
+
+ results = ask_from_list_index(msg, elems, elems_comments, &answer);
+
+ if (results == RETURN_OK)
+ *choice = strdup(elems[answer]);
+
+ return results;
+}
+
+enum return_type ask_from_list(char *msg, char ** elems, char ** choice)
+{
+ return ask_from_list_comments(msg, elems, NULL, choice);
+}
diff --git a/mdk-stage1/frontend.h b/mdk-stage1/frontend.h
index 1737ee7e7..4c2558b4a 100644
--- a/mdk-stage1/frontend.h
+++ b/mdk-stage1/frontend.h
@@ -53,6 +53,7 @@ void end_progression(void);
#endif
enum return_type ask_yes_no(char *msg);
+enum return_type ask_from_list_index(char *msg, char ** elems, char ** elems_comments, int *answer);
enum return_type ask_from_list(char *msg, char ** elems, char ** choice);
enum return_type ask_from_list_comments(char *msg, char ** elems, char ** elems_comments, char ** choice);
enum return_type ask_from_entries(char *msg, char ** questions, char *** answers, int entry_size, void (*callback_func)(char ** strings));
diff --git a/mdk-stage1/network.c b/mdk-stage1/network.c
index f02903c55..e4fdd4fe0 100644
--- a/mdk-stage1/network.c
+++ b/mdk-stage1/network.c
@@ -1,5 +1,4 @@
-/*
- * Guillaume Cottenceau (gc@mandrakesoft.com)
+ Cottenceau (gc@mandrakesoft.com)
*
* Copyright 2000 Mandrakesoft
*
@@ -743,173 +742,138 @@ static enum return_type get_http_proxy(char **http_proxy_host, char **http_proxy
}
-static int mirrorlist_entry_split(const char *entry, char *mirror[4]) /* mirror = { medium, protocol, host, path } */
+static int url_split(const char *url, const char *protocol, char **host, char **path)
{
- char *medium_sep, *protocol_sep, *host_sep, *path_sep;
+ char *protocol_sep, *host_sep;
- medium_sep = strchr(entry, ':');
- if (!medium_sep || medium_sep == entry) {
- log_message("NETWORK: no medium in \"%s\"", entry);
+ protocol_sep = strstr(url, "://");
+ if (!protocol_sep) {
+ log_message("NETWORK: no protocol in \"%s\"", url);
return -1;
}
- mirror[0] = strndup(entry, medium_sep - entry);
- entry = medium_sep + 1;
-
- protocol_sep = strstr(entry, "://");
- if (!protocol_sep || protocol_sep == entry) {
- log_message("NETWORK: no protocol in \"%s\"", entry);
+ if (strncmp(protocol, url, protocol_sep - url))
return -1;
- }
- mirror[1] = strndup(entry, protocol_sep - entry);
- entry = protocol_sep + 3;
-
- host_sep = strchr(entry, '/');
- if (!host_sep || host_sep == entry) {
- log_message("NETWORK: no hostname in \"%s\"", entry);
+ url = protocol_sep + 3;
+ host_sep = strchr(url, '/');
+ if (!host_sep || host_sep == url) {
+ log_message("NETWORK: no hostname in \"%s\"", url);
return -1;
}
- mirror[2] = strndup(entry, host_sep - entry);
- entry = host_sep;
-
- path_sep = strstr(entry, "/media/main");
- if (!path_sep || path_sep == entry) {
- log_message("NETWORK: this path isn't valid : \"%s\"", entry);
- return -1;
- }
-
- mirror[3] = strndup(entry, path_sep - entry);
+ *host = strndup(url, host_sep - url);
+ *path = strdup(host_sep);
return 0;
}
-
#define MIRRORLIST_MAX_ITEMS 500
-#define MIRRORLIST_MAX_MEDIA 10
-
-static int choose_mirror_from_host_list(char *mirrorlist[][4], const char *protocol, char *medium, char **selected_host, char **filepath)
-{
- enum return_type results;
- char *hostlist[MIRRORLIST_MAX_ITEMS+1] = { "Specify the mirror manually", "-----" };
- int hostlist_index = 2, mirrorlist_index;
-
- /* select hosts matching medium and protocol */
- for (mirrorlist_index = 0; mirrorlist[mirrorlist_index][0]; mirrorlist_index++) {
- if (!strcmp(mirrorlist[mirrorlist_index][0], medium) &&
- !strcmp(mirrorlist[mirrorlist_index][1], protocol)) {
- hostlist[hostlist_index] = mirrorlist[mirrorlist_index][2];
- hostlist_index++;
- if (hostlist_index == MIRRORLIST_MAX_ITEMS)
- break;
- }
- }
- hostlist[hostlist_index] = NULL;
-
- do {
- results = ask_from_list("Please select a mirror from the list below.",
- hostlist, selected_host);
-
- if (results == RETURN_BACK) {
- return RETURN_ERROR;
- } else if (results == RETURN_OK) {
- if (!strcmp(*selected_host, hostlist[0])) {
- /* enter the mirror manually */
- return RETURN_OK;
- } else if (!strcmp(*selected_host, hostlist[1])) {
- /* the separator has been selected */
- results = RETURN_ERROR;
- continue;
- }
- }
-
- /* select the path according to medium, protocol and host */
- for (mirrorlist_index = 0; mirrorlist[mirrorlist_index][0]; mirrorlist_index++) {
- if (!strcmp(mirrorlist[mirrorlist_index][0], medium) &&
- !strcmp(mirrorlist[mirrorlist_index][1], protocol) &&
- !strcmp(mirrorlist[mirrorlist_index][2], *selected_host)) {
- *filepath = mirrorlist[mirrorlist_index][3];
- return RETURN_OK;
- }
- }
-
- stg1_info_message("Unable to find the path for this mirror, please select another one");
- results = RETURN_ERROR;
-
- } while (results == RETURN_ERROR);
-
- return RETURN_ERROR;
-}
-
+typedef char *mirrorlist_t[2][MIRRORLIST_MAX_ITEMS+1];
-static int choose_mirror_from_list(char *http_proxy_host, char *http_proxy_port, const char *protocol, char **selected_host, char **filepath)
-{
- enum return_type results;
- char *mirrorlist[MIRRORLIST_MAX_ITEMS+1][4];
- int mirrorlist_number = 0;
- char *medialist[MIRRORLIST_MAX_MEDIA+1] = { "Specify the mirror manually", "-----" };
- int media_number = 2;
- char *selected_medium;
+static enum return_type get_mirrorlist(mirrorlist_t mirrorlist, int start, char *version, const char *protocol, char *http_proxy_host, char *http_proxy_port) {
int fd, size, line_pos = 0;
- char line[500];
+ char path[1024];
+ char line[1024];
+ char type[100] = DISTRIB_TYPE;
+ int mirror_idx = start;
+
int use_http_proxy = http_proxy_host && http_proxy_port && !streq(http_proxy_host, "") && !streq(http_proxy_port, "");
+ lowercase(type);
+ snprintf(path, sizeof(path) -1, "%s/%s.%s.%s.list", MIRRORLIST_PATH, type, version, ARCH);
- fd = http_download_file(MIRRORLIST_HOST, MIRRORLIST_PATH, &size, use_http_proxy ? "http" : NULL, http_proxy_host, http_proxy_port);
+ fd = http_download_file(MIRRORLIST_HOST, path, &size, use_http_proxy ? "http" : NULL, http_proxy_host, http_proxy_port);
if (fd < 0) {
- log_message("HTTP: unable to get mirrors list");
+ log_message("HTTP: unable to get mirrors list from %s (%s)", MIRRORLIST_HOST, path);
return RETURN_ERROR;
}
while (read(fd, line + line_pos, 1) > 0) {
if (line[line_pos] == '\n') {
+ char *url;
line[line_pos] = '\0';
line_pos = 0;
/* skip medium if it looks like an updates one */
- if (strstr(line, "updates"))
+ if (strstr(line, ",type=updates,"))
continue;
- if (mirrorlist_entry_split(line, mirrorlist[mirrorlist_number]) < 0)
+ url = strstr(line, ",url=");
+ if (!url)
continue;
+ url += 5;
- /* add medium in media list if different from previous one */
- if (media_number == 2 ||
- strcmp(mirrorlist[mirrorlist_number][0], medialist[media_number-1])) {
- medialist[media_number] = mirrorlist[mirrorlist_number][0];
- media_number++;
- }
+ if (url_split(url, protocol, &mirrorlist[0][mirror_idx], &mirrorlist[1][mirror_idx]) < 0)
+ continue;
- mirrorlist_number++;
+ mirror_idx++;
} else {
line_pos++;
}
- if (mirrorlist_number >= MIRRORLIST_MAX_ITEMS || media_number >= MIRRORLIST_MAX_MEDIA)
+ if (mirror_idx >= MIRRORLIST_MAX_ITEMS)
break;
}
close(fd);
- mirrorlist[mirrorlist_number][0] = NULL;
- medialist[media_number] = NULL;
+ mirrorlist[0][mirror_idx] = NULL;
+ mirrorlist[1][mirror_idx] = NULL;
+
+ return RETURN_OK;
+}
+
+static int choose_mirror_from_host_list(mirrorlist_t mirrorlist, char **selected_host, char **filepath)
+{
+ enum return_type results;
+ int mirror_idx = 0;
+
+ do {
+ results = ask_from_list_index("Please select a mirror from the list below.",
+ mirrorlist[0], NULL, &mirror_idx);
+
+ if (results == RETURN_BACK) {
+ return RETURN_ERROR;
+ } else if (results == RETURN_OK) {
+ if (mirror_idx == 0) {
+ /* enter the mirror manually */
+ return RETURN_OK;
+ }
+ *selected_host = strdup(mirrorlist[0][mirror_idx]);
+ *filepath = strdup(mirrorlist[1][mirror_idx]);
+ return RETURN_OK;
+ }
+ } while (results == RETURN_ERROR);
+
+ return RETURN_ERROR;
+}
+
+
+static int choose_mirror_from_list(char *http_proxy_host, char *http_proxy_port, const char *protocol, char **selected_host, char **filepath)
+{
+ enum return_type results;
+ char *versions[] = { "Specify the mirror manually", DISTRIB_VERSION, "cooker", NULL };
+ char *version = DISTRIB_VERSION;
do {
- results = ask_from_list("Please select a medium from the list below.",
- medialist, &selected_medium);
+ results = ask_from_list("Please select a medium from the list below.", versions, &version);
if (results == RETURN_BACK) {
return RETURN_BACK;
} else if (results == RETURN_OK) {
- if (!strcmp(selected_medium, medialist[0])) {
+ if (!strcmp(version, versions[0])) {
/* enter the mirror manually */
return RETURN_OK;
- } else if (!strcmp(selected_medium, medialist[1])) {
- /* the separator has been selected */
- results = RETURN_ERROR;
- continue;
} else {
/* a medium has been selected */
- results = choose_mirror_from_host_list(mirrorlist, protocol, selected_medium, selected_host, filepath);
+ mirrorlist_t mirrorlist;
+ mirrorlist[0][0] = "Specify the mirror manually";
+ mirrorlist[1][0] = NULL;
+
+ results = get_mirrorlist(mirrorlist, 1, version, protocol, http_proxy_host, http_proxy_port);
+ if (results == RETURN_ERROR)
+ return RETURN_ERROR;
+
+ results = choose_mirror_from_host_list(mirrorlist, selected_host, filepath);
}
}
} while (results == RETURN_ERROR);
@@ -943,7 +907,7 @@ enum return_type intf_select_and_up()
sel_intf->is_up = 0;
num_interfaces++;
}
-
+
results = bringup_networking(sel_intf);
if (results == RETURN_OK)
diff --git a/mdk-stage1/newt-frontend.c b/mdk-stage1/newt-frontend.c
index 4bedda82b..731818a0d 100644
--- a/mdk-stage1/newt-frontend.c
+++ b/mdk-stage1/newt-frontend.c
@@ -172,55 +172,39 @@ void end_progression_raw(void)
}
-enum return_type ask_from_list_comments(char *msg, char ** elems, char ** elems_comments, char ** choice)
+enum return_type ask_from_list_index(char *msg, char ** elems, char ** elems_comments, int * answer)
{
char * items[500];
- int answer = 0, rc;
- char ** sav_elems = elems;
- int i;
+ int rc;
- i = 0;
- while (elems && *elems) {
- int j = (*elems_comments) ? strlen(*elems_comments) : 0;
- items[i] = malloc(sizeof(char) * (strlen(*elems) + j + 4));
- strcpy(items[i], *elems);
- if (*elems_comments) {
- strcat(items[i], " (");
- strcat(items[i], *elems_comments);
- strcat(items[i], ")");
- }
- elems_comments++;
- i++;
- elems++;
+ if (elems_comments) {
+ int i;
+
+ i = 0;
+ while (elems && *elems) {
+ int j = (*elems_comments) ? strlen(*elems_comments) : 0;
+ items[i] = malloc(sizeof(char) * (strlen(*elems) + j + 4));
+ strcpy(items[i], *elems);
+ if (*elems_comments) {
+ strcat(items[i], " (");
+ strcat(items[i], *elems_comments);
+ strcat(items[i], ")");
+ }
+ elems_comments++;
+ i++;
+ elems++;
+ }
+ items[i] = NULL;
}
- items[i] = NULL;
- rc = newtWinMenu("Please choose...", msg, 52, 5, 5, 7, items, &answer, "Ok", "Cancel", NULL);
+ rc = newtWinMenu("Please choose...", msg, 52, 5, 5, 7, elems_comments ? items : elems, answer, "Ok", "Cancel", NULL);
if (rc == 2)
return RETURN_BACK;
- *choice = strdup(sav_elems[answer]);
-
return RETURN_OK;
}
-
-enum return_type ask_from_list(char *msg, char ** elems, char ** choice)
-{
- int answer = 0, rc;
-
- rc = newtWinMenu("Please choose...", msg, 52, 5, 5, 7, elems, &answer, "Ok", "Cancel", NULL);
-
- if (rc == 2)
- return RETURN_BACK;
-
- *choice = strdup(elems[answer]);
-
- return RETURN_OK;
-}
-
-
enum return_type ask_yes_no(char *msg)
{
int rc;
diff --git a/mdk-stage1/stdio-frontend.c b/mdk-stage1/stdio-frontend.c
index ffa306811..7d3c6f14b 100644
--- a/mdk-stage1/stdio-frontend.c
+++ b/mdk-stage1/stdio-frontend.c
@@ -240,7 +240,7 @@ void end_progression_raw(void)
}
-enum return_type ask_from_list_comments(char *msg, char ** elems, char ** elems_comments, char ** choice)
+enum return_type ask_from_list_index(char *msg, char ** elems, char ** elems_comments, int *answer)
{
int justify_number = 1;
void print_choice_number(int i) {
@@ -296,7 +296,7 @@ enum return_type ask_from_list_comments(char *msg, char ** elems, char ** elems_
return RETURN_BACK;
if (j >= 1 && j <= i) {
- *choice = strdup(sav_elems[j-1]);
+ *answer = j - 1;
return RETURN_OK;
}
@@ -304,12 +304,6 @@ enum return_type ask_from_list_comments(char *msg, char ** elems, char ** elems_
}
-enum return_type ask_from_list(char *msg, char ** elems, char ** choice)
-{
- return ask_from_list_comments(msg, elems, NULL, choice);
-}
-
-
enum return_type ask_yes_no(char *msg)
{
int j;
diff --git a/mdk-stage1/tools.c b/mdk-stage1/tools.c
index baba72b0d..8fc6864b5 100644
--- a/mdk-stage1/tools.c
+++ b/mdk-stage1/tools.c
@@ -612,3 +612,12 @@ int scall_(int retval, char * msg, char * file, int line)
log_perror(tmp);
return retval;
}
+
+void lowercase(char *s)
+{
+ int i = 0;
+ while (s[i]) {
+ s[i] = tolower(s[i]);
+ i++;
+ }
+}
diff --git a/mdk-stage1/tools.h b/mdk-stage1/tools.h
index fd5236a93..78ed4b087 100644
--- a/mdk-stage1/tools.h
+++ b/mdk-stage1/tools.h
@@ -60,6 +60,7 @@ char * floppy_device(void);
char * asprintf_(const char *msg, ...);
int scall_(int retval, char * msg, char * file, int line);
#define scall(retval, msg) scall_(retval, msg, __FILE__, __LINE__)
+void lowercase(char *s);
struct param_elem
{