Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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