Menu

[r5550]: / trunk / build / files / install.sh  Maximize  Restore  History

Download this file

750 lines (591 with data), 11.7 kB

  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
#!/bin/sh
. /.profile
. include/db.sh
. include/net.sh
get_product_name()
{
local _product
_product="FreeNAS"
VAL="${_product}"
export VAL
}
get_product_arch()
{
local _arch
_arch="amd64"
VAL="${_arch}"
export VAL
}
get_product_path()
{
local _path
_path=""
VAL="${_path}"
export VAL
}
get_image_name()
{
local _product
local _arch
local _path
get_product_name
_product="${VAL}"
get_product_arch
_arch="${VAL}"
get_product_path
_path="${VAL}"
VAL="${_path}/${_product}-${_arch}-embedded.gz"
export VAL
}
build_config()
{
# build_config ${_disk} ${_image}
# ${_config_file} ${_os_size} ${_swap_size}
local _disk=$1
local _image=$2
local _config_file=$3
local _os_size=$4
local _swap_size=$5
cat << EOF > "${_config_file}"
# Added to stop pc-sysinstall from complaining
installMode=fresh
installInteractive=no
installType=FreeBSD
installMedium=dvd
packageType=tar
disk0=${_disk}
partition=image
image=/cdrom/FreeNAS-amd64-embedded.gz
bootManager=bsd
commitDiskPart
EOF
}
wait_keypress()
{
local _tmp
_msg="${1}"
if [ -n "${_msg}" ]
then
echo "${_msg}"
fi
_msg="Press ENTER to continue."
read -p "${_msg}" _tmp
}
get_memory_disks_list()
{
local _disks
VAL=""
if [ -n "${__FREENAS_DEBUG__}" ]
then
_disks=`mdconfig -l`
VAL="${_disks}"
fi
export VAL
}
get_physical_disks_list()
{
local _disks
local _list
local _d
_list=""
_disks=`sysctl -n kern.disks`
for _d in ${_disks}
do
if echo "${_d}" | grep -vE '^cd' >/dev/null 2>&1
then
_list="${_list}${_d} "
fi
done
VAL="${_list}"
export VAL
}
get_media_description()
{
local _media
_media="${1}"
VAL=""
if [ -n "${_media}" ]
then
_description=`pc-sysinstall disk-list -c |grep "^${_media}"\
|awk -F':' '{print $2}'|sed -E 's|.*<(.*)>.*$|\1|'`
VAL="${_description}"
fi
export VAL
}
disk_is_mounted()
{
local _disk
local _dev
local _res
_res=0
_disk="${1}"
_dev="/dev/${_disk}"
mount -v|grep -E "^${_dev}[sp][0-9]+" >/dev/null 2>&1
_res=$?
return ${_res}
}
do_install()
{
local _disklist
local _tmpfile
local _answer
local _cdlist
local _items
local _cdrom
local _disk
local _image
local _os_size
local _swap_size
local _config_file
local _desc
local _list
local _msg
local _i
_tmpfile="/tmp/msg"
cat << EOD > "${_tmpfile}"
FreeNAS installer for Flash device or HDD.
WARNING: There will be some limitations:
1. This will erase ALL partitions and data on the destination disk
2. You can't use your destination disk for sharing data
Installing on USB key is the preferred way:
It saves you an IDE or SCSI channel for more hard drives.
EOD
_msg=`cat "${_tmpfile}"`
rm -f "${_tmpfile}"
dialog --title "FreeNAS installation" --yesno "${_msg}" 17 74
if [ "$?" != "0" ]
then
exit 1
fi
get_physical_disks_list
_disklist="${VAL}"
get_memory_disks_list
_disklist="${_disklist} ${VAL}"
_list=""
_items=0
for _disk in ${_disklist}
do
get_media_description "${_disk}"
_desc="${VAL}"
_list="${_list} ${_disk} '${_desc}'"
_items=$((${_items} + 1))
done
_tmpfile="/tmp/answer"
eval "dialog --title 'Choose destination media' \
--menu 'Select media where FreeNAS OS should be installed.' \
15 60 ${_items} ${_list}" 2>"${_tmpfile}"
if [ "$?" != "0" ]; then
exit 1
fi
_disk=`cat "${_tmpfile}"`
rm -f "${_tmpfile}"
if disk_is_mounted "${_disk}" ; then
wait_keypress "The destination drive is already in use!"
exit 1
fi
get_image_name
_image="${VAL}"
_config_file="/tmp/pc-sysinstall.cfg"
# _cdrom, _disk, _image, _config_file
# we can now build a config file for pc-sysinstall
build_config ${_disk} \
${_image} ${_config_file} \
${_os_size} ${_swap_size}
# Run pc-sysinstall against the config generated
ls /cdrom > /dev/null
/rescue/pc-sysinstall -c ${_config_file}
cat << EOD > "${_tmpfile}"
FreeNAS has been installed on ${_disk}.
You can now remove the CDROM and reboot the PC.
EOD
_msg=`cat "${_tmpfile}"`
rm -f "${_tmpfile}"
wait_keypress "${_msg}"
return 0
}
menu_null()
{
}
menu_reset()
{
}
menu_shell()
{
eval /bin/sh
}
menu_reboot()
{
dialog --yesno "Do you really want to reboot the system?" 5 46 no
if [ "$?" = "0" ]
then
reboot >/dev/null
fi
}
menu_shutdown()
{
dialog --yesno "Do you really want to shutdown the system?" 5 46 no
if [ "$?" = "0" ]
then
halt -p >/dev/null
fi
}
menu_install()
{
local _number
local _tmpfile
_tmpfile="/tmp/answer"
dialog --clear --title "Install & Upgrade" --menu "" 12 73 6 \
"1" "Install OS on HDD/Flash/USB" 2> "${_tmpfile}"
if [ "$?" != "0" ]
then
return 1
fi
_number=`cat "${_tmpfile}"`
case "${_number}" in
1) do_install ;;
esac
return 0
}
menu_upgrade()
{
# What we are really interested in doing here is preserving the
# existing XML config file.
local _number
local _tmpfile
_tmpfile="/tmp/answer"
dialog --clear --title "Upgrade" --menu "" 12 73 6 \
"1" "Upgrade and convert 'full' OS to 'embedded'" 2> "${_tmpfile}"
if [ "$?" != "0" ]
then
return 1
fi
_number=`cat "${_tmpfile}"`
case "${_number}" in
1) do_upgrade_1 ;;
2) ;;
3) ;;
4) ;;
5) ;;
6) ;;
esac
return 0
}
install_menu()
{
while :
do
local _number
echo " "
echo " "
echo "Console setup"
echo "-------------"
echo "1) Install/Upgrade to hard drive/flash device, etc."
echo "2) Upgrade existing installation."
echo "3) Shell"
echo "4) Reboot system"
echo "5) Shutdown System"
echo " "
read -p "Enter a number: " _number
case "${_number}" in
1) menu_install ;;
2) menu_upgrade ;;
3) menu_shell ;;
4) menu_reboot ;;
5) menu_shutdown ;;
esac
done
}
#
# This should be broken up =-)
#
menu_setports()
{
local _lanif
local _iflist
local _save_ifs
local _tmpfile
local _menulist
local _msg
#
# Display detected interfaces
#
get_interface_list;
_iflist="${VAL}"
_tmpfile="/tmp/msg"
cat << EOD > "${_tmpfile}"
If you don't know the names of your interfaces, you may use
auto-detection. In that case, disconnect all interfaces before you
begin, and reconnect each one when prompted to do so.
EOD
_msg=`cat "${_tmpfile}"`
rm -f "${_tmpfile}"
_save_ifs="${IFS}"
IFS="|"
for i in ${_iflist}
do
local _iface
local _mac
local _up
local _new
_iface=`echo ${i}|awk '{ print $1 }'`
_mac=`echo ${i}|awk '{ print $2 }'`
_up=`echo ${i}|awk '{ print $3 }'`
if [ "${_up}" = "true" ]
then
_new="${_iface} \"${_mac} (up)\""
else
_new="${_iface} ${_mac}"
fi
_menulist="${_menulist} ${_new}"
done
IFS="${_save_ifs}"
_menulist="${_menulist} auto Auto-detection"
_tmpfile="/tmp/answer"
eval "dialog --clear \
--title \"Configure LAN interface\" \
--menu \"${_msg}\" \
13 70 4 ${_menulist}" 2>"${_tmpfile}"
if [ "$?" != "0" ]; then
exit 1
fi
_lanif=`cat "${_tmpfile}"`
rm -f "${_tmpfile}"
if [ "${_lanif}" = "auto" ]
then
autodetect_interface "LAN"
_lanif="${VAL}"
fi
#
# Optional interfaces (XXX This needs testing XXX)
#
local _i1
local _i
local _loop
local _opt
_i=0
_loop=1
_opt="opt"
_menulist="${_menulist} none \"Finish and exit configuration\""
while [ "${_loop}" = "1" ]
do
local _tmp
local _var
local _val
_tmp=$(eval "echo \$${_opt}${_i}")
if [ -n "${_tmp}" ]
then
_i=`expr ${_i} + 1`
fi
_i1=`expr ${_i} + 1`
_tmpfile="/tmp/msg"
cat << EOD > "${_tmpfile}"
Select the optional OPT${_i1} interface name, auto-detection or none to
finish configuration.
EOD
_msg=`cat "${_tmpfile}"`
rm -f "${_tmpfile}"
_tmpfile="/tmp/answer"
eval "dialog --clear \
--title \"Configure OPT interface\" \
--menu \"${_msg}\" \
13 70 5 ${_menulist}" 2>"${_tmpfile}"
if [ "$?" != "0" ]; then
exit 1
fi
eval "${_opt}${_i}=`cat ${_tmpfile}`"
rm -f "${_tmpfile}"
_var=\$$(eval "echo ${_opt}${_i}")
_val=$(eval "echo $_var")
if [ -n "${_val}" ]
then
if [ "${_val}" = "auto" ]
then
local _ad
autodetect_interface "optional OPT${_i1}"
_ad="${VAL}"
if [ -n "${_ad}" ]
then
eval "${_opt}${_i}=${_ad}"
else
unset `echo "${_opt}${_i}"`
fi
elif [ "${_val}" = "none" ]
then
unset `echo "${_opt}${_i}"`
_loop=0
fi
fi
done
#
# Build up OPT list
#
local _count
local _ifoptlist
_count="${_i}"
_i=0
while [ "${_i}" -lt "${_count}" ]
do
local _var
local _val
_var=\$$(eval "echo ${_opt}${_i}")
_val=$(eval "echo $_var")
if [ -n "${_val}" ]
then
_ifoptlist="${_ifoptlist} ${_val}"
fi
_i=`expr "${_i}" + 1`
done
#
# Check for duplicate assignments
#
local _ifall
local _files
_i=0
_ifall="${_lanif}"
while [ "${_i}" -lt "${_count}" ]
do
local _var
local _val
_var=\$$(eval "echo ${_opt}${_i}")
_val=$(eval "echo $_var")
_ifall="${_ifall} ${_val}"
_i=`expr "${_i}" + 1`
done
for i in ${_ifall}
do
local _file
_file="/tmp/.${i}"
if [ -f "${_file}" ]
then
dialog --clear --title "Error" \
--msgbox "You can't assign the same interface twice!" 5 46
rm ${_files}
exit 1
fi
touch "${_file}"
_files="${_files} ${_file}"
done
rm ${_files}
#
# ...
#
_tmpfile="/tmp/msg"
cat << EOD > "${_tmpfile}"
The interfaces will be assigned as follows:
LAN -> ${_lanif}
EOD
_i=0
for _ifopt in ${_ifoptlist}
do
local _n
_n=`expr "${_i}" + 1`
echo "OPT${_n} -> ${_ifopt}" >> "${_tmpfile}"
_i=`expr "${_i}" + 1`
done
echo "\nDo you want to proceed?" >> "${_tmpfile}"
_msg=`cat "${_tmpfile}"`
rm -f "${_tmpfile}"
dialog --clear --yesno "${_msg}" 100 47
if [ "$?" != "0" ]
then
return 0
fi
#
# Save config here....
#
return 0
}
menu_setlanip()
{
local _iflist
local _ifs
get_interface_list
_iflist="${VAL}"
_ifs="${IFS}"
IFS="|"
for i in ${_iflist}
do
configure_ipv4_interface "${i}"
configure_ipv6_interface "${i}"
done
IFS="${_ifs}"
}
menu_password()
{
}
menu_defaults()
{
}
menu_ping()
{
local _tmpfile
local _answer
local _ret
_tmpfile=`tmpfile 2>/dev/null` || _tmpfile="/tmp/tui$$"
trap "rm -f $_tmpfile" 0 1 2 5 15
dialog --clear --inputbox \
"Enter a host name or IP address." 8 50 2>"${_tmpfile}"
_ret="$?"
_answer=`cat "${_tmpfile}"`
rm -f "${_tmpfile}"
[ -z "${_answer}" ] && exit 0
if [ "${_ret}" = "0" ]
then
echo
is_validip inet "${_answer}"
if [ "$?" = "0" ]
then
echo "IPv6 address detected..."
ping6 -c 3 -n "${_answer}"
else
echo "Hostname supposed, trying IPv4 and IPv6 ping..."
ping -c 3 -n "${_answer}"
ping6 -c 3 -n "${_answer}"
fi
fi
echo
read -p "Press ENTER to continue." _answer
}
config_menu()
{
while :
do
local _number
echo " "
echo " "
echo "Console setup"
echo "-------------"
echo "1) Assign interfaces"
echo "2) Set LAP IP address"
echo "3) Reset WebGUI password"
echo "4) Reset to factory defaults"
echo "5) Ping host"
echo "6) Shell"
echo "7) Reboot system"
echo "8) Shutdown system"
case "${PLATFORM}" in
*-live[cC][dD])
echo "9) Install/Upgrade to hard drive/flash device, etc." ;;
esac
echo " "
read -p "Enter a number: " _number
case "${_number}" in
1) menu_setports ;;
2) menu_setlanip ;;
3) menu_password ;;
4) menu_defaults ;;
5) menu_ping ;;
6) menu_shell ;;
7) menu_reboot ;;
8) menu_shutdown ;;
9) install_menu ;;
esac
done
}
main()
{
#install_menu;
#config_menu;
menu_setlanip
}
main;
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.