Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2642 - (show annotations) (download)
Wed Apr 2 11:28:21 2014 UTC (10 years, 1 month ago) by niro
File size: 11392 byte(s)
-use new DEFAULT_IMAGEROOT/IMAGEROOT variable
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 # some sane defaults
48 IMAGEROOT="${DEFAULT_IMAGEROOT}"
49 INSTALLROOT="${DEFAULT_INSTALLROOT}"
50 KERNELPKG="${DEFAULT_KERNELPKG}"
51 KERNELOPTS="${DEFAULT_KERNELOPTS}"
52 GRUBLEGACYOPTS=""
53 GRUB2OPTS=""
54 FDISKPARTIONBELOW256MB=0
55 SPECIALDEVICE=""
56 FORMFACTOR="${DEFAULT_FORMFACTOR}"
57 FORMAT_FILESYSTEM="${DEFAULT_FILESYSTEM}"
58
59 # TOTALLINES=linecount of ${CDIMAGENAME}-tarball -1 !
60 # -> now in images.conf
61 CDIMAGENAME=""
62 TOTALLINES=""
63 CURRENTLINE=0
64 if [ -e ${IMAGEROOT}/images.conf ]
65 then
66 source ${IMAGEROOT}/images.conf
67 # check if all required variables are set
68 [[ -z ${CDIMAGENAME} ]] && die "CDIMAGENAME is empty in ${IMAGEROOT}/images.conf"
69 [[ -z ${TOTALLINES} ]] && die "TOTALLINES is empty in ${IMAGEROOT}/images.conf"
70 else
71 die "${IMAGEROOT}/images.conf not found"
72 fi
73
74 ### helper scripts ###
75
76 trap_exit()
77 {
78 is_mounted --location "${INSTALLROOT}/dev" && umount ${INSTALLROOT}/dev
79 is_mounted --location "${INSTALLROOT}/proc" && umount ${INSTALLROOT}/proc
80 is_mounted --location "${INSTALLROOT}/sys" && umount ${INSTALLROOT}/sys
81 is_mounted --location "${INSTALLROOT}/boot" && umount ${INSTALLROOT}/boot
82 is_mounted --location "${INSTALLROOT}" && umount ${INSTALLROOT}
83
84 echo $"Installation aborted."
85 exit 1
86 }
87
88 install_meter()
89 {
90 while [[ ${CURRENTLINE} != ${TOTALLINES} ]]
91 do
92 CURRENTLINE=$(grep -c . /tmp/install.log)
93 PERCENT=$(( ${CURRENTLINE} * 100 / ${TOTALLINES}))
94 echo ${PERCENT}
95 sleep 1
96 done
97 rm -f /tmp/install.log
98 return 0
99 }
100
101 mount_rootfs()
102 {
103 local retval
104
105 if is_mounted --location "${INSTALLROOT}"
106 then
107 echo $"${INSTALLROOT} already mounted" >&2
108 else
109 mount "${ROOTHDD}" "${INSTALLROOT}" || dialog_die $"Could not mount rootfs - drive '${ROOTHDD}' -> '${INSTALLROOT}'"
110 fi
111 [[ -d ${INSTALLROOT}/boot ]] || install -d ${INSTALLROOT}/boot
112 }
113
114 umount_rootfs()
115 {
116 is_mounted --location ${INSTALLROOT}/boot && umount ${INSTALLROOT}/boot
117 is_mounted --location ${INSTALLROOT} && umount ${INSTALLROOT}
118 }
119
120 install_do_reboot()
121 {
122 reboot
123 }
124
125 run_hardware_detection()
126 {
127 local hwinfo
128
129 hwinfo="$(hwinfo --bios --storage --pci --gfxcard --sys)"
130
131 ## check for special devices/clients:
132 ## if zotac a zotac and the disk is a removeable device, then add rootdelay to kernelcmd
133 #local removable=0
134 #if [[ ! -z $(echo "${hwinfo}" | grep -i zotac) ]]
135 #then
136 #for i in /sys/block/[hs]d*/removable
137 #do
138 #if [[ $(< ${i}) = 1 ]]
139 #then
140 #removable=1
141 #fi
142 #done
143 ## smartcard = udevadm info -n /dev/sda -a | grep -i 'configuration.*card'
144
145 ## only add this for grub legacy, grub2 detect these settings on its own
146 #export GRUBLEGACYOPTS="rootdelay=8"
147 ## there are to zotac types in the wild, nvidia based gfx and intel
148 #if [[ ! -z $(echo "${hwinfo}" | grep -i nouveau) ]]
149 #then
150 #export SPECIALDEVICE="zotac_nvidia"
151 #else
152 #export SPECIALDEVICE="zotac_intel"
153 #fi
154 #fi
155
156 # check for special devices/clients:
157 # if a rangee and disk ist smaller then 256mb move partion one block further ahead
158 if [[ ! -z $(echo "${hwinfo}" | grep -i CLE266) ]]
159 then
160 # for a rangee always define partion startblock +1
161 export FDISKPARTIONBELOW256MB="1"
162 export SPECIALDEVICE="rangee"
163 export GRUBLEGACYOPTS=""
164 fi
165
166 # check for special devices/clients:
167 # check for maxdata / i810/ i815 Chipsets and disable KMS and use i810fb frambuffer
168 if [[ ! -z $(echo "${hwinfo}" | grep -i i810) ]] || [[ ! -z $(echo "${hwinfo}" | grep -i i815) ]]
169 then
170 export SPECIALDEVICE="maxdata"
171 export GRUBLEGACYOPTS=""
172 fi
173
174 # check for special devices/clients:
175 # check for laptops and activate cpufreq scaling
176 if [[ $(echo "${hwinfo}" | grep 'Formfactor:' | sed 's:.*Formfactor\:\ \"\(.*\)\":\1:') = laptop ]]
177 then
178 export FORMFACTOR="laptop"
179 export KERNELOPTS="${KERNELOPTS} cpufreq.governor=ondemand"
180 fi
181 }
182
183 run_hardware_detection_disks()
184 {
185 local bootdev
186
187 # all disks but exclude ramdisks
188 export ALL_DISKS=$(get_hwinfo disk | sed '/\/dev\/ram[0-9].*/d')
189 # remove the boot device from ALL_DISKS if it was an usbstick
190 if [[ $(grep '[[:space:]]/mnt/cdrom[[:space:]]' /proc/mounts | cut -d' ' -f3) != iso9660 ]]
191 then
192 bootdev="$(grep '[[:space:]]/mnt/cdrom[[:space:]]' /proc/mounts | cut -d' ' -f1 | sed 's:[0-9]::g')"
193 export ALL_DISKS=$(echo "${ALL_DISKS}" | grep -v "${bootdev}")
194 fi
195 export ALL_CDROMS="$(get_hwinfo cdrom)"
196 }
197
198 setup_hdd_partitions_auto()
199 {
200 ROOTHDD="${HDD}1"
201
202 # sanity check - should not happen
203 if is_mounted --device "${ROOTHDD}"
204 then
205 echo "partition: device ${ROOTHDD} is already mounted, umount it" >&2
206 umount "${ROOTHDD}"
207 fi
208
209 # run this only if FDISKPARTITIONBELOW256MB is not already 1
210 if [[ ${FDISKPARTIONBELOW256MB} != 1 ]]
211 then
212 if device_minimum_size "${HDD}" 256
213 then
214 FDISKPARTIONBELOW256MB=1
215 else
216 FDISKPARTIONBELOW256MB=0
217 fi
218 fi
219
220 ## delete disk
221 dd if=/dev/zero of=${HDD} count=1 &> /dev/null || dialog_die
222
223 if [[ ${FDISKPARTIONBELOW256MB} = 1 ]]
224 then
225 ## setup one bootable partition
226 #1. n= new disk
227 #2. p= primary disk
228 #3. 1= first partition
229 #4. 2= default sector start // small disk needs more space for grub2 mbr sector
230 #5. ''= defaul sector end
231 #6. a= bootable flag
232 #7. 1= boot flag for partition 1
233 #8. w= write/quit
234 fdisk ${HDD} &> /dev/null << EOF
235 n
236 p
237 1
238 2
239
240 a
241 1
242 w
243 EOF
244 else
245 ## setup one bootable partition
246 #1. n= new disk
247 #2. p= primary disk
248 #3. 1= first partition
249 #4. ''= default sector start
250 #5. ''= defaul sector end
251 #6. a= bootable flag
252 #7. 1= boot flag for partition 1
253 #8. w= write/quit
254 fdisk ${HDD} &> /dev/null << EOF
255 n
256 p
257 1
258
259
260 a
261 1
262 w
263 EOF
264 fi
265 }
266
267 setup_hdd_partitions_manual()
268 {
269 ROOTHDD="${HDD}1"
270 SWAPHDD=""
271 BOOTHDD=""
272 cfdisk ${HDD} || dialog_die
273 }
274
275 setup_hdd_format()
276 {
277 # sanity check - should not happen
278 if is_mounted --device "${ROOTHDD}"
279 then
280 echo "format: device ${ROOTHDD} is already mounted, umount it" >&2
281 umount "${ROOTHDD}"
282 fi
283
284 mkfs."${FORMAT_FILESYSTEM}" -q "${ROOTHDD}" || dialog_die
285 }
286
287 install_system_image()
288 {
289 pushd ${INSTALLROOT} > /dev/null
290 tar xvjpf ${IMAGEROOT}}/${CDIMAGENAME} -C ${INSTALLROOT}
291 popd > /dev/null
292 }
293
294 install_system_settings()
295 {
296 local CONFIG
297
298 # write fstab
299 CONFIG="${INSTALLROOT}/etc/fstab"
300 clearconfig
301 addconfig -e "UUID=$(get_uuid ${ROOTHDD})\t/\t${FORMAT_FILESYSTEM}\tnoatime,noauto\t1 1"
302 addconfig -e "proc\t/proc\tproc\tdefaults\t0 0"
303 addconfig -e "shm\t/dev/shm\ttmpfs\tdefaults\t0 0"
304
305 # install network config skeleton
306 CONFIG="${INSTALLROOT}/etc/conf.d/net.eth0"
307 clearconfig
308 addconfig 'ONBOOT="yes"'
309 addconfig 'NETWORKING="dhcp"'
310
311 # intel framebuffer quirk
312 CONFIG="${INSTALLROOT}/etc/splash/splash.conf"
313 if [ -e ${CONFIG} ] && [ -e /proc/fb ]
314 then
315 if [[ ! -z $(grep 'inteldrmfb' /proc/fb) ]]
316 then
317 fbdev=$(grep 'inteldrmfb' /proc/fb | sed 's:\([0-9]\).*:\1:')
318 [[ ${fbdev} != 0 ]] && sed -i "s:^\(SPLASH_DEV=\).*:\1\"/dev/fb${fbdev}\":" ${CONFIG} || dialog_die
319 fi
320 fi
321 }
322
323
324 ### 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 run_install_normal()
479 {
480 task_hardware_detection
481
482 task_setup_hdd_partitions_manual
483 dialog_setup_hdd_format
484 setup_hdd_format > /dev/null
485 mount_rootfs
486 (install_system_image > /tmp/install.log) 2> /tmp/install_errors.log | install_meter | dialog_install_system_image
487
488 dialog_install_settings
489 sleep 1
490 install_system_settings
491 if is_initrd_supported
492 then
493 dialog_install_initrd
494 initrd_config
495 initrd_install
496 fi
497
498 dialog_install_bootsector
499 bootloader_config
500 bootloader_install
501
502 umount_rootfs
503 dialog_install_successful
504 }
505
506 run_install_auto()
507 {
508 task_hardware_detection
509
510 task_setup_hdd_partitions_auto
511 dialog_setup_hdd_format
512 setup_hdd_format > /dev/null
513 mount_rootfs
514 (install_system_image > /tmp/install.log) 2> /tmp/install_errors.log | install_meter | dialog_install_system_image
515
516 dialog_install_settings
517 sleep 1
518 install_system_settings
519 if is_initrd_supported
520 then
521 dialog_install_initrd
522 initrd_config
523 initrd_install
524 fi
525
526 dialog_install_bootsector
527 bootloader_config
528 bootloader_install
529
530 umount_rootfs
531 dialog_install_successful
532 }
533
534 # set some proper traps
535 trap "trap_exit" SIGINT SIGQUIT
536
537 task_main
538
539 exit 0