Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6873 - (hide 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 niro 258 #!/bin/sh
2 niro 6819 # $Id$
3 niro 258
4 niro 6815 # ignore environment!
5     LC_ALL=C
6    
7 niro 6852 MLIBDIR="@@LIBDIR@@"
8 niro 6816
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 niro 6873 echo " \n \\ZnFlash Speicher erkannt, F2FS wird als Dateisystem bei der\\Zn \\" >> ${hwtmp}
246     echo " \n \\Znautomatischen Installation benutzt.\\Zn \\" >> ${hwtmp}
247 niro 6837 fi
248 niro 1574
249 niro 5006 echo " \" 14 70" >> ${hwtmp}
250 niro 1574 chmod a+x ${hwtmp}
251     ${hwtmp}
252    
253     # remove tmp file
254     if [[ -f ${hwtmp} ]]
255     then
256     rm ${hwtmp}
257     fi
258 niro 258 }
259    
260 niro 6826 dialog_setup_hdd_partitions()
261 niro 520 {
262     local i
263    
264 niro 6816 if [[ -z ${ALL_DISKS} ]]
265 niro 258 then
266     dialog \
267 niro 520 --backtitle "${TITLE}" \
268 niro 258 --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 niro 520 echo "--backtitle \"${TITLE}\" \\" >> /tmp/hddtmp.sh
275 niro 258 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 niro 6816 for i in ${ALL_DISKS}
281 niro 258 do
282 niro 520 echo "\"${i}\" \"\" \\" >> /tmp/hddtmp.sh
283 niro 258 done
284     echo -e "\n" >> /tmp/hddtmp.sh
285    
286     chmod a+x /tmp/hddtmp.sh
287 niro 520 HDD="$(/tmp/hddtmp.sh)"
288 niro 258 RES=$?
289 niro 520 [[ ${RES} -eq 1 ]] && return 1
290     if [[ ${RES} -eq 0 ]]
291 niro 258 then
292     dialog_setup_hdd_info
293 niro 6826 setup_hdd_partitions
294 niro 258 fi
295     fi
296     }
297    
298 niro 1574 dialog_setup_hdd_create_partitions()
299     {
300     dialog \
301     --backtitle "${TITLE}" \
302     --infobox "Erstelle Disk Partitionen ..." 3 70
303     }
304    
305 niro 520 dialog_setup_hdd_format()
306     {
307 niro 258 dialog \
308 niro 520 --backtitle "${TITLE}" \
309 niro 258 --infobox "Erstelle Datei-Systeme ..." 3 70
310     }
311    
312 niro 520 dialog_install_settings()
313     {
314 niro 258 dialog \
315 niro 520 --backtitle "${TITLE}" \
316 niro 258 --infobox "Speichere System-Einstellungen ..." 3 70
317     }
318    
319 niro 520 dialog_install_system_image()
320     {
321 niro 258 dialog \
322 niro 520 --backtitle "${TITLE}" \
323 niro 258 --gauge "Kopiere System-Image ..." 6 80
324     }
325    
326 niro 520 dialog_install_meter()
327     {
328     while [[ ${CURRENTLINE} != ${TOTALLINES} ]]
329     do
330 niro 525 CURRENTLINE=$(grep -c . /tmp/install.log)
331     PERCENT=$(( ${CURRENTLINE} * 100 / ${TOTALLINES}))
332 niro 258 echo ${PERCENT}
333     sleep 1
334     done
335     rm -f /tmp/install.log
336     return 0
337     }
338    
339 niro 520 dialog_install_bootsector()
340     {
341 niro 258 dialog \
342 niro 520 --backtitle "${TITLE}" \
343 niro 258 --infobox "Schreibe den Bootsektor ..." 3 70
344     }
345    
346 niro 520 dialog_install_successful()
347     {
348 niro 258 dialog \
349 niro 520 --backtitle "${TITLE}" \
350 niro 258 --colors \
351     --msgbox "Die Installation war \Z2erfolgreich\Zn." 5 81
352     }
353    
354 niro 520 dialog_install_failure()
355     {
356 niro 258 dialog \
357 niro 520 --backtitle "${TITLE}" \
358 niro 258 --colors \
359     --msgbox "Die Installation ist \Z1Fehlgeschlagen\Zn.\n\n\
360 niro 520 Fehler bei ${ERROR}, RetVal: ${RETVAL} \
361 niro 258 " 10 81
362     }
363    
364 niro 520 dialog_main()
365     {
366 niro 258 METHOD=0
367    
368 niro 520 while [[ ${METHOD} -le 2 ]]
369 niro 258 do
370 niro 520 METHOD=$(dialog \
371     --backtitle "${TITLE}" \
372 niro 258 --no-cancel \
373     --ok-label "Weiter" \
374     --stdout \
375 niro 6842 --menu "Konfiguration" 14 70 6 \
376 niro 258 "1" "AutoSta_LX installieren" \
377     "2" "Uebersicht gefundener Laufwerke" \
378     "3" "Beenden und neustarten" \
379 niro 520 "4" "Beenden und eine Shell starten")
380 niro 258 RES=$?
381 niro 524 [[ ${RES} -eq 1 ]] && exit 1
382 niro 520 if [[ ${RES} -eq 0 ]]
383     then
384     case ${METHOD} in
385 niro 6770 "1") dialog_setup_system_menu ;;
386 niro 1574 "2") dialog_hardware_detection ;;
387 niro 520 "3") install_do_reboot ;;
388     "4") /bin/bash --login -i ;;
389 niro 258 esac
390     fi
391     done
392     }
393    
394     #################################################
395 niro 6818 # Install Commands #
396 niro 258 #################################################
397 niro 1574 run_hardware_detection()
398     {
399 niro 3199 local hwinfo
400 niro 5003 hwinfo="$(hwinfo --bios --storage --pci --gfxcard --sys)"
401 niro 3199
402 niro 1574 # 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 niro 3199 if [[ ! -z $(echo "${hwinfo}" | grep -i zotac) ]]
406 niro 1574 then
407     for i in /sys/block/[hs]d*/removable
408     do
409     if [[ $(< ${i}) = 1 ]]
410     then
411     removable=1
412 niro 6837 # we assume that all removable disks are flash disks
413     export FLASHDISK=1
414 niro 1574 fi
415     done
416    
417 niro 2736 # only add this for grub legacy, grub2 detect these settings on its own
418     export GRUBLEGACYOPTS="rootdelay=8"
419 niro 5575 # there are two zotac types in the wild, nvidia based gfx and intel
420 niro 4847 if [[ ! -z $(echo "${hwinfo}" | grep -i nouveau) ]]
421     then
422     export SPECIALDEVICE="zotac_nvidia"
423     else
424     export SPECIALDEVICE="zotac_intel"
425     fi
426 niro 1574 fi
427 niro 3199
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 niro 3260
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 niro 5003
446 niro 5575 # 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 niro 6771 # 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 niro 5003 # 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 niro 1574 }
472    
473 niro 6816 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 niro 3199 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 niro 6826 setup_hdd_partitions()
507 niro 1574 {
508 niro 6826 case "${INSTALL_METHOD}" in
509 niro 6849 auto)
510 niro 6851 if [[ ${FLASHDISK} = 1 ]]
511 niro 6849 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 niro 6826 normal)
523     BOOTHDD="${HDD}1"
524     SWAPHDD="${HDD}2"
525     ROOTHDD="${HDD}3"
526     ;;
527 niro 1574
528 niro 6849 single)
529 niro 6827 BOOTHDD=""
530     SWAPHDD=""
531 niro 6826 ROOTHDD="${HDD}1"
532     ;;
533 niro 6837
534     flash)
535     BOOTHDD="${HDD}1"
536     SWAPHDD=""
537     ROOTHDD="${HDD}2"
538     ;;
539 niro 6826 esac
540    
541     if [[ ${INSTALL_METHOD} = auto ]]
542 niro 3199 then
543 niro 6826 # run this only if FDISKPARTITIONBELOW256MB is not already 1
544     if [[ ${FDISKPARTIONBELOW256MB} != 1 ]]
545 niro 3199 then
546 niro 6826 if hdd_size_below_256mb ${HDD}
547     then
548     FDISKPARTIONBELOW256MB=1
549     else
550     FDISKPARTIONBELOW256MB=0
551     fi
552 niro 3199 fi
553    
554 niro 6826 ## delete disk
555     dd if=/dev/zero of=${HDD} count=1 &> /dev/null || die
556 niro 1574
557 niro 6846 if [[ ${FLASHDISK} = 1 ]]
558 niro 6826 then
559 niro 6846 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 niro 1574 n
577     p
578     1
579 niro 3199 2
580 niro 6848 +50M
581 niro 6846 a
582     1
583     n
584     p
585     2
586 niro 1574
587 niro 6846
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 niro 6848 +50M
611 niro 3199 a
612     1
613 niro 6846 n
614     p
615     2
616    
617    
618 niro 3199 w
619     EOF
620 niro 6846 fi
621 niro 6826 else
622 niro 6846 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 niro 3199 n
635     p
636     1
637 niro 6846 2
638 niro 1574
639 niro 6846 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 niro 3199
658 niro 6846
659 niro 1574 a
660     1
661     w
662     EOF
663 niro 6846 fi
664 niro 6826 fi
665     else
666     ## hdds partitionieren manuell
667     cfdisk ${HDD} || die
668 niro 3199 fi
669 niro 1574 }
670    
671 niro 520 setup_hdd_format()
672     {
673 niro 6844 install -d /tmp
674     :> /tmp/format.log
675    
676 niro 6825 if [[ -n ${SWAPHDD} ]]
677     then
678     mkswap ${SWAPHDD} || die
679     fi
680     if [[ -n ${BOOTHDD} ]]
681     then
682 niro 6844 mkfs.${FORMAT_FILESYSTEM_BOOTHDD} ${BOOTHDD} &> /tmp/format.log || die
683 niro 6825 fi
684     if [[ -n ${ROOTHDD} ]]
685     then
686 niro 6844 mkfs.${FORMAT_FILESYSTEM_ROOTHDD} ${ROOTHDD} &> /tmp/format.log || die
687 niro 6825 fi
688 niro 258 }
689    
690 niro 520 install_mount_rootfs()
691     {
692 niro 6837 local opts
693    
694 niro 6825 if [[ -n ${SWAPHDD} ]]
695     then
696     swapon ${SWAPHDD} || die
697     fi
698     if [[ -n ${ROOTHDD} ]]
699     then
700 niro 6841 mount -t ${FORMAT_FILESYSTEM_ROOTHDD} ${ROOTHDD} ${INSTALL_ROOT} || die
701 niro 6825 fi
702     if [[ -n ${BOOTHDD} ]]
703     then
704 niro 6835 install -d ${INSTALL_ROOT}/boot || die
705 niro 6841 mount -t ${FORMAT_FILESYSTEM_BOOTHDD} ${BOOTHDD} ${INSTALL_ROOT}/boot || die
706 niro 6825 fi
707 niro 258
708 niro 6835 cd ${INSTALL_ROOT} || die
709 niro 280 }
710    
711 niro 520 install_system_image()
712     {
713 niro 6835 tar xvjpf ${CDPATH}/system/${CDIMAGENAME} -C ${INSTALL_ROOT}
714 niro 258 }
715    
716 niro 520 install_bootsector_chroot()
717     {
718 niro 1574 local my_roothdd
719 niro 6835 local grubconf=${INSTALL_ROOT}/boot/grub/grub.conf
720 niro 2573 local grub2conf=/boot/grub/grub.cfg
721 niro 6834 local CONFIG
722 niro 1574
723 niro 2554 # check for grub2
724 niro 6835 if [[ -f ${INSTALL_ROOT}/sbin/grub-mkconfig ]]
725 niro 258 then
726 niro 2554 # needed by grub-mkconfig on the first run
727 niro 6835 if [[ ! -f ${INSTALL_ROOT}/boot/grub/video.lst ]]
728 niro 2554 then
729 niro 6835 install -m0644 ${INSTALL_ROOT}/lib/grub/*/video.lst ${INSTALL_ROOT}/boot/grub/video.lst || die
730 niro 2554 fi
731 niro 522
732 niro 2557 # set kernelopts
733 niro 6835 if [[ -f ${INSTALL_ROOT}/etc/conf.d/grub ]]
734 niro 2557 then
735 niro 6835 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 niro 2557 else
738 niro 6839 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 niro 2557 fi
743 niro 6835 CONFIG=${INSTALL_ROOT}/.installrc
744 niro 6834 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 niro 2557
750 niro 2554 # grub-legacy
751 niro 1574 else
752 niro 2554 ### grubconf schreiben
753 niro 6835 source ${INSTALL_ROOT}/boot/kernelversion
754 niro 1574
755 niro 2554 #for alx only
756 niro 6835 if [ -e ${INSTALL_ROOT}/etc/alx_version ]
757 niro 2554 then
758     OLD_ALXVER="${ALXVER}"
759 niro 6835 source ${INSTALL_ROOT}/etc/alx_version
760 niro 2554 KRNVER="ALX-${ALXVER}"
761     ALXVER="${OLD_ALXVER}"
762     fi
763 niro 522
764 niro 2554 [[ -z ${KRNVER} ]] && KRNVER="AutoSta_LX"
765     [[ -z ${KRNINITRD} ]] && KRNINITRD="initrd"
766     [[ -z ${KRNIMG} ]] && KRNIMG="vmlinuz"
767 niro 1123
768 niro 2554 # 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 niro 1123
776 niro 6834 CONFIG="${grubconf}"
777     clearconfig
778     addconfig "default 0"
779     addconfig "timeout 3"
780 niro 2554 # using current root password
781 niro 6835 addconfig "password --md5 $(cat ${INSTALL_ROOT}/etc/shadow | grep root | cut -d: -f2)"
782 niro 6834 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 niro 2554 if is_initrd_supported
788     then
789 niro 6834 addconfig "initrd /boot/${KRNINITRD}"
790 niro 2554 fi
791 niro 6834 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 niro 2554 if is_initrd_supported
798     then
799 niro 6834 addconfig "initrd /boot/${KRNINITRD}"
800 niro 2554 fi
801 niro 6834 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 niro 2554 if is_initrd_supported
807     then
808 niro 6834 addconfig "initrd /boot/${KRNINITRD}"
809 niro 2554 fi
810    
811 niro 6818 # write bootsector chrooted (lfs/magellan)
812 niro 6835 CONFIG=${INSTALL_ROOT}/.installrc
813 niro 6834 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 niro 2554 fi
821 niro 528
822 niro 6834 ## enter chroot
823     enter_chroot_installrc
824 niro 528 }
825    
826 niro 1574 is_initrd_supported()
827 niro 528 {
828 niro 1574 # only generate initrds if the cmd exists
829 niro 6835 [[ -x ${INSTALL_ROOT}/sbin/mkinitrd ]] && return 0
830 niro 1574 return 1
831     }
832    
833     install_initrd_chroot()
834     {
835 niro 6829 local CONFIG
836    
837 niro 1574 # only generate initrds if the cmd exists
838     is_initrd_supported || return 0
839    
840 niro 6841 FSMODS="${FORMAT_FILESYSTEM_BOOTHDD} ${FORMAT_FILESYSTEM_ROOTHDD}"
841 niro 2573 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 niro 5003 OTHERMODS=""
847 niro 3202 case ${SPECIALDEVICE} in
848 niro 5575 zotac_intel|i845) FBMODS=""; DRMMODS="i915" ;;
849 niro 4847 zotac_nvidia) FBMODS=""; DRMMODS="nouveau" ;;
850 niro 3256 rangee) FBMODS="" ;; ## fallback to vesafb, viafb does not run on all CLE266 boards
851 niro 4853 # 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 niro 3202 *) FBMODS="uvesafb" ;;
855     esac
856 niro 2573
857 niro 5003 if [[ ${FORMFACTOR} = laptop ]]
858     then
859     OTHERMODS="acpi-cpufreq cpufreq_ondemand cpufreq_conservative cpufreq_powersave"
860     fi
861    
862 niro 2573 # install an appropriate uvesafb.conf
863 niro 6835 CONFIG=${INSTALL_ROOT}/etc/modprobe.d/uvesafb.conf
864 niro 6829 clearconfig
865     addconfig "options uvesafb mode_option=1024x768-32@60 scroll=ywrap"
866 niro 2573
867 niro 3202 # install an appropriate viafb.conf
868 niro 6835 CONFIG=${INSTALL_ROOT}/etc/modprobe.d/viafb.conf
869 niro 6829 clearconfig
870     addconfig "options viafb viafb_mode=1024x768 viafb_refresh=60"
871 niro 3202
872 niro 3260 # install an appropriate i810fb.conf
873 niro 6835 CONFIG=${INSTALL_ROOT}/etc/modprobe.d/i810fb.conf
874 niro 6829 clearconfig
875     addconfig "options i810fb xres=1024 yres=768 bpp=16 mtrr=1 hsync1=30 hsync2=62 vsync1=30 vsync2=60"
876 niro 3260
877 niro 6835 CONFIG=${INSTALL_ROOT}/.installrc
878 niro 6834 clearconfig
879 niro 6850 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 niro 6832 ## enter chroot
883 niro 6834 enter_chroot_installrc
884 niro 258 }
885    
886 niro 1574 is_uuid_supported()
887 niro 1180 {
888 niro 6837 # 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 niro 1574 then
892 niro 6838 if [[ -x $(type -P blkid) ]]
893 niro 1574 then
894 niro 6837 return 0
895 niro 1574 fi
896 niro 6837 else
897 niro 6838 if [[ -x $(type -P busybox.mkinitrd) ]]
898 niro 6837 then
899     # only detect uuids if supported
900     if [[ ! -z $(busybox.mkinitrd | grep blkid) ]]
901     then
902     return 0
903     fi
904     fi
905 niro 1574 fi
906    
907     return 1
908     }
909    
910     get_uuid()
911     {
912 niro 1180 local UUID
913     local SEC_TYPE
914     local TYPE
915 niro 6837 local blkidcmd
916 niro 1574
917 niro 1180 local dev="$1"
918     [[ -z ${dev} ]] && die "no dev given"
919    
920 niro 1187 # check if given device is already an UUID
921     if [[ ${dev/UUID=/}x != ${dev}x ]]
922     then
923     eval "${dev}"
924     else
925 niro 6837 # 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 niro 1187 fi
935 niro 1574 echo "${UUID}"
936 niro 1180 }
937    
938 niro 520 install_system_settings()
939     {
940 niro 6839 local CONFIG
941 niro 6840 local fstype
942 niro 6839
943     # write fstab
944     CONFIG=${INSTALL_ROOT}/etc/fstab
945     clearconfig
946 niro 6840
947     if [[ -n ${BOOTHDD} ]]
948 niro 1574 then
949 niro 6840 if is_uuid_supported
950 niro 6825 then
951 niro 6841 addconfig -e "UUID=$(get_uuid ${BOOTHDD})\t/boot\t${FORMAT_FILESYSTEM_BOOTHDD}\tnoatime,noauto\t1 1"
952 niro 6840 else
953 niro 6841 addconfig -e "${BOOTHDD}\t/boot\t${FORMAT_FILESYSTEM_BOOTHDD}\tnoatime,noauto\t1 1"
954 niro 6825 fi
955 niro 6840 fi
956    
957     if [[ -n ${ROOTHDD} ]]
958     then
959     if is_uuid_supported
960 niro 6825 then
961 niro 6841 addconfig -e "UUID=$(get_uuid ${ROOTHDD})\t/\t${FORMAT_FILESYSTEM_ROOTHDD}\tnoatime\t0 0"
962 niro 6840 else
963 niro 6841 addconfig -e "${ROOTHDD}\t/\t${FORMAT_FILESYSTEM_ROOTHDD}\tnoatime\t0 0"
964 niro 6825 fi
965 niro 1574 fi
966 niro 6840
967 niro 1187 # not needed busybox loads all with swapon -a, even if not mentioned in fstab
968 niro 6839 #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 niro 531
972     # install network config skeleton
973 niro 6835 install -m0644 ${INSTALL_ROOT}/etc/alxconfig-ng/skel/net/net.eth0 ${INSTALL_ROOT}/etc/conf.d/ || die
974 niro 3374
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 niro 6835 sed -i "s:^\(SPLASH_DEV=\).*:\1\"/dev/fb${fbdev}\":" ${INSTALL_ROOT}/etc/splash/splash.conf || die
984 niro 3374 fi
985     fi
986     fi
987 niro 258 }
988    
989 niro 6825 install_umount_rootfs()
990 niro 520 {
991 niro 6825 cd /
992     if [[ -n ${BOOTHDD} ]]
993 niro 1574 then
994 niro 6835 umount ${INSTALL_ROOT}/boot || die
995 niro 1574 fi
996 niro 6825 if [[ -n ${ROOTHDD} ]]
997     then
998 niro 6835 umount ${INSTALL_ROOT} || die
999 niro 6825 fi
1000     if [[ -n ${SWAPHDD} ]]
1001     then
1002     swapoff ${SWAPHDD} || die
1003     fi
1004 niro 280 }
1005 niro 520
1006     install_do_reboot()
1007     {
1008 niro 258 reboot
1009     }
1010    
1011     #################################################
1012 niro 6818 # Install Main Scripts #
1013 niro 258 #################################################
1014    
1015 niro 6825 run_install()
1016 niro 520 {
1017 niro 6825 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 niro 6873 # run hardware detections first to get the disktypes detected
1028     dialog_hardware_detection
1029    
1030 niro 6825 case "${method}" in
1031     auto)
1032 niro 6846 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 niro 6825 export INSTALL_METHOD="${method}"
1042     ;;
1043     normal)
1044 niro 6841 export FORMAT_FILESYSTEM_BOOTHDD="${FORMAT_FILESYSTEM}"
1045     export FORMAT_FILESYSTEM_ROOTHDD="${FORMAT_FILESYSTEM}"
1046 niro 6825 export INSTALL_METHOD="${method}"
1047     ;;
1048     single)
1049 niro 6841 export FORMAT_FILESYSTEM_BOOTHDD=""
1050     export FORMAT_FILESYSTEM_ROOTHDD="${FORMAT_FILESYSTEM}"
1051 niro 6825 export INSTALL_METHOD="${method}"
1052     ;;
1053 niro 6837 flash)
1054     export FORMAT_FILESYSTEM="f2fs"
1055 niro 6841 export FORMAT_FILESYSTEM_BOOTHDD="ext2"
1056     export FORMAT_FILESYSTEM_ROOTHDD="${FORMAT_FILESYSTEM}"
1057 niro 6837 export INSTALL_METHOD="${method}"
1058     ;;
1059 niro 6825 *)
1060 niro 6843 die "Unknown install method '${method}', aborting."
1061 niro 6825 ;;
1062     esac
1063    
1064 niro 6826 dialog_setup_hdd_partitions
1065 niro 258 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 niro 520
1070 niro 258 dialog_install_settings
1071     sleep 1
1072     install_system_settings
1073 niro 1574 install_initrd_chroot
1074 niro 2554
1075     dialog_install_bootsector
1076     install_bootsector_chroot
1077    
1078 niro 258 install_umount_rootfs
1079     dialog_install_successful
1080     }
1081    
1082 niro 6831 # set some proper traps
1083     trap "trap_exit" SIGINT SIGQUIT
1084    
1085 niro 522 dialog_main
1086 niro 258
1087     exit 0