-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathinstall.c
1673 lines (1382 loc) · 38.2 KB
/
install.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
*
* install.c Handling of installation
*
* Copyright (c) 1996-2008 Hubert Mantel, SuSE Linux AG (mantel@suse.de)
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <time.h>
#include <ctype.h>
#include <string.h>
#include <signal.h>
#include <netdb.h>
#include <errno.h>
#include <dirent.h>
#include <sys/mount.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/swap.h>
#include <sys/socket.h>
#include <sys/reboot.h>
#include <sys/vfs.h>
#include <arpa/inet.h>
#include <hd.h>
#include "global.h"
#include "linuxrc.h"
#include "util.h"
#include "dialog.h"
#include "window.h"
#include "net.h"
#include "display.h"
#include "module.h"
#include "keyboard.h"
#include "file.h"
#include "info.h"
#include "install.h"
#include "settings.h"
#include "auto2.h"
#include "url.h"
#include "checkmedia.h"
#ifndef MNT_DETACH
#define MNT_DETACH (1 << 1)
#endif
// maximum number of entries you can get in a dialog
// - this is just more than you can reasonably expect -
#define MAX_DIALOG_ITEMS 64
// flags for inst_choose_partition()
#define ICP_SWAP 1
#define ICP_BLOCK_ALL 2
static int inst_do_cdrom(void);
static int inst_do_harddisk(void);
static int inst_do_mountable(instmode_t scheme);
static int inst_do_network(instmode_t scheme);
static int add_instsys (void);
static void inst_yast_done (void);
static int inst_execute_yast (void);
static int inst_commit_install (void);
static int inst_choose_netsource (void);
static int inst_choose_netsource_cb (dia_item_t di);
static int inst_choose_display (void);
static int inst_choose_display_cb (dia_item_t di);
static int inst_choose_source (void);
static int inst_choose_source_cb (dia_item_t di);
static int inst_menu_cb (dia_item_t di);
static int choose_dud(char **dev);
static dia_item_t di_inst_menu_last = di_none;
static dia_item_t di_inst_choose_source_last = di_none;
static dia_item_t di_inst_choose_netsource_last = di_none;
static dia_item_t di_inst_choose_display_last = di_none;
static int ask_for_swap(int64_t size, char *msg);
/*
* Menu: install, system start, rescue
*
* return values:
* 0 : ok
* 1 : abort
*/
int inst_menu()
{
dia_item_t di;
dia_item_t items[] = {
di_inst_install,
di_inst_update,
di_inst_rescue,
di_inst_system,
di_inst_net_config,
di_inst_check_media,
di_none
};
/* hope this is correct... */
/* ... apparently not: keep VNC & SSH settings (bnc #447433) */
config.net.do_setup &= DS_VNC | DS_SSH;
if(di_inst_menu_last == di_none) {
di_inst_menu_last = config.rescue ? di_inst_rescue : config.upgrade ? di_inst_update : di_inst_install;
}
di = dia_menu2("Start Installation", 40, inst_menu_cb, items, di_inst_menu_last);
return di == di_none ? 1 : 0;
}
/*
* return values:
* -1 : abort (aka ESC)
* 0 : ok
* other: stay in menu
*/
int inst_menu_cb(dia_item_t di)
{
int err = 0;
di_inst_menu_last = di;
switch(di) {
case di_inst_install:
config.rescue = 0;
config.upgrade = 0;
err = inst_start_install();
break;
case di_inst_update:
config.rescue = 0;
config.upgrade = 1;
err = inst_start_install();
break;
case di_inst_rescue:
config.rescue = 1;
err = inst_start_install();
break;
case di_inst_system:
util_boot_system();
err = 1;
break;
case di_inst_net_config:
net_config();
err = 1;
break;
case di_inst_check_media:
check_media(NULL);
err = 1;
break;
default:
break;
}
config.redraw_menu = 0;
return err ? 1 : 0;
}
/*
* Menu: network protocol
*
* return values:
* 0 : ok
* 1 : error
*/
int inst_choose_netsource()
{
int i, j;
slist_t *sl;
dia_item_t di;
dia_item_t items[MAX_DIALOG_ITEMS] = {
di_netsource_ftp,
di_netsource_http,
di_netsource_https,
di_netsource_nfs,
di_netsource_smb,
di_netsource_tftp,
};
j = 6; // first 6 items have aleady been filled in
for(sl = config.extern_scheme, i = inst_extern; sl; sl = sl->next, i++) {
if(sl->value && url_is_network(i)) {
items[j] = dia_get_id(sl->key, sl->value);
if(++j >= MAX_DIALOG_ITEMS - 1) break;
}
}
items[j] = di_none;
if(di_inst_choose_netsource_last == di_none && config.url.install) {
switch(config.url.install->scheme) {
case inst_ftp:
di_inst_choose_netsource_last = di_netsource_ftp;
break;
case inst_http:
di_inst_choose_netsource_last = di_netsource_http;
break;
case inst_https:
di_inst_choose_netsource_last = di_netsource_https;
break;
case inst_smb:
di_inst_choose_netsource_last = di_netsource_smb;
break;
case inst_tftp:
di_inst_choose_netsource_last = di_netsource_tftp;
break;
default:
di_inst_choose_netsource_last = di_netsource_nfs;
break;
}
}
di = dia_menu2("Choose the network protocol.", 33, inst_choose_netsource_cb, items, di_inst_choose_netsource_last);
return di == di_none ? 1 : 0;
}
/*
* return values:
* -1 : abort (aka ESC)
* 0 : ok
* other: stay in menu
*/
int inst_choose_netsource_cb(dia_item_t di)
{
int err = 0;
instmode_t scheme;
char *s;
di_inst_choose_netsource_last = di;
switch(di) {
case di_netsource_nfs:
err = inst_do_network(inst_nfs);
break;
case di_netsource_smb:
err = inst_do_network(inst_smb);
break;
case di_netsource_ftp:
err = inst_do_network(inst_ftp);
break;
case di_netsource_http:
err = inst_do_network(inst_http);
break;
case di_netsource_https:
err = inst_do_network(inst_https);
break;
case di_netsource_tftp:
err = inst_do_network(inst_tftp);
break;
default:
s = dia_get_label(di);
if(s) {
scheme = url_scheme2id(s);
err = inst_do_network(scheme);
}
else {
err = 1;
}
break;
}
if(err) dia_message("No repository found.", MSGTYPE_ERROR);
return err ? 1 : 0;
}
/*
* Menu: installer UI variant
*
* return values:
* 0 : ok
* 1 : error
*/
int inst_choose_display()
{
if(!config.manual && (config.net.displayip || config.vnc || config.usessh)) {
net_ask_password();
return 0;
}
else {
dia_item_t di;
dia_item_t items[] = {
di_display_qt,
di_display_console,
di_display_vnc,
di_display_ssh,
di_display_x11,
di_none
};
di = dia_menu2("Select the display type.", 33, inst_choose_display_cb, items, di_inst_choose_display_last);
return di == di_none ? 1 : 0;
}
}
/*
* return values:
* 0 : ok
* other: stay in menu
*/
int inst_choose_display_cb(dia_item_t di)
{
int result = 0;
di_inst_choose_display_last = di;
switch(di) {
case di_display_x11:
dia_input2("Enter the name of the host running the X11 server.", &config.net.displayip, 40, 0);
if(!config.net.displayip) result = 1;
break;
case di_display_vnc:
config.vnc = 1;
net_ask_password();
if(!config.net.vncpassword) {
config.vnc = 0;
result = 1;
}
break;
case di_display_ssh:
config.usessh = 1;
config.vnc = 0;
net_ask_password();
if(!(config.net.sshpassword || config.net.sshpassword_enc)) {
config.usessh = 0;
result = 1;
}
break;
case di_display_console:
config.textmode = 1;
break;
case di_display_qt:
config.textmode = 0;
break;
default:
break;
}
return result;
}
/*
* Ask for repo location.
*
* return:
* 0: ok
* 1: abort
*/
int inst_choose_source()
{
int i, j;
slist_t *sl;
dia_item_t di;
dia_item_t items[MAX_DIALOG_ITEMS] = {
di_source_cdrom,
di_source_net,
di_source_hd
};
j = 3; // first 3 items have aleady been filled in
for(sl = config.extern_scheme, i = inst_extern; sl; sl = sl->next, i++) {
if(sl->value && url_is_mountable(i) && !url_is_network(i)) {
items[j] = dia_get_id(sl->key, sl->value);
if(++j >= MAX_DIALOG_ITEMS - 1) break;
}
}
items[j] = di_none;
if(di_inst_choose_source_last == di_none) {
di_inst_choose_source_last = di_source_cdrom;
if(config.url.install) {
if(config.url.install->is.network) {
di_inst_choose_source_last = di_source_net;
}
else if(!config.url.install->is.cdrom) {
di_inst_choose_source_last = di_source_hd;
}
}
}
di = dia_menu2("Choose the source medium.", 33, inst_choose_source_cb, items, di_inst_choose_source_last);
return di == di_none ? 1 : 0;
}
/*
* Repo location menu.
*
* return values:
* -1 : abort (aka ESC)
* 0 : ok
* other: stay in menu
*/
int inst_choose_source_cb(dia_item_t di)
{
int err = 0, rc = 0;
instmode_t scheme;
char *s;
di_inst_choose_source_last = di;
switch(di) {
case di_source_cdrom:
err = inst_do_cdrom();
break;
case di_source_net:
rc = inst_choose_netsource();
break;
case di_source_hd:
err = inst_do_harddisk();
break;
default:
s = dia_get_label(di);
if(s) {
scheme = url_scheme2id(s);
err = inst_do_mountable(scheme);
}
else {
err = 1;
}
break;
}
if(err) {
dia_message("No repository found.", MSGTYPE_ERROR);
rc = 1;
}
return rc;
}
/*
* build a partition list
*
* flags:
* 0: list all partitions with file systems on it
* ICP_BLOCK_ALL: list all block devices + partitions (empty or used)
* ICP_SWAP: present selection for suitable swap partitions
*/
int inst_choose_partition(char **partition, int flags, char *txt_menu, char *txt_input)
{
int i, j, rc, item_cnt, item_cnt1, item_cnt2, item_cnt3;
char **items, **values;
char **items1, **values1;
char **items2, **values2;
char **items3, **values3;
char *type;
slist_t *sl;
// buf[] must be able to hold a command (of fixed known length) + filename[256],
// so make a bit larger than 256
char buf[512], *dev;
int found = 0, item_mk_part = 0, item_mk_file = 0;
char *s, *tmp = NULL;
static char *last_part = NULL;
int last_item, last_found, last_item1 = 0, last_item2 = 0, last_item3 = 0;
char *module;
slist_t *device_list = NULL;
util_update_disk_list(NULL, 1);
util_update_swap_list();
if((flags & ICP_BLOCK_ALL)) {
util_update_cdrom_list();
for(sl = config.cdroms; sl; sl = sl->next) {
slist_append_str(&device_list, sl->key);
}
for(sl = config.disks; sl; sl = sl->next) {
slist_append_str(&device_list, sl->key);
}
}
for(sl = config.partitions; sl; sl = sl->next) {
slist_append_str(&device_list, sl->key);
}
for(i = 0, sl = device_list; sl; sl = sl->next) i++;
/*
* Just max values, actual lists might be shorter.
* list1: swap, list2: with fs or empty, list3: with fs
*/
items1 = calloc(i + 4, sizeof *items1);
values1 = calloc(i + 4, sizeof *values1);
items2 = calloc(i + 4, sizeof *items2);
values2 = calloc(i + 4, sizeof *values2);
items3 = calloc(i + 4, sizeof *items3);
values3 = calloc(i + 4, sizeof *values3);
for(item_cnt1 = item_cnt2 = item_cnt3 = 0, sl = device_list; sl; sl = sl->next) {
if(
sl->key && !slist_getentry(config.swaps, sl->key) /* don't show active swaps */
) {
if(blk_size(long_dev(sl->key)) < (128 << 10)) continue;
if(*partition && !strcmp(sl->key, *partition)) found = 1;
last_found = last_part && !strcmp(sl->key, last_part) ? 1 : 0;
sprintf(buf, "%s (%s)", sl->key, blk_ident(long_dev(sl->key)));
type = util_fstype(long_dev(sl->key), NULL);
if(type && !strcmp(type, "swap")) {
values1[item_cnt1] = strdup(sl->key);
items1[item_cnt1++] = strdup(buf);
if(last_found) last_item1 = item_cnt1;
}
else if(type || (flags & (ICP_SWAP | ICP_BLOCK_ALL))) {
values2[item_cnt2] = strdup(sl->key);
items2[item_cnt2++] = strdup(buf);
if(last_found) last_item2 = item_cnt2;
if(type) {
values3[item_cnt3] = strdup(sl->key);
items3[item_cnt3++] = strdup(buf);
if(last_found) last_item3 = item_cnt3;
}
}
}
}
if(*partition && !found) {
sprintf(buf, "%s (%s)", *partition, blk_ident(long_dev(*partition)));
values2[item_cnt2] = strdup(*partition);
items2[item_cnt2++] = strdup(buf);
}
if((flags & ICP_SWAP)) {
values1[item_cnt1] = NULL;
items1[item_cnt1++] = strdup("create swap partition");
item_mk_part = item_cnt1;
if(config.swap_file_size) {
values1[item_cnt1] = NULL;
items1[item_cnt1++] = strdup("create swap file");
item_mk_file = item_cnt1;
}
}
if((flags & ICP_SWAP)) {
item_cnt = item_cnt1;
items = items1;
values = values1;
last_item = last_item1;
}
else if((flags & ICP_BLOCK_ALL)) {
item_cnt = item_cnt2;
items = items2;
values = values2;
last_item = last_item2;
}
else {
item_cnt = item_cnt3;
items = items3;
values = values3;
last_item = last_item3;
}
rc = 1;
if(item_cnt) {
i = dia_list(txt_menu, 36, NULL, items, last_item, align_left);
if(i == 0) rc = -1;
if(i > 0 && values[i - 1]) {
str_copy(&last_part, values[i - 1]);
str_copy(partition, values[i - 1]);
rc = 0;
}
if((flags & ICP_SWAP)) {
if(i == item_mk_part) {
do {
i = dia_list("create a swap partition", 36, NULL, items2, last_item2, align_left);
if(i > 0 && values2[i - 1]) {
str_copy(&last_part, values2[i - 1]);
dev = long_dev(values2[i - 1]);
sprintf(buf, "Warning: all data on %s will be deleted!", dev);
j = dia_contabort(buf, NO);
if(j == YES) {
sprintf(buf, "/sbin/mkswap %s", dev);
if(!lxrc_run(buf)) {
log_info("swapon %s\n", dev);
if(swapon(dev, 0)) {
log_info("swapon: ");
perror_info(dev);
dia_message("Error activating swap space.", MSGTYPE_ERROR);
}
else {
rc = 0;
}
}
else {
dia_message("mkswap failed", MSGTYPE_ERROR);
}
}
else {
rc = 1;
}
}
}
while(rc && i);
}
else if(i == item_mk_file) {
do {
i = dia_list("select partition for swap file", 36, NULL, items3, last_item3, align_left);
if(i > 0 && values3[i - 1]) {
str_copy(&last_part, values3[i - 1]);
dev = long_dev(values3[i - 1]);
util_fstype(dev, &module);
if(module) mod_modprobe(module, NULL);
j = util_mount_rw(dev, config.mountpoint.swap, NULL);
if(j) {
dia_message("mount failed", MSGTYPE_ERROR);
}
else {
char *tmp, file[256];
int fd;
window_t win;
unsigned swap_size = config.swap_file_size << (20 - 18); /* in 256k chunks */
sprintf(file, "%s/suseswap.img", config.mountpoint.swap);
tmp = calloc(1, 1 << 18);
fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if(fd >= 0) {
sprintf(buf, "creating swap file 'suseswap.img' (%u MB)", config.swap_file_size);
dia_status_on(&win, buf);
for(j = 0; j < swap_size; j++) {
if(write(fd, tmp, 1 << 18) != 1 << 18) break;
fsync(fd);
dia_status(&win, (j + 1) * 100 / swap_size);
}
close(fd);
dia_status_off(&win);
}
free(tmp);
if(j != swap_size) {
dia_message("failed to create swapfile", MSGTYPE_ERROR);
}
else {
sprintf(buf, "/sbin/mkswap %s", file);
if(!lxrc_run(buf)) {
log_info("swapon %s\n", file);
if(swapon(file, 0)) {
log_info("swapon: ");
perror_info(file);
dia_message("Error activating swap space.", MSGTYPE_ERROR);
}
else {
umount2(config.mountpoint.swap, MNT_DETACH);
rc = 0;
}
}
else {
dia_message("mkswap failed", MSGTYPE_ERROR);
}
}
if(rc) util_umount(config.mountpoint.swap);
}
}
}
while(rc && i);
}
}
}
else {
str_copy(&tmp, *partition);
rc = dia_input2(txt_input, &tmp, 30, 0);
if(!rc) {
s = tmp;
if(tmp && strstr(tmp, "/dev/") == tmp) s = tmp + sizeof "/dev/" - 1;
str_copy(partition, s);
str_copy(&tmp, NULL);
}
}
slist_free(device_list);
for(i = 0; i < item_cnt1; i++) { free(items1[i]); free(values1[i]); }
free(items1);
free(values1);
for(i = 0; i < item_cnt2; i++) { free(items2[i]); free(values2[i]); }
free(items2);
free(values2);
for(i = 0; i < item_cnt3; i++) { free(items3[i]); free(values3[i]); }
free(items3);
free(values3);
// log_info("rc = %d\n", rc);
return rc;
}
/*
* Select and mount cdrom repo.
*
* return:
* 0: ok
* 1: failed
*/
int inst_do_cdrom()
{
int err = 0;
char *device = NULL;
if(net_config_needed(0) && net_config()) return 1;
if(
config.url.install &&
config.url.install->scheme == inst_cdrom
) {
str_copy(&device, config.url.install->device);
}
url_free(config.url.install);
config.url.install = url_set("cd:");
str_copy(&config.url.install->device, device);
str_copy(&config.url.install->used.device, long_dev(device));
err = auto2_find_repo() ? 0 : 1;
str_copy(&device, NULL);
return err;
}
/*
* Select and mount disk repo.
*
* return:
* 0: ok
* 1: failed
*/
int inst_do_harddisk()
{
int err = 0;
char *device = NULL, *path = NULL;
if(net_config_needed(0) && net_config()) return 1;
if(
config.url.install &&
(
config.url.install->scheme == inst_disk ||
config.url.install->scheme == inst_hd
)
) {
str_copy(&device, config.url.install->device);
str_copy(&path, config.url.install->path);
}
if(inst_choose_partition(&device, 0, "Choose the hard disk partition.", "Enter the hard disk partition (e.g., /dev/sda1)")) err = 1;
if(!err && dia_input2("Enter the source directory.", &path, 30, 0)) err = 1;
if(!err) {
url_free(config.url.install);
config.url.install = url_set("hd:");
str_copy(&config.url.install->device, device);
str_copy(&config.url.install->path, path ?: "/");
str_copy(&config.url.install->used.device, long_dev(device));
err = auto2_find_repo() ? 0 : 1;
}
str_copy(&device, NULL);
str_copy(&path, NULL);
return err;
}
/*
* Select and mount local repo.
*
* return:
* 0: ok
* 1: failed
*/
int inst_do_mountable(instmode_t scheme)
{
int err = 0;
char *device = NULL, *path = NULL;
if(net_config_needed(0) && net_config()) return 1;
if(
config.url.install &&
config.url.install->scheme == scheme
) {
str_copy(&device, config.url.install->device);
str_copy(&path, config.url.install->path);
}
if(url_is_blockdev(scheme)) {
if(inst_choose_partition(&device, ICP_BLOCK_ALL, "Choose disk / partition.", "Enter the device name (e.g., /dev/sda1)")) err = 1;
}
if(!err && !url_is_nopath(scheme)) {
if(dia_input2("Enter the source directory.", &path, 30, 0)) err = 1;
}
if(!err) {
char *tmp_url = NULL;
strprintf(&tmp_url, "%s:", url_scheme2name(scheme));
url_free(config.url.install);
config.url.install = url_set(tmp_url);
str_copy(&tmp_url, NULL);
str_copy(&config.url.install->device, device);
str_copy(&config.url.install->path, path ?: "/");
str_copy(&config.url.install->used.device, long_dev(device));
err = auto2_find_repo() ? 0 : 1;
}
str_copy(&device, NULL);
str_copy(&path, NULL);
return err;
}
/*
* Select and mount network repo.
*
* return:
* 0: ok
* 1: failed
*/
int inst_do_network(instmode_t scheme)
{
int i, err = 0, port = 0, n_port = 0, proxy_port = 0;
unsigned u;
char *s;
char *buf = NULL, *buf2 = NULL, *path = NULL, *share = NULL, *domain = NULL,
*user = NULL, *password = NULL, *proxy_user = NULL, *proxy_password = NULL,
*n_user = NULL, *n_password = NULL;
char **to_free[] = {
&buf, &buf2, &path, &share, &domain, &user, &password, &proxy_user, &proxy_password,
&n_user, &n_password
};
inet_t server = {}, proxy = {};
/* setup network */
if(net_config_needed(1) && net_config()) return 1;
/* get current values */
if(config.url.install) {
str_copy(&path, config.url.install->path);
name2inet(&server, config.url.install->server);
str_copy(&share, config.url.install->share);
str_copy(&domain, config.url.install->domain);
str_copy(&user, config.url.install->user);
str_copy(&password, config.url.install->password);
port = config.url.install->port;
}
/* server name */
strprintf(&buf, "Enter the name of the %s server.", url_scheme2name_upper(scheme));
if(net_get_address2(buf, &server, 1, &n_user, &n_password, &n_port)) err = 1;
if(!err && n_port) port = n_port;
/* smb share */
if(!err && scheme == inst_smb && dia_input2("Enter the share name on the SMB server.", &share, 30, 0)) err = 1;
/* path */
if(!err && dia_input2("Enter the directory on the server.", &path, 30, 0)) err = 1;
/* ensure leading "/" if mountable */
if(!err && url_is_mountable(scheme)) {
if(path) {
if(*path != '/') {
strprintf(&path, "/%s", path);
}
}
else {
path = strdup("/");
}
}
/* user, password */
if(!err && url_is_auth(scheme)) {
if(!n_user) {
strprintf(&buf,
"Do you need a username and password to access the %s server?",
url_scheme2name_upper(scheme)
);
i = dia_yesno(buf, NO);
if(i == ESCAPE) {
err = 1;
}
else {
if(i == NO) {
str_copy(&user, NULL);
str_copy(&password, NULL);
}
else {
strprintf(&buf, "Enter the user name with which to access the %s server.", url_scheme2name_upper(scheme));
strprintf(&buf2, "Enter the password for the %s server.", url_scheme2name_upper(scheme));
if(
dia_input2(buf, &user, 20, 0) ||
dia_input2(buf2, &password, 20, 1)
) err = 1;
}
}
}
else {
str_copy(&user, n_user);
str_copy(&password, n_password);
}
}
/* smb user, password, workgroup */
if(!err && scheme == inst_smb) {
i = dia_yesno("If you want to access the share as guest,you do not need to specify user name, password, and workgroup.\n"
"Access the share as guest?", YES);
if(i == ESCAPE) {
err = 1;
}
else {
if(i == YES) {
str_copy(&user, NULL);
str_copy(&password, NULL);
str_copy(&domain, NULL);
}
else {
if(
dia_input2("Enter your user name on the SMB server.", &user, 20, 0) ||
dia_input2("Enter your password on the SMB server.", &password, 20, 1) ||
dia_input2("Enter your workgroup.If you do not need to specify a workgroup,leave the field empty.", &domain, 20, 0)
) err = 1;
}
}
}
/* proxy setup */
if(!err && (scheme == inst_http || scheme == inst_https || scheme == inst_ftp)) {
/* get current proxy values*/
if(config.url.proxy) {
proxy_port = config.url.proxy->port;
name2inet(&proxy, config.url.proxy->server);
str_copy(&proxy_user, config.url.proxy->user);
str_copy(&proxy_password, config.url.proxy->password);
}
strprintf(&buf, "Use a %s proxy?", url_scheme2name_upper(inst_http));
i = dia_yesno(buf, NO);
if(i == ESCAPE) {
err = 1;