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