Magellan Linux

Contents of /mcore-src/trunk/mcore-install/bin/mcore-install.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1294 - (show annotations) (download) (as text)
Sun Feb 6 23:21:42 2011 UTC (13 years, 3 months ago) by niro
File MIME type: application/x-sh
File size: 13948 byte(s)
-use hwdetection from magellan installer for better disk detection
-renamed INSTALLPATH variable to INSTALL_ROOT to honor hwdetection
-support variable filesystems in disk format
-dropped all old boot/swat/root setups and keep the flash like root only setup, which already is used in autoinstall
-always support initrd and use uuids
-dropped internal get_uuid function, using the one from hwdetection
-added addconfig() and clearconfig() functions to create configfiles
-cleaner messages
-clear the screen when dropping into a shell
-local all retval variables
-fixed MLIBDIR typo
-ignore system language settings
-detect kernelnames and settings for grub and do not rely on the deprecated kernelversion file anymore


1 #!/bin/bash
2 # $Id$
3
4 # ignore environment!
5 LC_ALL=C
6
7 MLIBDIR="/usr/lib/mcore-install"
8
9 # images: (get ${CDIMAGENAME})
10 source /mnt/cdrom/system/images.conf
11
12 # includes
13 source ${MLIBDIR}/functions/hwdetection.sh
14
15 ### System/Config Version
16 VERSION="@@VERSION@@"
17 TITLE="mcore-install - ${VERSION}"
18
19 CDPATH="/mnt/cdrom"
20 INSTALL_ROOT="/mnt/magellan"
21
22 ### linecount of system.tar.gz -1 !
23 CURRENTLINE=0
24 #TOTALLINES=11072 # -> now in images.conf
25
26 # standart kernel opts
27 KERNELOPTS="quiet"
28
29 # default specialdevices
30 SPECIALDEVICE=""
31
32 # target filesystem
33 FORMAT_FILESYSTEM="ext3"
34
35 #################################################
36 # DIALOG BOXEN #
37 #################################################
38
39 die()
40 {
41 ERROR="$1"
42 RETVAL="$?"
43 dialog_install_failure
44 exit 1
45 }
46
47 dialog_warning()
48 {
49 local retval
50
51 dialog \
52 --backtitle "${TITLE}" \
53 --colors \
54 --defaultno \
55 --yesno "\Z1 !!! Achtung !!! \Zn\n\n\
56 Diese Festplatte wird unwiederruflich geloescht werden.\n\n\
57 Soll ich wirklich fortfahren ?" 10 70
58 retval=$?
59 if [[ ${retval} -eq 1 ]]
60 then
61 clear
62 echo "Der Vorgang wurde abgebrochen."
63 exit 1
64 fi
65 }
66
67 dialog_setup_hdd_info()
68 {
69 local SHDD="$(echo $HDD | sed 's/\/dev\///')"
70
71 dialog \
72 --colors \
73 --title "[ Festplatten Partitionierung ]" \
74 --backtitle "${TITLE}" \
75 --ok-label "Weiter" \
76 --msgbox "\nBitte legen Sie 1 Partition an.\n\n\
77 [ \Z3${SHDD}1\Zn ] Typ: \Z3Linux\Zn mit dem gesamten Speicher\n\
78 Bitte ${SHDD}1 als \Z3bootable\Zn markieren." 12 81
79 }
80
81 dialog_setup_hdd_info_auto()
82 {
83 local SHDD="$(echo $HDD | sed 's/\/dev\///')"
84
85 dialog \
86 --colors \
87 --title "[ Festplatten Partitionierung ]" \
88 --backtitle "${TITLE}" \
89 --ok-label "Weiter" \
90 --msgbox "\nAchtung!\n\
91 Alle Daten werden von der Disk [ \Z3${HDD}\Zn ] gelöscht!" 12 81
92 }
93
94 dialog_setup_system_menu()
95 {
96 local i
97 local retval
98
99 i=$(dialog \
100 --backtitle "${TITLE}" \
101 --title "[ Festplatten Partitionierung ]" \
102 --cancel-label "Abbrechen" \
103 --ok-label "Weiter" \
104 --stdout \
105 --colors \
106 --menu "\nWaehlen Sie die Installations-Methode" 14 70 5 \
107 "1" "Automatisches Setup (Empfohlen)" \
108 "" "" \
109 "" "\Z1Experten Modi:\Zn" \
110 "2" "Normale IDE-Disk (Manuell)")
111 retval=$?
112 [[ ${retval} -eq 1 ]] && return 1
113 if [[ ${retval} -eq 0 ]]
114 then
115 case "${i}" in
116 "1") run_install_auto ;;
117 "2") run_install_normal ;;
118 "") dialog_setup_system_menu;;
119 esac
120 fi
121 }
122
123 dialog_hardware_detection()
124 {
125 local i
126 local hwtmp
127
128 if [ -x $(which mktemp &> /dev/null) ]
129 then
130 hwtmp="$(mktemp)"
131 else
132 hwtmp="/tmp/hwtmp.sh"
133 fi
134
135 run_hardware_detection_disks
136
137 echo "dialog \\" > ${hwtmp}
138 echo "--backtitle \"${TITLE}\" \\" >> ${hwtmp}
139 echo "--ok-label \"Weiter\" \\" >> ${hwtmp}
140 echo "--stdout \\" >> ${hwtmp}
141 echo "--colors \\" >> ${hwtmp}
142 echo "--msgbox \"Gefundene Hardware:\n\n \\" >> ${hwtmp}
143 echo " Festplatten:\n \\" >> ${hwtmp}
144
145 if [[ ! -z ${ALL_DISKS} ]]
146 then
147 for i in ${ALL_DISKS}
148 do
149 echo " \\Z3${i}\\Zn\n \\" >> ${hwtmp}
150 done
151 fi
152
153 if [[ ! -z ${ALL_CDROMS} ]]
154 then
155 echo " \n \\" >> ${hwtmp}
156 echo " CDROM Laufwerke:\n \\" >> ${hwtmp}
157 for i in ${ALL_CDROMS}
158 do
159 echo " \\Z3${i}\\Zn\n \\" >> ${hwtmp}
160 done
161 fi
162
163 # other devices
164 run_hardware_detection
165 case "${SPECIALDEVICE}" in
166 zotac) echo " \n \\Z2Zotac Device erkannt!\\Zn \\" >> ${hwtmp} ;;
167 *) echo " \n \\ZnStandard Device erkannt!\\Zn \\" >> ${hwtmp} ;;
168 esac
169
170 echo " \" 13 70" >> ${hwtmp}
171 chmod a+x ${hwtmp}
172 ${hwtmp}
173
174 # remove tmp file
175 if [[ -f ${hwtmp} ]]
176 then
177 rm ${hwtmp}
178 fi
179 }
180
181 dialog_setup_hdd_partitions_manuell()
182 {
183 local i
184 local retval
185
186 if [[ -z ${ALL_DISKS} ]]
187 then
188 dialog \
189 --backtitle "${TITLE}" \
190 --ok-label "Beenden" \
191 --msgbox "Kein geeignetes Laufwerk gefunden.\nDie Installation ist fehlgeschlagen." 6 70
192 exit 1
193 else
194 echo "dialog \\" > /tmp/hddtmp.sh
195 echo "--backtitle \"${TITLE}\" \\" >> /tmp/hddtmp.sh
196 echo "--ok-label \"Weiter\" \\" >> /tmp/hddtmp.sh
197 echo "--cancel-label \"Beenden\" \\" >> /tmp/hddtmp.sh
198 echo "--stdout \\" >> /tmp/hddtmp.sh
199 echo "--menu \"Installations Laufwerk auswaehlen:\" 10 70 3 \\" >> /tmp/hddtmp.sh
200
201 for i in ${ALL_DISKS}
202 do
203 echo "\"${i}\" \"\" \\" >> /tmp/hddtmp.sh
204 done
205 echo -e "\n" >> /tmp/hddtmp.sh
206
207 chmod a+x /tmp/hddtmp.sh
208 HDD="$(/tmp/hddtmp.sh)"
209 retval=$?
210 [[ ${retval} -eq 1 ]] && return 1
211 if [[ ${retval} -eq 0 ]]
212 then
213 dialog_setup_hdd_info
214 setup_hdd_partitions_manuell
215 fi
216 fi
217 }
218
219 dialog_setup_hdd_partitions_auto()
220 {
221 local i
222 local retval
223
224 if [[ -z ${ALL_DISKS} ]]
225 then
226 dialog \
227 --backtitle "${TITLE}" \
228 --ok-label "Beenden" \
229 --msgbox "Kein geeignetes Laufwerk gefunden.\nDie Installation ist fehlgeschlagen." 6 70
230 exit 1
231 else
232 echo "dialog \\" > /tmp/hddtmp.sh
233 echo "--backtitle \"${TITLE}\" \\" >> /tmp/hddtmp.sh
234 echo "--ok-label \"Weiter\" \\" >> /tmp/hddtmp.sh
235 echo "--cancel-label \"Beenden\" \\" >> /tmp/hddtmp.sh
236 echo "--stdout \\" >> /tmp/hddtmp.sh
237 echo "--menu \"Installations Laufwerk auswaehlen:\" 10 70 3 \\" >> /tmp/hddtmp.sh
238
239 for i in ${ALL_DISKS}
240 do
241 echo "\"${i}\" \"\" \\" >> /tmp/hddtmp.sh
242 done
243 echo -e "\n" >> /tmp/hddtmp.sh
244
245 chmod a+x /tmp/hddtmp.sh
246 HDD="$(/tmp/hddtmp.sh)"
247 retval=$?
248 [[ ${retval} -eq 1 ]] && return 1
249 if [[ ${retval} -eq 0 ]]
250 then
251 dialog_setup_hdd_info_auto
252 dialog_setup_hdd_create_partitions
253 setup_hdd_partitions_auto
254 fi
255 fi
256 }
257
258 dialog_setup_hdd_create_partitions()
259 {
260 dialog \
261 --backtitle "${TITLE}" \
262 --infobox "Erstelle Disk Partitionen ..." 3 70
263 }
264
265 dialog_setup_hdd_format()
266 {
267 dialog \
268 --backtitle "${TITLE}" \
269 --infobox "Erstelle Datei-Systeme ..." 3 70
270 }
271
272 dialog_install_settings()
273 {
274 dialog \
275 --backtitle "${TITLE}" \
276 --infobox "Speichere System-Einstellungen ..." 3 70
277 }
278
279 dialog_install_system_image()
280 {
281 dialog \
282 --backtitle "${TITLE}" \
283 --gauge "Kopiere System-Image ..." 6 80
284 }
285
286 dialog_install_initrd()
287 {
288 dialog \
289 --backtitle "${TITLE}" \
290 --infobox "Erstelle Initrd ..." 3 70
291 }
292
293 dialog_install_meter()
294 {
295 while [[ ${CURRENTLINE} != ${TOTALLINES} ]]
296 do
297 CURRENTLINE=$(grep -c . /tmp/install.log)
298 PERCENT=$(( ${CURRENTLINE} * 100 / ${TOTALLINES}))
299 echo "${PERCENT}"
300 sleep 1
301 done
302 rm -f /tmp/install.log
303 return 0
304 }
305
306 dialog_install_bootsector()
307 {
308 dialog \
309 --backtitle "${TITLE}" \
310 --infobox "Schreibe den Bootsektor ..." 3 70
311 }
312
313 dialog_install_successful()
314 {
315 dialog \
316 --backtitle "${TITLE}" \
317 --colors \
318 --msgbox "Die Installation war \Z2erfolgreich\Zn." 5 81
319 }
320
321 dialog_install_failure()
322 {
323 dialog \
324 --backtitle "${TITLE}" \
325 --colors \
326 --msgbox "Die Installation ist \Z1Fehlgeschlagen\Zn.\n\n\
327 Fehler bei ${ERROR}, RetVal: ${RETVAL} \
328 " 10 81
329 }
330
331 dialog_main()
332 {
333 local method=0
334 local retval
335
336 while [[ ${method} -le 2 ]]
337 do
338 method=$(dialog \
339 --backtitle "${TITLE}" \
340 --no-cancel \
341 --ok-label "Weiter" \
342 --stdout \
343 --menu "Konfiguration" 14 70 5 \
344 "1" "mCore installieren" \
345 "2" "Uebersicht gefundener Laufwerke" \
346 "3" "Beenden und neustarten" \
347 "4" "Beenden und eine Shell starten")
348 retval=$?
349 [[ ${retval} -eq 1 ]] && exit 1
350 if [[ ${retval} -eq 0 ]]
351 then
352 case ${method} in
353 "1") dialog_setup_system_menu ;;
354 "2") dialog_hardware_detection ;;
355 "3") install_do_reboot ;;
356 "4") clear;/bin/bash --login -i ;;
357 esac
358 fi
359 done
360 }
361
362 #################################################
363 # Install Komandos #
364 #################################################
365 run_hardware_detection()
366 {
367 # check for special devices/clients:
368 # if the device is a zotac and has a removeable device as boot disk,
369 # then add a rootdelay of 8 seconds to kernelcmd
370 local removable=0
371 if [[ ! -z $(lspci -v | grep -i zotac) ]]
372 then
373 for i in /sys/block/[hs]d*/removable
374 do
375 if [[ $(< ${i}) = 1 ]]
376 then
377 removable=1
378 fi
379 done
380
381 export KERNELOPTS="${KERNELOPTS} rootdelay=8"
382 export SPECIALDEVICE="zotac"
383 fi
384 }
385
386 run_hardware_detection_disks()
387 {
388 # all disks but exclude ramdisks
389 export ALL_DISKS=$(get_hwinfo disk | sed '/\/dev\/ram[0-9].*/d')
390 export ALL_CDROMS="$(get_hwinfo cdrom)"
391 }
392
393 setup_hdd_partitions_auto()
394 {
395 ROOTHDD="${HDD}1"
396
397 ## delete disk
398 dd if=/dev/zero of="${HDD}" count=1 &> /dev/null || die
399
400 ## setup one bootable partition
401 #1. n= new disk
402 #2. p= primary disk
403 #3. 1= first partition
404 #4. ''= default sector start
405 #5. ''= defaul sector end
406 #6. a= bootable flag
407 #7. 1= boot flag for partition 1
408 #8. w= write/quit
409 fdisk "${HDD}" &> /dev/null << EOF
410 n
411 p
412 1
413
414
415 a
416 1
417 w
418 EOF
419 }
420
421 setup_hdd_partitions_manuell()
422 {
423 ROOTHDD="${HDD}1"
424 cfdisk "${HDD}" || die
425 }
426
427 setup_hdd_format()
428 {
429 # defaults to ext3
430 [[ -z ${FORMAT_FILESYSTEM} ]] && FORMAT_FILESYSTEM="ext3"
431
432 mkfs."${FORMAT_FILESYSTEM}" -q "${ROOTHDD}" || die
433 }
434
435 install_mount_rootfs()
436 {
437 mount "${ROOTHDD}" "${INSTALL_ROOT}" || die
438 install -d ${INSTALL_ROOT}/boot || die
439 cd ${INSTALL_ROOT} || die
440 }
441
442 install_system_image()
443 {
444 tar xvjpf ${CDPATH}/system/${CDIMAGENAME} -C ${INSTALL_ROOT}
445 }
446
447 install_bootsector()
448 {
449 local uuid
450 local initrd
451 local kernelversion
452 local grubtitle
453 local chroot
454 local grubdisk
455 local CONFIG
456
457 # setup a proper boot device
458 if [[ -z ${BOOTHDD} ]]
459 then
460 grubdisk="${ROOTHDD}"
461 else
462 grubdisk="${BOOTHDD}"
463 fi
464
465 # first of all, create a device.map
466 create_device_map
467
468 # get kernelnames
469 initrd=/boot/$(readlink ${INSTALL_ROOT}/boot/initrd)
470 kernelversion=$(readlink ${INSTALL_ROOT}/boot/vmlinuz | sed "s:kernel-::g")
471
472 # for mcore only
473 if [ -f ${INSTALL_ROOT}/etc/mcore_version ]
474 then
475 grubtitle="mCore-$(< ${INSTALL_ROOT}/etc/mcore_version) (${kernelversion})"
476 else
477 grubtitle="mCore (${kernelversion})"
478 fi
479
480 # uuid support
481 uuid=$(get_uuid "${ROOTHDD}")
482
483 CONFIG="${INSTALL_ROOT}/boot/grub/grub.conf"
484 clearconfig
485 addconfig 'default 0'
486 addconfig 'timeout 3'
487 if [[ -f ${INSTALL_ROOT}/boot/grub/splash.xpm.gz ]]
488 then
489 addconfig "splashimage $(convert_device ${grubdisk})/boot/grub/splash.xpm.gz"
490 fi
491 # using current root password
492 addconfig "password --md5 $(cat ${INSTALL_ROOT}/etc/shadow | grep root | cut -d: -f2)"
493 addconfig
494 addconfig '# normal boot'
495 addconfig "title ${grubtitle}"
496 addconfig "root $(convert_device ${grubdisk})"
497 addconfig "kernel /boot/kernel-${kernelversion} root=${uuid} ${KERNELOPTS}"
498 addconfig "initrd /boot/${initrd}"
499
500 [[ ! -z ${INSTALL_ROOT} ]] && chroot=chrooted
501
502 # update grub
503 ${chroot} grub --batch --no-floppy &> /dev/null << EOF
504 root $(convert_device ${grubdisk})
505 setup $(convert_device ${grubdisk} | sed "s:,[0-9]::")
506 quit
507 EOF
508
509 return 0
510 }
511
512 create_device_map()
513 {
514 local chroot
515
516 [[ ! -z ${INSTALL_ROOT} ]] && chroot=chrooted
517
518 # create device.map
519 ${chroot} grub --batch --no-floppy --no-config-file --device-map=/boot/grub/device.map </dev/null &> /dev/null
520 }
521
522 convert_device()
523 {
524 local device="$1"
525 local root_part=
526
527 # extract device type (block) and major number for root drive
528 local major_minor=$(ls -Ll ${device} | awk '{if ($6 < 64) printf("%c%d0", $1, $5); else printf("%c%d1", $1, $5)}')
529
530 # find the matching BIOS device
531 for bios_drive in $(grep -v '^#' ${INSTALL_ROOT}/boot/grub/device.map | awk '{print $2}')
532 do
533 bios_major_minor=$(ls -Ll ${bios_drive} 2>/dev/null | awk '{if ($6 < 64) printf("%c%d0", $1, $5); else printf("%c%d1", $1, $5)}')
534
535 if [[ ${major_minor} = ${bios_major_minor} ]]
536 then
537 # we found it
538 root_drive=$(grep ${bios_drive} ${INSTALL_ROOT}/boot/grub/device.map | awk '{print $1}')
539 root_part=$(ls -Ll ${device} | awk '{print $6}')
540 root_part=$(( ${root_part} % 16 - 1 ))
541 break
542 fi
543 done
544
545 drive=$(echo ${root_drive} | sed "s:)$:,${root_part}):")
546 echo ${drive}
547 }
548
549 install_initrd()
550 {
551 local initrd
552 local kernelversion
553
554 initrd=/boot/$(readlink ${INSTALL_ROOT}/boot/initrd)
555 kernelversion=$(readlink ${INSTALL_ROOT}/boot/vmlinuz | sed "s:kernel-::g")
556
557 create_initrd --initrd "${initrd}" --kernelversion "${kernelversion}" &> /dev/null
558 }
559
560 install_system_settings()
561 {
562 local CONFIG
563 local uuid
564
565 # schreibe fstab
566 uuid=$(get_uuid "${ROOTHDD}")
567 CONFIG="${INSTALL_ROOT}/etc/fstab"
568 clearconfig
569 addconfig -e "UUID=${uuid}\t/\text3\tnoatime\t0 0"
570 addconfig -e "proc\t/proc\tproc\tdefaults\t0 0"
571 addconfig -e "shm\t/dev/shm\ttmpfs\tdefaults\t0 0"
572
573 # install network config skeleton
574 CONFIG="${INSTALL_ROOT}/etc/conf.d/net.eth0"
575 clearconfig
576 addconfig 'ONBOOT="yes"'
577 addconfig 'NETWORKING="dhcp"'
578 }
579
580 install_umount_rootfs()
581 {
582 cd /
583 umount ${INSTALL_ROOT} || die
584 }
585
586 install_do_reboot()
587 {
588 reboot
589 }
590
591 #################################################
592 # Install Ablauf Scripte #
593 #################################################
594
595 addconfig()
596 {
597 local opts
598
599 if [[ -z ${CONFIG} ]]
600 then
601 echo "You must define \$CONFIG varibale first!"
602 return 1
603 fi
604
605 if [[ ! -d $(dirname ${CONFIG}) ]]
606 then
607 install -d $(dirname ${CONFIG})
608 fi
609
610 # check for opts
611 case $1 in
612 -n) shift; opts=" -n" ;;
613 -e) shift; opts=" -e" ;;
614 esac
615
616 echo ${opts} "$@" >> ${CONFIG}
617 }
618
619 clearconfig()
620 {
621 if [[ -z ${CONFIG} ]]
622 then
623 echo "You must define \$CONFIG varibale first!"
624 return 1
625 fi
626
627 if [[ ! -d $(dirname ${CONFIG}) ]]
628 then
629 install -d $(dirname ${CONFIG})
630 fi
631 : > ${CONFIG}
632 }
633
634 run_install_normal()
635 {
636 dialog_hardware_detection
637
638 dialog_setup_hdd_partitions_manuell
639 dialog_setup_hdd_format
640 setup_hdd_format > /dev/null
641 install_mount_rootfs
642 (install_system_image > /tmp/install.log) 2> /tmp/install_errors.log | dialog_install_meter | dialog_install_system_image
643
644 dialog_install_bootsector
645 install_bootsector
646
647 dialog_install_settings
648 sleep 1
649 install_system_settings
650 dialog_install_initrd
651 install_initrd
652 install_umount_rootfs
653 dialog_install_successful
654 }
655
656 run_install_auto()
657 {
658 dialog_hardware_detection
659
660 dialog_setup_hdd_partitions_auto
661 dialog_setup_hdd_format
662 setup_hdd_format > /dev/null
663 install_mount_rootfs
664 (install_system_image > /tmp/install.log) 2> /tmp/install_errors.log | dialog_install_meter | dialog_install_system_image
665
666 dialog_install_bootsector
667 install_bootsector
668
669 dialog_install_settings
670 sleep 1
671 install_system_settings
672 dialog_install_initrd
673 install_initrd
674 install_umount_rootfs
675 dialog_install_successful
676 }
677
678 dialog_main
679
680 exit 0