Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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