Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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