Magellan Linux

Contents of /trunk/installer-simple/bin/installer.sh.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2892 - (show annotations) (download)
Fri Jul 31 11:40:56 2015 UTC (8 years, 9 months ago) by niro
File size: 16016 byte(s)
-added more hardware quirks
1 #!/bin/bash
2 # $Id$
3 #
4 # Simple Installation Script
5 # merged from alxinstall-ng and mcore-installer
6 #
7 # Niels Rogalla <niro@magellan-linux.de>
8 #
9
10 # setup locales
11 TEXTDOMAIN=installer
12
13 # include dir
14 INSTALLER_LIBDIR="%LIBDIR%"
15
16 # TOTALLINES=linecount of ${CDIMAGENAME}-tarball -1 !
17 # -> now in images.conf
18 CURRENTLINE=0
19
20 die()
21 {
22 echo "Error: $@"
23 exit 1
24 }
25
26 # load common includes
27 for inc in %SYSCONFDIR%/installer.conf \
28 ${INSTALLER_LIBDIR}/functions/common.sh \
29 ${INSTALLER_LIBDIR}/functions/common-dialogs.sh \
30 ${INSTALLER_LIBDIR}/functions/hwdetection.sh \
31 ${INSTALLER_LIBDIR}/functions/bootloader.sh \
32 ${INSTALLER_LIBDIR}/functions/initrd-tools.sh \
33 ${INSTALLER_LIBDIR}/functions/installer-dialogs.sh
34 do
35 if [ -e ${inc} ]
36 then
37 source "${inc}"
38 else
39 die "'${inc}' not found"
40 fi
41 done
42
43 ### System/Config Version
44 VERSION="%VERSIONTAG%"
45 TITLE="${DEFAULT_TITLE} - ${VERSION}"
46
47 # initialize global variables so they are exportable
48 # some sane defaults
49 INSTALL_METHOD=""
50 LIVEROOT="${DEFAULT_LIVEROOT}"
51 IMAGEROOT="${DEFAULT_IMAGEROOT}"
52 INSTALLROOT="${DEFAULT_INSTALLROOT}"
53 KERNELPKG="${DEFAULT_KERNELPKG}"
54 KERNELOPTS="${DEFAULT_KERNELOPTS}"
55 GRUBLEGACYOPTS=""
56 GRUB2OPTS=""
57 FDISKPARTIONBELOW256MB=0
58 SPECIALDEVICE=""
59 FORMFACTOR="${DEFAULT_FORMFACTOR}"
60 FORMAT_FILESYSTEM="${DEFAULT_FILESYSTEM}"
61 FLASHDISK=0
62
63 # TOTALLINES=linecount of ${CDIMAGENAME}-tarball -1 !
64 # -> now in images.conf
65 CDIMAGENAME=""
66 TOTALLINES=""
67 CURRENTLINE=0
68 if [ -e ${IMAGEROOT}/images.conf ]
69 then
70 source ${IMAGEROOT}/images.conf
71 # check if all required variables are set
72 [[ -z ${CDIMAGENAME} ]] && die "CDIMAGENAME is empty in ${IMAGEROOT}/images.conf"
73 [[ -z ${TOTALLINES} ]] && die "TOTALLINES is empty in ${IMAGEROOT}/images.conf"
74 else
75 die "${IMAGEROOT}/images.conf not found"
76 fi
77
78 ### helper scripts ###
79
80 trap_exit()
81 {
82 is_mounted --location "${INSTALLROOT}/dev" && umount ${INSTALLROOT}/dev
83 is_mounted --location "${INSTALLROOT}/proc" && umount ${INSTALLROOT}/proc
84 is_mounted --location "${INSTALLROOT}/sys" && umount ${INSTALLROOT}/sys
85 is_mounted --location "${INSTALLROOT}/boot" && umount ${INSTALLROOT}/boot
86 is_mounted --location "${INSTALLROOT}" && umount ${INSTALLROOT}
87 [[ -n ${SWAPHDD} ]] && swapoff ${SWAPHDD}
88
89 echo $"Installation aborted."
90 exit 1
91 }
92
93 install_meter()
94 {
95 while [[ ${CURRENTLINE} != ${TOTALLINES} ]]
96 do
97 CURRENTLINE=$(grep -c . /tmp/install.log)
98 PERCENT=$(( ${CURRENTLINE} * 100 / ${TOTALLINES}))
99 echo ${PERCENT}
100 sleep 1
101 done
102 rm -f /tmp/install.log
103 return 0
104 }
105
106 mount_rootfs()
107 {
108 local retval
109
110 if [[ -n ${SWAPHDD} ]]
111 then
112 swapon ${SWAPHDD} || dialog_die $"Could not enable swap space '${SWAPHDD}'"
113 fi
114
115 if [[ -n ${ROOTHDD} ]]
116 then
117 if is_mounted --location "${INSTALLROOT}"
118 then
119 echo $"${INSTALLROOT} already mounted" >&2
120 else
121 mount -t "${FORMAT_FILESYSTEM_ROOTHDD}" "${ROOTHDD}" "${INSTALLROOT}" || dialog_die $"Could not mount rootfs - drive '${ROOTHDD}' -> '${INSTALLROOT}'"
122 fi
123 fi
124
125 [[ -d ${INSTALLROOT}/boot ]] || install -d ${INSTALLROOT}/boot
126
127 if [[ -n ${BOOTHDD} ]]
128 then
129 if is_mounted --location "${INSTALLROOT}"/boot
130 then
131 echo $"${INSTALLROOT}/boot already mounted" >&2
132 else
133 mount -t "${FORMAT_FILESYSTEM_BOOTHDD}" "${BOOTHDD}" "${INSTALLROOT}"/boot || dialog_die $"Could not mount bootfs - drive '${BOOTHDD}' -> '${INSTALLROOT}/boot'"
134 fi
135 fi
136 }
137
138 umount_rootfs()
139 {
140 is_mounted --location ${INSTALLROOT}/boot && umount ${INSTALLROOT}/boot
141 is_mounted --location ${INSTALLROOT} && umount ${INSTALLROOT}
142
143 if [[ -n ${SWAPHDD} ]]
144 then
145 swapoff ${SWAPHDD} || die
146 fi
147 }
148
149 install_do_reboot()
150 {
151 reboot
152 }
153
154 run_hardware_detection()
155 {
156 local hwinfo
157
158 hwinfo="$(hwinfo --bios --storage --pci --gfxcard --sys)"
159
160 # check for special devices/clients:
161 # if zotac a zotac and the disk is a removeable device, then add rootdelay to kernelcmd
162 local removable=0
163 if [[ ! -z $(echo "${hwinfo}" | grep -i zotac) ]]
164 then
165 for i in /sys/block/[hs]d*/removable
166 do
167 if [[ $(< ${i}) = 1 ]]
168 then
169 removable=1
170 # we assume that all removable disks are flash disks on a zotac
171 export FLASHDISK=1
172 fi
173 done
174 # smartcard = udevadm info -n /dev/sda -a | grep -i 'configuration.*card'
175
176 # only add this for grub legacy, grub2 detect these settings on its own
177 export GRUBLEGACYOPTS="rootdelay=8"
178 # there are to zotac types in the wild, nvidia based gfx and intel
179 if [[ ! -z $(echo "${hwinfo}" | grep -i nouveau) ]]
180 then
181 export SPECIALDEVICE="zotac_nvidia"
182 else
183 export SPECIALDEVICE="zotac_intel"
184 fi
185 fi
186
187 # check for special devices/clients:
188 # if a rangee and disk ist smaller then 256mb move partion one block further ahead
189 if [[ ! -z $(echo "${hwinfo}" | grep -i CLE266) ]]
190 then
191 # for a rangee always define partion startblock +1
192 export FDISKPARTIONBELOW256MB="1"
193 export SPECIALDEVICE="rangee"
194 export GRUBLEGACYOPTS=""
195 fi
196
197 # check for special devices/clients:
198 # check for maxdata / i810/ i815 Chipsets and disable KMS and use i810fb frambuffer
199 if [[ ! -z $(echo "${hwinfo}" | grep -i i810) ]] || [[ ! -z $(echo "${hwinfo}" | grep -i i815) ]]
200 then
201 export SPECIALDEVICE="maxdata"
202 export GRUBLEGACYOPTS=""
203 fi
204
205 # check for i845 Chipsets and enable KMS and use 915 drm driver later in initrd
206 if [[ ! -z $(echo "${hwinfo}" | grep -i i845) ]]
207 then
208 export SPECIALDEVICE="i845"
209 # unset default video=1024x768 opt or the drm driver breaks
210 export KERNELOPTS="quiet"
211 export GRUBLEGACYOPTS=""
212 # enable full kms support
213 export GRUB2GFXPAYLOAD="keep"
214 fi
215
216 # check for radeon gfxcards
217 if [[ ! -z $(echo "${hwinfo}" | grep -i radeon) ]]
218 then
219 # enable full kms support
220 export GRUB2GFXPAYLOAD="keep"
221 fi
222
223 # requires nomsi to prevent massive IRQ error spam
224 # see: http://ubuntuforums.org/showthread.php?t=1234983
225 if [[ ! -z $(echo "${hwinfo}" | grep -i 'P5VD2-X') ]] || [[ ! -z $(echo "${hwinfo}" | grep -i 'VT8237') ]] || [[ ! -z $(echo "${hwinfo}" | grep -i 'VX700') ]]
226 then
227 export SPECIALDEVICE="nomsi"
228 export KERNELOPTS="${KERNELOPTS} pci=nomsi,noaer"
229 fi
230
231 # check for special devices/clients:
232 # check for laptops and activate cpufreq scaling
233 if [[ $(echo "${hwinfo}" | grep 'Formfactor:' | sed 's:.*Formfactor\:\ \"\(.*\)\":\1:') = laptop ]]
234 then
235 export FORMFACTOR="laptop"
236 export KERNELOPTS="${KERNELOPTS} cpufreq.governor=ondemand"
237 fi
238 }
239
240 run_hardware_detection_disks()
241 {
242 local bootdev
243
244 # all disks but exclude ramdisks
245 export ALL_DISKS=$(get_hwinfo disk | sed '/\/dev\/ram[0-9].*/d')
246 # remove the boot device from ALL_DISKS if it was an usbstick
247 if [[ $(grep '[[:space:]]${LIVEROOT}[[:space:]]' /proc/mounts | cut -d' ' -f3) != iso9660 ]]
248 then
249 bootdev=$(grep "[[:space:]]${LIVEROOT}[[:space:]]" /proc/mounts | cut -d' ' -f1 | sed 's:[0-9]::g')
250 export ALL_DISKS=$(echo "${ALL_DISKS}" | grep -v "${bootdev}")
251 fi
252 export ALL_CDROMS="$(get_hwinfo cdrom)"
253 }
254
255 setup_hdd_partitions()
256 {
257 # sanity check - should not happen
258 if is_mounted --device "${ROOTHDD}"
259 then
260 echo "partition: device ${ROOTHDD} is already mounted, umount it" >&2
261 umount "${ROOTHDD}"
262 fi
263 if [[ -n ${BOOTHDD} ]]
264 then
265 if is_mounted --device "${BOOTHDD}"
266 then
267 echo "partition: device ${BOOTHDD} is already mounted, umount it" >&2
268 umount "${BOOTHDD}"
269 fi
270 fi
271
272 if [[ ${INSTALL_METHOD} = auto ]]
273 then
274 # run this only if FDISKPARTITIONBELOW256MB is not already 1
275 if [[ ${FDISKPARTIONBELOW256MB} != 1 ]]
276 then
277 if device_minimum_size "${HDD}" 256
278 then
279 FDISKPARTIONBELOW256MB=1
280 else
281 FDISKPARTIONBELOW256MB=0
282 fi
283 fi
284
285 ## delete disk
286 dd if=/dev/zero of=${HDD} count=1 &> /dev/null || dialog_die
287
288 if [[ ${FLASHDISK} = 1 ]]
289 then
290 if [[ ${FDISKPARTIONBELOW256MB} = 1 ]]
291 then
292 ## setup one bootable partition
293 # 1. n= new disk
294 # 2. p= primary disk
295 # 3. 1= first partition
296 # 4. 2= default sector start // small disk needs more space for grub2 mbr sector
297 # 5. ''= defaul sector end
298 # 6. a= bootable flag
299 # 7. 1= boot flag for partition 1
300 # 8. n= new disk
301 #10. p= primary disk
302 #11. 2= second partition
303 #12. ''= default sector start
304 #13. ''= defaul sector end
305 #14. w= write/quit
306 fdisk ${HDD} &> /dev/null << EOF
307 n
308 p
309 1
310 2
311 +50M
312 a
313 1
314 n
315 p
316 2
317
318
319 w
320 EOF
321 else
322 ## setup one bootable partition
323 # 1. n= new disk
324 # 2. p= primary disk
325 # 3. 1= first partition
326 # 4. ''= default sector start
327 # 5. ''= defaul sector end
328 # 6. a= bootable flag
329 # 7. 1= boot flag for partition 1
330 # 8. n= new disk
331 #10. p= primary disk
332 #11. 2= second partition
333 #12. ''= default sector start
334 #13. ''= defaul sector end
335 #14. w= write/quit
336 fdisk ${HDD} &> /dev/null << EOF
337 n
338 p
339 1
340
341 +50M
342 a
343 1
344 n
345 p
346 2
347
348
349 w
350 EOF
351 fi
352 else
353 if [[ ${FDISKPARTIONBELOW256MB} = 1 ]]
354 then
355 ## setup one bootable partition
356 #1. n= new disk
357 #2. p= primary disk
358 #3. 1= first partition
359 #4. 2= default sector start // small disk needs more space for grub2 mbr sector
360 #5. ''= defaul sector end
361 #6. a= bootable flag
362 #7. 1= boot flag for partition 1
363 #8. w= write/quit
364 fdisk ${HDD} &> /dev/null << EOF
365 n
366 p
367 1
368 2
369
370 a
371 1
372 w
373 EOF
374 else
375 ## setup one bootable partition
376 #1. n= new disk
377 #2. p= primary disk
378 #3. 1= first partition
379 #4. ''= default sector start
380 #5. ''= defaul sector end
381 #6. a= bootable flag
382 #7. 1= boot flag for partition 1
383 #8. w= write/quit
384 fdisk ${HDD} &> /dev/null << EOF
385 n
386 p
387 1
388
389
390 a
391 1
392 w
393 EOF
394 fi
395 fi
396 else
397 cfdisk ${HDD} || dialog_die
398 fi
399 }
400
401 setup_hdd_format()
402 {
403 install -d /tmp
404 :> /tmp/format.log
405
406 if [[ -n ${SWAPHDD} ]]
407 then
408 # sanity check - should not happen
409 if is_mounted --device "${SWAPHDD}"
410 then
411 echo "format: device ${SWAPHDD} is already mounted, umount it" >&2
412 umount "${SWAPHDD}"
413 fi
414 mkswap ${SWAPHDD} || die
415 fi
416
417 if [[ -n ${BOOTHDD} ]]
418 then
419 # sanity check - should not happen
420 if is_mounted --device "${BOOTHDD}"
421 then
422 echo "format: device ${BOOTHDD} is already mounted, umount it" >&2
423 umount "${BOOTHDD}"
424 fi
425
426 mkfs."${FORMAT_FILESYSTEM_BOOTHDD}" "${BOOTHDD}" &>> /tmp/format.log || dialog_die
427 fi
428
429 if [[ -n ${ROOTHDD} ]]
430 then
431 # sanity check - should not happen
432 if is_mounted --device "${ROOTHDD}"
433 then
434 echo "format: device ${ROOTHDD} is already mounted, umount it" >&2
435 umount "${ROOTHDD}"
436 fi
437
438 mkfs."${FORMAT_FILESYSTEM_ROOTHDD}" "${ROOTHDD}" &>> /tmp/format.log || dialog_die
439 fi
440 }
441
442 install_system_image()
443 {
444 pushd ${INSTALLROOT} > /dev/null
445 tar xvjpf ${IMAGEROOT}/${CDIMAGENAME} -C ${INSTALLROOT}
446 popd > /dev/null
447 }
448
449 install_system_settings()
450 {
451 local CONFIG
452
453 # write fstab
454 CONFIG="${INSTALLROOT}/etc/fstab"
455 clearconfig
456 if [[ -n ${BOOTHDD} ]]
457 then
458 addconfig -e "UUID=$(get_uuid ${BOOTHDD})\t/\t${FORMAT_FILESYSTEM_BOOTHDD}\tnoatime\t1 1"
459 fi
460 if [[ -n ${ROOTHDD} ]]
461 then
462 addconfig -e "UUID=$(get_uuid ${ROOTHDD})\t/\t${FORMAT_FILESYSTEM_ROOTHDD}\tnoatime\t0 0"
463 fi
464 if [[ -n ${SWAPHDD} ]]
465 then
466 addconfig -e "UUID='$(get_uuid ${SWAPHDD})'\tswap\tswap\tpri=1\t0 0"
467 fi
468 addconfig -e "proc\t/proc\tproc\tdefaults\t0 0"
469 addconfig -e "shm\t/dev/shm\ttmpfs\tdefaults\t0 0"
470
471 # install network config skeleton
472 CONFIG="${INSTALLROOT}/etc/conf.d/net.eth0"
473 clearconfig
474 addconfig 'ONBOOT="yes"'
475 addconfig 'NETWORKING="dhcp"'
476
477 # intel framebuffer quirk
478 CONFIG="${INSTALLROOT}/etc/splash/splash.conf"
479 if [ -e ${CONFIG} ] && [ -e /proc/fb ]
480 then
481 if [[ ! -z $(grep 'inteldrmfb' /proc/fb) ]]
482 then
483 fbdev=$(grep 'inteldrmfb' /proc/fb | sed 's:\([0-9]\).*:\1:')
484 [[ ${fbdev} != 0 ]] && sed -i "s:^\(SPLASH_DEV=\).*:\1\"/dev/fb${fbdev}\":" ${CONFIG} || dialog_die
485 fi
486 fi
487 }
488
489
490 ### installer dialogs ###
491
492 dialog_die()
493 {
494 ERROR="$1"
495 RETVAL="$?"
496 dialog_install_failure
497 exit 1
498 }
499
500 dialog_warning()
501 {
502 local retval
503
504 yesnobox $"\Z1 !!! Warning !!! \Zn\n\n\This harddrive will be irreversibly erased.\n\n\Do you want to continue ?"
505 retval=$?
506 if [[ ${retval} -eq 1 ]]
507 then
508 clear
509 echo $"The process was aborted."
510 exit 1
511 fi
512 }
513
514
515 ### installer tasks ###
516
517 task_setup_system_menu()
518 {
519 local mode
520 local retval
521
522 mode="$(dialog_setup_system_menu)"
523 retval=$?
524 [[ ${retval} -eq 1 ]] && return 1
525 if [[ ${retval} -eq 0 ]]
526 then
527 case "${mode}" in
528 "1") run_install auto ;;
529 "2") run_install normal ;;
530 "") task_setup_system_menu;;
531 esac
532 fi
533 }
534
535 task_hardware_detection()
536 {
537 local message
538
539 run_hardware_detection_disks
540
541 message+=$"Harddrives:\n"
542
543 if [[ ! -z ${ALL_DISKS} ]]
544 then
545 for i in ${ALL_DISKS}
546 do
547 message+="\Z3${i}\Zn "
548 done
549 message+="\n"
550 fi
551
552 if [[ ! -z ${ALL_CDROMS} ]]
553 then
554 message+="\n"
555 message+=$"Optical disk drives:\n"
556 for i in ${ALL_CDROMS}
557 do
558 message+="\Z3${i}\Zn"
559 done
560 message+="\n"
561 fi
562
563 # other devices
564 run_hardware_detection
565 case "${SPECIALDEVICE}" in
566 zotac*) message+=$"\n\Z2Zotac device detected.\Zn" ;;
567 rangee) message+=$"\n\Z2Rangee device detected.\Zn" ;;
568 maxdata) message+=$"\n\Z2Maxdata device detected.\Zn" ;;
569 i845) message+=$"\n\Z2Intel i845 VGA device detected.\Zn" ;;
570 nomsi) message+=$"\n\Z2Mainboard with P5VD2-X/VT8237/VX700 chipset detected.\Zn"
571 message+=$"\n\Z2Disabling Message Signaled Interrupts (MSI) capability of the kernel.\Zn" ;;
572 *) message+=$"\n\ZnCommon device detected.\Zn" ;;
573 esac
574 if [[ ${FORMFACTOR} = laptop ]]
575 then
576 message+=$"\n\ZnFormfactor Laptop, activating 'ondemand' powersaving mode.\Zn"
577 fi
578 if [[ ${FLASHDISK} = 1 ]]
579 then
580 message+=$"\n\ZnFlash memory detected.\Zn"
581 message+=$"\n\ZnF2FS will be used as default filesystem withn the auto installation mode.\Zn"
582 fi
583
584 messagebox -y 12 -h $"Detected hardware:" "${message}"
585 }
586
587 task_setup_hdd_partitions()
588 {
589 local i
590 local retval
591
592 if [[ -z ${ALL_DISKS} ]]
593 then
594 dialog_no_harddrive_found
595 exit 1
596 else
597 HDD=$(dialog_select_target_harddrive)
598 retval=$?
599 [[ ${retval} -eq 1 ]] && return 1
600 if [[ ${retval} -eq 0 ]]
601 then
602 dialog_setup_hdd_info
603 setup_hdd_partitions
604 fi
605 fi
606 }
607
608 task_main()
609 {
610 local method=0
611 local retval
612
613 while [[ ${method} -le 2 ]]
614 do
615 method=$(dialog_main)
616 retval=$?
617 [[ ${retval} -eq 1 ]] && exit 1
618 if [[ ${retval} -eq 0 ]]
619 then
620 case ${method} in
621 "1") task_setup_system_menu ;;
622 "2") task_hardware_detection ;;
623 "3") install_do_reboot ;;
624 "4") /bin/bash --login -i ;;
625 esac
626 fi
627 done
628 }
629
630 run_install()
631 {
632 local method="$1"
633
634 task_hardware_detection
635
636 case "${method}" in
637 auto)
638 if [[ ${FLASHDISK} = 1 ]]
639 then
640 export BOOTHDD="${HDD}1"
641 export SWAPHDD=""
642 export ROOTHDD="${HDD}2"
643 export FORMAT_FILESYSTEM_BOOTHDD="f2fs"
644 export FORMAT_FILESYSTEM_ROOTHDD="ext2"
645 else
646 export BOOTHDD=""
647 export SWAPHDD=""
648 export ROOTHDD="${HDD}1"
649 export FORMAT_FILESYSTEM_BOOTHDD=""
650 export FORMAT_FILESYSTEM_ROOTHDD="${FORMAT_FILESYSTEM}"
651 fi
652 export INSTALL_METHOD="${method}"
653 ;;
654 normal)
655 export BOOTHDD="${HDD}1"
656 export SWAPHDD="${HDD}2"
657 export ROOTHDD="${HDD}3"
658 export FORMAT_FILESYSTEM_BOOTHDD="${FORMAT_FILESYSTEM}"
659 export FORMAT_FILESYSTEM_ROOTHDD="${FORMAT_FILESYSTEM}"
660 export INSTALL_METHOD="${method}"
661 ;;
662 single)
663 export BOOTHDD=""
664 export SWAPHDD=""
665 export ROOTHDD="${HDD}1"
666 export FORMAT_FILESYSTEM_BOOTHDD=""
667 export FORMAT_FILESYSTEM_ROOTHDD="${FORMAT_FILESYSTEM}"
668 export INSTALL_METHOD="${method}"
669 ;;
670 flash)
671 export BOOTHDD="${HDD}1"
672 export SWAPHDD=""
673 export ROOTHDD="${HDD}2"
674 export FORMAT_FILESYSTEM_BOOTHDD="${FORMAT_FILESYSTEM}"
675 export FORMAT_FILESYSTEM_ROOTHDD="f2fs"
676 export INSTALL_METHOD="${method}"
677 ;;
678 *)
679 die "Unknown install method '${method}', aborting."
680 ;;
681 esac
682
683 task_setup_hdd_partitions
684 dialog_setup_hdd_format
685 setup_hdd_format > /dev/null
686 mount_rootfs
687 (install_system_image > /tmp/install.log) 2> /tmp/install_errors.log | install_meter | dialog_install_system_image
688
689 dialog_install_settings
690 sleep 1
691 install_system_settings
692 if is_initrd_supported
693 then
694 dialog_install_initrd
695 initrd_config
696 initrd_install
697 fi
698
699 dialog_install_bootsector
700 bootloader_config
701 bootloader_install
702
703 umount_rootfs
704 dialog_install_successful
705 }
706
707 # set some proper traps
708 trap "trap_exit" SIGINT SIGQUIT
709
710 task_main
711
712 exit 0