--- trunk/installer-simple/bin/installer.sh.in 2014/01/07 13:56:51 2424 +++ trunk/installer-simple/bin/installer.sh.in 2016/06/13 15:03:52 2948 @@ -7,8 +7,9 @@ # Niels Rogalla # -# ignore the environment -LC_ALL=C +# setup locales +TEXTDOMAIN=installer + # include dir INSTALLER_LIBDIR="%LIBDIR%" @@ -27,6 +28,8 @@ ${INSTALLER_LIBDIR}/functions/common.sh \ ${INSTALLER_LIBDIR}/functions/common-dialogs.sh \ ${INSTALLER_LIBDIR}/functions/hwdetection.sh \ + ${INSTALLER_LIBDIR}/functions/bootloader.sh \ + ${INSTALLER_LIBDIR}/functions/initrd-tools.sh \ ${INSTALLER_LIBDIR}/functions/installer-dialogs.sh do if [ -e ${inc} ] @@ -37,28 +40,50 @@ fi done -# TOTALLINES=linecount of ${CDIMAGENAME}-tarball -1 ! -# -> now in images.conf -CDIMAGENAME="" -TOTALLINES="" -CURRENTLINE=0 -if [ -e /mnt/cdrom/system/images.conf ] -then - source /mnt/cdrom/system/images.conf - # check if all required variables are set - [[ -z ${CDIMAGENAME} ]] && die "CDIMAGENAME is empty in /mnt/cdrom/system/images.conf" - [[ -z ${TOTALLINES} ]] && die "TOTALLINES is empty in /mnt/cdrom/system/images.conf" -else - die "/mnt/cdrom/system/images.conf not found" -fi +# fetch cmdline +for argv in $* +do + case $1 in + --liveroot) shift; cmdliveroot="$1" ;; + --imageroot) shift; cmdimageroot="$1" ;; + --installroot) shift; cmdinstallroot="$1" ;; + --filesystem) shift; cmdformatfilesystem="$1" ;; + --help) + echo "$0 options:" + echo " --liveroot [path] - override default liveroot" + echo " --imageroot [path] - override default imageroot" + echo " --installroot [path] - override default installroot" + echo " --filesystem [fstype] - override default filesystem used to format the disk" + exit 0 ;; + esac + shift +done ### System/Config Version VERSION="%VERSIONTAG%" TITLE="${DEFAULT_TITLE} - ${VERSION}" +# initialize global variables so they are exportable # some sane defaults -CDROOT="${DEFAULT_CDROOT}" -INSTALLROOT="${DEFAULT_INSTALLROOT}" +INSTALL_METHOD="" +if [[ -n ${cmdliveroot} ]] +then + LIVEROOT="${cmdliveroot}" +else + LIVEROOT="${DEFAULT_LIVEROOT}" +fi +if [[ -n ${cmdimageroot} ]] +then + IMAGEROOT="${cmdimageroot}" +else + IMAGEROOT="${DEFAULT_IMAGEROOT}" +fi +if [[ -n ${cmdinstallroot} ]] +then + INSTALLROOT="${cmdinstallroot}" +else + INSTALLROOT="${DEFAULT_INSTALLROOT}" +fi KERNELPKG="${DEFAULT_KERNELPKG}" KERNELOPTS="${DEFAULT_KERNELOPTS}" GRUBLEGACYOPTS="" @@ -66,11 +91,30 @@ FDISKPARTIONBELOW256MB=0 SPECIALDEVICE="" FORMFACTOR="${DEFAULT_FORMFACTOR}" -FORMAT_FILESYSTEM="${DEFAULT_FILESYSTEM}" +if [[ -n ${cmdformatfilesystem} ]] +then + FORMAT_FILESYSTEM="${cmdformatfilesystem}" +else + FORMAT_FILESYSTEM="${DEFAULT_FILESYSTEM}" +fi +FLASHDISK=0 -################################################# -# DIALOG BOXEN # -################################################# +# TOTALLINES=linecount of ${CDIMAGENAME}-tarball -1 ! +# -> now in images.conf +CDIMAGENAME="" +TOTALLINES="" +CURRENTLINE=0 +if [ -e ${IMAGEROOT}/images.conf ] +then + source ${IMAGEROOT}/images.conf + # check if all required variables are set + [[ -z ${CDIMAGENAME} ]] && die "CDIMAGENAME is empty in ${IMAGEROOT}/images.conf" + [[ -z ${TOTALLINES} ]] && die "TOTALLINES is empty in ${IMAGEROOT}/images.conf" +else + die "${IMAGEROOT}/images.conf not found" +fi + +### helper scripts ### trap_exit() { @@ -79,278 +123,76 @@ is_mounted --location "${INSTALLROOT}/sys" && umount ${INSTALLROOT}/sys is_mounted --location "${INSTALLROOT}/boot" && umount ${INSTALLROOT}/boot is_mounted --location "${INSTALLROOT}" && umount ${INSTALLROOT} + [[ -n ${SWAPHDD} ]] && swapoff ${SWAPHDD} echo $"Installation aborted." exit 1 } -dialog_die() -{ - ERROR="$1" - RETVAL="$?" - dialog_install_failure - exit 1 -} - -dialog_warning() -{ - local retval - - yesnobox $"\Z1 !!! Warning !!! \Zn\n\n\This harddrive will be irreversibly erased.\n\n\Do you want to continue ?" - retval=$? - if [[ ${retval} -eq 1 ]] - then - clear - echo $"The process was aborted." - exit 1 - fi -} - -dialog_setup_hdd_info() -{ - local SHDD="${HDD//\/dev\/}" - - messagebox -h $"[ Harddrive partitioning ]" \ - $"\nPlease create 1 partition.\n\n\[ \Z3${SHDD}1\Zn ] type: \Z3linux\Zn with the whole diskspace\n\Please mark ${SHDD}1 \Z3bootable\Zn." -} - -dialog_setup_hdd_info_auto() +install_meter() { - local SHDD="${HDD//\/dev\/}" - - messagebox -h $"[ Harddrive partitioning ]" \ - $"\Z1Warning!\Zn\n\nAll data on disk [ \Z3${HDD}\Zn ] will be erased!" + while [[ ${CURRENTLINE} != ${TOTALLINES} ]] + do + CURRENTLINE=$(grep -c . /tmp/install.log) + PERCENT=$(( ${CURRENTLINE} * 100 / ${TOTALLINES})) + echo ${PERCENT} + sleep 1 + done + rm -f /tmp/install.log + return 0 } -dialog_setup_system_menu() +mount_rootfs() { - local mode local retval - mode=$(menubox -h $"[ Harddrive partitioning ]" $"\nSelect an installation mode" \ - $"1:Automatic setup (recommended)" \ - ":" \ - $":\Z1Expert modes:\Zn" \ - $"2:Common IDE-disk (manual setup)") - retval=$? - [[ ${retval} -eq 1 ]] && return 1 - if [[ ${retval} -eq 0 ]] - then - case "${mode}" in - "1") run_install_auto ;; - "2") run_install_normal ;; - "") dialog_setup_system_menu;; - esac - fi -} - -dialog_hardware_detection() -{ - local message - - run_hardware_detection_disks - - message+=$"Harddrives:\n" - - if [[ ! -z ${ALL_DISKS} ]] + if [[ -n ${SWAPHDD} ]] then - for i in ${ALL_DISKS} - do - message+="\Z3${i}\Zn " - done - message+="\n" + swapon ${SWAPHDD} || dialog_die $"Could not enable swap space '${SWAPHDD}'" fi - if [[ ! -z ${ALL_CDROMS} ]] + if [[ -n ${ROOTHDD} ]] then - message+="\n" - message+=$"Optical disk drives:\n" - for i in ${ALL_CDROMS} - do - message+="\Z3${i}\Zn" - done - message+="\n" - fi - - # other devices - run_hardware_detection - case "${SPECIALDEVICE}" in - zotac*) message+=$"\n\Z2Zotac device detected.\Zn" ;; - rangee) message+=$"\n\Z2Rangee device detected.\Zn" ;; - maxdata) message+=$"\n\Z2Maxdata device detected.\Zn" ;; - *) message+=$"\n \\ZnCommon device detected.\Zn" ;; - esac - if [[ ${FORMFACTOR} = laptop ]] - then - message+=$"\n\ZnFormfactor Laptop, activating 'ondemand' powersaving mode.\Zn" - fi - - messagebox -y 15 -h $"Detected hardware:" "${message}" -} - -dialog_setup_hdd_partitions_manual() -{ - local i - local retval - - if [[ -z ${ALL_DISKS} ]] - then - dialog_no_harddrive_found - exit 1 - else - HDD=$(dialog_select_target_harddrive) - retval=$? - [[ ${retval} -eq 1 ]] && return 1 - if [[ ${retval} -eq 0 ]] + if is_mounted --location "${INSTALLROOT}" then - dialog_setup_hdd_info - setup_hdd_partitions_manual + echo $"${INSTALLROOT} already mounted" >&2 + else + mount -t "${FORMAT_FILESYSTEM_ROOTHDD}" "${ROOTHDD}" "${INSTALLROOT}" || dialog_die $"Could not mount rootfs - drive '${ROOTHDD}' -> '${INSTALLROOT}'" fi fi -} -dialog_setup_hdd_partitions_auto() -{ - local i - local retval + [[ -d ${INSTALLROOT}/boot ]] || install -d ${INSTALLROOT}/boot - if [[ -z ${ALL_DISKS} ]] + if [[ -n ${BOOTHDD} ]] then - dialog_no_harddrive_found - exit 1 - else - HDD=$(dialog_select_target_harddrive) - retval=$? - [[ ${retval} -eq 1 ]] && return 1 - if [[ ${retval} -eq 0 ]] + if is_mounted --location "${INSTALLROOT}"/boot then - dialog_setup_hdd_info_auto - dialog_setup_hdd_create_partitions - setup_hdd_partitions_auto + echo $"${INSTALLROOT}/boot already mounted" >&2 + else + mount -t "${FORMAT_FILESYSTEM_BOOTHDD}" "${BOOTHDD}" "${INSTALLROOT}"/boot || dialog_die $"Could not mount bootfs - drive '${BOOTHDD}' -> '${INSTALLROOT}/boot'" fi fi } -run_hardware_detection_disks() +umount_rootfs() { - local bootdev + is_mounted --location ${INSTALLROOT}/boot && umount ${INSTALLROOT}/boot + is_mounted --location ${INSTALLROOT} && umount ${INSTALLROOT} - # all disks but exclude ramdisks - export ALL_DISKS=$(get_hwinfo disk | sed '/\/dev\/ram[0-9].*/d') - # remove the boot device from ALL_DISKS if it was an usbstick - if [[ $(grep '[[:space:]]/mnt/cdrom[[:space:]]' /proc/mounts | cut -d' ' -f3) != iso9660 ]] + if [[ -n ${SWAPHDD} ]] then - bootdev="$(grep '[[:space:]]/mnt/cdrom[[:space:]]' /proc/mounts | cut -d' ' -f1 | sed 's:[0-9]::g')" - export ALL_DISKS=$(echo "${ALL_DISKS}" | grep -v "${bootdev}") + swapoff ${SWAPHDD} || die fi - export ALL_CDROMS="$(get_hwinfo cdrom)" -} - -dialog_setup_hdd_create_partitions() -{ - dialog \ - --backtitle "${TITLE}" \ - --infobox "Erstelle Disk Partitionen ..." 3 70 -} - -dialog_setup_hdd_format() -{ - dialog \ - --backtitle "${TITLE}" \ - --infobox "Erstelle Datei-Systeme ..." 3 70 -} - -dialog_install_settings() -{ - dialog \ - --backtitle "${TITLE}" \ - --infobox "Speichere System-Einstellungen ..." 3 70 -} - -dialog_install_system_image() -{ - dialog \ - --backtitle "${TITLE}" \ - --gauge "Kopiere System-Image ..." 6 80 -} - -install_meter() -{ - while [[ ${CURRENTLINE} != ${TOTALLINES} ]] - do - CURRENTLINE=$(grep -c . /tmp/install.log) - PERCENT=$(( ${CURRENTLINE} * 100 / ${TOTALLINES})) - echo ${PERCENT} - sleep 1 - done - rm -f /tmp/install.log - return 0 } - -dialog_install_bootsector() -{ - dialog \ - --backtitle "${TITLE}" \ - --infobox "Schreibe den Bootsektor ..." 3 70 -} - -dialog_install_successful() -{ - dialog \ - --backtitle "${TITLE}" \ - --colors \ - --msgbox "Die Installation war \Z2erfolgreich\Zn." 5 81 -} - -dialog_install_failure() -{ - dialog \ - --backtitle "${TITLE}" \ - --colors \ - --msgbox "Die Installation ist \Z1Fehlgeschlagen\Zn.\n\n\ - Fehler bei ${ERROR}, RetVal: ${RETVAL} \ - " 10 81 -} - -dialog_main() +install_do_reboot() { - local method=0 - local retval - - while [[ ${method} -le 2 ]] - do - method=$(dialog \ - --backtitle "${TITLE}" \ - --no-cancel \ - --ok-label "Weiter" \ - --stdout \ - --menu "Konfiguration" 14 70 5 \ - "1" "AutoSta_LX installieren" \ - "2" "Uebersicht gefundener Laufwerke" \ - "3" "Beenden und neustarten" \ - "4" "Beenden und eine Shell starten") - retval=$? - [[ ${retval} -eq 1 ]] && exit 1 - if [[ ${retval} -eq 0 ]] - then - case ${method} in - "1") dialog_setup_system_menu ;; - "2") dialog_hardware_detection ;; - "3") install_do_reboot ;; - "4") /bin/bash --login -i ;; - esac - fi - done + reboot } -################################################# -# Install Komandos # -################################################# run_hardware_detection() { local hwinfo - hwinfo="$(hwinfo --bios --storage --pci --gfxcard --sys)" # check for special devices/clients: @@ -363,8 +205,11 @@ if [[ $(< ${i}) = 1 ]] then removable=1 + # we assume that all removable disks are flash disks on a zotac + export FLASHDISK=1 fi done + # smartcard = udevadm info -n /dev/sda -a | grep -i 'configuration.*card' # only add this for grub legacy, grub2 detect these settings on its own export GRUBLEGACYOPTS="rootdelay=8" @@ -395,6 +240,32 @@ export GRUBLEGACYOPTS="" fi + # check for i845 Chipsets and enable KMS and use 915 drm driver later in initrd + if [[ ! -z $(echo "${hwinfo}" | grep -i i845) ]] + then + export SPECIALDEVICE="i845" + # unset default video=1024x768 opt or the drm driver breaks + export KERNELOPTS="quiet" + export GRUBLEGACYOPTS="" + # enable full kms support + export GRUB2GFXPAYLOAD="keep" + fi + + # check for radeon gfxcards + if [[ ! -z $(echo "${hwinfo}" | grep -i radeon) ]] + then + # enable full kms support + export GRUB2GFXPAYLOAD="keep" + fi + + # requires nomsi to prevent massive IRQ error spam + # see: http://ubuntuforums.org/showthread.php?t=1234983 + if [[ ! -z $(echo "${hwinfo}" | grep -i 'P5VD2-X') ]] || [[ ! -z $(echo "${hwinfo}" | grep -i 'VT8237') ]] || [[ ! -z $(echo "${hwinfo}" | grep -i 'VX700') ]] + then + export SPECIALDEVICE="nomsi" + export KERNELOPTS="${KERNELOPTS} pci=nomsi,noaer" + fi + # check for special devices/clients: # check for laptops and activate cpufreq scaling if [[ $(echo "${hwinfo}" | grep 'Formfactor:' | sed 's:.*Formfactor\:\ \"\(.*\)\":\1:') = laptop ]] @@ -404,410 +275,557 @@ fi } -hdd_size_below_256mb() +run_hardware_detection_disks() { - local hdd="$1" - local size - local retval - [[ -z ${hdd} ]] && dialog_die "Error: get_hdd_size() no \$hdd given!" + local bootdev - size=$(fdisk -l ${hdd} | grep "Disk.*${hdd}" | sed 's:.*,\ \(.*\)\ byte.*:\1:') - if [[ ${size} -le 257000000 ]] + # all disks but exclude ramdisks + export ALL_DISKS=$(get_hwinfo disk | sed '/\/dev\/ram[0-9].*/d') + # remove the boot device from ALL_DISKS if it was an usbstick + if [[ $(grep '[[:space:]]${LIVEROOT}[[:space:]]' /proc/mounts | cut -d' ' -f3) != iso9660 ]] then - retval="0" - else - retval="1" + bootdev=$(grep "[[:space:]]${LIVEROOT}[[:space:]]" /proc/mounts | cut -d' ' -f1 | sed 's:[0-9]::g') + export ALL_DISKS=$(echo "${ALL_DISKS}" | grep -v "${bootdev}") fi - - return "${retval}" + export ALL_CDROMS="$(get_hwinfo cdrom)" } -setup_hdd_partitions_auto() +auto_partition_clear_disk() { - ROOTHDD="${HDD}1" - - # run this only if FDISKPARTITIONBELOW256MB is not already 1 - if [[ ${FDISKPARTIONBELOW256MB} != 1 ]] + if [ -e ${HDD} ] then - if hdd_size_below_256mb ${HDD} - then - FDISKPARTIONBELOW256MB=1 - else - FDISKPARTIONBELOW256MB=0 - fi + dd if=/dev/zero of=${HDD} count=1 &> /dev/null || dialog_die + else + echo "clear disk: device ${HDD} does not exist" >&2 fi +} - ## delete disk - dd if=/dev/zero of=${HDD} count=1 &> /dev/null || dialog_die - - if [[ ${FDISKPARTIONBELOW256MB} = 1 ]] +auto_partition_command() +{ + if [ -e ${HDD} ] then - ## setup one bootable partition - #1. n= new disk - #2. p= primary disk - #3. 1= first partition - #4. 2= default sector start // small disk needs more space for grub2 mbr sector - #5. ''= defaul sector end - #6. a= bootable flag - #7. 1= boot flag for partition 1 - #8. w= write/quit fdisk ${HDD} &> /dev/null << EOF -n -p -1 -2 - -a -1 -w +$(echo "${PARTITION_OPTS}") EOF else - ## setup one bootable partition - #1. n= new disk - #2. p= primary disk - #3. 1= first partition - #4. ''= default sector start - #5. ''= defaul sector end - #6. a= bootable flag - #7. 1= boot flag for partition 1 - #8. w= write/quit - fdisk ${HDD} &> /dev/null << EOF -n -p -1 - - -a -1 -w -EOF + echo "partition command: device ${HDD} does not exist" >&2 fi } -setup_hdd_partitions_manual() -{ - ROOTHDD="${HDD}1" - - ## hdds partitionieren manual - cfdisk ${HDD} || dialog_die -} - -setup_hdd_format() -{ - mke2fs -j -q ${ROOTHDD} || dialog_die -} - -install_mount_rootfs() -{ - mount ${ROOTHDD} ${INSTALLROOT} || dialog_die - install -d ${INSTALLROOT}/boot || dialog_die - cd ${INSTALLROOT} || dialog_die -} - -install_system_image() -{ - tar xvjpf ${CDROOT}/system/${CDIMAGENAME} -C ${INSTALLROOT} -} - -install_bootsector_chroot() +setup_hdd_partitions() { - local my_roothdd - local grubconf=${INSTALLROOT}/boot/grub/grub.conf - local grub2conf=/boot/grub/grub.cfg + local partition_number + local partition_type + local partition_start_sector + local partition_size - # check for grub2 - if [[ -f ${INSTALLROOT}/sbin/grub-mkconfig ]] + # sanity check - should not happen + if is_mounted --device "${ROOTHDD}" + then + echo "partition: device ${ROOTHDD} is already mounted, umount it" >&2 + umount "${ROOTHDD}" + fi + if [[ -n ${BOOTHDD} ]] then - # needed by grub-mkconfig on the first run - if [[ ! -f ${INSTALLROOT}/boot/grub/video.lst ]] + if is_mounted --device "${BOOTHDD}" then - install -m0644 ${INSTALLROOT}/lib/grub/*/video.lst ${INSTALLROOT}/boot/grub/video.lst || dialog_die + echo "partition: device ${BOOTHDD} is already mounted, umount it" >&2 + umount "${BOOTHDD}" fi + fi - # set kernelopts - if [[ -f ${INSTALLROOT}/etc/conf.d/grub ]] + if [[ ${INSTALL_METHOD} = auto ]] + then + # run this only if FDISKPARTITIONBELOW256MB is not already 1 + if [[ ${FDISKPARTIONBELOW256MB} != 1 ]] then - sed -i "s:^\(export GRUB_CMDLINE_LINUX_DEFAULT=\).*:\1\"${KERNELOPTS}\":" ${INSTALLROOT}/etc/conf.d/grub || dialog_die - else - echo "export GRUB_CMDLINE_LINUX_DEFAULT=\"${KERNELOPTS}\"" > ${INSTALLROOT}/etc/conf.d/grub || dialog_die + if device_minimum_size "${HDD}" 256 + then + FDISKPARTIONBELOW256MB=1 + else + FDISKPARTIONBELOW256MB=0 + fi fi - echo 'grub-mkdevicemap' > ${INSTALLROOT}/root/.installrc || dialog_die - echo "LC_ALL=C grub-mkconfig -o ${grub2conf} &> /dev/null" >> ${INSTALLROOT}/root/.installrc || dialog_die - echo "grub-install --no-floppy ${HDD} &> /dev/null" >> ${INSTALLROOT}/root/.installrc || dialog_die - echo "exit 0" >> ${INSTALLROOT}/root/.installrc || dialog_die - # grub-legacy - else - ### grubconf schreiben - source ${INSTALLROOT}/boot/kernelversion + ## delete disk + auto_partition_clear_disk - #for alx only - if [ -e ${INSTALLROOT}/etc/alx_version ] + # setup partition options + export PARTITION_OPTS + + if [[ -n ${BOOTHDD} ]] then - OLD_ALXVER="${ALXVER}" - source ${INSTALLROOT}/etc/alx_version - KRNVER="ALX-${ALXVER}" - ALXVER="${OLD_ALXVER}" + # create a boot disk with 50meg size - bootable + partition_type="p" + partition_number="1" + if [[ ${FDISKPARTIONBELOW256MB} = 1 ]] + then + # 2= default sector start // small disk needs more space for grub2 mbr sector + partition_start_sector="2" + else + # '' use default sector start + partition_start_sector="" + fi + # 50meg size + partition_size="+50M" + + # create a boot disk with 50meg size - bootable + # n= new disk + # p= primary disk + # w= write/quit + PARTITION_OPTS="n +${partition_type} +${partition_number} +${partition_start_sector} +${partition_size} +w" + # create the disk + auto_partition_command + + # mark the disk bootable + PARTITION_OPTS="a +${partition_number} +w" + auto_partition_command + fi - [[ -z ${KRNVER} ]] && KRNVER="AutoSta_LX" - [[ -z ${KRNINITRD} ]] && KRNINITRD="initrd" - [[ -z ${KRNIMG} ]] && KRNIMG="vmlinuz" + if [[ -n ${SWAPHDD} ]] + then + # p= primary disk + partition_type="p" + if [[ -n ${BOOTHDD} ]] + then + # boot disk exist, partition 2 + partition_number="2" + else + # boot disk does not exist, partition 1 + partition_number="1" + fi + if [[ ${FDISKPARTIONBELOW256MB} = 1 ]] + then + # fake sector 2 and fdisk finds the next free sector which must be selected with enter + partition_start_sector="2 +" + else + # '' use default sector start + partition_start_sector="" + fi + partition_start_sector="" + # +2G disk size + partition_size="+2G" + + # create a swap disk with 2GB size + PARTITION_OPTS="n +${partition_type} +${partition_number} +${partition_start_sector} +${partition_size} +w" + # create the disk + auto_partition_command + + # mark disk as swap space + PARTITION_OPTS=" +t" + if [[ ${partition_number} != 1 ]] + then + PARTITION_OPTS+=" +${partition_number}" + fi + PARTITION_OPTS+=" +82 +w" + auto_partition_command + fi - # uuid support - if is_uuid_supported + if [[ -n ${ROOTHDD} ]] then - my_roothdd="UUID=$(get_uuid ${ROOTHDD})" - else - my_roothdd="${ROOTHDD}" + # p= primary disk + partition_type="p" + if [[ -z ${BOOTHDD} ]] && [[ -z ${SWAPHDD} ]] + then + # boot and swap disk does not exist, partition 1 + partition_number="1" + fi + if [[ -n ${BOOTHDD} ]] || [[ -n ${SWAPHDD} ]] + then + # boot or swap disk exist, partition 2 + partition_number="2" + fi + if [[ -n ${BOOTHDD} ]] && [[ -n ${SWAPHDD} ]] + then + # boot and swap disk does exist, partition 3 + partition_number="3" + fi + if [[ ${FDISKPARTIONBELOW256MB} = 1 ]] + then + if [[ -z ${BOOTHDD} ]] + then + # 2= default sector start // small disk needs more space for grub2 mbr sector + partition_start_sector="2" + else + # fake sector 2 and fdisk finds the next free sector which must be selected with enter + partition_start_sector="2 +" + fi + else + # '' use default sector start + partition_start_sector="" + fi + # '' default sector end + partition_size="" + + # create system disk with remaining space + # w= write/quit + PARTITION_OPTS="n +${partition_type} +${partition_number} +${partition_start_sector} +${partition_size} +w" + # create the disk + auto_partition_command + + # no boot disk? then this is the boot disk + if [[ -z ${BOOTHDD} ]] + then + # mark the disk bootable + PARTITION_OPTS="a +${partition_number} +w" + auto_partition_command + fi fi + else + cfdisk ${HDD} || dialog_die + fi +} - : > ${grubconf} || dialog_die - echo "default 0" >> ${grubconf} || dialog_die - echo "timeout 3" >> ${grubconf} || dialog_die - # using current root password - echo "password --md5 $(cat ${INSTALLROOT}/etc/shadow | grep root | cut -d: -f2)" >> ${grubconf} || dialog_die +setup_hdd_format() +{ + install -d /tmp + :> /tmp/format.log - echo >> ${grubconf} || dialog_die - echo "# normal boot" >> ${grubconf} || dialog_die - echo "title ${KRNVER}" >> ${grubconf} || dialog_die - echo "root (hd0,0)" >> ${grubconf} || dialog_die - echo "kernel /boot/${KRNIMG} root=${my_roothdd} ${KERNELOPTS} ${GRUBLEGACYOPTS}" >> ${grubconf} || dialog_die - if is_initrd_supported + if [[ -n ${SWAPHDD} ]] + then + # sanity check - should not happen + if is_mounted --device "${SWAPHDD}" then - echo "initrd /boot/${KRNINITRD}" >> ${grubconf} || dialog_die + echo "format: device ${SWAPHDD} is already mounted, umount it" >&2 + umount "${SWAPHDD}" fi + mkswap ${SWAPHDD} || die + fi - echo >> ${grubconf} || dialog_die - echo "# admin boot" >> ${grubconf} || dialog_die - echo "title ${KRNVER} - Re-run hardware-detection" >> ${grubconf} || dialog_die - echo "lock" >> ${grubconf} || dialog_die - echo "root (hd0,0)" >> ${grubconf} || dialog_die - echo "kernel /boot/${KRNIMG} root=${my_roothdd} ${KERNELOPTS} ${GRUBLEGACYOPTS} hardware-auto-detection" >> ${grubconf} || dialog_die - if is_initrd_supported + if [[ -n ${BOOTHDD} ]] + then + # sanity check - should not happen + if is_mounted --device "${BOOTHDD}" then - echo "initrd /boot/${KRNINITRD}" >> ${grubconf} || dialog_die + echo "format: device ${BOOTHDD} is already mounted, umount it" >&2 + umount "${BOOTHDD}" fi - echo >> ${grubconf} || dialog_die - echo "title ${KRNVER} - Reset *all* local settings" >> ${grubconf} || dialog_die - echo "lock" >> ${grubconf} || dialog_die - echo "root (hd0,0)" >> ${grubconf} || dialog_die - echo "kernel /boot/${KRNIMG} root=${my_roothdd} ${KERNELOPTS} ${GRUBLEGACYOPTS} alx-reset-settings" >> ${grubconf} || dialog_die - if is_initrd_supported + mkfs."${FORMAT_FILESYSTEM_BOOTHDD}" "${BOOTHDD}" &>> /tmp/format.log || dialog_die + fi + + if [[ -n ${ROOTHDD} ]] + then + # sanity check - should not happen + if is_mounted --device "${ROOTHDD}" then - echo "initrd /boot/${KRNINITRD}" >> ${grubconf} || dialog_die + echo "format: device ${ROOTHDD} is already mounted, umount it" >&2 + umount "${ROOTHDD}" fi - # bootsector schreiben chrooted schreiben (lfs/magellan) - cat > ${INSTALLROOT}/root/.installrc << CHROOTEOF -/usr/sbin/grub --no-floppy --batch << "EOF" 1> /dev/null 2> /dev/null -root (hd0,0) -setup (hd0) -quit -EOF -exit 0 -CHROOTEOF + mkfs."${FORMAT_FILESYSTEM_ROOTHDD}" "${ROOTHDD}" &>> /tmp/format.log || dialog_die fi +} - ## enter chroot - mount -t proc proc ${INSTALLROOT}/proc - mount -t sysfs sysfs ${INSTALLROOT}/sys - mount -o bind /dev ${INSTALLROOT}/dev - chroot ${INSTALLROOT} /bin/bash --rcfile /root/.installrc -i - umount ${INSTALLROOT}/proc - umount ${INSTALLROOT}/sys - umount ${INSTALLROOT}/dev - rm ${INSTALLROOT}/root/.installrc -} - -is_initrd_supported() -{ - # only generate initrds if the cmd exists - [[ -x ${INSTALLROOT}/sbin/mkinitrd ]] && return 0 - return 1 -} - -install_initrd_chroot() -{ - # only generate initrds if the cmd exists - is_initrd_supported || return 0 - - DISKMODS="sd_mod" - OLDPATAMODS="amd74xx piix sis5513 via82cxxx" - PATAMODS="ata_piix pata_amd pata_mpiix pata_oldpiix pata_sis pata_via" - SATAMODS="sata_via sata_sis sata_nv" - DRMMODS="i915 mga nouveau r128 radeon savage sis tdfx ttm via" - OTHERMODS="" - case ${SPECIALDEVICE} in - zotac_intel) FBMODS=""; DRMMODS="i915" ;; - zotac_nvidia) FBMODS=""; DRMMODS="nouveau" ;; - rangee) FBMODS="" ;; ## fallback to vesafb, viafb does not run on all CLE266 boards - # not working with kms enabled drivers -> segfaults - #maxdata) FBMODS="i810fb" ;; ## check for maxdata / i810/ i815 Chipsets and disable KMS and use i810fb frambuffer - maxdata) FBMODS="" ;; - *) FBMODS="uvesafb" ;; - esac +install_system_image() +{ + pushd ${INSTALLROOT} > /dev/null + tar xvjpf ${IMAGEROOT}/${CDIMAGENAME} -C ${INSTALLROOT} + popd > /dev/null +} - if [[ ${FORMFACTOR} = laptop ]] +install_system_settings() +{ + local CONFIG + + # write fstab + CONFIG="${INSTALLROOT}/etc/fstab" + clearconfig + if [[ -n ${BOOTHDD} ]] then - OTHERMODS="acpi-cpufreq cpufreq_ondemand cpufreq_conservative cpufreq_powersave" + addconfig -e "UUID=$(get_uuid ${BOOTHDD})\t/\t${FORMAT_FILESYSTEM_BOOTHDD}\tnoatime\t1 1" fi + if [[ -n ${ROOTHDD} ]] + then + addconfig -e "UUID=$(get_uuid ${ROOTHDD})\t/\t${FORMAT_FILESYSTEM_ROOTHDD}\tnoatime\t0 0" + fi + if [[ -n ${SWAPHDD} ]] + then + addconfig -e "UUID='$(get_uuid ${SWAPHDD})'\tswap\tswap\tpri=1\t0 0" + fi + addconfig -e "proc\t/proc\tproc\tdefaults\t0 0" + addconfig -e "shm\t/dev/shm\ttmpfs\tdefaults\t0 0" - # install an appropriate uvesafb.conf - install -d ${INSTALLROOT}/etc/modprobe.d || dialog_die - echo "options uvesafb mode_option=1024x768-32@60 scroll=ywrap" > ${INSTALLROOT}/etc/modprobe.d/uvesafb.conf || dialog_die - - # install an appropriate viafb.conf - echo "options viafb viafb_mode=1024x768 viafb_refresh=60" > ${INSTALLROOT}/etc/modprobe.d/viafb.conf || dialog_die + # install network config skeleton + CONFIG="${INSTALLROOT}/etc/conf.d/net.eth0" + clearconfig + addconfig 'ONBOOT="yes"' + addconfig 'NETWORKING="dhcp"' + + # intel framebuffer quirk + CONFIG="${INSTALLROOT}/etc/splash/splash.conf" + if [ -e ${CONFIG} ] && [ -e /proc/fb ] + then + if [[ ! -z $(grep 'inteldrmfb' /proc/fb) ]] + then + fbdev=$(grep 'inteldrmfb' /proc/fb | sed 's:\([0-9]\).*:\1:') + [[ ${fbdev} != 0 ]] && sed -i "s:^\(SPLASH_DEV=\).*:\1\"/dev/fb${fbdev}\":" ${CONFIG} || dialog_die + fi + fi +} - # install an appropriate i810fb.conf - echo "options i810fb xres=1024 yres=768 bpp=16 mtrr=1 hsync1=30 hsync2=62 vsync1=30 vsync2=60" > ${INSTALLROOT}/etc/modprobe.d/i810fb.conf || dialog_die - cat > ${INSTALLROOT}/root/.installrc << CHROOTEOF -echo "MODULES=\"${FORMAT_FILESYSTEM} ${DISKMODS} ${OLDATAMODS} ${PATAMODS} ${SATAMODS} ${DRMMODS} ${FBMODS} ${OTHERMODS}\"" > /etc/conf.d/mkinitrd -mkinitrd -f /boot/$(readlink /boot/initrd) $(readlink /boot/vmlinuz | sed "s:kernel-::g") > /dev/null -exit 0 -CHROOTEOF +### installer dialogs ### - ## enters chroot - mount -t proc proc ${INSTALLROOT}/proc - mount -t sysfs sysfs ${INSTALLROOT}/sys - mount -o bind /dev ${INSTALLROOT}/dev - chroot ${INSTALLROOT} /bin/bash --rcfile /root/.installrc -i - umount ${INSTALLROOT}/proc - umount ${INSTALLROOT}/sys - umount ${INSTALLROOT}/dev - rm ${INSTALLROOT}/root/.installrc +dialog_die() +{ + ERROR="$1" + RETVAL="$?" + dialog_install_failure + exit 1 } -is_uuid_supported() +dialog_warning() { - if [[ -x $(type -P busybox.mkinitrd) ]] + local retval + + yesnobox $"\Z1 !!! Warning !!! \Zn\n\n\This harddrive will be irreversibly erased.\n\n\Do you want to continue ?" + retval=$? + if [[ ${retval} -eq 1 ]] then - # only detect uuids if supported - if [[ ! -z $(busybox.mkinitrd | grep blkid) ]] - then - return 0 - fi + clear + echo $"The process was aborted." + exit 1 fi - - return 1 } -get_uuid() -{ - local UUID - local SEC_TYPE - local TYPE - local dev="$1" - [[ -z ${dev} ]] && dialog_die "no dev given" +### installer tasks ### - # check if given device is already an UUID - if [[ ${dev/UUID=/}x != ${dev}x ]] +task_setup_system_menu() +{ + local mode + local retval + + mode="$(dialog_setup_system_menu)" + retval=$? + [[ ${retval} -eq 1 ]] && return 1 + if [[ ${retval} -eq 0 ]] then - eval "${dev}" - else - eval $(busybox.mkinitrd blkid ${dev} | grep "${dev}:" | sed 's/.*:\ //') + case "${mode}" in + "1") run_install auto ;; + "2") run_install normal ;; + "") task_setup_system_menu;; + esac fi - echo "${UUID}" } -install_system_settings() +task_hardware_detection() { - # schreibe fstab - if is_uuid_supported + local message + + run_hardware_detection_disks + + message+=$"Harddrives:\n" + + if [[ ! -z ${ALL_DISKS} ]] then - echo -e "UUID=$(get_uuid ${ROOTHDD})\t/\t${FORMAT_FILESYSTEM}\tnoatime\t0 0" >> ${INSTALLROOT}/etc/fstab || dialog_die - else - echo -e "${ROOTHDD}\t/\t${FORMAT_FILESYSTEM}\tnoatime\t0 0" >> ${INSTALLROOT}/etc/fstab || dialog_die + for i in ${ALL_DISKS} + do + message+="\Z3${i}\Zn " + done + message+="\n" fi - # not needed busybox loads all with swapon -a, even if not mentioned in fstab - #echo -e "UUID='$(get_uuid ${SWAPHDD})'\tswap\tswap\tpri=1\t0 0" >> ${INSTALLROOT}/etc/fstab || dialog_die - echo -e "proc\t/proc\tproc\tdefaults\t0 0" >> ${INSTALLROOT}/etc/fstab || dialog_die - echo -e "shm\t/dev/shm\ttmpfs\tdefaults\t0 0" >> ${INSTALLROOT}/etc/fstab || dialog_die - # install network config skeleton - install -m0644 ${INSTALLROOT}/etc/alxconfig-ng/skel/net/net.eth0 ${INSTALLROOT}/etc/conf.d/ || dialog_die + if [[ ! -z ${ALL_CDROMS} ]] + then + message+="\n" + message+=$"Optical disk drives:\n" + for i in ${ALL_CDROMS} + do + message+="\Z3${i}\Zn" + done + message+="\n" + fi - # intel framebufer quirk - if [[ -e /proc/fb ]] + # other devices + run_hardware_detection + case "${SPECIALDEVICE}" in + zotac*) message+=$"\n\Z2Zotac device detected.\Zn" ;; + rangee) message+=$"\n\Z2Rangee device detected.\Zn" ;; + maxdata) message+=$"\n\Z2Maxdata device detected.\Zn" ;; + i845) message+=$"\n\Z2Intel i845 VGA device detected.\Zn" ;; + nomsi) message+=$"\n\Z2Mainboard with P5VD2-X/VT8237/VX700 chipset detected.\Zn" + message+=$"\n\Z2Disabling Message Signaled Interrupts (MSI) capability of the kernel.\Zn" ;; + *) message+=$"\n\ZnCommon device detected.\Zn" ;; + esac + if [[ ${FORMFACTOR} = laptop ]] then - if [[ ! -z $(grep 'inteldrmfb' /proc/fb) ]] - then - fbdev=$(grep 'inteldrmfb' /proc/fb | sed 's:\([0-9]\).*:\1:') - if [[ ${fbdev} != 0 ]] - then - sed -i "s:^\(SPLASH_DEV=\).*:\1\"/dev/fb${fbdev}\":" ${INSTALLROOT}/etc/splash/splash.conf || dialog_die - fi - fi + message+=$"\n\ZnFormfactor Laptop, activating 'ondemand' powersaving mode.\Zn" + fi + if [[ ${FLASHDISK} = 1 ]] + then + message+=$"\n\ZnFlash memory detected.\Zn" + message+=$"\n\ZnF2FS will be used as default filesystem within the auto installation mode.\Zn" fi -} -install_umount_rootfs() -{ - cd / - umount ${INSTALLROOT}/boot || dialog_die - umount ${INSTALLROOT} || dialog_die + messagebox -y 12 -h $"Detected hardware:" "${message}" } -install_do_reboot() +task_select_target_hdd() { - reboot + if [[ -z ${ALL_DISKS} ]] + then + dialog_no_harddrive_found + exit 1 + else + export HDD=$(dialog_select_target_harddrive) + fi } -################################################# -# Install Ablauf Scripte # -################################################# - -run_install_normal() +task_setup_hdd_partitions() { - dialog_hardware_detection - - dialog_setup_hdd_partitions_manual - dialog_setup_hdd_format - setup_hdd_format > /dev/null - install_mount_rootfs - (install_system_image > /tmp/install.log) 2> /tmp/install_errors.log | install_meter | dialog_install_system_image + local retval - dialog_install_settings - sleep 1 - install_system_settings - install_initrd_chroot + if [[ -z ${HDD} ]] + then + dialog_no_harddrive_found + exit 1 + else + dialog_setup_hdd_info + setup_hdd_partitions + fi +} - dialog_install_bootsector - install_bootsector_chroot +task_main() +{ + local method=0 + local retval - install_umount_rootfs - dialog_install_successful + while [[ ${method} -le 2 ]] + do + method=$(dialog_main) + retval=$? + [[ ${retval} -eq 1 ]] && exit 1 + if [[ ${retval} -eq 0 ]] + then + case ${method} in + "1") task_setup_system_menu ;; + "2") task_hardware_detection ;; + "3") install_do_reboot ;; + "4") /bin/bash --login -i ;; + esac + fi + done } -run_install_auto() +run_install() { - dialog_hardware_detection + local method="$1" + + task_hardware_detection + task_select_target_hdd - dialog_setup_hdd_partitions_auto + case "${method}" in + auto) + if [[ ${FLASHDISK} = 1 ]] + then + export BOOTHDD="${HDD}1" + export SWAPHDD="" + export ROOTHDD="${HDD}2" + export FORMAT_FILESYSTEM_BOOTHDD="ext2" + export FORMAT_FILESYSTEM_ROOTHDD="f2fs" + else + # ext4 seems not to be compatible again + if [[ ${FORMAT_FILESYSTEM} = ext4 ]] + then + export BOOTHDD="${HDD}1" + export SWAPHDD="" + export ROOTHDD="${HDD}2" + export FORMAT_FILESYSTEM_BOOTHDD="ext2" + export FORMAT_FILESYSTEM_ROOTHDD="${FORMAT_FILESYSTEM}" + else + export BOOTHDD="" + export SWAPHDD="" + export ROOTHDD="${HDD}1" + export FORMAT_FILESYSTEM_BOOTHDD="" + export FORMAT_FILESYSTEM_ROOTHDD="${FORMAT_FILESYSTEM}" + fi + fi + export INSTALL_METHOD="${method}" + ;; + normal) + export BOOTHDD="${HDD}1" + export SWAPHDD="${HDD}2" + export ROOTHDD="${HDD}3" + export FORMAT_FILESYSTEM_BOOTHDD="${FORMAT_FILESYSTEM}" + export FORMAT_FILESYSTEM_ROOTHDD="${FORMAT_FILESYSTEM}" + export INSTALL_METHOD="${method}" + ;; + single) + export BOOTHDD="" + export SWAPHDD="" + export ROOTHDD="${HDD}1" + export FORMAT_FILESYSTEM_BOOTHDD="" + export FORMAT_FILESYSTEM_ROOTHDD="${FORMAT_FILESYSTEM}" + export INSTALL_METHOD="${method}" + ;; + flash) + export BOOTHDD="${HDD}1" + export SWAPHDD="" + export ROOTHDD="${HDD}2" + export FORMAT_FILESYSTEM_BOOTHDD="ext2" + export FORMAT_FILESYSTEM_ROOTHDD="f2fs" + export INSTALL_METHOD="${method}" + ;; + *) + die "Unknown install method '${method}', aborting." + ;; + esac + + task_setup_hdd_partitions dialog_setup_hdd_format setup_hdd_format > /dev/null - install_mount_rootfs + mount_rootfs (install_system_image > /tmp/install.log) 2> /tmp/install_errors.log | install_meter | dialog_install_system_image dialog_install_settings sleep 1 install_system_settings - install_initrd_chroot + if is_initrd_supported + then + dialog_install_initrd + initrd_config + initrd_install + fi dialog_install_bootsector - install_bootsector_chroot + bootloader_config + bootloader_install - install_umount_rootfs + umount_rootfs dialog_install_successful } # set some proper traps trap "trap_exit" SIGINT SIGQUIT -dialog_main +task_main exit 0