Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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