Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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