Magellan Linux

Contents of /alx-src/trunk/alxinstall-ng/bin/alxinstall-ng.sh.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6873 - (show annotations) (download)
Fri Jul 24 08:31:23 2015 UTC (8 years, 9 months ago) by niro
File size: 25012 byte(s)
-hardware detection was run to late, flash disk could not detected propably within the auto install stage, fixed F2FS dialog that a user does not assume F2FS gets automatically used with all installation types
1 #!/bin/sh
2 # $Id$
3
4 # ignore environment!
5 LC_ALL=C
6
7 MLIBDIR="@@LIBDIR@@"
8
9 # images: (get ${CDIMAGENAME})
10 source /mnt/cdrom/system/images.conf
11
12 # includes
13 source ${MLIBDIR}/functions/generic.sh
14 source ${MLIBDIR}/functions/hwdetection.sh
15
16 ### System/Config Version
17 VERSION="@@VERSION@@"
18 TITLE="alxinstall-ng - ${VERSION}"
19
20 # locations
21 CDPATH="/mnt/cdrom"
22 INSTALL_ROOT="/mnt/magellan"
23
24 # default system settings
25 # standard kernel opts
26 DEFAULT_KERNELOPTS="quiet video=1024x768"
27
28 # grub options
29 DEFAULT_GRUBLEGACYOPTS=""
30 DEFAULT_GRUB2OPTS=""
31 DEFAULT_GRUB2GFXPAYLOAD="1024x768x16,1024x768"
32
33 # default specialdevices
34 DEFAULT_FORMFACTOR="desktop"
35
36 # target filesystem
37 DEFAULT_FORMAT_FILESYSTEM="ext4"
38
39 # initialize global variables so they are exportable
40 INSTALL_METHOD=""
41 KERNELOPTS=""
42 GRUBLEGACYOPTS=""
43 GRUB2OPTS=""
44 GRUB2GFXPAYLOAD=""
45 FORMFACTOR=""
46 FORMAT_FILESYSTEM=""
47 FORMAT_FILESYSTEM_BOOTHDD=""
48 FORMAT_FILESYSTEM_ROOTHDD=""
49 FDISKPARTIONBELOW256MB=0
50 SPECIALDEVICE=""
51 FLASHDISK=0
52 ### linecount of system.tar.gz -1 !
53 CURRENTLINE=0
54 #TOTALLINES=11072 # -> now in images.conf
55
56 #################################################
57 # DIALOG BOXES #
58 #################################################
59
60 die()
61 {
62 ERROR=$1
63 RETVAL=$?
64 dialog_install_failure
65 trap_exit
66 exit 1
67 }
68
69 dialog_warning()
70 {
71 dialog \
72 --backtitle "${TITLE}" \
73 --colors \
74 --defaultno \
75 --yesno "\Z1 !!! Achtung !!! \Zn\n\n\
76 Diese Festplatte wird unwiederruflich geloescht werden.\n\n\
77 Soll ich wirklich fortfahren ?" 10 70
78 RES=$?
79 if [[ ${RES} -eq 1 ]]
80 then
81 clear
82 echo "Der Vorgang wurde abgebrochen."
83 exit 1
84 fi
85 }
86
87 dialog_setup_hdd_info()
88 {
89 case "${INSTALL_METHOD}" in
90 auto)
91 dialog_setup_hdd_info_auto
92 dialog_setup_hdd_create_partitions
93 ;;
94 normal) dialog_setup_hdd_info_normal ;;
95 single) dialog_setup_hdd_info_single ;;
96 flash) dialog_setup_hdd_info_flash ;;
97 esac
98 }
99
100 dialog_setup_hdd_info_normal()
101 {
102 local SHDD="$(echo ${HDD} | sed 's/\/dev\///')"
103
104 dialog \
105 --colors \
106 --title "[ Festplatten Partitionierung ]" \
107 --backtitle "${TITLE}" \
108 --ok-label "Weiter" \
109 --msgbox "\nBitte legen Sie 3 Partitionen an.\n\n\
110 [ \Z3${SHDD}1\Zn ] Typ: \Z3Linux\Zn mit ca. 50MB\n\
111 [ \Z3${SHDD}2\Zn ] Typ: \Z3Linux Swap\Zn mit ca. 256MB\n\
112 [ \Z3${SHDD}3\Zn ] Typ: \Z3Linux \Zn mit dem Rest (min. 256MB)\n\n\
113 Bitte ${SHDD}1 als \Z3bootable\Zn markieren." 12 81
114 }
115
116 dialog_setup_hdd_info_single()
117 {
118 local SHDD="$(echo $HDD | sed 's/\/dev\///')"
119
120 dialog \
121 --colors \
122 --title "[ Festplatten Partitionierung ]" \
123 --backtitle "${TITLE}" \
124 --ok-label "Weiter" \
125 --msgbox "\nBitte legen Sie 1 Partition an.\n\n\
126 [ \Z3${SHDD}1\Zn ] Typ: \Z3Linux\Zn mit dem gesamten Speicher\n\
127 Bitte ${SHDD}1 als \Z3bootable\Zn markieren." 12 81
128 }
129
130 dialog_setup_hdd_info_flash()
131 {
132 local SHDD="$(echo ${HDD} | sed 's/\/dev\///')"
133
134 dialog \
135 --colors \
136 --title "[ Festplatten Partitionierung ]" \
137 --backtitle "${TITLE}" \
138 --ok-label "Weiter" \
139 --msgbox "\nBitte legen Sie 2 Partitionen an.\n\n\
140 [ \Z3${SHDD}1\Zn ] Typ: \Z3Linux\Zn mit ca. 50MB\n\
141 [ \Z3${SHDD}2\Zn ] Typ: \Z3Linux \Zn mit dem Rest (min. 256MB)\n\n\
142 Bitte ${SHDD}1 als \Z3bootable\Zn markieren." 12 81
143 }
144
145 dialog_setup_hdd_info_auto()
146 {
147 local SHDD="$(echo $HDD | sed 's/\/dev\///')"
148
149 dialog \
150 --colors \
151 --title "[ Festplatten Partitionierung ]" \
152 --backtitle "${TITLE}" \
153 --ok-label "Weiter" \
154 --msgbox "\nAchtung!\n\
155 Alle Daten werden von der Disk [ \Z3${HDD}\Zn ] gelöscht!" 12 81
156 }
157
158 dialog_setup_system_menu()
159 {
160 local i
161
162 i=$(dialog \
163 --backtitle "${TITLE}" \
164 --title "[ Festplatten Partitionierung ]" \
165 --cancel-label "Abbrechen" \
166 --ok-label "Weiter" \
167 --stdout \
168 --colors \
169 --menu "\nWaehlen Sie die Installations-Methode" 14 70 6 \
170 "1" "Automatisches Setup (Empfohlen)" \
171 "" "" \
172 "" "\Z1Experten Modi:\Zn" \
173 "2" "Normale IDE-Disk (Manuell)" \
174 "3" "Normale IDE Disk (Single)" \
175 "4" "Flash SDHC/NAND oder USBStick (Manuell)")
176 RES=$?
177 [[ ${RES} -eq 1 ]] && return 1
178 if [[ ${RES} -eq 0 ]]
179 then
180 case "${i}" in
181 "1") run_install auto ;;
182 "2") run_install normal ;;
183 "3") run_install single ;;
184 "4") run_install flash ;;
185 "") dialog_setup_system_menu;;
186 esac
187 fi
188 }
189
190 dialog_hardware_detection()
191 {
192 local i
193 local hwtmp
194
195 if [ -x $(type -P mktemp) ]
196 then
197 hwtmp="$(mktemp)"
198 else
199 hwtmp="/tmp/hwtmp.sh"
200 fi
201
202 run_hardware_detection_disks
203
204 echo "dialog \\" > ${hwtmp}
205 echo "--backtitle \"${TITLE}\" \\" >> ${hwtmp}
206 echo "--ok-label \"Weiter\" \\" >> ${hwtmp}
207 echo "--stdout \\" >> ${hwtmp}
208 echo "--colors \\" >> ${hwtmp}
209 echo "--msgbox \"Gefundene Hardware:\n\n \\" >> ${hwtmp}
210 echo " Festplatten:\n \\" >> ${hwtmp}
211
212 if [[ ! -z ${ALL_DISKS} ]]
213 then
214 for i in ${ALL_DISKS}
215 do
216 echo " \\Z3${i}\\Zn\n \\" >> ${hwtmp}
217 done
218 fi
219
220 if [[ ! -z ${ALL_CDROMS} ]]
221 then
222 echo " \n \\" >> ${hwtmp}
223 echo " CDROM Laufwerke:\n \\" >> ${hwtmp}
224 for i in ${ALL_CDROMS}
225 do
226 echo " \\Z3${i}\\Zn\n \\" >> ${hwtmp}
227 done
228 fi
229
230 # other devices
231 run_hardware_detection
232 case "${SPECIALDEVICE}" in
233 zotac*) echo " \n \\Z2Zotac Device erkannt.\\Zn \\" >> ${hwtmp} ;;
234 rangee) echo " \n \\Z2Rangee Device erkannt.\\Zn \\" >> ${hwtmp} ;;
235 maxdata) echo " \n \\Z2Maxdata Device erkannt.\\Zn \\" >> ${hwtmp} ;;
236 i845) echo " \n \\Z2Intel i845 Device erkannt.\\Zn \\" >> ${hwtmp} ;;
237 *) echo " \n \\ZnStandard Device erkannt.\\Zn \\" >> ${hwtmp} ;;
238 esac
239 if [[ ${FORMFACTOR} = laptop ]]
240 then
241 echo " \n \\ZnFormfactor Laptop, Powersave Modus 'ondemand' wird aktiviert.\\Zn \\" >> ${hwtmp}
242 fi
243 if [[ ${FLASHDISK} = 1 ]]
244 then
245 echo " \n \\ZnFlash Speicher erkannt, F2FS wird als Dateisystem bei der\\Zn \\" >> ${hwtmp}
246 echo " \n \\Znautomatischen Installation benutzt.\\Zn \\" >> ${hwtmp}
247 fi
248
249 echo " \" 14 70" >> ${hwtmp}
250 chmod a+x ${hwtmp}
251 ${hwtmp}
252
253 # remove tmp file
254 if [[ -f ${hwtmp} ]]
255 then
256 rm ${hwtmp}
257 fi
258 }
259
260 dialog_setup_hdd_partitions()
261 {
262 local i
263
264 if [[ -z ${ALL_DISKS} ]]
265 then
266 dialog \
267 --backtitle "${TITLE}" \
268 --ok-label "Beenden" \
269 --msgbox "Kein geeignetes Laufwerk gefunden.\nDie Installation ist fehlgeschlagen." 6 70
270 exit 1
271 else
272
273 echo "dialog \\" > /tmp/hddtmp.sh
274 echo "--backtitle \"${TITLE}\" \\" >> /tmp/hddtmp.sh
275 echo "--ok-label \"Weiter\" \\" >> /tmp/hddtmp.sh
276 echo "--cancel-label \"Beenden\" \\" >> /tmp/hddtmp.sh
277 echo "--stdout \\" >> /tmp/hddtmp.sh
278 echo "--menu \"Installations Laufwerk auswaehlen:\" 10 70 3 \\" >> /tmp/hddtmp.sh
279
280 for i in ${ALL_DISKS}
281 do
282 echo "\"${i}\" \"\" \\" >> /tmp/hddtmp.sh
283 done
284 echo -e "\n" >> /tmp/hddtmp.sh
285
286 chmod a+x /tmp/hddtmp.sh
287 HDD="$(/tmp/hddtmp.sh)"
288 RES=$?
289 [[ ${RES} -eq 1 ]] && return 1
290 if [[ ${RES} -eq 0 ]]
291 then
292 dialog_setup_hdd_info
293 setup_hdd_partitions
294 fi
295 fi
296 }
297
298 dialog_setup_hdd_create_partitions()
299 {
300 dialog \
301 --backtitle "${TITLE}" \
302 --infobox "Erstelle Disk Partitionen ..." 3 70
303 }
304
305 dialog_setup_hdd_format()
306 {
307 dialog \
308 --backtitle "${TITLE}" \
309 --infobox "Erstelle Datei-Systeme ..." 3 70
310 }
311
312 dialog_install_settings()
313 {
314 dialog \
315 --backtitle "${TITLE}" \
316 --infobox "Speichere System-Einstellungen ..." 3 70
317 }
318
319 dialog_install_system_image()
320 {
321 dialog \
322 --backtitle "${TITLE}" \
323 --gauge "Kopiere System-Image ..." 6 80
324 }
325
326 dialog_install_meter()
327 {
328 while [[ ${CURRENTLINE} != ${TOTALLINES} ]]
329 do
330 CURRENTLINE=$(grep -c . /tmp/install.log)
331 PERCENT=$(( ${CURRENTLINE} * 100 / ${TOTALLINES}))
332 echo ${PERCENT}
333 sleep 1
334 done
335 rm -f /tmp/install.log
336 return 0
337 }
338
339 dialog_install_bootsector()
340 {
341 dialog \
342 --backtitle "${TITLE}" \
343 --infobox "Schreibe den Bootsektor ..." 3 70
344 }
345
346 dialog_install_successful()
347 {
348 dialog \
349 --backtitle "${TITLE}" \
350 --colors \
351 --msgbox "Die Installation war \Z2erfolgreich\Zn." 5 81
352 }
353
354 dialog_install_failure()
355 {
356 dialog \
357 --backtitle "${TITLE}" \
358 --colors \
359 --msgbox "Die Installation ist \Z1Fehlgeschlagen\Zn.\n\n\
360 Fehler bei ${ERROR}, RetVal: ${RETVAL} \
361 " 10 81
362 }
363
364 dialog_main()
365 {
366 METHOD=0
367
368 while [[ ${METHOD} -le 2 ]]
369 do
370 METHOD=$(dialog \
371 --backtitle "${TITLE}" \
372 --no-cancel \
373 --ok-label "Weiter" \
374 --stdout \
375 --menu "Konfiguration" 14 70 6 \
376 "1" "AutoSta_LX installieren" \
377 "2" "Uebersicht gefundener Laufwerke" \
378 "3" "Beenden und neustarten" \
379 "4" "Beenden und eine Shell starten")
380 RES=$?
381 [[ ${RES} -eq 1 ]] && exit 1
382 if [[ ${RES} -eq 0 ]]
383 then
384 case ${METHOD} in
385 "1") dialog_setup_system_menu ;;
386 "2") dialog_hardware_detection ;;
387 "3") install_do_reboot ;;
388 "4") /bin/bash --login -i ;;
389 esac
390 fi
391 done
392 }
393
394 #################################################
395 # Install Commands #
396 #################################################
397 run_hardware_detection()
398 {
399 local hwinfo
400 hwinfo="$(hwinfo --bios --storage --pci --gfxcard --sys)"
401
402 # check for special devices/clients:
403 # if zotac a zotac and the disk is a removeable device, then add rootdelay to kernelcmd
404 local removable=0
405 if [[ ! -z $(echo "${hwinfo}" | grep -i zotac) ]]
406 then
407 for i in /sys/block/[hs]d*/removable
408 do
409 if [[ $(< ${i}) = 1 ]]
410 then
411 removable=1
412 # we assume that all removable disks are flash disks
413 export FLASHDISK=1
414 fi
415 done
416
417 # only add this for grub legacy, grub2 detect these settings on its own
418 export GRUBLEGACYOPTS="rootdelay=8"
419 # there are two zotac types in the wild, nvidia based gfx and intel
420 if [[ ! -z $(echo "${hwinfo}" | grep -i nouveau) ]]
421 then
422 export SPECIALDEVICE="zotac_nvidia"
423 else
424 export SPECIALDEVICE="zotac_intel"
425 fi
426 fi
427
428 # check for special devices/clients:
429 # if a rangee and disk ist smaller then 256mb move partion one block further ahead
430 if [[ ! -z $(echo "${hwinfo}" | grep -i CLE266) ]]
431 then
432 # for a rangee always define partion startblock +1
433 export FDISKPARTIONBELOW256MB="1"
434 export SPECIALDEVICE="rangee"
435 export GRUBLEGACYOPTS=""
436 fi
437
438 # check for special devices/clients:
439 # check for maxdata / i810/ i815 Chipsets and disable KMS and use i810fb frambuffer
440 if [[ ! -z $(echo "${hwinfo}" | grep -i i810) ]] || [[ ! -z $(echo "${hwinfo}" | grep -i i815) ]]
441 then
442 export SPECIALDEVICE="maxdata"
443 export GRUBLEGACYOPTS=""
444 fi
445
446 # check for i845 Chipsets and disable KMS and use 915 drm driver
447 if [[ ! -z $(echo "${hwinfo}" | grep -i i845) ]]
448 then
449 export SPECIALDEVICE="i845"
450 # unset default video=1024x768 opt or the drm driver breaks
451 export KERNELOPTS="quiet"
452 export GRUBLEGACYOPTS=""
453 # enable full kms support
454 export GRUB2GFXPAYLOAD="keep"
455 fi
456
457 # check for radeon gfxcards
458 if [[ ! -z $(echo "${hwinfo}" | grep -i radeon) ]]
459 then
460 # enable full kms support
461 export GRUB2GFXPAYLOAD="keep"
462 fi
463
464 # check for special devices/clients:
465 # check for laptops and activate cpufreq scaling
466 if [[ $(echo "${hwinfo}" | grep 'Formfactor:' | sed 's:.*Formfactor\:\ \"\(.*\)\":\1:') = laptop ]]
467 then
468 export FORMFACTOR="laptop"
469 export KERNELOPTS="${KERNELOPTS} cpufreq.governor=ondemand"
470 fi
471 }
472
473 run_hardware_detection_disks()
474 {
475 local bootdev
476
477 # all disks but exclude ramdisks
478 export ALL_DISKS=$(get_hwinfo disk | sed '/\/dev\/ram[0-9].*/d')
479 # remove the boot device from ALL_DISKS if it was an usbstick
480 if [[ $(grep '[[:space:]]/mnt/cdrom[[:space:]]' /proc/mounts | cut -d' ' -f3) != iso9660 ]]
481 then
482 bootdev="$(grep '[[:space:]]/mnt/cdrom[[:space:]]' /proc/mounts | cut -d' ' -f1 | sed 's:[0-9]::g')"
483 export ALL_DISKS=$(echo "${ALL_DISKS}" | grep -v "${bootdev}")
484 fi
485 export ALL_CDROMS="$(get_hwinfo cdrom)"
486 }
487
488 hdd_size_below_256mb()
489 {
490 local hdd="$1"
491 local size
492 local retval
493 [[ -z ${hdd} ]] && die "Error: get_hdd_size() no \$hdd given!"
494
495 size=$(fdisk -l ${hdd} | grep "Disk.*${hdd}" | sed 's:.*,\ \(.*\)\ byte.*:\1:')
496 if [[ ${size} -le 257000000 ]]
497 then
498 retval="0"
499 else
500 retval="1"
501 fi
502
503 return "${retval}"
504 }
505
506 setup_hdd_partitions()
507 {
508 case "${INSTALL_METHOD}" in
509 auto)
510 if [[ ${FLASHDISK} = 1 ]]
511 then
512 BOOTHDD="${HDD}1"
513 SWAPHDD=""
514 ROOTHDD="${HDD}2"
515 else
516 BOOTHDD=""
517 SWAPHDD=""
518 ROOTHDD="${HDD}1"
519 fi
520 ;;
521
522 normal)
523 BOOTHDD="${HDD}1"
524 SWAPHDD="${HDD}2"
525 ROOTHDD="${HDD}3"
526 ;;
527
528 single)
529 BOOTHDD=""
530 SWAPHDD=""
531 ROOTHDD="${HDD}1"
532 ;;
533
534 flash)
535 BOOTHDD="${HDD}1"
536 SWAPHDD=""
537 ROOTHDD="${HDD}2"
538 ;;
539 esac
540
541 if [[ ${INSTALL_METHOD} = auto ]]
542 then
543 # run this only if FDISKPARTITIONBELOW256MB is not already 1
544 if [[ ${FDISKPARTIONBELOW256MB} != 1 ]]
545 then
546 if hdd_size_below_256mb ${HDD}
547 then
548 FDISKPARTIONBELOW256MB=1
549 else
550 FDISKPARTIONBELOW256MB=0
551 fi
552 fi
553
554 ## delete disk
555 dd if=/dev/zero of=${HDD} count=1 &> /dev/null || die
556
557 if [[ ${FLASHDISK} = 1 ]]
558 then
559 if [[ ${FDISKPARTIONBELOW256MB} = 1 ]]
560 then
561 ## setup one bootable partition
562 # 1. n= new disk
563 # 2. p= primary disk
564 # 3. 1= first partition
565 # 4. 2= default sector start // small disk needs more space for grub2 mbr sector
566 # 5. ''= defaul sector end
567 # 6. a= bootable flag
568 # 7. 1= boot flag for partition 1
569 # 8. n= new disk
570 #10. p= primary disk
571 #11. 2= second partition
572 #12. ''= default sector start
573 #13. ''= defaul sector end
574 #14. w= write/quit
575 fdisk ${HDD} &> /dev/null << EOF
576 n
577 p
578 1
579 2
580 +50M
581 a
582 1
583 n
584 p
585 2
586
587
588 w
589 EOF
590 else
591 ## setup one bootable partition
592 # 1. n= new disk
593 # 2. p= primary disk
594 # 3. 1= first partition
595 # 4. ''= default sector start
596 # 5. ''= defaul sector end
597 # 6. a= bootable flag
598 # 7. 1= boot flag for partition 1
599 # 8. n= new disk
600 #10. p= primary disk
601 #11. 2= second partition
602 #12. ''= default sector start
603 #13. ''= defaul sector end
604 #14. w= write/quit
605 fdisk ${HDD} &> /dev/null << EOF
606 n
607 p
608 1
609
610 +50M
611 a
612 1
613 n
614 p
615 2
616
617
618 w
619 EOF
620 fi
621 else
622 if [[ ${FDISKPARTIONBELOW256MB} = 1 ]]
623 then
624 ## setup one bootable partition
625 #1. n= new disk
626 #2. p= primary disk
627 #3. 1= first partition
628 #4. 2= default sector start // small disk needs more space for grub2 mbr sector
629 #5. ''= defaul sector end
630 #6. a= bootable flag
631 #7. 1= boot flag for partition 1
632 #8. w= write/quit
633 fdisk ${HDD} &> /dev/null << EOF
634 n
635 p
636 1
637 2
638
639 a
640 1
641 w
642 EOF
643 else
644 ## setup one bootable partition
645 #1. n= new disk
646 #2. p= primary disk
647 #3. 1= first partition
648 #4. ''= default sector start
649 #5. ''= defaul sector end
650 #6. a= bootable flag
651 #7. 1= boot flag for partition 1
652 #8. w= write/quit
653 fdisk ${HDD} &> /dev/null << EOF
654 n
655 p
656 1
657
658
659 a
660 1
661 w
662 EOF
663 fi
664 fi
665 else
666 ## hdds partitionieren manuell
667 cfdisk ${HDD} || die
668 fi
669 }
670
671 setup_hdd_format()
672 {
673 install -d /tmp
674 :> /tmp/format.log
675
676 if [[ -n ${SWAPHDD} ]]
677 then
678 mkswap ${SWAPHDD} || die
679 fi
680 if [[ -n ${BOOTHDD} ]]
681 then
682 mkfs.${FORMAT_FILESYSTEM_BOOTHDD} ${BOOTHDD} &> /tmp/format.log || die
683 fi
684 if [[ -n ${ROOTHDD} ]]
685 then
686 mkfs.${FORMAT_FILESYSTEM_ROOTHDD} ${ROOTHDD} &> /tmp/format.log || die
687 fi
688 }
689
690 install_mount_rootfs()
691 {
692 local opts
693
694 if [[ -n ${SWAPHDD} ]]
695 then
696 swapon ${SWAPHDD} || die
697 fi
698 if [[ -n ${ROOTHDD} ]]
699 then
700 mount -t ${FORMAT_FILESYSTEM_ROOTHDD} ${ROOTHDD} ${INSTALL_ROOT} || die
701 fi
702 if [[ -n ${BOOTHDD} ]]
703 then
704 install -d ${INSTALL_ROOT}/boot || die
705 mount -t ${FORMAT_FILESYSTEM_BOOTHDD} ${BOOTHDD} ${INSTALL_ROOT}/boot || die
706 fi
707
708 cd ${INSTALL_ROOT} || die
709 }
710
711 install_system_image()
712 {
713 tar xvjpf ${CDPATH}/system/${CDIMAGENAME} -C ${INSTALL_ROOT}
714 }
715
716 install_bootsector_chroot()
717 {
718 local my_roothdd
719 local grubconf=${INSTALL_ROOT}/boot/grub/grub.conf
720 local grub2conf=/boot/grub/grub.cfg
721 local CONFIG
722
723 # check for grub2
724 if [[ -f ${INSTALL_ROOT}/sbin/grub-mkconfig ]]
725 then
726 # needed by grub-mkconfig on the first run
727 if [[ ! -f ${INSTALL_ROOT}/boot/grub/video.lst ]]
728 then
729 install -m0644 ${INSTALL_ROOT}/lib/grub/*/video.lst ${INSTALL_ROOT}/boot/grub/video.lst || die
730 fi
731
732 # set kernelopts
733 if [[ -f ${INSTALL_ROOT}/etc/conf.d/grub ]]
734 then
735 sed -i "s:^\(export GRUB_CMDLINE_LINUX_DEFAULT=\).*:\1\"${KERNELOPTS}\":" ${INSTALL_ROOT}/etc/conf.d/grub || die
736 sed -i "s:^\(export GRUB_GFXPAYLOAD_LINUX=\).*:\1\"${GRUB2GFXPAYLOAD}\":" ${INSTALL_ROOT}/etc/conf.d/grub || die
737 else
738 CONFIG=${INSTALL_ROOT}/etc/conf.d/grub
739 clearconfig
740 addconfig "export GRUB_CMDLINE_LINUX_DEFAULT=\"${KERNELOPTS}\""
741 addconfig "export GRUB_GFXPAYLOAD_LINUX=\"${GRUB2GFXPAYLOAD}\""
742 fi
743 CONFIG=${INSTALL_ROOT}/.installrc
744 clearconfig
745 addconfig 'grub-mkdevicemap'
746 addconfig "LC_ALL=C grub-mkconfig -o ${grub2conf} &> /dev/null"
747 addconfig "grub-install --no-floppy ${HDD} &> /dev/null"
748 addconfig "exit 0"
749
750 # grub-legacy
751 else
752 ### grubconf schreiben
753 source ${INSTALL_ROOT}/boot/kernelversion
754
755 #for alx only
756 if [ -e ${INSTALL_ROOT}/etc/alx_version ]
757 then
758 OLD_ALXVER="${ALXVER}"
759 source ${INSTALL_ROOT}/etc/alx_version
760 KRNVER="ALX-${ALXVER}"
761 ALXVER="${OLD_ALXVER}"
762 fi
763
764 [[ -z ${KRNVER} ]] && KRNVER="AutoSta_LX"
765 [[ -z ${KRNINITRD} ]] && KRNINITRD="initrd"
766 [[ -z ${KRNIMG} ]] && KRNIMG="vmlinuz"
767
768 # uuid support
769 if is_uuid_supported
770 then
771 my_roothdd="UUID=$(get_uuid ${ROOTHDD})"
772 else
773 my_roothdd="${ROOTHDD}"
774 fi
775
776 CONFIG="${grubconf}"
777 clearconfig
778 addconfig "default 0"
779 addconfig "timeout 3"
780 # using current root password
781 addconfig "password --md5 $(cat ${INSTALL_ROOT}/etc/shadow | grep root | cut -d: -f2)"
782 addconfig
783 addconfig "# normal boot"
784 addconfig "title ${KRNVER}"
785 addconfig "root (hd0,0)"
786 addconfig "kernel /boot/${KRNIMG} root=${my_roothdd} ${KERNELOPTS} ${GRUBLEGACYOPTS}"
787 if is_initrd_supported
788 then
789 addconfig "initrd /boot/${KRNINITRD}"
790 fi
791 addconfig
792 addconfig "# admin boot"
793 addconfig "title ${KRNVER} - Re-run hardware-detection"
794 addconfig "lock"
795 addconfig "root (hd0,0)"
796 addconfig "kernel /boot/${KRNIMG} root=${my_roothdd} ${KERNELOPTS} ${GRUBLEGACYOPTS} hardware-auto-detection"
797 if is_initrd_supported
798 then
799 addconfig "initrd /boot/${KRNINITRD}"
800 fi
801 addconfig
802 addconfig "title ${KRNVER} - Reset *all* local settings"
803 addconfig "lock"
804 addconfig "root (hd0,0)"
805 addconfig "kernel /boot/${KRNIMG} root=${my_roothdd} ${KERNELOPTS} ${GRUBLEGACYOPTS} alx-reset-settings"
806 if is_initrd_supported
807 then
808 addconfig "initrd /boot/${KRNINITRD}"
809 fi
810
811 # write bootsector chrooted (lfs/magellan)
812 CONFIG=${INSTALL_ROOT}/.installrc
813 clearconfig
814 addconfig '/usr/sbin/grub --no-floppy --batch << "EOF" 1> /dev/null 2> /dev/null'
815 addconfig 'root (hd0,0)'
816 addconfig 'setup (hd0)'
817 addconfig 'quit'
818 addconfig 'EOF'
819 addconfig 'exit 0'
820 fi
821
822 ## enter chroot
823 enter_chroot_installrc
824 }
825
826 is_initrd_supported()
827 {
828 # only generate initrds if the cmd exists
829 [[ -x ${INSTALL_ROOT}/sbin/mkinitrd ]] && return 0
830 return 1
831 }
832
833 install_initrd_chroot()
834 {
835 local CONFIG
836
837 # only generate initrds if the cmd exists
838 is_initrd_supported || return 0
839
840 FSMODS="${FORMAT_FILESYSTEM_BOOTHDD} ${FORMAT_FILESYSTEM_ROOTHDD}"
841 DISKMODS="sd_mod"
842 OLDPATAMODS="amd74xx piix sis5513 via82cxxx"
843 PATAMODS="ata_piix pata_amd pata_mpiix pata_oldpiix pata_sis pata_via"
844 SATAMODS="sata_via sata_sis sata_nv"
845 DRMMODS="i915 mga nouveau r128 radeon savage sis tdfx ttm via"
846 OTHERMODS=""
847 case ${SPECIALDEVICE} in
848 zotac_intel|i845) FBMODS=""; DRMMODS="i915" ;;
849 zotac_nvidia) FBMODS=""; DRMMODS="nouveau" ;;
850 rangee) FBMODS="" ;; ## fallback to vesafb, viafb does not run on all CLE266 boards
851 # not working with kms enabled drivers -> segfaults
852 #maxdata) FBMODS="i810fb" ;; ## check for maxdata / i810/ i815 Chipsets and disable KMS and use i810fb frambuffer
853 maxdata) FBMODS="" ;;
854 *) FBMODS="uvesafb" ;;
855 esac
856
857 if [[ ${FORMFACTOR} = laptop ]]
858 then
859 OTHERMODS="acpi-cpufreq cpufreq_ondemand cpufreq_conservative cpufreq_powersave"
860 fi
861
862 # install an appropriate uvesafb.conf
863 CONFIG=${INSTALL_ROOT}/etc/modprobe.d/uvesafb.conf
864 clearconfig
865 addconfig "options uvesafb mode_option=1024x768-32@60 scroll=ywrap"
866
867 # install an appropriate viafb.conf
868 CONFIG=${INSTALL_ROOT}/etc/modprobe.d/viafb.conf
869 clearconfig
870 addconfig "options viafb viafb_mode=1024x768 viafb_refresh=60"
871
872 # install an appropriate i810fb.conf
873 CONFIG=${INSTALL_ROOT}/etc/modprobe.d/i810fb.conf
874 clearconfig
875 addconfig "options i810fb xres=1024 yres=768 bpp=16 mtrr=1 hsync1=30 hsync2=62 vsync1=30 vsync2=60"
876
877 CONFIG=${INSTALL_ROOT}/.installrc
878 clearconfig
879 addconfig "echo \"MODULES=\\\"${FSMODS} ${DISKMODS} ${OLDATAMODS} ${PATAMODS} ${SATAMODS} ${DRMMODS} ${FBMODS} ${OTHERMODS}\\\"\" > /etc/conf.d/mkinitrd"
880 addconfig "mkinitrd -f /boot/$(readlink /boot/initrd) $(readlink /boot/vmlinuz | sed "s:kernel-::g") > /dev/null"
881 addconfig "exit 0"
882 ## enter chroot
883 enter_chroot_installrc
884 }
885
886 is_uuid_supported()
887 {
888 # f2fs needs special treatments as the old busybox does not support this fs
889 # use the blkid from util-linux instead of busybox
890 if [[ ${FORMAT_FILESYSTEM} = f2fs ]]
891 then
892 if [[ -x $(type -P blkid) ]]
893 then
894 return 0
895 fi
896 else
897 if [[ -x $(type -P busybox.mkinitrd) ]]
898 then
899 # only detect uuids if supported
900 if [[ ! -z $(busybox.mkinitrd | grep blkid) ]]
901 then
902 return 0
903 fi
904 fi
905 fi
906
907 return 1
908 }
909
910 get_uuid()
911 {
912 local UUID
913 local SEC_TYPE
914 local TYPE
915 local blkidcmd
916
917 local dev="$1"
918 [[ -z ${dev} ]] && die "no dev given"
919
920 # check if given device is already an UUID
921 if [[ ${dev/UUID=/}x != ${dev}x ]]
922 then
923 eval "${dev}"
924 else
925 # f2fs needs special treatments as the old busybox does not support this fs
926 # use the blkid from util-linux instead of busybox
927 if [[ ${FORMAT_FILESYSTEM} = f2fs ]]
928 then
929 blkidcmd="blkid"
930 else
931 blkidcmd="busybox.mkinitrd blkid"
932 fi
933 eval $(${blkidcmd} ${dev} | grep "${dev}:" | sed 's/.*:\ //')
934 fi
935 echo "${UUID}"
936 }
937
938 install_system_settings()
939 {
940 local CONFIG
941 local fstype
942
943 # write fstab
944 CONFIG=${INSTALL_ROOT}/etc/fstab
945 clearconfig
946
947 if [[ -n ${BOOTHDD} ]]
948 then
949 if is_uuid_supported
950 then
951 addconfig -e "UUID=$(get_uuid ${BOOTHDD})\t/boot\t${FORMAT_FILESYSTEM_BOOTHDD}\tnoatime,noauto\t1 1"
952 else
953 addconfig -e "${BOOTHDD}\t/boot\t${FORMAT_FILESYSTEM_BOOTHDD}\tnoatime,noauto\t1 1"
954 fi
955 fi
956
957 if [[ -n ${ROOTHDD} ]]
958 then
959 if is_uuid_supported
960 then
961 addconfig -e "UUID=$(get_uuid ${ROOTHDD})\t/\t${FORMAT_FILESYSTEM_ROOTHDD}\tnoatime\t0 0"
962 else
963 addconfig -e "${ROOTHDD}\t/\t${FORMAT_FILESYSTEM_ROOTHDD}\tnoatime\t0 0"
964 fi
965 fi
966
967 # not needed busybox loads all with swapon -a, even if not mentioned in fstab
968 #addconfig -e "UUID='$(get_uuid ${SWAPHDD})'\tswap\tswap\tpri=1\t0 0"
969 addconfig -e "proc\t/proc\tproc\tdefaults\t0 0"
970 addconfig -e "shm\t/dev/shm\ttmpfs\tdefaults\t0 0"
971
972 # install network config skeleton
973 install -m0644 ${INSTALL_ROOT}/etc/alxconfig-ng/skel/net/net.eth0 ${INSTALL_ROOT}/etc/conf.d/ || die
974
975 # intel framebufer quirk
976 if [[ -e /proc/fb ]]
977 then
978 if [[ ! -z $(grep 'inteldrmfb' /proc/fb) ]]
979 then
980 fbdev=$(grep 'inteldrmfb' /proc/fb | sed 's:\([0-9]\).*:\1:')
981 if [[ ${fbdev} != 0 ]]
982 then
983 sed -i "s:^\(SPLASH_DEV=\).*:\1\"/dev/fb${fbdev}\":" ${INSTALL_ROOT}/etc/splash/splash.conf || die
984 fi
985 fi
986 fi
987 }
988
989 install_umount_rootfs()
990 {
991 cd /
992 if [[ -n ${BOOTHDD} ]]
993 then
994 umount ${INSTALL_ROOT}/boot || die
995 fi
996 if [[ -n ${ROOTHDD} ]]
997 then
998 umount ${INSTALL_ROOT} || die
999 fi
1000 if [[ -n ${SWAPHDD} ]]
1001 then
1002 swapoff ${SWAPHDD} || die
1003 fi
1004 }
1005
1006 install_do_reboot()
1007 {
1008 reboot
1009 }
1010
1011 #################################################
1012 # Install Main Scripts #
1013 #################################################
1014
1015 run_install()
1016 {
1017 local method="$1"
1018
1019 # setup install environment
1020 export KERNELOPTS="${DEFAULT_KERNELOPTS}"
1021 export GRUBLEGACYOPTS="${GRUBLEGACYOPTS}"
1022 export GRUB2OPTS="${GRUB2OPTS}"
1023 export GRUB2GFXPAYLOAD="${DEFAULT_GRUB2GFXPAYLOAD}"
1024 export FORMFACTOR="${DEFAULT_FORMFACTOR}"
1025 export FORMAT_FILESYSTEM="${DEFAULT_FORMAT_FILESYSTEM}"
1026
1027 # run hardware detections first to get the disktypes detected
1028 dialog_hardware_detection
1029
1030 case "${method}" in
1031 auto)
1032 if [[ ${FLASHDISK} = 1 ]]
1033 then
1034 export FORMAT_FILESYSTEM="f2fs"
1035 export FORMAT_FILESYSTEM_BOOTHDD="ext2"
1036 export FORMAT_FILESYSTEM_ROOTHDD="${FORMAT_FILESYSTEM}"
1037 else
1038 export FORMAT_FILESYSTEM_BOOTHDD=""
1039 export FORMAT_FILESYSTEM_ROOTHDD="${FORMAT_FILESYSTEM}"
1040 fi
1041 export INSTALL_METHOD="${method}"
1042 ;;
1043 normal)
1044 export FORMAT_FILESYSTEM_BOOTHDD="${FORMAT_FILESYSTEM}"
1045 export FORMAT_FILESYSTEM_ROOTHDD="${FORMAT_FILESYSTEM}"
1046 export INSTALL_METHOD="${method}"
1047 ;;
1048 single)
1049 export FORMAT_FILESYSTEM_BOOTHDD=""
1050 export FORMAT_FILESYSTEM_ROOTHDD="${FORMAT_FILESYSTEM}"
1051 export INSTALL_METHOD="${method}"
1052 ;;
1053 flash)
1054 export FORMAT_FILESYSTEM="f2fs"
1055 export FORMAT_FILESYSTEM_BOOTHDD="ext2"
1056 export FORMAT_FILESYSTEM_ROOTHDD="${FORMAT_FILESYSTEM}"
1057 export INSTALL_METHOD="${method}"
1058 ;;
1059 *)
1060 die "Unknown install method '${method}', aborting."
1061 ;;
1062 esac
1063
1064 dialog_setup_hdd_partitions
1065 dialog_setup_hdd_format
1066 setup_hdd_format > /dev/null
1067 install_mount_rootfs
1068 (install_system_image > /tmp/install.log) 2> /tmp/install_errors.log | dialog_install_meter | dialog_install_system_image
1069
1070 dialog_install_settings
1071 sleep 1
1072 install_system_settings
1073 install_initrd_chroot
1074
1075 dialog_install_bootsector
1076 install_bootsector_chroot
1077
1078 install_umount_rootfs
1079 dialog_install_successful
1080 }
1081
1082 # set some proper traps
1083 trap "trap_exit" SIGINT SIGQUIT
1084
1085 dialog_main
1086
1087 exit 0