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