Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[r10132]: branches / 8.0.4 / build / files / install.sh Maximize Restore History

Download this file

install.sh    340 lines (298 with data), 8.2 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
#!/bin/sh
# Setup a semi-sane environment
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
export PATH
HOME=/root
export HOME
TERM=${TERM:-cons25}
export TERM
get_product_name()
{
echo "FreeNAS"
}
get_product_path()
{
echo "/cdrom"
}
get_image_name()
{
echo "$(get_product_path)/$(get_product_name)-"*".img.xz"
}
build_config()
{
# build_config ${_disk} ${_image} ${_config_file}
local _disk=$1
local _image=$2
local _config_file=$3
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=${_image}
bootManager=bsd
commitDiskPart
EOF
}
wait_keypress()
{
local _tmp
read -p "Press ENTER to continue." _tmp
}
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
local _description
local _cap
_media=$1
VAL=""
if [ -n "${_media}" ]; then
_description=`pc-sysinstall disk-list -c |grep "^${_media}"\
| awk -F':' '{print $2}'|sed -E 's|.*<(.*)>.*$|\1|'`
_cap=`diskinfo ${_media} | awk '{
capacity = $3;
if (capacity >= 1099511627776) {
printf("%.1f TiB", capacity / 1099511627776.0);
} else if (capacity >= 1073741824) {
printf("%.1f GiB", capacity / 1073741824.0);
} else if (capacity >= 1048576) {
printf("%.1f MiB", capacity / 1048576.0);
} else {
printf("%d Bytes", capacity);
}}'`
VAL="${_description} -- ${_cap}"
fi
export VAL
}
disk_is_mounted()
{
local _dev
_dev="/dev/$1"
mount -v|grep -qE "^${_dev}[sp][0-9]+"
return $?
}
new_install_verify()
{
local _type="$1" _disk="$2"
local _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, SATA or SCSI channel for more hard drives.
Proceed with the ${_type} onto ${_disk}?
EOD
_msg=`cat "${_tmpfile}"`
rm -f "${_tmpfile}"
dialog --title "Start FreeNAS installation" --yesno "${_msg}" 13 74
[ $? -eq 0 ] || exit 1
}
ask_upgrade()
{
local _disk="$1"
local _tmpfile="/tmp/msg"
cat << EOD > "${_tmpfile}"
The FreeNAS installer can preserve your existing parameters, or
it can do a fresh install overwriting the current settings,
configuration, etc.
Would you like to upgrade the installation on ${_disk}?
EOD
_msg=`cat "${_tmpfile}"`
rm -f "${_tmpfile}"
dialog --title "Upgrade this FreeNAS installation" --yesno "${_msg}" 8 74
return $?
}
disk_is_freenas()
{
local _disk="$1"
local _rv=1
mkdir /tmp/data_old
mount /dev/${_disk}s4 /tmp/data_old
ls /tmp/data_old > /tmp/data_old.ls
if [ -f /tmp/data_old/freenas-v1.db ]; then
_rv=0
fi
cp -R /tmp/data_old /tmp/data_preserved
umount /tmp/data_old
if [ $_rv -eq 0 ]; then
mount /dev/${_disk}s1a /tmp/data_old
# ah my old friend, the can't see the mount til I access the mountpoint
# bug
ls /tmp/data_old > /dev/null
cp /tmp/data_old/conf/base/etc/hostid /tmp/
if [ -d /tmp/data_old/root/.ssh ]; then
cp -R /tmp/data_old/root/.ssh /tmp/
fi
if [ -d /tmp/data_old/boot/modules ]; then
mkdir /tmp/modules
for i in `ls /tmp/data_old/boot/modules`
do
cp /tmp/data_old/boot/modules/$i /tmp/modules/
done
fi
if [ -d /tmp/data_old/usr/local/fusionio ]; then
cp -R /tmp/data_old/usr/local/fusionio /tmp/
fi
umount /tmp/data_old
fi
rmdir /tmp/data_old
return ${_rv}
}
menu_install()
{
local _disklist
local _tmpfile
local _answer
local _cdlist
local _items
local _disk
local _config_file
local _desc
local _list
local _msg
local _i
local _do_upgrade
local _menuheight
get_physical_disks_list
_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"
if [ ${_items} -ge 10 ]; then
_items=10
_menuheight=20
else
_menuheight=8
_menuheight=$((${_menuheight} + ${_items}))
fi
eval "dialog --title 'Choose destination media' \
--menu 'Select media where FreeNAS OS should be installed.' \
${_menuheight} 60 ${_items} ${_list}" 2>${_tmpfile}
[ $? -eq 0 ] || exit 1
_disk=`cat "${_tmpfile}"`
rm -f "${_tmpfile}"
# Debugging seatbelts
if disk_is_mounted "${_disk}" ; then
dialog --msgbox "The destination drive is already in use!" 4 74
exit 1
fi
_do_upgrade=0
if disk_is_freenas ${_disk} ; then
if ask_upgrade ${_disk} ; then
new_install_verify "upgrade" ${_disk}
_do_upgrade=1
else
new_install_verify "installation" ${_disk}
fi
else
new_install_verify "installation" ${_disk}
fi
_config_file="/tmp/pc-sysinstall.cfg"
# _disk, _image, _config_file
# we can now build a config file for pc-sysinstall
build_config ${_disk} "$(get_image_name)" ${_config_file}
# Run pc-sysinstall against the config generated
# Hack #1
export ROOTIMAGE=1
# Hack #2
ls /cdrom > /dev/null
/rescue/pc-sysinstall -c ${_config_file}
if [ ${_do_upgrade} -eq 1 ]; then
mkdir /tmp/data_new
mount /dev/${_disk}s4 /tmp/data_new
ls /tmp/data_new > /dev/null
cp -R /tmp/data_preserved/ /tmp/data_new
cp /dev/null /tmp/data_new/need-update
touch /tmp/data_new/cd_update
umount /tmp/data_new
mount /dev/${_disk}s1a /tmp/data_new
ls /tmp/data_new > /dev/null
cp /tmp/hostid /tmp/data_new/conf/base/etc
if [ -d /tmp/.ssh ]; then
cp -R /tmp/.ssh /tmp/data_new/root/
fi
if [ -d /tmp/modules ]; then
for i in `ls /tmp/modules`
do
cp /tmp/modules/$i /tmp/data_new/boot/modules
done
fi
if [ -d /tmp/fusionio ]; then
cp -R /tmp/fusionio /tmp/data_new/usr/local/
fi
umount /tmp/data_new
rmdir /tmp/data_new
dialog --msgbox 'The installer has preserved your database file.
FreeNAS will migrate this file, if necessary, to the current format.' 6 74
fi
if [ ${_do_upgrade} -eq 1 ]; then
dialog --msgbox 'FreeNAS has been successfully upgraded on '${_disk}.'
Please remove the CDROM and reboot this machine.' 6 74
else
dialog --msgbox 'FreeNAS has been successfully installed on '${_disk}.'
Please remove the CDROM and reboot this machine.' 6 74
fi
return 0
}
menu_shell()
{
/bin/sh
}
menu_reboot()
{
echo "Rebooting the system..."
reboot >/dev/null
}
menu_shutdown()
{
echo "Halting and powering down..."
halt -p >/dev/null
}
main()
{
local _tmpfile="/tmp/answer"
local _number
while :; do
dialog --clear --title "FreeNAS 8.0.4-BETA2 Console Setup" --menu "" 12 73 6 \
"1" "Install/Upgrade to hard drive/flash device, etc." \
"2" "Shell" \
"3" "Reboot System" \
"4" "Shutdown System" \
2> "${_tmpfile}"
_number=`cat "${_tmpfile}"`
case "${_number}" in
1) menu_install ;;
2) menu_shell ;;
3) menu_reboot ;;
4) menu_shutdown ;;
esac
done
}
main