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