Menu

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

Download this file

354 lines (308 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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
#!/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
. /etc/version-info
get_product_path()
{
echo "/cdrom"
}
get_image_name()
{
find "$(get_product_path)" -name "$SW_NAME-$SW_ARCH-embedded.xz" -type f
}
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
case "${_d}" in
cd*)
;;
*)
_list="${_list}${_d} "
;;
esac
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"
local _disk="$2"
local _tmpfile="/tmp/msg"
cat << EOD > "${_tmpfile}"
WARNING:
- This will erase ALL partitions and data on ${_disk}.
- You can't use ${_disk} for sharing data.
NOTE:
- Installing on flash media is preferred to installing on a
hard drive.
Proceed with the ${_type}?
EOD
_msg=`cat "${_tmpfile}"`
rm -f "${_tmpfile}"
dialog --title "$SW_NAME ${_type}" --yesno "${_msg}" 13 74
[ $? -eq 0 ] || exit 1
}
ask_upgrade()
{
local _disk="$1"
local _tmpfile="/tmp/msg"
cat << EOD > "${_tmpfile}"
The $SW_NAME 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 $SW_NAME installation" --yesno "${_msg}" 8 74
return $?
}
disk_is_freenas()
{
local _disk="$1"
local _rv=1
mkdir -p /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 -pR /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 -p /tmp/data_old/conf/base/etc/hostid /tmp/
if [ -d /tmp/data_old/root/.ssh ]; then
cp -pR /tmp/data_old/root/.ssh /tmp/
fi
if [ -d /tmp/data_old/boot/modules ]; then
mkdir -p /tmp/modules
for i in `ls /tmp/data_old/boot/modules`
do
cp -p /tmp/data_old/boot/modules/$i /tmp/modules/
done
fi
if [ -d /tmp/data_old/usr/local/fusionio ]; then
cp -pR /tmp/data_old/usr/local/fusionio /tmp/
fi
umount /tmp/data_old
fi
rmdir /tmp/data_old
if [ -f /tmp/hostid ]; then
return 0
else
return 1
fi
}
menu_install()
{
local _action
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
local readonly CD_UPGRADE_SENTINEL="/data/cd-upgrade"
local readonly NEED_UPDATE_SENTINEL="/data/need-update"
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 the drive where $SW_NAME 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
_action="installation"
if disk_is_freenas ${_disk} ; then
if ask_upgrade ${_disk} ; then
_do_upgrade=1
_action="upgrade"
fi
fi
new_install_verify "$_action" ${_disk}
_config_file="/tmp/pc-sysinstall.cfg"
# Start critical section.
trap "dialog --msgbox \"The $SW_NAME $_action on $_disk has failed\" 6 74" EXIT
set -e
# _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 $(get_product_path) > /dev/null
/rescue/pc-sysinstall -c ${_config_file}
if [ ${_do_upgrade} -eq 1 ]; then
# Mount: /data
mkdir -p /tmp/data
mount /dev/${_disk}s4 /tmp/data
ls /tmp/data > /dev/null
cp -pR /tmp/data_preserved/ /tmp/data
: > /tmp/$NEED_UPDATE_SENTINEL
: > /tmp/$CD_UPGRADE_SENTINEL
umount /tmp/data
# Mount: /
mount /dev/${_disk}s1a /tmp/data
ls /tmp/data > /dev/null
cp -p /tmp/hostid /tmp/data/conf/base/etc
if [ -d /tmp/.ssh ]; then
cp -pR /tmp/.ssh /tmp/data/root/
fi
if [ -d /tmp/modules ]; then
for i in `ls /tmp/modules`
do
cp -p /tmp/modules/$i /tmp/data/boot/modules
done
fi
if [ -d /tmp/fusionio ]; then
cp -pR /tmp/fusionio /tmp/data/usr/local/
fi
umount /tmp/data
rmdir /tmp/data
dialog --msgbox "The installer has preserved your database file.
$SW_NAME will migrate this file, if necessary, to the current format." 6 74
fi
# End critical section.
set +e
trap - EXIT
dialog --msgbox "The $SW_NAME $_action on ${_disk} succeeded!
Please remove the CDROM and reboot." 6 74
return 0
}
menu_shell()
{
/bin/sh
}
menu_reboot()
{
echo "Rebooting..."
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 "$SW_NAME $SW_VERSION Console Setup" --menu "" 12 73 6 \
"1" "Install/Upgrade" \
"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
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.