Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1660 - (show annotations) (download) (as text)
Thu Mar 10 22:06:27 2011 UTC (13 years, 1 month ago) by niro
File MIME type: application/x-sh
File size: 14234 byte(s)
-use ext4 as default filesystem and honor this in fstab
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="ext4"
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 local bootdev
389
390 # all disks but exclude ramdisks
391 export ALL_DISKS=$(get_hwinfo disk | sed '/\/dev\/ram[0-9].*/d')
392 # remove the boot device from ALL_DISKS if it was an usbstick
393 if [[ $(grep '[[:space:]]/mnt/cdrom[[:space:]]' /proc/mounts | cut -d' ' -f3) != iso9660 ]]
394 then
395 bootdev="$(grep '[[:space:]]/mnt/cdrom[[:space:]]' /proc/mounts | cut -d' ' -f1 | sed 's:[0-9]::g')"
396 export ALL_DISKS=$(echo "${ALL_DISKS}" | grep -v "${bootdev}")
397 fi
398 export ALL_CDROMS="$(get_hwinfo cdrom)"
399 }
400
401 setup_hdd_partitions_auto()
402 {
403 ROOTHDD="${HDD}1"
404
405 ## delete disk
406 dd if=/dev/zero of="${HDD}" count=1 &> /dev/null || die
407
408 ## setup one bootable partition
409 #1. n= new disk
410 #2. p= primary disk
411 #3. 1= first partition
412 #4. ''= default sector start
413 #5. ''= defaul sector end
414 #6. a= bootable flag
415 #7. 1= boot flag for partition 1
416 #8. w= write/quit
417 fdisk "${HDD}" &> /dev/null << EOF
418 n
419 p
420 1
421
422
423 a
424 1
425 w
426 EOF
427 }
428
429 setup_hdd_partitions_manuell()
430 {
431 ROOTHDD="${HDD}1"
432 cfdisk "${HDD}" || die
433 }
434
435 setup_hdd_format()
436 {
437 mkfs."${FORMAT_FILESYSTEM}" -q "${ROOTHDD}" || die
438 }
439
440 install_mount_rootfs()
441 {
442 mount "${ROOTHDD}" "${INSTALL_ROOT}" || die
443 install -d ${INSTALL_ROOT}/boot || die
444 cd ${INSTALL_ROOT} || die
445 }
446
447 install_system_image()
448 {
449 tar xvjpf ${CDPATH}/system/${CDIMAGENAME} -C ${INSTALL_ROOT}
450 }
451
452 install_bootsector()
453 {
454 local uuid
455 local initrd
456 local kernelversion
457 local grubtitle
458 local chroot
459 local grubdisk
460 local CONFIG
461
462 # setup a proper boot device
463 if [[ -z ${BOOTHDD} ]]
464 then
465 grubdisk="${ROOTHDD}"
466 else
467 grubdisk="${BOOTHDD}"
468 fi
469
470 # first of all, create a device.map
471 create_device_map
472
473 # get kernelnames
474 initrd=/boot/$(readlink ${INSTALL_ROOT}/boot/initrd)
475 kernelversion=$(readlink ${INSTALL_ROOT}/boot/vmlinuz | sed "s:kernel-::g")
476
477 # for mcore only
478 if [ -f ${INSTALL_ROOT}/etc/mcore_version ]
479 then
480 grubtitle="mCore-$(< ${INSTALL_ROOT}/etc/mcore_version) (${kernelversion})"
481 else
482 grubtitle="mCore (${kernelversion})"
483 fi
484
485 # uuid support
486 uuid=$(get_uuid "${ROOTHDD}")
487
488 CONFIG="${INSTALL_ROOT}/boot/grub/grub.conf"
489 clearconfig
490 addconfig 'default 0'
491 addconfig 'timeout 3'
492 if [[ -f ${INSTALL_ROOT}/boot/grub/splash.xpm.gz ]]
493 then
494 addconfig "splashimage $(convert_device ${grubdisk})/boot/grub/splash.xpm.gz"
495 fi
496 # using current root password
497 addconfig "password --md5 $(cat ${INSTALL_ROOT}/etc/shadow | grep root | cut -d: -f2)"
498 addconfig
499 addconfig '# normal boot'
500 addconfig "title ${grubtitle}"
501 addconfig "root $(convert_device ${grubdisk})"
502 addconfig "kernel /boot/kernel-${kernelversion} root=${uuid} ${KERNELOPTS}"
503 addconfig "initrd /boot/${initrd}"
504
505 [[ ! -z ${INSTALL_ROOT} ]] && chroot=chrooted
506
507 # update grub
508 ${chroot} grub --batch --no-floppy &> /dev/null << EOF
509 root $(convert_device ${grubdisk})
510 setup $(convert_device ${grubdisk} | sed "s:,[0-9]::")
511 quit
512 EOF
513
514 return 0
515 }
516
517 create_device_map()
518 {
519 local chroot
520
521 [[ ! -z ${INSTALL_ROOT} ]] && chroot=chrooted
522
523 # create device.map
524 ${chroot} grub --batch --no-floppy --no-config-file --device-map=/boot/grub/device.map </dev/null &> /dev/null
525 }
526
527 convert_device()
528 {
529 local device="$1"
530 local root_part=
531
532 # extract device type (block) and major number for root drive
533 local major_minor=$(ls -Ll ${device} | awk '{if ($6 < 64) printf("%c%d0", $1, $5); else printf("%c%d1", $1, $5)}')
534
535 # find the matching BIOS device
536 for bios_drive in $(grep -v '^#' ${INSTALL_ROOT}/boot/grub/device.map | awk '{print $2}')
537 do
538 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)}')
539
540 if [[ ${major_minor} = ${bios_major_minor} ]]
541 then
542 # we found it
543 root_drive=$(grep ${bios_drive} ${INSTALL_ROOT}/boot/grub/device.map | awk '{print $1}')
544 root_part=$(ls -Ll ${device} | awk '{print $6}')
545 root_part=$(( ${root_part} % 16 - 1 ))
546 break
547 fi
548 done
549
550 drive=$(echo ${root_drive} | sed "s:)$:,${root_part}):")
551 echo ${drive}
552 }
553
554 install_initrd()
555 {
556 local initrd
557 local kernelversion
558
559 initrd=/boot/$(readlink ${INSTALL_ROOT}/boot/initrd)
560 kernelversion=$(readlink ${INSTALL_ROOT}/boot/vmlinuz | sed "s:kernel-::g")
561
562 create_initrd --initrd "${initrd}" --kernelversion "${kernelversion}" &> /dev/null
563 }
564
565 install_system_settings()
566 {
567 local CONFIG
568 local uuid
569
570 # schreibe fstab
571 uuid=$(get_uuid "${ROOTHDD}")
572 CONFIG="${INSTALL_ROOT}/etc/fstab"
573 clearconfig
574 addconfig -e "UUID=${uuid}\t/\t${FORMAT_FILESYSTEM}\tnoatime\t0 0"
575 addconfig -e "proc\t/proc\tproc\tdefaults\t0 0"
576 addconfig -e "shm\t/dev/shm\ttmpfs\tdefaults\t0 0"
577
578 # install network config skeleton
579 CONFIG="${INSTALL_ROOT}/etc/conf.d/net.eth0"
580 clearconfig
581 addconfig 'ONBOOT="yes"'
582 addconfig 'NETWORKING="dhcp"'
583 }
584
585 install_umount_rootfs()
586 {
587 cd /
588 umount ${INSTALL_ROOT} || die
589 }
590
591 install_do_reboot()
592 {
593 reboot
594 }
595
596 #################################################
597 # Install Ablauf Scripte #
598 #################################################
599
600 addconfig()
601 {
602 local opts
603
604 if [[ -z ${CONFIG} ]]
605 then
606 echo "You must define \$CONFIG varibale first!"
607 return 1
608 fi
609
610 if [[ ! -d $(dirname ${CONFIG}) ]]
611 then
612 install -d $(dirname ${CONFIG})
613 fi
614
615 # check for opts
616 case $1 in
617 -n) shift; opts=" -n" ;;
618 -e) shift; opts=" -e" ;;
619 esac
620
621 echo ${opts} "$@" >> ${CONFIG}
622 }
623
624 clearconfig()
625 {
626 if [[ -z ${CONFIG} ]]
627 then
628 echo "You must define \$CONFIG varibale first!"
629 return 1
630 fi
631
632 if [[ ! -d $(dirname ${CONFIG}) ]]
633 then
634 install -d $(dirname ${CONFIG})
635 fi
636 : > ${CONFIG}
637 }
638
639 run_install_normal()
640 {
641 dialog_hardware_detection
642
643 dialog_setup_hdd_partitions_manuell
644 dialog_setup_hdd_format
645 setup_hdd_format > /dev/null
646 install_mount_rootfs
647 (install_system_image > /tmp/install.log) 2> /tmp/install_errors.log | dialog_install_meter | dialog_install_system_image
648
649 dialog_install_bootsector
650 install_bootsector
651
652 dialog_install_settings
653 sleep 1
654 install_system_settings
655 dialog_install_initrd
656 install_initrd
657 install_umount_rootfs
658 dialog_install_successful
659 }
660
661 run_install_auto()
662 {
663 dialog_hardware_detection
664
665 dialog_setup_hdd_partitions_auto
666 dialog_setup_hdd_format
667 setup_hdd_format > /dev/null
668 install_mount_rootfs
669 (install_system_image > /tmp/install.log) 2> /tmp/install_errors.log | dialog_install_meter | dialog_install_system_image
670
671 dialog_install_bootsector
672 install_bootsector
673
674 dialog_install_settings
675 sleep 1
676 install_system_settings
677 dialog_install_initrd
678 install_initrd
679 install_umount_rootfs
680 dialog_install_successful
681 }
682
683 dialog_main
684
685 exit 0