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