Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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