--- trunk/installer-simple/bin/installer.sh.in 2014/01/03 13:19:11 2323 +++ trunk/installer-simple/bin/installer.sh.in 2015/07/31 10:09:08 2885 @@ -7,438 +7,146 @@ # Niels Rogalla # -#images: (get ${CDIMAGENAME}) -source /mnt/cdrom/system/images.conf +# setup locales +TEXTDOMAIN=installer -#Includes -source /usr/lib/installer/functions/findhdd.sh > /dev/null -### bugfix ############################### -cdromdev="$(echo ${cdromdev} | sed 's/ //')" -######################################## +# include dir +INSTALLER_LIBDIR="%LIBDIR%" -### System/Config Version -VERSION="%VERSIONTAG%" -TITLE="Installer - ${VERSION}" - -CDPATH="/mnt/cdrom" -INSTALLPATH="/mnt/magellan" - -### WICHTIG: anzahl lines in der autosta_lx.tar.gz -1 +# TOTALLINES=linecount of ${CDIMAGENAME}-tarball -1 ! +# -> now in images.conf CURRENTLINE=0 -#TOTALLINES=11072 # -> now in images.conf - -# standard kernel opts -KERNELOPTS="quiet video=1024x768" - -# grub options -GRUBLEGACYOPTS="" -GRUB2OPTS="" - -# fdisk options -FDISKPARTIONBELOW256MB=0 - -# default specialdevices -SPECIALDEVICE="" -FORMFACTOR="desktop" - -# target filesystem -FORMAT_FILESYSTEM="ext4" - -################################################# -# DIALOG BOXEN # -################################################# die() { - ERROR=$1 - RETVAL=$? - dialog_install_failure + echo "Error: $@" exit 1 } -dialog_warning() -{ - dialog \ - --backtitle "${TITLE}" \ - --colors \ - --defaultno \ - --yesno "\Z1 !!! Achtung !!! \Zn\n\n\ - Diese Festplatte wird unwiederruflich geloescht werden.\n\n\ - Soll ich wirklich fortfahren ?" 10 70 - RES=$? - if [[ ${RES} -eq 1 ]] +# load common includes +for inc in %SYSCONFDIR%/installer.conf \ + ${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} ] then - clear - echo "Der Vorgang wurde abgebrochen." - exit 1 + source "${inc}" + else + die "'${inc}' not found" fi -} +done -dialog_setup_hdd_info() -{ - local SHDD="$(echo ${HDD} | sed 's/\/dev\///')" - - dialog \ - --colors \ - --title "[ Festplatten Partitionierung ]" \ - --backtitle "${TITLE}" \ - --ok-label "Weiter" \ - --msgbox "\nBitte legen Sie 3 Partitionen an.\n\n\ - [ \Z3${SHDD}1\Zn ] Typ: \Z3Linux\Zn mit ca. 50MB\n\ - [ \Z3${SHDD}2\Zn ] Typ: \Z3Linux Swap\Zn mit ca. 256MB\n\ - [ \Z3${SHDD}3\Zn ] Typ: \Z3Linux \Zn mit dem Rest (min. 256MB)\n\n\ - Bitte ${SHDD}1 als \Z3bootable\Zn markieren." 12 81 -} - -dialog_setup_hdd_info_flash() -{ - local SHDD="$(echo $HDD | sed 's/\/dev\///')" +### System/Config Version +VERSION="%VERSIONTAG%" +TITLE="${DEFAULT_TITLE} - ${VERSION}" - dialog \ - --colors \ - --title "[ Festplatten Partitionierung ]" \ - --backtitle "${TITLE}" \ - --ok-label "Weiter" \ - --msgbox "\nBitte legen Sie 1 Partition an.\n\n\ - [ \Z3${SHDD}1\Zn ] Typ: \Z3Linux\Zn mit dem gesamten Speicher\n\ - Bitte ${SHDD}1 als \Z3bootable\Zn markieren." 12 81 -} +# some sane defaults +LIVEROOT="${DEFAULT_LIVEROOT}" +IMAGEROOT="${DEFAULT_IMAGEROOT}" +INSTALLROOT="${DEFAULT_INSTALLROOT}" +KERNELPKG="${DEFAULT_KERNELPKG}" +KERNELOPTS="${DEFAULT_KERNELOPTS}" +GRUBLEGACYOPTS="" +GRUB2OPTS="" +FDISKPARTIONBELOW256MB=0 +SPECIALDEVICE="" +FORMFACTOR="${DEFAULT_FORMFACTOR}" +FORMAT_FILESYSTEM="${DEFAULT_FILESYSTEM}" -dialog_setup_hdd_info_auto() -{ - local SHDD="$(echo $HDD | sed 's/\/dev\///')" +# 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() +{ + is_mounted --location "${INSTALLROOT}/dev" && umount ${INSTALLROOT}/dev + is_mounted --location "${INSTALLROOT}/proc" && umount ${INSTALLROOT}/proc + is_mounted --location "${INSTALLROOT}/sys" && umount ${INSTALLROOT}/sys + is_mounted --location "${INSTALLROOT}/boot" && umount ${INSTALLROOT}/boot + is_mounted --location "${INSTALLROOT}" && umount ${INSTALLROOT} - dialog \ - --colors \ - --title "[ Festplatten Partitionierung ]" \ - --backtitle "${TITLE}" \ - --ok-label "Weiter" \ - --msgbox "\nAchtung!\n\ - Alle Daten werden von der Disk [ \Z3${HDD}\Zn ] gelöscht!" 12 81 + echo $"Installation aborted." + exit 1 } -dialog_setup_system_menu() +install_meter() { - local i - - i=$(dialog \ - --backtitle "${TITLE}" \ - --title "[ Festplatten Partitionierung ]" \ - --cancel-label "Abbrechen" \ - --ok-label "Weiter" \ - --stdout \ - --colors \ - --menu "\nWaehlen Sie die Installations-Methode" 14 70 5 \ - "1" "Automatisches Setup (Empfohlen)" \ - "" "" \ - "" "\Z1Experten Modi:\Zn" \ - "2" "Normale IDE-Disk (Manuell)" \ - "3" "Flash-Speicher (Manuell)") - RES=$? - [[ ${RES} -eq 1 ]] && return 1 - if [[ ${RES} -eq 0 ]] - then - case "${i}" in - "1") run_install_auto ;; - "2") run_install_normal ;; - "3") run_install_flash ;; - "") dialog_setup_system_menu;; - esac - fi + 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_hardware_detection() +mount_rootfs() { - local i - local hwtmp - - if [ -x $(which mktemp &> /dev/null) ] - then - hwtmp="$(mktemp)" - else - hwtmp="/tmp/hwtmp.sh" - fi - - [[ ! -z ${installdevs} ]] && installdevs="" - - echo "dialog \\" > ${hwtmp} - echo "--backtitle \"${TITLE}\" \\" >> ${hwtmp} - echo "--ok-label \"Weiter\" \\" >> ${hwtmp} - echo "--stdout \\" >> ${hwtmp} - echo "--colors \\" >> ${hwtmp} - echo "--msgbox \"Gefundene Hardware:\n\n \\" >> ${hwtmp} - echo " Festplatten:\n \\" >> ${hwtmp} - - if [[ ! -z ${scsidisks} ]] - then - for i in ${scsidisks} - do - if [[ ${i} != ${cdromdev} ]] - then - echo " \\Z7SCSI: \\Z3${i}\\Zn\n \\" >> ${hwtmp} - installdevs="${installdevs} ${i}" - fi - done - fi - - if [[ ! -z ${idedisks} ]] - then - for i in ${idedisks} - do - if [[ ${i} != ${cdromdev} ]] - then - echo " \\Z7IDE: \\Z3${i}\\Zn\n \\" >> ${hwtmp} - installdevs="${installdevs} ${i}" - fi - done - fi - - if [[ ! -z ${cdromdev} ]] - then - echo " \n \\" >> ${hwtmp} - echo " \\Z7andere Laufwerke:\n \\" >> ${hwtmp} - echo " CDROM: \\Z3${cdromdev}\\Zn\n \\" >> ${hwtmp} - fi - - # other devices - run_hardware_detection - case "${SPECIALDEVICE}" in - zotac*) echo " \n\n\n \\Z2Zotac Device erkannt.\\Zn \\" >> ${hwtmp} ;; - rangee) echo " \n\n\n \\Z2Rangee Device erkannt.\\Zn \\" >> ${hwtmp} ;; - maxdata) echo " \n\n\n \\Z2Maxdata Device erkannt.\\Zn \\" >> ${hwtmp} ;; - *) echo " \n\n\n \\ZnStandard Device erkannt.\\Zn \\" >> ${hwtmp} ;; - esac - if [[ ${FORMFACTOR} = laptop ]] - then - echo " \n \\ZnFormfactor Laptop, Powersave Modus 'ondemand' wird aktiviert.\\Zn \\" >> ${hwtmp} - fi - - echo " \" 14 70" >> ${hwtmp} - chmod a+x ${hwtmp} - ${hwtmp} + local retval - # remove tmp file - if [[ -f ${hwtmp} ]] + if [[ -n ${SWAPHDD} ]] then - rm ${hwtmp} + swapon ${SWAPHDD} || dialog_die $"Could not enable swap space '${SWAPHDD}'" fi -} - -dialog_setup_hdd_partitions_manuell() -{ - local i - if [[ -z ${installdevs} ]] + if [[ -n ${ROOTHDD} ]] then - dialog \ - --backtitle "${TITLE}" \ - --ok-label "Beenden" \ - --msgbox "Kein geeignetes Laufwerk gefunden.\nDie Installation ist fehlgeschlagen." 6 70 - exit 1 - else - - echo "dialog \\" > /tmp/hddtmp.sh - echo "--backtitle \"${TITLE}\" \\" >> /tmp/hddtmp.sh - echo "--ok-label \"Weiter\" \\" >> /tmp/hddtmp.sh - echo "--cancel-label \"Beenden\" \\" >> /tmp/hddtmp.sh - echo "--stdout \\" >> /tmp/hddtmp.sh - echo "--menu \"Installations Laufwerk auswaehlen:\" 10 70 3 \\" >> /tmp/hddtmp.sh - - for i in ${installdevs} - do - echo "\"${i}\" \"\" \\" >> /tmp/hddtmp.sh - done - echo -e "\n" >> /tmp/hddtmp.sh - - chmod a+x /tmp/hddtmp.sh - HDD="$(/tmp/hddtmp.sh)" - RES=$? - [[ ${RES} -eq 1 ]] && return 1 - if [[ ${RES} -eq 0 ]] + if is_mounted --location "${INSTALLROOT}" then - dialog_setup_hdd_info - setup_hdd_partitions_manuell + echo $"${INSTALLROOT} already mounted" >&2 + else + mount "${ROOTHDD}" "${INSTALLROOT}" || dialog_die $"Could not mount rootfs - drive '${ROOTHDD}' -> '${INSTALLROOT}'" fi fi -} -dialog_setup_hdd_partitions_manuell_flash() -{ - local i + [[ -d ${INSTALLROOT}/boot ]] || install -d ${INSTALLROOT}/boot - if [[ -z ${installdevs} ]] + if [[ -n ${BOOTHDD} ]] then - dialog \ - --backtitle "${TITLE}" \ - --ok-label "Beenden" \ - --msgbox "Kein geeignetes Laufwerk gefunden.\nDie Installation ist fehlgeschlagen." 6 70 - exit 1 - else - - echo "dialog \\" > /tmp/hddtmp.sh - echo "--backtitle \"${TITLE}\" \\" >> /tmp/hddtmp.sh - echo "--ok-label \"Weiter\" \\" >> /tmp/hddtmp.sh - echo "--cancel-label \"Beenden\" \\" >> /tmp/hddtmp.sh - echo "--stdout \\" >> /tmp/hddtmp.sh - echo "--menu \"Installations Laufwerk auswaehlen:\" 10 70 3 \\" >> /tmp/hddtmp.sh - - for i in ${installdevs} - do - echo "\"${i}\" \"\" \\" >> /tmp/hddtmp.sh - done - echo -e "\n" >> /tmp/hddtmp.sh - - chmod a+x /tmp/hddtmp.sh - HDD="$(/tmp/hddtmp.sh)" - RES=$? - [[ ${RES} -eq 1 ]] && return 1 - if [[ ${RES} -eq 0 ]] + if is_mounted --location "${INSTALLROOT}"/boot then - dialog_setup_hdd_info_flash - setup_hdd_partitions_manuell_flash + echo $"${INSTALLROOT}/boot already mounted" >&2 + else + mount "${BOOTHDD}" "${INSTALLROOT}"/boot || dialog_die $"Could not mount bootfs - drive '${BOOTHDD}' -> '${INSTALLROOT}/boot'" fi fi } -dialog_setup_hdd_partitions_auto() +umount_rootfs() { - local i + is_mounted --location ${INSTALLROOT}/boot && umount ${INSTALLROOT}/boot + is_mounted --location ${INSTALLROOT} && umount ${INSTALLROOT} - if [[ -z ${installdevs} ]] + if [[ -n ${SWAPHDD} ]] then - dialog \ - --backtitle "${TITLE}" \ - --ok-label "Beenden" \ - --msgbox "Kein geeignetes Laufwerk gefunden.\nDie Installation ist fehlgeschlagen." 6 70 - exit 1 - else - - echo "dialog \\" > /tmp/hddtmp.sh - echo "--backtitle \"${TITLE}\" \\" >> /tmp/hddtmp.sh - echo "--ok-label \"Weiter\" \\" >> /tmp/hddtmp.sh - echo "--cancel-label \"Beenden\" \\" >> /tmp/hddtmp.sh - echo "--stdout \\" >> /tmp/hddtmp.sh - echo "--menu \"Installations Laufwerk auswaehlen:\" 10 70 3 \\" >> /tmp/hddtmp.sh - - for i in ${installdevs} - do - echo "\"${i}\" \"\" \\" >> /tmp/hddtmp.sh - done - echo -e "\n" >> /tmp/hddtmp.sh - - chmod a+x /tmp/hddtmp.sh - HDD="$(/tmp/hddtmp.sh)" - RES=$? - [[ ${RES} -eq 1 ]] && return 1 - if [[ ${RES} -eq 0 ]] - then - dialog_setup_hdd_info_auto - dialog_setup_hdd_create_partitions - setup_hdd_partitions_auto - fi + swapoff ${SWAPHDD} || die fi } -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 -} - -dialog_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() { - METHOD=0 - - 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") - RES=$? - [[ ${RES} -eq 1 ]] && exit 1 - if [[ ${RES} -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 @@ -450,13 +158,14 @@ local removable=0 if [[ ! -z $(echo "${hwinfo}" | grep -i zotac) ]] then - for i in /sys/block/[hs]d*/removable - do - if [[ $(< ${i}) = 1 ]] - then - removable=1 - fi - done + #for i in /sys/block/[hs]d*/removable + #do + # if [[ $(< ${i}) = 1 ]] + # then + # removable=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" @@ -496,54 +205,79 @@ fi } -hdd_size_below_256mb() +run_hardware_detection_disks() { - local hdd="$1" - local size - local retval - [[ -z ${hdd} ]] && 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 + 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 + export ALL_CDROMS="$(get_hwinfo cdrom)" +} + +setup_hdd_partitions() +{ + case "${INSTALL_METHOD}" in + auto) + BOOTHDD="" + SWAPHDD="" + ROOTHDD="${HDD}1" + ;; + normal) + BOOTHDD="${HDD}1" + SWAPHDD="${HDD}2" + ROOTHDD="${HDD}3" + ;; + esac + + # sanity check - should not happen + if is_mounted --device "${ROOTHDD}" then - retval="0" - else - retval="1" + echo "partition: device ${ROOTHDD} is already mounted, umount it" >&2 + umount "${ROOTHDD}" fi - - return "${retval}" -} - -setup_hdd_partitions_auto() -{ - ROOTHDD="${HDD}1" - - # run this only if FDISKPARTITIONBELOW256MB is not already 1 - if [[ ${FDISKPARTIONBELOW256MB} != 1 ]] + if [[ -n ${BOOTHDD} ]] then - if hdd_size_below_256mb ${HDD} + if is_mounted --device "${BOOTHDD}" then - FDISKPARTIONBELOW256MB=1 - else - FDISKPARTIONBELOW256MB=0 + echo "partition: device ${BOOTHDD} is already mounted, umount it" >&2 + umount "${BOOTHDD}" fi fi - ## delete disk - dd if=/dev/zero of=${HDD} count=1 &> /dev/null || die - - if [[ ${FDISKPARTIONBELOW256MB} = 1 ]] + if [[ ${INSTALL_METHOD} = auto ]] 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 + # run this only if FDISKPARTITIONBELOW256MB is not already 1 + if [[ ${FDISKPARTIONBELOW256MB} != 1 ]] + then + if device_minimum_size "${HDD}" 256 + then + FDISKPARTIONBELOW256MB=1 + else + FDISKPARTIONBELOW256MB=0 + fi + fi + + ## delete disk + dd if=/dev/zero of=${HDD} count=1 &> /dev/null || dialog_die + + if [[ ${FDISKPARTIONBELOW256MB} = 1 ]] + 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 @@ -553,17 +287,17 @@ 1 w 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 + 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 @@ -573,400 +307,287 @@ 1 w EOF + fi + else + cfdisk ${HDD} || dialog_die fi } -setup_hdd_partitions_manuell() -{ - BOOTHDD="${HDD}1" - SWAPHDD="${HDD}2" - ROOTHDD="${HDD}3" - - ## hdds partitionieren manuell - cfdisk ${HDD} || die -} - -setup_hdd_partitions_manuell_flash() -{ - ROOTHDD="${HDD}1" - - ## hdds partitionieren manuell - cfdisk ${HDD} || die -} - setup_hdd_format() { - mkswap ${SWAPHDD} || die - mke2fs -j -q ${BOOTHDD} || die - mke2fs -j -q ${ROOTHDD} || die -} - -setup_hdd_format_flash() -{ - mke2fs -j -q ${ROOTHDD} || die -} + install -d /tmp + :> /tmp/format.log -install_mount_rootfs() -{ - swapon ${SWAPHDD} || die - mount ${ROOTHDD} ${INSTALLPATH} || die - install -d ${INSTALLPATH}/boot || die - mount ${BOOTHDD} ${INSTALLPATH}/boot || die - cd ${INSTALLPATH} || die -} - -install_mount_rootfs_flash() -{ - mount ${ROOTHDD} ${INSTALLPATH} || die - install -d ${INSTALLPATH}/boot || die - cd ${INSTALLPATH} || die -} - -install_system_image() -{ - tar xvjpf ${CDPATH}/system/${CDIMAGENAME} -C ${INSTALLPATH} -} - -install_bootsector_chroot() -{ - local my_roothdd - local grubconf=${INSTALLPATH}/boot/grub/grub.conf - local grub2conf=/boot/grub/grub.cfg - - # check for grub2 - if [[ -f ${INSTALLPATH}/sbin/grub-mkconfig ]] + if [[ -n ${SWAPHDD} ]] then - # needed by grub-mkconfig on the first run - if [[ ! -f ${INSTALLPATH}/boot/grub/video.lst ]] + # sanity check - should not happen + if is_mounted --device "${SWAPHDD}" then - install -m0644 ${INSTALLPATH}/lib/grub/*/video.lst ${INSTALLPATH}/boot/grub/video.lst || die + echo "format: device ${SWAPHDD} is already mounted, umount it" >&2 + umount "${SWAPHDD}" fi + mkswap ${SWAPHDD} || die + fi - # set kernelopts - if [[ -f ${INSTALLPATH}/etc/conf.d/grub ]] + if [[ -n ${BOOTHDD} ]] + then + # sanity check - should not happen + if is_mounted --device "${BOOTHDD}" then - sed -i "s:^\(export GRUB_CMDLINE_LINUX_DEFAULT=\).*:\1\"${KERNELOPTS}\":" ${INSTALLPATH}/etc/conf.d/grub || die - else - echo "export GRUB_CMDLINE_LINUX_DEFAULT=\"${KERNELOPTS}\"" > ${INSTALLPATH}/etc/conf.d/grub || die + echo "format: device ${BOOTHDD} is already mounted, umount it" >&2 + umount "${BOOTHDD}" fi - echo 'grub-mkdevicemap' > ${INSTALLPATH}/root/.installrc || die - echo "LC_ALL=C grub-mkconfig -o ${grub2conf} &> /dev/null" >> ${INSTALLPATH}/root/.installrc || die - echo "grub-install --no-floppy ${HDD} &> /dev/null" >> ${INSTALLPATH}/root/.installrc || die - echo "exit 0" >> ${INSTALLPATH}/root/.installrc || die - # grub-legacy - else - ### grubconf schreiben - source ${INSTALLPATH}/boot/kernelversion + mkfs."${FORMAT_FILESYSTEM_BOOTHDD}" "${BOOTHDD}" &>> /tmp/format.log || dialog_die + fi - #for alx only - if [ -e ${INSTALLPATH}/etc/alx_version ] + if [[ -n ${ROOTHDD} ]] + then + # sanity check - should not happen + if is_mounted --device "${ROOTHDD}" then - OLD_ALXVER="${ALXVER}" - source ${INSTALLPATH}/etc/alx_version - KRNVER="ALX-${ALXVER}" - ALXVER="${OLD_ALXVER}" + echo "format: device ${ROOTHDD} is already mounted, umount it" >&2 + umount "${ROOTHDD}" fi - [[ -z ${KRNVER} ]] && KRNVER="AutoSta_LX" - [[ -z ${KRNINITRD} ]] && KRNINITRD="initrd" - [[ -z ${KRNIMG} ]] && KRNIMG="vmlinuz" - - # uuid support - if is_uuid_supported - then - my_roothdd="UUID=$(get_uuid ${ROOTHDD})" - else - my_roothdd="${ROOTHDD}" - fi + mkfs."${FORMAT_FILESYSTEM_ROOTHDD}" "${ROOTHDD}" &>> /tmp/format.log || dialog_die + fi +} - : > ${grubconf} || die - echo "default 0" >> ${grubconf} || die - echo "timeout 3" >> ${grubconf} || die - # using current root password - echo "password --md5 $(cat ${INSTALLPATH}/etc/shadow | grep root | cut -d: -f2)" >> ${grubconf} || die +install_system_image() +{ + pushd ${INSTALLROOT} > /dev/null + tar xvjpf ${IMAGEROOT}/${CDIMAGENAME} -C ${INSTALLROOT} + popd > /dev/null +} - echo >> ${grubconf} || die - echo "# normal boot" >> ${grubconf} || die - echo "title ${KRNVER}" >> ${grubconf} || die - echo "root (hd0,0)" >> ${grubconf} || die - echo "kernel /boot/${KRNIMG} root=${my_roothdd} ${KERNELOPTS} ${GRUBLEGACYOPTS}" >> ${grubconf} || die - if is_initrd_supported - then - echo "initrd /boot/${KRNINITRD}" >> ${grubconf} || die - fi +install_system_settings() +{ + local CONFIG - echo >> ${grubconf} || die - echo "# admin boot" >> ${grubconf} || die - echo "title ${KRNVER} - Re-run hardware-detection" >> ${grubconf} || die - echo "lock" >> ${grubconf} || die - echo "root (hd0,0)" >> ${grubconf} || die - echo "kernel /boot/${KRNIMG} root=${my_roothdd} ${KERNELOPTS} ${GRUBLEGACYOPTS} hardware-auto-detection" >> ${grubconf} || die - if is_initrd_supported - then - echo "initrd /boot/${KRNINITRD}" >> ${grubconf} || die - fi + # write fstab + CONFIG="${INSTALLROOT}/etc/fstab" + clearconfig + if [[ -n ${BOOTHDD} ]] + then + 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" - echo >> ${grubconf} || die - echo "title ${KRNVER} - Reset *all* local settings" >> ${grubconf} || die - echo "lock" >> ${grubconf} || die - echo "root (hd0,0)" >> ${grubconf} || die - echo "kernel /boot/${KRNIMG} root=${my_roothdd} ${KERNELOPTS} ${GRUBLEGACYOPTS} alx-reset-settings" >> ${grubconf} || die - if is_initrd_supported + # 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 - echo "initrd /boot/${KRNINITRD}" >> ${grubconf} || die + 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 - - # bootsector schreiben chrooted schreiben (lfs/magellan) - cat > ${INSTALLPATH}/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 fi +} - ## enters chroot - mount -t proc proc ${INSTALLPATH}/proc - mount -t sysfs sysfs ${INSTALLPATH}/sys - mount -o bind /dev ${INSTALLPATH}/dev - chroot ${INSTALLPATH} /bin/bash --rcfile /root/.installrc -i - umount ${INSTALLPATH}/proc - umount ${INSTALLPATH}/sys - umount ${INSTALLPATH}/dev - rm ${INSTALLPATH}/root/.installrc -} - -is_initrd_supported() -{ - # only generate initrds if the cmd exists - [[ -x ${INSTALLPATH}/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 - if [[ ${FORMFACTOR} = laptop ]] - then - OTHERMODS="acpi-cpufreq cpufreq_ondemand cpufreq_conservative cpufreq_powersave" - fi +### installer dialogs ### - # install an appropriate uvesafb.conf - install -d ${INSTALLPATH}/etc/modprobe.d || die - echo "options uvesafb mode_option=1024x768-32@60 scroll=ywrap" > ${INSTALLPATH}/etc/modprobe.d/uvesafb.conf || die +dialog_die() +{ + ERROR="$1" + RETVAL="$?" + dialog_install_failure + exit 1 +} - # install an appropriate viafb.conf - echo "options viafb viafb_mode=1024x768 viafb_refresh=60" > ${INSTALLPATH}/etc/modprobe.d/viafb.conf || die +dialog_warning() +{ + local retval - # install an appropriate i810fb.conf - echo "options i810fb xres=1024 yres=768 bpp=16 mtrr=1 hsync1=30 hsync2=62 vsync1=30 vsync2=60" > ${INSTALLPATH}/etc/modprobe.d/i810fb.conf || die + 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 +} - cat > ${INSTALLPATH}/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 - ## enters chroot - mount -t proc proc ${INSTALLPATH}/proc - mount -t sysfs sysfs ${INSTALLPATH}/sys - mount -o bind /dev ${INSTALLPATH}/dev - chroot ${INSTALLPATH} /bin/bash --rcfile /root/.installrc -i - umount ${INSTALLPATH}/proc - umount ${INSTALLPATH}/sys - umount ${INSTALLPATH}/dev - rm ${INSTALLPATH}/root/.installrc -} +### installer tasks ### -is_uuid_supported() +task_setup_system_menu() { - if [[ -x $(which busybox.mkinitrd &> /dev/null) ]] - then - # only detect uuids if supported - if [[ ! -z $(busybox.mkinitrd | grep blkid) ]] - then - return 0 - fi - fi + local mode + local retval - return 1 + mode="$(dialog_setup_system_menu)" + retval=$? + [[ ${retval} -eq 1 ]] && return 1 + if [[ ${retval} -eq 0 ]] + then + case "${mode}" in + "1") run_install auto ;; + "2") run_install normal ;; + "") task_setup_system_menu;; + esac + fi } -get_uuid() +task_hardware_detection() { - local UUID - local SEC_TYPE - local TYPE + local message + + run_hardware_detection_disks - local dev="$1" - [[ -z ${dev} ]] && die "no dev given" + message+=$"Harddrives:\n" - # check if given device is already an UUID - if [[ ${dev/UUID=/}x != ${dev}x ]] + if [[ ! -z ${ALL_DISKS} ]] then - eval "${dev}" - else - eval $(busybox.mkinitrd blkid ${dev} | grep "${dev}:" | sed 's/.*:\ //') + for i in ${ALL_DISKS} + do + message+="\Z3${i}\Zn " + done + message+="\n" fi - echo "${UUID}" -} -install_system_settings() -{ - # schreibe fstab - if is_uuid_supported + if [[ ! -z ${ALL_CDROMS} ]] then - echo -e "UUID=$(get_uuid ${BOOTHDD})\t/boot\t${FORMAT_FILESYSTEM}\tnoatime,noauto\t1 1" > ${INSTALLPATH}/etc/fstab || die - echo -e "UUID=$(get_uuid ${ROOTHDD})\t/\t${FORMAT_FILESYSTEM}\tnoatime\t0 0" >> ${INSTALLPATH}/etc/fstab || die - else - echo -e "${BOOTHDD}\t/boot\t${FORMAT_FILESYSTEM}\tnoatime,noauto\t1 1" > ${INSTALLPATH}/etc/fstab || die - echo -e "${ROOTHDD}\t/\t${FORMAT_FILESYSTEM}\tnoatime\t0 0" >> ${INSTALLPATH}/etc/fstab || die + message+="\n" + message+=$"Optical disk drives:\n" + for i in ${ALL_CDROMS} + 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" >> ${INSTALLPATH}/etc/fstab || die - echo -e "proc\t/proc\tproc\tdefaults\t0 0" >> ${INSTALLPATH}/etc/fstab || die - echo -e "shm\t/dev/shm\ttmpfs\tdefaults\t0 0" >> ${INSTALLPATH}/etc/fstab || die - # install network config skeleton - install -m0644 ${INSTALLPATH}/etc/alxconfig-ng/skel/net/net.eth0 ${INSTALLPATH}/etc/conf.d/ || die - - # 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" ;; + *) 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}\":" ${INSTALLPATH}/etc/splash/splash.conf || die - fi - fi + message+=$"\n\ZnFormfactor Laptop, activating 'ondemand' powersaving mode.\Zn" fi + + messagebox -y 12 -h $"Detected hardware:" "${message}" } -install_system_settings_flash() +task_setup_hdd_partitions() { - # schreibe fstab - if is_uuid_supported + local i + local retval + + if [[ -z ${ALL_DISKS} ]] then - echo -e "UUID=$(get_uuid ${ROOTHDD})\t/\t${FORMAT_FILESYSTEM}\tnoatime\t0 0" > ${INSTALLPATH}/etc/fstab || die + dialog_no_harddrive_found + exit 1 else - echo -e "${ROOTHDD}\t/\t${FORMAT_FILESYSTEM}\tnoatime\t0 0" > ${INSTALLPATH}/etc/fstab || die + HDD=$(dialog_select_target_harddrive) + retval=$? + [[ ${retval} -eq 1 ]] && return 1 + if [[ ${retval} -eq 0 ]] + then + dialog_setup_hdd_info + setup_hdd_partitions + fi fi - echo -e "proc\t/proc\tproc\tdefaults\t0 0" >> ${INSTALLPATH}/etc/fstab || die - echo -e "shm\t/dev/shm\ttmpfs\tdefaults\t0 0" >> ${INSTALLPATH}/etc/fstab || die } -install_umount_rootfs() +task_main() { - cd / - umount ${INSTALLPATH}/boot || die - umount ${INSTALLPATH} || die - swapoff ${SWAPHDD} || die -} + local method=0 + local retval -install_umount_rootfs_flash() -{ - cd / - umount ${INSTALLPATH} || die + 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 } -install_do_reboot() +run_install() { - reboot -} + local method="$1" -################################################# -# Install Ablauf Scripte # -################################################# + task_hardware_detection -run_install_normal() -{ - dialog_hardware_detection + case "${method}" in + auto) + export FORMAT_FILESYSTEM_BOOTHDD="" + export FORMAT_FILESYSTEM_ROOTHDD="${FORMAT_FILESYSTEM}" + export INSTALL_METHOD="${method}" + ;; + normal) + export FORMAT_FILESYSTEM_BOOTHDD="${FORMAT_FILESYSTEM}" + export FORMAT_FILESYSTEM_ROOTHDD="${FORMAT_FILESYSTEM}" + export INSTALL_METHOD="${method}" + ;; + single) + export FORMAT_FILESYSTEM_BOOTHDD="" + export FORMAT_FILESYSTEM_ROOTHDD="${FORMAT_FILESYSTEM}" + export INSTALL_METHOD="${method}" + ;; + *) + die "Unknown install method '${method}', aborting." + ;; + esac - dialog_setup_hdd_partitions_manuell + task_setup_hdd_partitions dialog_setup_hdd_format setup_hdd_format > /dev/null - install_mount_rootfs - (install_system_image > /tmp/install.log) 2> /tmp/install_errors.log | dialog_install_meter | dialog_install_system_image + 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 - - dialog_install_bootsector - install_bootsector_chroot - - install_umount_rootfs - dialog_install_successful -} - -run_install_flash() -{ - dialog_hardware_detection - - dialog_setup_hdd_partitions_manuell_flash - dialog_setup_hdd_format - setup_hdd_format_flash > /dev/null - install_mount_rootfs_flash - (install_system_image > /tmp/install.log) 2> /tmp/install_errors.log | dialog_install_meter | dialog_install_system_image - - dialog_install_settings - sleep 1 - install_system_settings_flash - 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_flash + umount_rootfs dialog_install_successful } -run_install_auto() -{ - dialog_hardware_detection - - dialog_setup_hdd_partitions_auto - dialog_setup_hdd_format - setup_hdd_format_flash > /dev/null - install_mount_rootfs_flash - (install_system_image > /tmp/install.log) 2> /tmp/install_errors.log | dialog_install_meter | dialog_install_system_image - - dialog_install_settings - sleep 1 - install_system_settings_flash - install_initrd_chroot - - dialog_install_bootsector - install_bootsector_chroot - - install_umount_rootfs_flash - dialog_install_successful -} +# set some proper traps +trap "trap_exit" SIGINT SIGQUIT -dialog_main +task_main exit 0