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
|
#!/bin/sh
#TODO: get backend code out of here!!
interactive_partition() {
target_umountall
# Select disk to partition
DISCS=$(finddisks _)
DISCS="$DISCS OTHER - DONE +"
notify "Available Disks:\n\n$(_getavaildisks)\n"
DISC=""
while true; do
# Prompt the user with a list of known disks
ask_option no "Select the disk you want to partition (select DONE when finished)" 14 55 7 $DISCS || return 1
DISC=$ANSWER_OPTION
if [ "$DISC" = "OTHER" ]; then
_dia_DIALOG --inputbox "Enter the full path to the device you wish to partition" 8 65 "/dev/sda" 2>$ANSWER || return 1
DISC=$(cat $ANSWER)
fi
# Leave our loop if the user is done partitioning
[ "$DISC" = "DONE" ] && break
# Partition disc
notify "Now you'll be put into the cfdisk program where you can partition your hard drive. You should make a swap partition and as many data partitions as you will need.\
NOTE: cfdisk may tell you to reboot after creating partitions. If you need to reboot, just re-enter this install program, skip this step and go on to step 2."
cfdisk $DISC
done
return 0
}
interactive_configure_system()
{
[ "$EDITOR" ] || interactive_get_editor
FILE=""
# main menu loop
while true; do
DEFAULT=no
[ -n "$FILE" ] && DEFAULT="$FILE"
ask_option $DEFAULT "Configuration" \
"/etc/rc.conf" "System Config" \
"/etc/fstab" "Filesystem Mountpoints" \
"/etc/mkinitcpio.conf" "Initramfs Config" \
"/etc/modprobe.conf" "Kernel Modules" \
"/etc/resolv.conf" "DNS Servers" \
"/etc/hosts" "Network Hosts" \
"/etc/hosts.deny" "Denied Network Services" \
"/etc/hosts.allow" "Allowed Network Services" \
"/etc/locale.gen" "Glibc Locales" \
"/etc/pacman.d/mirrorlist" "Pacman Mirror List" \
"Root-Password" "Set the root password" \
"Return" "Return to Main Menu" || FILE="Return"
FILE=$ANSWER_OPTION
if [ "$FILE" = "Return" -o -z "$FILE" ]; then # exit
break
elif [ "$FILE" = "Root-Password" ]; then # non-file
while true; do
chroot ${var_TARGET_DIR} passwd root && break
done
else #regular file
$EDITOR ${var_TARGET_DIR}/${FILE}
fi
done
}
# set_clock()
# prompts user to set hardware clock and timezone
#
# params: none
# returns: 1 on failure
interactive_set_clock()
{
# utc or local?
ask_option no "Is your hardware clock in UTC or local time?" \
"UTC" " " \
"local" " " \
|| return 1
HARDWARECLOCK=$ANSWER_OPTION
# timezone?
tzselect > $ANSWER || return 1
TIMEZONE=$(cat $ANSWER)
# set system clock from hwclock - stolen from rc.sysinit
local HWCLOCK_PARAMS=""
if [ "$HARDWARECLOCK" = "UTC" ]; then
HWCLOCK_PARAMS="$HWCLOCK_PARAMS --utc"
else
HWCLOCK_PARAMS="$HWCLOCK_PARAMS --localtime"
fi
if [ "$TIMEZONE" != "" -a -e "/usr/share/zoneinfo/$TIMEZONE" ]; then
/bin/rm -f /etc/localtime
/bin/cp "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime
fi
/sbin/hwclock --hctosys $HWCLOCK_PARAMS --noadjfile
# display and ask to set date/time
dialog --calendar "Set the date.\nUse <TAB> to navigate and arrow keys to change values." 0 0 0 0 0 2> $ANSWER || return 1
local _date="$(cat $ANSWER)"
dialog --timebox "Set the time.\nUse <TAB> to navigate and up/down to change values." 0 0 2> $ANSWER || return 1
local _time="$(cat $ANSWER)"
echo "date: $_date time: $_time" >$LOG
# save the time
# DD/MM/YYYY hh:mm:ss -> YYYY-MM-DD hh:mm:ss
local _datetime="$(echo "$_date" "$_time" | sed 's#\(..\)/\(..\)/\(....\) \(..\):\(..\):\(..\)#\3-\2-\1 \4:\5:\6#g')"
echo "setting date to: $_datetime" >$LOG
date -s "$_datetime" 2>&1 >$LOG
/sbin/hwclock --systohc $HWCLOCK_PARAMS --noadjfile
return 0
}
interactive_autoprepare()
{
DISCS=$(finddisks)
if [ $(echo $DISCS | wc -w) -gt 1 ]; then
notify "Available Disks:\n\n$(_getavaildisks)\n"
ask_option no "Select the hard drive to use" $(finddisks _) || return 1
DISC=$ANSWER_OPTION
else
DISC=$DISCS
fi
SET_DEFAULTFS=""
BOOT_PART_SET=""
SWAP_PART_SET=""
ROOT_PART_SET=""
CHOSEN_FS=""
# get just the disk size in 1000*1000 MB
DISC_SIZE=$(hdparm -I /dev/sda | grep -F '1000*1000' | sed "s/^.*:[ \t]*\([0-9]*\) MBytes.*$/\1/")
while [ "$SET_DEFAULTFS" = "" ]; do
FSOPTS="ext2 ext2 ext3 ext3"
[ "$(which mkreiserfs 2>/dev/null)" ] && FSOPTS="$FSOPTS reiserfs Reiser3"
[ "$(which mkfs.xfs 2>/dev/null)" ] && FSOPTS="$FSOPTS xfs XFS"
[ "$(which mkfs.jfs 2>/dev/null)" ] && FSOPTS="$FSOPTS jfs JFS"
while [ "$BOOT_PART_SET" = "" ]; do
_dia_DIALOG --inputbox "Enter the size (MB) of your /boot partition. Minimum value is 16.\n\nDisk space left: $DISC_SIZE MB" 8 65 "32" 2>$ANSWER || return 1
BOOT_PART_SIZE="$(cat $ANSWER)"
if [ "$BOOT_PART_SIZE" = "" ]; then
notify "ERROR: You have entered an invalid size, please enter again."
else
if [ "$BOOT_PART_SIZE" -ge "$DISC_SIZE" -o "$BOOT_PART_SIZE" -lt "16" -o "$SBOOT_PART_SIZE" = "$DISC_SIZE" ]; then
notify "ERROR: You have entered a too large size, please enter again."
else
BOOT_PART_SET=1
fi
fi
done
DISC_SIZE=$(($DISC_SIZE-$BOOT_PART_SIZE))
while [ "$SWAP_PART_SET" = "" ]; do
_dia_DIALOG --inputbox "Enter the size (MB) of your swap partition. Minimum value is > 0.\n\nDisk space left: $DISC_SIZE MB" 8 65 "256" 2>$ANSWER || return 1
SWAP_PART_SIZE=$(cat $ANSWER)
if [ "$SWAP_PART_SIZE" = "" -o "$SWAP_PART_SIZE" -le "0" ]; then
notify "ERROR: You have entered an invalid size, please enter again."
else
if [ "$SWAP_PART_SIZE" -ge "$DISC_SIZE" ]; then
notify "ERROR: You have entered a too large size, please enter again."
else
SWAP_PART_SET=1
fi
fi
done
DISC_SIZE=$(($DISC_SIZE-$SWAP_PART_SIZE))
while [ "$ROOT_PART_SET" = "" ]; do
_dia_DIALOG --inputbox "Enter the size (MB) of your / partition. The /home partition will use the remaining space.\n\nDisk space left: $DISC_SIZE MB" 8 65 "7500" 2>$ANSWER || return 1
ROOT_PART_SIZE=$(cat $ANSWER)
if [ "$ROOT_PART_SIZE" = "" -o "$ROOT_PART_SIZE" -le "0" ]; then
notify "ERROR: You have entered an invalid size, please enter again."
else
if [ "$ROOT_PART_SIZE" -ge "$DISC_SIZE" ]; then
notify "ERROR: You have entered a too large size, please enter again."
else
ask_yesno "$(($DISC_SIZE-$ROOT_PART_SIZE)) MB will be used for your /home partition. Is this OK?" 0 0 && ROOT_PART_SET=1
fi
fi
done
while [ "$CHOSEN_FS" = "" ]; do
_dia_DIALOG --menu "Select a filesystem for / and /home:" 13 45 6 $FSOPTS 2>$ANSWER || return 1
FSTYPE=$(cat $ANSWER)
ask_yesno "$FSTYPE will be used for / and /home. Is this OK?" 0 0 && CHOSEN_FS=1
done
SET_DEFAULTFS=1
done
_dia_DIALOG --defaultno --yesno "$DISC will be COMPLETELY ERASED! Are you absolutely sure?" 0 0 \
|| return 1
DEVICE=$DISC
FSSPECS=$(echo $DEFAULTFS | sed -e "s|/:7500:ext3|/:$ROOT_PART_SIZE:$FSTYPE|g" -e "s|/home:\*:ext3|/home:\*:$FSTYPE|g" -e "s|swap:256|swap:$SWAP_PART_SIZE|g" -e "s|/boot:32|/boot:$BOOT_PART_SIZE|g")
sfdisk_input=""
# we assume a /dev/hdX format (or /dev/sdX)
PART_ROOT="${DEVICE}3"
if [ "$S_MKFS" = "1" ]; then
notify "You have already prepared your filesystems manually"
return 0
fi
# validate DEVICE
if [ ! -b "$DEVICE" ]; then
notify "Device '$DEVICE' is not valid"
return 1
fi
# validate DEST
if [ ! -d "$var_TARGET_DIR" ]; then
notify "Destination directory '$var_TARGET_DIR' is not valid"
return 1
fi
# / required
if [ $(echo $FSSPECS | grep '/:' | wc -l) -ne 1 ]; then
notify "Need exactly one root partition"
return 1
fi
rm -f /tmp/.fstab
target_umountall
# setup input var for sfdisk
for fsspec in $FSSPECS; do
fssize=$(echo $fsspec | tr -d ' ' | cut -f2 -d:)
if [ "$fssize" = "*" ]; then
fssize_spec=';'
else
fssize_spec=",$fssize"
fi
fstype=$(echo $fsspec | tr -d ' ' | cut -f3 -d:)
if [ "$fstype" = "swap" ]; then
fstype_spec=",S"
else
fstype_spec=","
fi
bootflag=$(echo $fsspec | tr -d ' ' | cut -f4 -d:)
if [ "$bootflag" = "+" ]; then
bootflag_spec=",*"
else
bootflag_spec=""
fi
sfdisk_input="${sfdisk_input}${fssize_spec}${fstype_spec}${bootflag_spec}\n"
done
sfdisk_input=$(printf "$sfdisk_input")
# invoke sfdisk
printk off
infofy "Partitioning $DEVICE"
sfdisk $DEVICE -uM >$LOG 2>&1 <<EOF
$sfdisk_input
EOF
if [ $? -gt 0 ]; then
notify "Error partitioning $DEVICE (see $LOG for details)"
printk on
return 1
fi
printk on
# need to mount root first, then do it again for the others
part=1
for fsspec in $FSSPECS; do
mountpoint=$(echo $fsspec | tr -d ' ' | cut -f1 -d:)
fstype=$(echo $fsspec | tr -d ' ' | cut -f3 -d:)
if echo $mountpoint | tr -d ' ' | grep '^/$' 2>&1 > /dev/null; then
_mkfs yes ${DEVICE}${part} "$fstype" "$var_TARGET_DIR" "$mountpoint" || return 1
fi
part=$(($part + 1))
done
# make other filesystems
part=1
for fsspec in $FSSPECS; do
mountpoint=$(echo $fsspec | tr -d ' ' | cut -f1 -d:)
fstype=$(echo $fsspec | tr -d ' ' | cut -f3 -d:)
if [ $(echo $mountpoint | tr -d ' ' | grep '^/$' | wc -l) -eq 0 ]; then
_mkfs yes ${DEVICE}${part} "$fstype" "$var_TARGET_DIR" "$mountpoint" || return 1
fi
part=$(($part + 1))
done
notify "Auto-prepare was successful"
return 0
}
interactive_mountpoints() {
while [ "$PARTFINISH" != "DONE" ]; do
: >/tmp/.fstab
: >/tmp/.parts
# Determine which filesystems are available
FSOPTS="ext2 ext2 ext3 ext3"
[ "$(which mkreiserfs 2>/dev/null)" ] && FSOPTS="$FSOPTS reiserfs Reiser3"
[ "$(which mkfs.xfs 2>/dev/null)" ] && FSOPTS="$FSOPTS xfs XFS"
[ "$(which mkfs.jfs 2>/dev/null)" ] && FSOPTS="$FSOPTS jfs JFS"
[ "$(which mkfs.vfat 2>/dev/null)" ] && FSOPTS="$FSOPTS vfat VFAT"
# Select mountpoints
notify "Available Disks:\n\n$(_getavaildisks)\n"
PARTS=$(findpartitions _)
_dia_DIALOG --menu "Select the partition to use as swap" 21 50 13 NONE - $PARTS 2>$ANSWER || return 1
PART=$(cat $ANSWER)
PARTS="$(echo $PARTS | sed -e "s#${PART}\ _##g")"
if [ "$PART" != "NONE" ]; then
DOMKFS="no"
ask_yesno "Would you like to create a filesystem on $PART?\n\n(This will overwrite existing data!)" 0 0 && DOMKFS="yes"
echo "$PART:swap:swap:$DOMKFS" >>/tmp/.parts
fi
_dia_DIALOG --menu "Select the partition to mount as /" 21 50 13 $PARTS 2>$ANSWER || return 1
PART=$(cat $ANSWER)
PARTS="$(echo $PARTS | sed -e "s#${PART}\ _##g")"
PART_ROOT=$PART
# Select root filesystem type
_dia_DIALOG --menu "Select a filesystem for $PART" 13 45 6 $FSOPTS 2>$ANSWER || return 1
FSTYPE=$(cat $ANSWER)
DOMKFS="no"
ask_yesno "Would you like to create a filesystem on $PART?\n\n(This will overwrite existing data!)" 0 0 && DOMKFS="yes"
echo "$PART:$FSTYPE:/:$DOMKFS" >>/tmp/.parts
#
# Additional partitions
#
_dia_DIALOG --menu "Select any additional partitions to mount under your new root (select DONE when finished)" 21 50 13 $PARTS DONE _ 2>$ANSWER || return 1
PART=$(cat $ANSWER)
while [ "$PART" != "DONE" ]; do
PARTS="$(echo $PARTS | sed -e "s#${PART}\ _##g")"
# Select a filesystem type
_dia_DIALOG --menu "Select a filesystem for $PART" 13 45 6 $FSOPTS 2>$ANSWER || return 1
FSTYPE=$(cat $ANSWER)
MP=""
while [ "${MP}" = "" ]; do
_dia_DIALOG --inputbox "Enter the mountpoint for $PART" 8 65 "/boot" 2>$ANSWER || return 1
MP=$(cat $ANSWER)
if grep ":$MP:" /tmp/.parts; then
notify "ERROR: You have defined 2 identical mountpoints! Please select another mountpoint."
MP=""
fi
done
DOMKFS="no"
ask_yesno "Would you like to create a filesystem on $PART?\n\n(This will overwrite existing data!)" 0 0 && DOMKFS="yes"
echo "$PART:$FSTYPE:$MP:$DOMKFS" >>/tmp/.parts
_dia_DIALOG --menu "Select any additional partitions to mount under your new root" 21 50 13 $PARTS DONE _ 2>$ANSWER || return 1
PART=$(cat $ANSWER)
done
ask_yesno "Would you like to create and mount the filesytems like this?\n\nSyntax\n------\nDEVICE:TYPE:MOUNTPOINT:FORMAT\n\n$(for i in $(cat /tmp/.parts); do echo "$i\n";done)" 18 0 && PARTFINISH="DONE"
done
target_umountall
for line in $(cat /tmp/.parts); do
PART=$(echo $line | cut -d: -f 1)
FSTYPE=$(echo $line | cut -d: -f 2)
MP=$(echo $line | cut -d: -f 3)
DOMKFS=$(echo $line | cut -d: -f 4)
umount ${TARGET_DIR}${MP}
if [ "$DOMKFS" = "yes" ]; then
if [ "$FSTYPE" = "swap" ]; then
infofy "Creating and activating swapspace on $PART"
else
infofy "Creating $FSTYPE on $PART, mounting to ${TARGET_DIR}${MP}"
fi
_mkfs yes $PART $FSTYPE $var_TARGET_DIR $MP || return 1
else
if [ "$FSTYPE" = "swap" ]; then
infofy "Activating swapspace on $PART"
else
infofy "Mounting $PART to ${TARGET_DIR}${MP}"
fi
_mkfs no $PART $FSTYPE $var_TARGET_DIR $MP || return 1
fi
sleep 1
done
notify "Partitions were successfully mounted."
return 0
}
# select_packages()
# prompts the user to select packages to install
#
# params: none
# returns: 1 on error
interactive_select_packages() {
notify "Package selection is split into two stages. First you will select package categories that contain packages you may be interested in. Then you will be presented with a full list of packages for each category, allowing you to fine-tune.\n\n"
# set up our install location if necessary and sync up
# so we can get package lists
target_prepare_pacman || ( notify "Pacman preparation failed! Check $LOG for errors." && return 1 )
# show group listing for group selection, base is ON by default, all others are OFF
local _catlist="base ^ ON"
for i in $($PACMAN -Sg | sed "s/^base$/ /g"); do
_catlist="${_catlist} ${i} - OFF"
done
_dia_DIALOG --checklist "Select Package Categories\nDO NOT deselect BASE unless you know what you're doing!" 19 55 12 $_catlist 2>$ANSWER || return 1
_catlist="$(cat $ANSWER)" # _catlist now contains all categories (the tags from the dialog checklist)
# assemble a list of packages with groups, marking pre-selected ones
# <package> <group> <selected>
local _pkgtmp="$($PACMAN -Sl core | awk '{print $2}')" # all packages in core repository
local _pkglist=''
$PACMAN -Si $_pkgtmp | awk '/^Name/{ printf("%s ",$3) } /^Group/{ print $3 }' > $ANSWER
while read pkgname pkgcat; do
# check if this package is in a selected group
# slightly ugly but sorting later requires newlines in the variable
if [ "${_catlist/"\"$pkgcat\""/XXXX}" != "${_catlist}" ]; then
_pkglist="$(echo -e "${_pkglist}\n${pkgname} ${pkgcat} ON")"
else
_pkglist="$(echo -e "${_pkglist}\n${pkgname} ${pkgcat} OFF")"
fi
done < $ANSWER
# sort by category
_pkglist="$(echo "$_pkglist" | sort -f -k 2)"
_dia_DIALOG --checklist "Select Packages To Install." 19 60 12 $_pkglist 2>$ANSWER || return 1
TARGET_PACKAGES="$(cat $ANSWER)" # contains now all package names
return 0
}
# Hand-hold through setting up networking
#
# args: none
# returns: 1 on failure
interactive_runtime_network() {
INTERFACE=""
S_DHCP=""
local ifaces
ifaces=$(ifconfig -a |grep "Link encap:Ethernet"|sed 's/ \+Link encap:Ethernet \+HWaddr \+/ /g')
if [ "$ifaces" = "" ]; then
notify "Cannot find any ethernet interfaces. This usually means udev was\nunable to load the module and you must do it yourself. Switch to\nanother VT, load the appropriate module, and run this step again."
return 1
fi
_dia_DIALOG --nocancel --ok-label "Select" --menu "Select a network interface" 14 55 7 $ifaces 2>$ANSWER
case $? in
0) INTERFACE=$(cat $ANSWER) ;;
*) return 1 ;;
esac
ask_yesno "Do you want to use DHCP?" 0 0
if [ $? -eq 0 ]; then
infofy "Please wait. Polling for DHCP server on $INTERFACE..."
dhcpcd $INTERFACE >$LOG 2>&1
if [ $? -ne 0 ]; then
notify "Failed to run dhcpcd. See $LOG for details."
return 1
fi
if [ ! $(ifconfig $INTERFACE | grep 'inet addr:') ]; then
notify "DHCP request failed." || return 1
fi
S_DHCP=1
else
NETPARAMETERS=""
while [ "$NETPARAMETERS" = "" ]; do
_dia_DIALOG --inputbox "Enter your IP address" 8 65 "192.168.0.2" 2>$ANSWER || return 1
IPADDR=$(cat $ANSWER)
_dia_DIALOG --inputbox "Enter your netmask" 8 65 "255.255.255.0" 2>$ANSWER || return 1
SUBNET=$(cat $ANSWER)
_dia_DIALOG --inputbox "Enter your broadcast" 8 65 "192.168.0.255" 2>$ANSWER || return 1
BROADCAST=$(cat $ANSWER)
_dia_DIALOG --inputbox "Enter your gateway (optional)" 8 65 "192.168.0.1" 2>$ANSWER || return 1
GW=$(cat $ANSWER)
_dia_DIALOG --inputbox "Enter your DNS server IP" 8 65 "192.168.0.1" 2>$ANSWER || return 1
DNS=$(cat $ANSWER)
_dia_DIALOG --inputbox "Enter your HTTP proxy server, for example:\nhttp://name:port\nhttp://ip:port\nhttp://username:password@ip:port\n\n Leave the field empty if no proxy is needed to install." 16 65 "" 2>$ANSWER || return 1
PROXY_HTTP=$(cat $ANSWER)
_dia_DIALOG --inputbox "Enter your FTP proxy server, for example:\nhttp://name:port\nhttp://ip:port\nhttp://username:password@ip:port\n\n Leave the field empty if no proxy is needed to install." 16 65 "" 2>$ANSWER || return 1
PROXY_FTP=$(cat $ANSWER)
ask_yesno "Are these settings correct?\n\nIP address: $IPADDR\nNetmask: $SUBNET\nGateway (optional): $GW\nDNS server: $DNS\nHTTP proxy server: $PROXY_HTTP\nFTP proxy server: $PROXY_FTP" 0 0
case $? in
1) ;;
0) NETPARAMETERS="1" ;;
esac
done
echo "running: ifconfig $INTERFACE $IPADDR netmask $SUBNET broadcast $BROADCAST up" >$LOG
ifconfig $INTERFACE $IPADDR netmask $SUBNET broadcast $BROADCAST up >$LOG 2>&1 || notify "Failed to setup $INTERFACE interface." || return 1
if [ "$GW" != "" ]; then
route add default gw $GW >$LOG 2>&1 || notify "Failed to setup your gateway." || return 1
fi
if [ "$PROXY_HTTP" = "" ]; then
unset http_proxy
else
export http_proxy=$PROXY_HTTP
fi
if [ "$PROXY_FTP" = "" ]; then
unset ftp_proxy
else
export ftp_proxy=$PROXY_FTP
fi
echo "nameserver $DNS" >/etc/resolv.conf
fi
notify "The network is configured."
return 0
}
interactive_install_grub() {
get_grub_map
local grubmenu="$var_TARGET_DIR/boot/grub/menu.lst"
[ ! -f $grubmenu ] && show_warning "No grub?" "Error: Couldn't find $grubmenu. Is GRUB installed?" && return 1
# try to auto-configure GRUB...
if [ "$PART_ROOT" != "" -a "$S_GRUB" != "1" ]; then
grubdev=$(mapdev $PART_ROOT)
local _rootpart="${PART_ROOT}"
local _uuid="$(getuuid ${PART_ROOT})"
# attempt to use a UUID if the root device has one
if [ -n "${_uuid}" ]; then
_rootpart="/dev/disk/by-uuid/${_uuid}"
fi
# look for a separately-mounted /boot partition
bootdev=$(mount | grep $var_TARGET_DIR/boot | cut -d' ' -f 1)
if [ "$grubdev" != "" -o "$bootdev" != "" ]; then
subdir=
if [ "$bootdev" != "" ]; then
grubdev=$(mapdev $bootdev)
else
subdir="/boot"
fi
# keep the file from being completely bogus
if [ "$grubdev" = "DEVICE NOT FOUND" ]; then
notify "Your root boot device could not be autodetected by setup. Ensure you adjust the 'root (hd0,0)' line in your GRUB config accordingly."
grubdev="(hd0,0)"
fi
# remove default entries by truncating file at our little tag (#-*)
sed -i -e '/#-\*/q'
cat >>$grubmenu <<EOF
# (0) Arch Linux
title Arch Linux
root $grubdev
kernel $subdir/vmlinuz26 root=${_rootpart} ro
initrd $subdir/kernel26.img
# (1) Arch Linux
title Arch Linux Fallback
root $grubdev
kernel $subdir/vmlinuz26 root=${_rootpart} ro
initrd $subdir/kernel26-fallback.img
# (2) Windows
#title Windows
#rootnoverify (hd0,0)
#makeactive
#chainloader +1
EOF
fi
fi
notify "Before installing GRUB, you must review the configuration file. You will now be put into the editor. After you save your changes and exit the editor, you can install GRUB."
[ "$EDITOR" ] || interactive_get_editor
$EDITOR $grubmenu
DEVS=$(finddisks _)
DEVS="$DEVS $(findpartitions _)"
if [ "$DEVS" = "" ]; then
notify "No hard drives were found"
return 1
fi
_dia_DIALOG --menu "Select the boot device where the GRUB bootloader will be installed (usually the MBR and not a partition)." 14 55 7 $DEVS 2>$ANSWER || return 1
ROOTDEV=$(cat $ANSWER)
infofy "Installing the GRUB bootloader..."
cp -a $var_TARGET_DIR/usr/lib/grub/i386-pc/* $var_TARGET_DIR/boot/grub/
sync
# freeze xfs filesystems to enable grub installation on xfs filesystems
if [ -x /usr/sbin/xfs_freeze ]; then
/usr/sbin/xfs_freeze -f $var_TARGET_DIR/boot > /dev/null 2>&1
/usr/sbin/xfs_freeze -f $var_TARGET_DIR/ > /dev/null 2>&1
fi
# look for a separately-mounted /boot partition
bootpart=$(mount | grep $var_TARGET_DIR/boot | cut -d' ' -f 1)
if [ "$bootpart" = "" ]; then
if [ "$PART_ROOT" = "" ]; then
_dia_DIALOG --inputbox "Enter the full path to your root device" 8 65 "/dev/sda3" 2>$ANSWER || return 1
bootpart=$(cat $ANSWER)
else
bootpart=$PART_ROOT
fi
fi
_dia_DIALOG --defaultno --yesno "Do you have your system installed on software raid?\nAnswer 'YES' to install grub to another hard disk." 0 0
if [ $? -eq 0 ]; then
_dia_DIALOG --menu "Please select the boot partition device, this cannot be autodetected!\nPlease redo grub installation for all partitions you need it!" 14 55 7 $DEVS 2>$ANSWER || return 1
bootpart=$(cat $ANSWER)
fi
bootpart=$(mapdev $bootpart)
bootdev=$(mapdev $ROOTDEV)
if [ "$bootpart" = "" ]; then
notify "Error: Missing/Invalid root device: $bootpart"
return 1
fi
if [ "$bootpart" = "DEVICE NOT FOUND" -o "$bootdev" = "DEVICE NOT FOUND" ]; then
notify "GRUB root and setup devices could not be auto-located. You will need to manually run the GRUB shell to install a bootloader."
return 1
fi
$var_TARGET_DIR/sbin/grub --no-floppy --batch >/tmp/grub.log 2>&1 <<EOF
root $bootpart
setup $bootdev
quit
EOF
cat /tmp/grub.log >$LOG
# unfreeze xfs filesystems
if [ -x /usr/sbin/xfs_freeze ]; then
/usr/sbin/xfs_freeze -u $var_TARGET_DIR/boot > /dev/null 2>&1
/usr/sbin/xfs_freeze -u $var_TARGET_DIR/ > /dev/null 2>&1
fi
if grep "Error [0-9]*: " /tmp/grub.log >/dev/null; then
notify "Error installing GRUB. (see $LOG for output)"
return 1
fi
notify "GRUB was successfully installed."
return 0
}
# select_source(). taken from setup. TODO: decouple ui
# displays installation source selection menu
# and sets up relevant config files
#
# params: none
# returns: nothing
interactive_select_source()
{
var_PKG_SOURCE_TYPE=
var_FILE_URL="file:///src/core/pkg"
var_SYNC_URL=
var_MIRRORLIST="/etc/pacman.d/mirrorlist"
ask_option no "Please select an installation source" \
"1" "CD-ROM or OTHER SOURCE" \
"2" "FTP/HTTP"
case $ANSWER_OPTION in
"1") var_PKG_SOURCE_TYPE="cd" ;;
"2") var_PKG_SOURCE_TYPE="ftp" ;;
esac
if [ "$var_PKG_SOURCE_TYPE" = "cd" ]; then
TITLE="Arch Linux CDROM or OTHER SOURCE Installation"
notify "Packages included on this disk have been mounted to /src/core/pkg. If you wish to use your own packages from another source, manually mount them there."
if [ ! -d /src/core/pkg ]; then
notify "Package directory /src/core/pkg is missing!"
return 1
fi
echo "Using CDROM for package installation" >$LOG
else
TITLE="Arch Linux FTP/HTTP Installation"
notify "If you wish to load your ethernet modules manually, please do so now in an another terminal."
fi
return 0
}
# select_mirror(). taken from setup.
# Prompt user for preferred mirror and set $var_SYNC_URL
#
# args: none
# returns: nothing
interactive_select_mirror() {
notify "Keep in mind ftp.archlinux.org is throttled.\nPlease select another mirror to get full download speed."
# FIXME: this regex doesn't honor commenting
MIRRORS=$(egrep -o '((ftp)|(http))://[^/]*' "${MIRRORLIST}" | sed 's|$| _|g')
_dia_DIALOG --menu "Select an FTP/HTTP mirror" 14 55 7 \
$MIRRORS \
"Custom" "_" 2>$ANSWER || return 1
local _server=$(cat $ANSWER)
if [ "${_server}" = "Custom" ]; then
_dia_DIALOG --inputbox "Enter the full URL to core repo." 8 65 \
"ftp://ftp.archlinux.org/core/os/i686" 2>$ANSWER || return 1
var_SYNC_URL=$(cat $ANSWER)
else
# Form the full URL for our mirror by grepping for the server name in
# our mirrorlist and pulling the full URL out. Substitute 'core' in
# for the repository name, and ensure that if it was listed twice we
# only return one line for the mirror.
var_SYNC_URL=$(egrep -o "${_server}.*" "${MIRRORLIST}" | sed 's/\$repo/core/g' | head -n1)
fi
echo "Using mirror: $var_SYNC_URL" >$LOG
}
# geteditor(). taken from original setup code.
# prompts the user to choose an editor
# sets EDITOR global variable
#
interactive_get_editor() {
ask_option no "Select a Text Editor to Use" \
"1" "nano (easier)" \
"2" "vi"
case $ANSWER_OPTION in
"1") EDITOR="nano" ;;
"2") EDITOR="vi" ;;
*) EDITOR="nano" ;;
esac
}
|