1 /* Copyright (C) 1995 Florian La Roche */
2 /* Who wants to help coding? I don't like doing this... */
4 /* You can just start setup as normal user and see how far it is coded
5 right now. This will do a fake installation and won't actually chnage
6 any data on your computer. */
8 /* TODO: write a good package selection code
9 change functions to return better error code
12 /* Show an extra text-box with the contents of all external commands,
13 before they are executed. So you can abort the installation, if any
14 wrong commands are to be executed. (So don't format wrong partition.) */
17 /* If defined, don't actually execute any comands and don't actually modify
18 any files. So you can test any possible installation without doing any
19 damage to your computer.
20 The file FDISK.TEST is used instead of real "fdisk -l" output, so that
21 it can be started as normal user. */
26 /* max length of a partition name like e.g. '/dev/hda1' */
27 #define MAX_DEV_NAME 25
29 /* max number of possible Linux/Swap/MsDos partitions */
32 char *progname = NULL;
37 fprintf(stderr, "%s: %s\n", progname, s);
42 my_system(const char *s,...)
53 i = dialog_msgbox("I will run the following command:", sh, 10, 65, 1);
62 i = dialog_msgbox("Error-Exit on the following command:",
68 /* We support to install from DOS/Linux-partitions. */
76 enum partition_type type;
77 char name[MAX_DEV_NAME];
80 } partitions[MAX_PARTS];
81 int num_partition = 0;
87 get_line(char *line, int size, FILE * f)
94 while (size-- && ((c = getc(f)) != EOF) && (c != '\n'))
97 return (int) (ptr - line);
101 read_partitions(void)
107 int ret = system("fdisk -l 2>/dev/null 1>/tmp/fdisk.output");
108 if ((ret >> 8) != 0) {
109 error("fdisk didn't run");
111 if ((f = fopen("/tmp/fdisk.output", "r")) == NULL)
113 if ((f = fopen("FDISK.TEST", "r")) == NULL)
115 error("cannot read fdisk output");
117 while (num_partition <= MAX_PARTS
118 && (length = get_line(line, 200, f)) >= 0) {
119 if (strncmp(line, "/dev/", 5) == 0) {
122 char *t = partitions[num_partition].name;
125 while (n < MAX_DEV_NAME && *s != '\0'
126 && !isspace((unsigned char) *s)) {
131 /* Read the size of the partition. */
133 while (isspace((unsigned char) *t))
135 partitions[num_partition].blocks = atoi(t);
136 if (strstr(line, "Linux native")) {
137 partitions[num_partition].type = Linux;
140 } else if (strstr(line, "Linux swap")) {
141 partitions[num_partition].type = Swap;
144 } else if (strstr(line, "DOS")) {
145 partitions[num_partition].type = MsDos;
153 unlink("/tmp/fdisk.output");
158 select_partition(const char *title, const char *prompt, int y, int x)
161 char info[MAX_PARTS][40];
162 char *items[MAX_PARTS * 2];
163 int num_pa[MAX_PARTS];
166 for (i = 0; i < num_partition; i++) {
167 if (partitions[i].type == Linux) {
168 items[num * 2] = partitions[i].name;
169 sprintf(info[num], "Linux partition with %d blocks",
170 partitions[i].blocks);
171 items[num * 2 + 1] = info[num];
176 ret = dialog_menu(title, prompt, y + num, x, num, num, items);
178 if (ret >= 0) /* item selected */
184 select_install_partition(void)
186 return select_partition("Select Install Partition",
187 "\\nWhere do you want to install Linux?\\n", 9, 60);
191 select_source_partition(void)
193 return select_partition("Select Source Partition",
194 "\\nOn which partition is the source?\\n", 9, 60);
197 const char *null = ">/dev/null 2>/dev/null";
198 const char *install_partition = NULL;
201 extract_packages(const char *source_path)
207 if (my_system("mkdir -p /install/var/installed/packages %s", null))
209 if (my_system("cd /install; for i in /source%s/*.tgz; do "
210 "tar xzplvvkf $i >> var/installed/packages/base "
211 "2>>var/installed/packages/ERROR; done", source_path))
214 if ((f = fopen("/install/etc/fstab", "w")) == NULL) {
215 /* i = */ dialog_msgbox("Error", "Cannot write /etc/fstab",
219 fprintf(f, "%s / ext2 defaults 1 1\n", install_partition);
220 fprintf(f, "none /proc proc defaults 0 2\n");
221 /* XXX write swap-partitions */
227 install_premounted(void)
229 extract_packages("");
233 install_harddisk(void)
238 if ((part = select_source_partition()) <= -1)
240 name = partitions[part].name;
242 if (my_system("mount -t ext2 %s /source %s", name, null))
244 ret = dialog_inputbox("Path in partition",
245 "Please enter the directory in which the "
246 "source files are.", 13, 50, "", FALSE);
251 extract_packages(strdup(dialog_input_result));
252 if (my_system("umount /source %s", null))
259 if (my_system("ifconfig eth0 134.96.81.36 netmask 255.255.255.224 "
260 "broadcast 134.96.81.63 %s", null))
262 if (my_system("route add -net 134.96.81.32 %s", null))
264 if (my_system("mount -t nfs 134.96.81.38:"
265 "/local/ftp/pub/linux/ELF.binary/tar /source %s", null))
267 extract_packages("/base");
268 if (my_system("umount /source %s", null))
270 if (my_system("ifconfig eth0 down %s", null))
281 "1", "Harddisk Install",
282 "2", "Network Install(NFS)",
283 "3", "Premounted on /source"
286 if (num_linux == 0) {
290 if ((part = select_install_partition()) <= -1)
292 install_partition = name = partitions[part].name;
293 if (my_system("mke2fs %s %s", name, null))
295 if (my_system("mount -t ext2 %s /install %s", name, null))
297 ret = dialog_menu("Choose install medium",
298 "\\nPlease say from where you want to install.\\n",
299 12, 62, 3, 3, items1);
309 install_premounted();
311 case -2: /* cancel */
315 if (my_system("umount /install %s", null))
320 main(int argc, char **argv)
326 "1", "Display a help text",
327 "2", "Start an installation",
328 "3", "Exit to the shell"
334 if (num_linux == 0) {
335 printf("\n\nPlease start \"fdisk\" or \"cfdisk\" and create a"
336 "\nnative Linux-partition to install Linux on.\n\n");
343 ret = dialog_menu("Linux Install Utility",
344 "\\nCopyright (C) 1995 Florian La Roche\\n"
345 "\\nPre-Alpha version, be careful, read the doc!!!"
346 "\\nemail: florian@jurix.jura.uni-sb.de, "
347 "flla@stud.uni-sb.de\\n",
348 15, 64, 3, 3, items1);
352 ret = dialog_textbox("Help Text",
353 "setup.help", 20, 70);
362 case -2: /* cancel */
368 printf("\nExecute \"reboot\" to restart your computer...\n");