Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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