Menu

[r5280]: / experimental / ix / build / install.sh  Maximize  Restore  History

Download this file

512 lines (409 with data), 8.4 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
#!/bin/sh
__FREENAS_DEBUG__=1
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="/home/jpaetzel/images"
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 ${_install_type} ${_cdrom} ${_disk} ${_image}
# ${_config_file}
# Couple of issues here.
# The mount point in the setting of image should match that
# of the mount point used by install_mount_cd
# There is magic used to determine what to do if
# _install_type is set to 1
local _install_type=$1
local _cdrom=$2
local _disk=$3
local _image=$4
local _config_file=$5
if [ "$_install_type" = "1" ]; then
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=/mnt/cdrom${_image}
rootimage=1
bootManager=bsd
commitDiskPart
EOF
fi
}
wait_keypress()
{
local _tmp
_msg=$1
if [ -n "${_msg}" ]
then
echo "${_msg}"
fi
_msg="Press ENTER to continue."
read -p "${_msg}" _tmp
}
get_cdrom_list()
{
local _disks
local _list
local _d
_list=""
_disks=`sysctl -n kern.disks`
for _d in ${_disks}
do
if echo "${_d}" | grep -E '^cd' >/dev/null >/dev/null 2>&1
then
_list="${_list}${_d} "
fi
done
VAL="${_list}"
export VAL
}
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 -m|grep "^${_media}"\
|cut -f2 -d:|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}
}
install_mount_cd()
{
local _cdrom
local _mntpath
echo "Mount CDROM."
_cdrom=$1
_mntpath="/mnt/cdrom"
if [ ! -d "${_mntpath}" ]
then
mkdir -p "${_mntpath}"
if [ "$?" != "0" ]
then
echo "Error: Failed to create directory '${_mntpath}'"
return 1
fi
fi
if [ -z "${__FREENAS_DEBUG__}" ]
then
mount_cd9660 "/dev/${_cdrom}" "${_mntpath}"
else
mount_nullfs "/home/jpaetzel/images/" "${_mntpath}"
fi
if [ "$?" != "0" ]
then
echo "Error: Failed to mount device '${_cdrom}'!"
rmdir "${_mntpath}"
return 1
fi
return 0
}
install_unmount_cd()
{
local _mntpath
local _res
echo "Unmount CDROM."
_mntpath="/mnt/cdrom"
umount "${_mntpath}"
_res=$?
rmdir "${_mntpath}"
return ${_res}
}
do_install_1()
{
local _disklist
local _tmpfile
local _answer
local _cdlist
local _items
local _cdrom
local _disk
local _image
local _install_type
local _config_file
local _desc
local _list
local _msg
local _i
_tmpfile="/tmp/msg"
cat << EOD > "${_tmpfile}"
FreeNAS 'embedded' installer for Flash device or HDD.
- Create 1 partition for OS image
- Uses a RAM disk to limit read/write access to the device
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_cdrom_list
_cdlist="${VAL}"
if [ -z "${_cdlist}" ]
then
wait_keypress "Failed to detect any CDROM."
exit 1
fi
_list=""
for _cd in ${_cdlist}
do
get_media_description "${_cd}"
_desc="${VAL}"
_list="${_list} ${_cd} '${_desc}'"
done
_tmpfile="/tmp/answer"
eval "dialog --title 'Choose installation media' \
--menu 'Select CD/DVD drive for installation.' \
10 60 6 ${_list}" 2>"${_tmpfile}"
if [ "$?" != "0" ]
then
exit 1
fi
### XXXX
_cdrom=`cat "${_tmpfile}"`
rm -f "${_tmpfile}"
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
### XXXX
_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}"
# Can we avoid magic? We need a way to tell build_config
# how we are going to lay out the disk, for the OS,
# swap, data. For the moment 1 is defined as use the
# whole device for a single slice that contains the image
_install_type="1"
_config_file="/tmp/pc-sysinstall.cfg"
# _install_type, _cdrom, _disk, _image, _config_file
# we can now build a config file for pc-sysinstall
build_config ${_install_type} ${_cdrom} ${_disk} \
${_image} ${_config_file}
install_mount_cd ${_cdrom}
# Run pc-sysinstall against the config generated
../pc-sysinstall/pc-sysinstall -c ${_config_file}
install_unmount_cd
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_ping()
{
local _tmpfile
local _host
local _res
_tmpfile="/tmp/answer"
trap "rm -f ${_tmpfile}" 0 1 2 5 15
dialog --inputbox "Enter a host name or IP address." 8 50 2>"${_tmpfile}"
_res=$?
_host=`cat "${_tmpfile}"`
if [ -n "${_host}" ] && [ "${_res}" = "0" ]
then
:
fi
}
menu_shell()
{
eval /bin/sh
}
menu_reboot()
{
dialog --yesno "Do you really want to reboot the system?" 5 46 no
if [ "$?" = "0" ]
then
shutdown -r now >/dev/null
fi
}
menu_shutdown()
{
dialog --yesno "Do you really want to shutdown the system?" 5 46 no
if [ "$?" = "0" ]
then
shutdown -p now >/dev/null
fi
}
menu_install()
{
local _number
local _tmpfile
_tmpfile="/tmp/answer"
dialog --clear --title "Install & Upgrade" --menu "" 12 73 6 \
"1" "Install 'embedded' OS on HDD/Flash/USB" \
"2" "Install 'embedded' OS on HDD/Flash/USB + DATA + SWAP partition" \
"3" "Install 'full' OS on HDD + DATA + SWAP partition" \
"4" "Upgrade 'embedded' OS from CDROM" \
"5" "Upgrade 'full' OS from CDROM" \
"6" "Upgrade and convert 'full' OS to 'embedded'" 2> "${_tmpfile}"
if [ "$?" != "0" ]
then
return 1
fi
_number=`cat "${_tmpfile}"`
case "${_number}" in
1) do_install_1 ;;
2) ;;
3) ;;
4) ;;
5) ;;
6) ;;
esac
return 0
}
menu()
{
while :
do
local _number
echo " "
echo " "
echo "Console setup"
echo "-------------"
echo "1) Assign interfaces"
echo "2) Set LAN 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"
echo "9) Install/Upgrade to hard drive/flash device, etc."
echo " "
read -p "Enter a number: " _number
case "${_number}" in
1) menu_null ;;
2) menu_null ;;
3) menu_null ;;
4) menu_null ;;
5) menu_ping ;;
6) menu_shell ;;
7) menu_reboot ;;
8) menu_shutdown ;;
9) menu_install ;;
esac
done
}
main()
{
menu;
}
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.