#!/bin/bash # # X-Amiga install script # Version 2007-10 # # Requires dialog, mktemp, lshw, vbetest (from lrmi), fdisk, cfdisk, sfdisk, imagemagick, splashutils, beep TITLE="X-AMIGA Installer" INSTALLER=/installer # Location of installer PACKAGES=$INSTALLER/packages # Location of packages MNT=/mnt # Location of target device(s) MEDIA=/mnt # Location of cdrom/usb devices XTARGET=$MNT/xamiga # Target for Linux files ATARGET=$MNT/amiga # Target for Amiga-specific files XAHOME=$XTARGET/home/xamiga # Home folder for xamiga user LIST=`mktemp -d` # Installer-generated files (mktemp allows safe temporary file creation) BUILD=`mktemp -d` # Build directory (copied to $XTARGET) mkdir -p $BUILD/boot/grub $BUILD/usr/bin $BUILD/etc/init.d $BUILD/etc/splash/xamiga/images umount $ATARGET $XTARGET 2>/dev/null # Need to unmount in case installer is being re-run rmdir $ATARGET 2>/dev/null [ -d $XTARGET ] || mkdir $XTARGET BOOTLDR="None" welcome() { # Initial 'welcome' screen dialog --backtitle "$TITLE" --title "Welcome!" \ --msgbox "\nThis installer will set up X-Amiga on your computer.\n\nNo changes will be made to your system until you press the 'Install' button at the end.\n\nPress 'Enter' to continue. You can press 'Esc' at any time to exit." 0 0 test $? = 255 && exit_installer } detect_hardware() { # Detect system hardware dialog --backtitle "$TITLE" --title "Hardware detection" \ --msgbox "\nThe installer will first try to determine your computer's hardware. The list it produces will be available in subsequent steps.\n\nPress 'OK' to start hardware detection (this will take a few seconds...)" 0 0 # Use 'lshw' to detect hardware # sed deletes first 19 characters from each line (could have used 'cut' instead...) lshw -short | sed "s/^.\{19\}//" > $LIST/hardware test $? = 255 && exit_installer } list_hardware() { # Print list of hardware tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/test$$ trap "rm -f $tempfile" 0 1 2 5 15 cat $LIST/hardware | expand >> $tempfile dialog --clear --title "Hardware list" \ --textbox "$tempfile" 0 0 test $? = 255 && exit_installer } partition() { # Partition hard drive dialog --backtitle "$TITLE" --title "1 - Partitioning" \ --msgbox "\nX-Amiga needs a free partition or hard drive.\n\nThis must be a Linux partition (type 83).\n\nIf your drive is already partitioned, you can skip this step by choosing Skip on the next screen." 0 0 test $? = 255 && exit_installer } select_drive() { # Select drive for partitioning # Produce list of drives in form /dev/hdx # sed erases everything after : sfdisk -s | grep ^/dev | sed 's/:.*//' > $LIST/drives # Pick initial drive from drives list DRIVES=`cat $LIST/drives` DRIVE=`sed q $LIST/drives` tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/test$$ trap "rm -f $tempfile" 0 1 2 5 15 dialog --backtitle "$TITLE" --title "Select drive" --cancel-label "Skip" --colors \ --inputbox "\nThe following drives have been detected:\n\n\Z4$DRIVES\Zn\n\n\nWhich drive would you like to partition?" 0 0 $DRIVE 2> $tempfile case $? in 0) if grep -wq `cat $tempfile` $LIST/drives then DRIVE=`cat $tempfile` [ -f $LIST/ptable ] && rm -f $LIST/ptable # This is modified version of cfdisk - writing is disabled; output used later as input for sfdisk $INSTALLER/bin/cfdisk $DRIVE mv /tmp/ptable $LIST/ptable 2>/dev/null else drive_error; select_drive fi;; 1) [ -f $LIST/ptable ] && rm -f $LIST/ptable;; 255) exit_installer;; esac } drive_error() { # If user chooses invalid drive dialog --backtitle "$TITLE" --title "Error" --colors \ --msgbox "\nPlease select a valid drive!\n\nThe following drives have been found:\n\n\Z4$DRIVES\Zn" 0 0 test $? = 255 && exit_installer } install_dest() { # Select X-Amiga (Linux) destination # Create list of Linux partitions from target's partition table # If cfdisk was used, use its output ptable; otherwise, use current ptable # sed erases everything after 1st space if [ -f $LIST/ptable ] then grep "^/dev.*Id=83" $LIST/ptable | sed 's/ .*//' > $LIST/partitions else fdisk -l | grep "^/dev.* 83 " | sed 's/ .*//' > $LIST/partitions fi PART=`sed q $LIST/partitions` tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/test$$ trap "rm -f $tempfile" 0 1 2 5 15 dialog --backtitle "$TITLE" --title "2 - Install destination" --cancel-label "Skip" \ --inputbox "\nWhere would you like to install X-Amiga? (eg. /dev/hda1)" 0 0 $PART 2> $tempfile case $? in 0) if grep -wq `cat $tempfile` $LIST/partitions then INSTALLDEST=`cat $tempfile` else partition_error; install_dest fi;; 1) INSTALLDEST="None";; 255) exit_installer;; esac } amiga_dest() { # Select destination for Amiga-specific files tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/test$$ trap "rm -f $tempfile" 0 1 2 5 15 [ $INSTALLDEST = "None" -o -z $INSTALLDEST ] && PART=`sed q $LIST/partitions` || PART=$INSTALLDEST dialog --backtitle "$TITLE" --title "3 - Amiga destination" --cancel-label "Skip" \ --inputbox "\nSelect a partition for Amiga files (Kickstart ROM, operating system).\n\nThe X-Amiga partition is the default." 0 0 $PART 2> $tempfile case $? in 0) if grep -wq `cat $tempfile` $LIST/partitions then AMIGADEST=`cat $tempfile` else partition_error; amiga_dest fi;; 1) AMIGADEST="None";; 255) exit_installer;; esac } partition_error() { # If user chooses invalid partition PARTITIONS=`cat $LIST/partitions` dialog --backtitle "$TITLE" --title "Error" --colors \ --msgbox "\nPlease select a valid Linux partition!\n\nThe following Linux partitions have been found:\n\n\Z4$PARTITIONS\Zn" 0 0 test $? = 255 && exit_installer } select_bootloader() { # Choose bootloader (currently only GRUB) BOOTDEV="None" tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/test$$ trap "rm -f $tempfile" 0 1 2 5 15 dialog --backtitle "$TITLE" --title "4 - Bootloader" --cancel-label "Skip" \ --menu "\nA bootloader will be needed to boot your computer into the X-Amiga system.\n\nIf you already have a bootloader just select 'None'." 0 0 2 \ "GRUB" "GRand Unified Bootloader" \ "None" "Do not install a bootloader" 2> $tempfile case $? in 0) BOOTLDR=`cat $tempfile` if [ $BOOTLDR = "GRUB" ] then select_bootdev else rm -f $BUILD/boot/grub/grub.conf 2>/dev/null fi;; 1) BOOTLDR="None";; 255) exit_installer;; esac } select_bootdev() { # Select device on which to install bootloader tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/test$$ trap "rm -f $tempfile" 0 1 2 5 15 dialog --backtitle "$TITLE" --title "Confirm boot device" --cancel-label "Skip" \ --inputbox "\nPlease confirm your boot device (eg. /dev/hda). GRUB will be installed into the MBR (Master Boot Record)." 0 0 $DRIVE 2> $tempfile case $? in 0) if grep -wq `cat $tempfile` $LIST/drives then BOOTDEV=`cat $tempfile` else drive_error; select_bootdev fi;; 1) BOOTDEV="None";; 255) exit_installer;; esac } select_video() { # Select videomode from list generated using vbetest # Create list of video modes using vbetest echo 'q' | vbetest > $LIST/videomodes # sed deletes '[' and ']', replaces color info, appends 'off' to end of line VIDEOMODES=`cat $LIST/videomodes | grep -F [ | sed "s/\[//;s/\]//;s/ (16 color palette)/x4/;s/ (256 color palette)/x8/;s/ (5:5:5)/x15/;s/ (5:6:5)/x16/;s/ (8:8:8)/x24/;s/$/ off/"` # Set first item in radiolist as default VIDEOMODES=`echo $VIDEOMODES | sed "s/off/on/"` tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/test$$ trap "rm -f $tempfile" 0 1 2 5 15 dialog --backtitle "$TITLE" --title "5 - Video mode" --cancel-label "Skip" \ --radiolist "\nSelect the resolution at which you would like to run UAE:" 14 64 6 $VIDEOMODES 2> $tempfile case $? in 0) VIDEOMODE=`cat $tempfile` # sed searches for line beginning with [$VIDEOMODE, deletes everything before '] ' and after ' (' # (could have used grep and cut instead...) VIDEORES=`cat $LIST/videomodes | sed '/\['"$VIDEOMODE"'/!d;s/.*] //;s/ (.*//'` 2>/dev/null # $VIDEORES is in form 'xres x yres' # sed deletes everything after x and before x to get individual values XRES=`echo $VIDEORES | sed 's/x.*//'` YRES=`echo $VIDEORES | sed 's/.*x//'` # sed replaces color info, searches for line beginning with [$VIDEOMODE, deletes everything before second space VIDEODEP=`cat $LIST/videomodes | sed 's/(16 color palette)/4/;s/(256 color palette)/8/;s/(5:5:5)/15/;s/(5:6:5)/16/;s/(8:8:8)/24/' | sed '/\['"$VIDEOMODE"'/!d;s/.* //'` 2>/dev/null # Add 512 for VGA mode VIDEOMODE=`expr $VIDEOMODE + 512` ;; 1) VIDEOMODE="None" VIDEORES="Nothing" VIDEODEP="zero";; 255) exit_installer;; esac } select_sound() { # Select computer's sound card from list # alsalist is a tab-separated text file ALSALIST=`cat $INSTALLER/alsalist | sed '1d;s/$/ off/'` tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/test$$ trap "rm -f $tempfile" 0 1 2 5 15 dialog --backtitle "$TITLE" --title "6 - Sound card" --cancel-label "Skip" --help-button --help-label "Hardware list" \ --radiolist "\nSelect your audio device:" 17 96 10 $ALSALIST 2> $tempfile case $? in 0) AUDIO=`cat $tempfile`;; 1) AUDIO="None";; 2) list_hardware select_sound;; 255) exit_installer;; esac } net_tools() { # Install suite of networking tools dialog --backtitle "$TITLE" --title "7 - Networking" \ --yesno "\nWould you like to install networking tools? Some configuration may be needed later." 0 0 case $? in 0) NET="Yes";; 1) NET="No";; 255) exit_installer;; esac } root_pass() { # Set root password error=1 while [ $error -ne 0 ] do tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/test$$ trap "rm -f $tempfile" 0 1 2 5 15 dialog --backtitle "$TITLE" --title "8 - Password" --cancel-label "Skip" \ --insecure --passwordbox "\nPlease enter a system password." 9 44 2> $tempfile case $? in 0) ROOTPASS=`cat $tempfile` dialog --backtitle "$TITLE" --title "8 - Password" --cancel-label "Skip" \ --insecure --passwordbox "\nPlease re-enter password." 9 44 2> $tempfile ROOTPASS2=`cat $tempfile` if [ "$ROOTPASS2" = "$ROOTPASS" ] then error=0 else dialog --backtitle "$TITLE" --title "Error" \ --msgbox "\nPasswords don't match!" 0 0; error=1; test $? = 255 && exit_installer fi;; 1) return;; 255) exit_installer;; esac done } view_summary() { # Print summary of choices so far # Check if deleting partition, or entire drive... if [ -f $LIST/ptable ] then warning_msg="Partitioning will erase all data on drive $DRIVE" elif [ -n "$INSTALLDEST" -a $INSTALLDEST != "None" -a -n "$AMIGADEST" -a $AMIGADEST != "None" -a "$INSTALLDEST" != "$AMIGADEST" ] then warning_msg="All data on partitions $INSTALLDEST and $AMIGADEST will be erased" elif [ -n $INSTALLDEST -a $INSTALLDEST != "None" ] then warning_msg="All data on partition $INSTALLDEST will be erased" elif [ -n $AMIGADEST -a $AMIGADEST != "None" ] then warning_msg="All data on partition $AMIGADEST will be erased" else warning_msg="No install destination selected" fi [ $BOOTLDR = "GRUB" ] && BOOTDEV_S=$BOOTDEV || BOOTDEV_S="--" dialog --backtitle "$TITLE" --title "View summary" --ok-label "Continue" --no-collapse --colors \ --msgbox "\nThese are your chosen installation settings:\n\n \Z2Install destination:\Zn $INSTALLDEST\n \Z2Amiga destination:\Zn $AMIGADEST\n \Z2Boot loader:\Zn $BOOTLDR\n \Z2Boot device:\Zn $BOOTDEV_S\n \Z2Video:\Zn $VIDEORES in $VIDEODEP bit color\n \Z2VGA mode:\Zn $VIDEOMODE\n \Z2Sound:\Zn $AUDIO\n \Z2Networking tools:\Zn $NET\n\n \Z1Important: $warning_msg\Zn" 0 0 test $? = 255 && exit_installer } settings_menu() { # Options to change settings or continue while true do tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/test$$ trap "rm -f $tempfile" 0 1 2 5 15 dialog --backtitle "$TITLE" --title "Settings menu" --cancel-label "Continue" \ --menu "\nSelect an option if you need to change a setting.\nWhen you are ready, press 'Continue'." 17 56 9 \ "1" "Partitioning" \ "2" "Install destination" \ "3" "Amiga destination" \ "4" "Bootloader" \ "5" "Video mode" \ "6" "Sound card" \ "7" "Networking" \ "8" "Password" \ "9" "View summary" 2> $tempfile case $? in 0) choice=`cat $tempfile` case $choice in 1) select_drive;; 2) install_dest;; 3) amiga_dest;; 4) select_bootloader;; 5) select_video;; 6) select_sound;; 7) net_tools;; 8) root_pass;; 9) view_summary;; esac;; 1) return;; 255) exit_installer;; esac done } error_check() { # Simple error checking - all these are critical for installation [ -z $ROOTPASS ] && error_msg=" * No password entered! *" && error=1 [ $VIDEOMODE = "None" ] && error_msg=" * No video mode selected! *" && error=1 [ $BOOTLDR = "GRUB" -a $BOOTDEV = "None" ] && error_msg=" * No GRUB boot device selected! *" && error=1 [ -z $INSTALLDEST -o $INSTALLDEST = "None" ] && error_msg=" * No install destination selected! *" && error=1 error_message } error_message() { # Display error message, using message generated in 'error_check' while [ $error -ne 0 ] do dialog --backtitle "$TITLE" --title "Installer error" --ok-label "Go back" --no-collapse --colors \ --msgbox "\nThe installer has encountered an error:\n\n\Z1$error_msg\Zn\n\nPlease go back and check your settings carefully." 0 0 test $? = 255 && exit_installer error_msg="" error=0 settings_menu error_check done } install_start() { # Ready to start installing dialog --backtitle "$TITLE" --title "Ready to install" --ok-label "Install" \ --msgbox "\nThe installer is now ready to set up X-Amiga on your computer.\n\nPress 'Install' to begin installation.\n\nPress 'Esc' to exit the installer." 11 66 test $? = 255 && exit_installer } create_log() { # Create log of hardware details, installer details, partition table, kernel config, and Gentoo's emerge output touch $BUILD/log echo "*** X-AMIGA INSTALLER LOG (dialog) ***" >> $BUILD/log echo -e "--------------------------------------\n\n" >> $BUILD/log echo -e "DRIVES (fdisk):\n" >> $BUILD/log cat $LIST/drives >> $BUILD/log log_separator echo -e "VIDEO MODES (vbetest):\n" >> $BUILD/log cat $LIST/videomodes >> $BUILD/log log_separator echo -e "INSTALLER OPTIONS \n" >> $BUILD/log echo "Install destination: $INSTALLDEST" >> $BUILD/log echo "Amiga destination: $AMIGADEST" >> $BUILD/log echo "Boot loader: $BOOTLDR" >> $BUILD/log echo "Boot device: $BOOTDEV_S" >> $BUILD/log echo "Video: $VIDEORES in $VIDEODEP bit color" >> $BUILD/log echo "VGA mode: $VIDEOMODE" >> $BUILD/log echo "Sound: $AUDIO" >> $BUILD/log echo "Networking: $NET" >> $BUILD/log log_separator echo -e "PARTITION TABLE\n" >> $BUILD/log [ -f $LIST/ptable ] && cat $LIST/ptable >> $BUILD/log log_separator } log_separator() { # Makes log file easier to read echo -e "\n--------------------------------------------------------------------------------" >> $BUILD/log } log_error() { # Note progress in log file [ "${1}" != "0" ] && echo "$log_msg Error" >> $BUILD/log || echo "$log_msg OK" >> $BUILD/log } prep_drive() { # Prepare destination drive - partition, format, create directory tree dialog --backtitle "$TITLE" --title "" \ --infobox "\n\n Preparing destination drive..." 8 64 if [ -f $LIST/ptable ] then sfdisk $DRIVE < $LIST/ptable >> $BUILD/log 2>&1 SWAP=`grep "^/dev/.*Id=82" $LIST/ptable | cut -b 1-9` [ $SWAP ] && mkswap $SWAP >> $BUILD/log 2>&1 log_separator fi mke2fs $INSTALLDEST >> $BUILD/log 2>&1 log_separator log_msg="Mounting X-Amiga destination $INSTALLDEST..." mount $INSTALLDEST $XTARGET log_error $? # Check if amigadest exists, and if different from installdest if [ $AMIGADEST != "None" -a $AMIGADEST != $INSTALLDEST ] then mke2fs $AMIGADEST >> $BUILD/log 2>&1 && log_separator mkdir $ATARGET log_msg="Mounting Amiga-file destination $AMIGADEST..." mount $AMIGADEST $ATARGET log_error $? else mkdir $XTARGET/amiga $ATARGET log_msg="Bind-mounting Amiga-file destination $XTARGET/amiga..." mount -o bind $XTARGET/amiga $ATARGET log_error $? fi # Create directories log_msg="Creating Linux directories..." mkdir -p $XTARGET/amiga $XTARGET/bin $XTARGET/dev $XTARGET/etc $XTARGET/home $XTARGET/lib $XTARGET/mnt $XTARGET/proc $XTARGET/sbin $XTARGET/sys $XTARGET/tmp $XTARGET/usr $XTARGET/var $XTARGET/etc/init.d $XTARGET/lib/firmware $XTARGET/var/lib $XTARGET/var/log $XTARGET/var/run $XTARGET/usr/sbin log_error $? log_msg="Creating Amiga directories..." mkdir -p $ATARGET/OS $ATARGET/ROM $ATARGET/ADF log_error $? chmod 1777 $XTARGET/tmp # Create essential device nodes (udev takes care of rest later) cd $XTARGET/dev log_msg="Creating device nodes..." ( mknod -m 0600 console c 5 1 mknod -m 0600 null c 1 3 mknod -m 0600 tty c 5 0 mknod -m 0600 tty0 c 4 0 mknod -m 0600 tty1 c 4 1 ) log_error $? log_msg="Assigning ownership to nodes..." ( chown root:tty tty chown root:tty tty0 chown root:tty tty1 ) log_error $? log_separator } install_packages() { # This is main installation loop # Remove unnecessary items from packagelist log_msg="Finalizing package list..." ( [ $NET = "No" ] && NONET="network" [ $BOOTLDR = "None" ] && NOBOOT="boot" sed '/,'"$NONET"',/d;/,'"$NOBOOT"',/d' < $INSTALLER/packagelist > $LIST/packagelist ) log_error $? # packagelist is comma-separated list of packages PACKAGELIST=`cut -d "," -f1 $LIST/packagelist` # Count packages so number of steps can be calculated (for progress bar) PACKAGETOTAL=`sed -n '$=' $LIST/packagelist` STEPS=`expr $PACKAGETOTAL - 1` POS=1 echo -e "Installing packages..." >> $BUILD/log log_separator cd $XTARGET ( for PACKAGE in $PACKAGELIST do CATEGORY=`grep $PACKAGE $LIST/packagelist | cut -d "," -f2` ITEM=`grep $PACKAGE $LIST/packagelist | cut -d "," -f3` TOTAL=`grep $PACKAGE $LIST/packagelist | cut -d "," -f4` STAGE="Installing $CATEGORY system: $ITEM of $TOTAL" echo "XXX" echo -e "\n" echo "$STAGE" echo "XXX" echo $PROGRESS PROGRESS=`expr $POS '*' 100 / $STEPS` POS=`expr $POS + 1` echo $PACKAGE >> $BUILD/log tar xjf $PACKAGES/$PACKAGE >> $BUILD/log 2>&1 log_separator done ) | dialog --backtitle "$TITLE" --title "Installing X-Amiga..." --gauge "" 8 48 } system_files() { # Create system files dialog --backtitle "$TITLE" --title "" \ --infobox "\n\n Creating system files & tidying up..." 8 64 # Create busybox symlinks cd $BUILD log_msg="Creating busybox symlinks..." tar xf $XTARGET/usr/share/busybox/busybox-links.tar log_error $? # Some directories can be deleted... echo "Removing unnecessary directories..." >> $BUILD/log rm -rf $XTARGET/etc/conf.d $XTARGET/etc/env.d $XTARGET/etc/init.d/alsasound $XTARGET/etc/init.d/splash $XTARGET/usr/include $XTARGET/usr/lib/pkgconfig $XTARGET/usr/share/X11 $XTARGET/usr/share/aclocal $XTARGET/usr/share/busybox $XTARGET/usr/share/doc $XTARGET/usr/share/info $XTARGET/usr/share/man $XTARGET/lost+found $XTARGET/root $ATARGET/lost+found $XTARGET/usr/share/locale $XTARGET/usr/share/splashutils $XTARGET/usr/share/tabset $XTARGET/usr/share/terminfo 2>/dev/null # Remove static libraries echo "Removing static libraries..." >> $BUILD/log rm -rf $XTARGET/usr/lib/*.a $XTARGET/usr/lib/*.la $XTARGET/usr/lib/alsa-lib/smixer/*.a $XTARGET/usr/lib/alsa-lib/smixer/*.la 2>/dev/null # Create kernel modules list log_msg="Creating modules list..." touch $BUILD/etc/init.d/modules log_error $? [ -n $AUDIO -a $AUDIO != "None" -a $AUDIO != "dummy" ] && echo "snd_$AUDIO" >> $BUILD/etc/init.d/modules # Generate fstab, based on choices for install destination, amiga destination and swap partition # Need to check if install destination is same as Amiga destination log_msg="Generating fstab..." ( if [ $AMIGADEST != $INSTALLDEST ] then sed "s|INSTALLDEST|$INSTALLDEST|;s|AMIGADEST|$AMIGADEST|" < $INSTALLER/proto/fstab.0 > $LIST/fstab else sed "s|INSTALLDEST|$INSTALLDEST|;/^AMIGADEST*/ d" < $INSTALLER/proto/fstab.0 > $LIST/fstab fi # Does partition table contain swap partition? if [ -f $LIST/ptable ] then SWAP=`grep "^/dev/.*Id=82" $LIST/ptable | cut -b 1-9` # sed deletes everything after first space; deletes numbers else SWAP=`fdisk -l $(echo $INSTALLDEST | sed 's/ .*//;s/[0-9].*//') | grep "^/dev.* 82 " | cut -b 1-9` fi if [ $SWAP ] then sed "s|SWAP|$SWAP|" < $LIST/fstab > $BUILD/etc/fstab else sed "/^SWAP*/ d" < $LIST/fstab > $BUILD/etc/fstab fi ) log_error $? # Generate mtab log_msg="Generating mtab..." ( sed "s|INSTALLDEST|$INSTALLDEST|" < $INSTALLER/proto/mtab.0 > $BUILD/etc/mtab ) log_error $? # Generate grub.conf, based on choices for install destination and video mode # Loop through list of available drives, looking for destination # Then set grub's root using correct format (hdx,y) log_msg="Generating grub.conf..." ( n=0 dev0=`echo $INSTALLDEST | sed "s/[0-9].*//"` grep "/dev" $LIST/drives | sed "s/:.*//" | while read dev do if [ $dev = $dev0 ] then p=`echo $INSTALLDEST | sed "s/.\{8\}//"` pg=$(( $p - 1 )) GRUBROOT=`echo "(hd"$n","$pg")"` sed "s|GRUBROOT|$GRUBROOT|;s|INSTALLDEST|$INSTALLDEST|;s|VIDEOMODE|$VIDEOMODE|;s|VIDEORES|$VIDEORES|" < $INSTALLER/proto/grub.conf.0 > $BUILD/boot/grub/grub.conf break; else n=`expr $n + 1` fi done ) log_error $? # Generate startxa command (startx + E-UAE) log_msg="Generating startxa..." ( sed "s/VIDEORES/$VIDEORES/;s/VIDEODEP/$VIDEODEP/" < $INSTALLER/proto/startxa.0 > $BUILD/usr/bin/startxa chmod +x $BUILD/usr/bin/startxa ) log_error $? # Generate splash images using ImageMagick log_msg="Generating splash images..." ( convert $INSTALLER/proto/splash.png.0 -resize $VIDEORES -gravity center -extent $VIDEORES $BUILD/etc/splash/xamiga/images/silent-$VIDEORES.png convert $INSTALLER/proto/splash.png.1 -resize $VIDEORES -gravity center -extent $VIDEORES $BUILD/etc/splash/xamiga/images/verbose-$VIDEORES.png ) log_error $? # Generate appropriate splash cfg file log_msg="Generating splash config..." sed "s/VIDEORES/$VIDEORES/;s/VIDEODEP/$VIDEODEP/;s/XRES/$XRES/;s/YRES/$YRES/" < $INSTALLER/proto/splashcfg.0 > $BUILD/etc/splash/xamiga/$VIDEORES.cfg log_error $? # Generate initrd echo "Generating splash initrd" >> $BUILD/log # splash_geninitramfs works in /etc - must use bind mounting since /etc is read-only... cp -a $INSTALLER/proto/splash $BUILD/etc mount -o bind $BUILD/etc /etc splash_geninitramfs xamiga -r $VIDEORES -g $BUILD/boot/fbsplash-xamiga-$VIDEORES --no8bpp -v >> $BUILD/log 2>&1 umount /etc # Copy system files to target log_msg="Copying system files..." ( cd $XTARGET tar xjf $INSTALLER/system/system.tar.bz2 cp -a $BUILD/* $XTARGET/ ) log_error $? # Create xamiga user log_msg="Creating xamiga user..." ( XAHOME=$XTARGET/home/xamiga mkdir $XAHOME chmod 755 $XAHOME find $XAHOME -print | xargs chown xamiga:xamiga ) log_error $? # If $AMIGADEST is defined, mount it on startup [ $AMIGADEST != "None" -a $AMIGADEST != $INSTALLDEST ] && echo -e "\n# Mount Amiga directory\nmount -o rw $AMIGADEST /amiga" >> $XTARGET/etc/init.d/rcS # Chroot into target and configure system log_msg="Configuring target system..." ( mount -o bind /dev $XTARGET/dev mount -t proc none $XTARGET/proc mount -o bind /sys $XTARGET/sys chroot $XTARGET /bin/sh -c "echo 'xamiga:$ROOTPASS' | /usr/sbin/chpasswd && exit" >> $BUILD/log 2>&1 # Set ALSA if sound card exists if [ $AUDIO != "None" -a $AUDIO != "dummy" ] then echo -e "\nConfiguring ALSA...\n" >> $BUILD/log modprobe "snd_$AUDIO" sleep 2 chroot $XTARGET /bin/sh -c " amixer set Master 31 unmute amixer set PCM 15 unmute alsactl store exit" >> $BUILD/log 2>&1 fi umount $XTARGET/sys umount $XTARGET/proc umount $XTARGET/dev ) log_error $? # Install GRUB if necessary if [ $BOOTLDR = "GRUB" ] then echo -e "\nInstalling GRUB...\n" >> $BUILD/log grub-install --root-directory=$XTARGET $BOOTDEV >> $BUILD/log 2>&1 cd $XTARGET/boot/grub ln -s grub.conf menu.lst fi # Copy log to target echo "Installation finished! Copying log file to target..." >> $BUILD/log cp -a $BUILD/log /$XTARGET } install_end() { dialog --backtitle "$TITLE" --title "Finished installing" --yes-label "Continue" --no-label "Finish" \ --yesno "\nMain installation has finished!\n\nPress 'Continue' if you want to set up Amiga files.\n\nPress 'Finish' for post-installation notes and exit." 11 66 case $? in 0) AMIGA=1;; 1) AMIGA=0 return;; 255) exit_installer;; esac } rom_setup() { dialog --backtitle "$TITLE" --title "Kickstart ROM setup" \ --yesno "\nWould you like to transfer an Amiga Kickstart ROM from CDROM or USB drive?" 8 64 case $? in 0) DIRTYPE="Amiga ROM" insert_medium choose_src ROMDIR=$DEST ROMFILE=$(basename $(find $DEST -name *.rom)) 2>/dev/null KEYFILE=$(basename $(find $DEST -name *.key)) 2>/dev/null;; 1) ROMDIR="" ROMFILE="" KEYFILE="" return;; 255) exit_installer;; esac } os_setup() { dialog --backtitle "$TITLE" --title "Amiga OS setup" \ --yesno "\nWould you like to transfer a previously installed Amiga Operating System from CDROM or USB drive?" 8 64 case $? in 0) DIRTYPE="Amiga OS" insert_medium choose_src OSDIR=$DEST # Essential: change ownership and permissions for OS directories chown -R xamiga:xamiga $OSDIR chmod -R 755 $OSDIR ;; 1) OSDIR="" return;; 255) exit_installer;; esac } floppy_setup() { dialog --backtitle "$TITLE" --title "Amiga floppy setup" \ --yesno "\nWould you like to transfer a directory containing ADF images?" 8 64 case $? in 0) DIRTYPE="Amiga ADF" insert_medium choose_src ADFDIR=$DEST;; 1) AFDIR="" return;; 255) exit_installer;; esac } insert_medium() { dialog --backtitle "$TITLE" --title "Insert medium" --ok-label "OK" \ --msgbox "\nPlease insert a CDROM or USB drive.\n\nWait a few seconds for the device to settle before pressing 'OK'." 0 0 test $? = 255 && exit_installer # Mounts variety of CDROM devices # (Same code as used in initrd) # CDROM DEVICES DEVICES="/dev/cdrom* /dev/cdroms/* /dev/ide/cd/* /dev/sr*" # USB Keychain/Storage DEVICES="$DEVICES /dev/sd*" # IDE devices DEVICES="$DEVICES /dev/hd*" # USB using the USB Block Driver DEVICES="$DEVICES /dev/ubd* /dev/ubd/*" # Mount CDROM for i in $DEVICES do # Mount only block devices if [ -b "$i" ] then mount -r -t iso9660 $i $MEDIA/cdrom >/dev/null 2>&1 if [ $? = 0 ] then break fi fi done } choose_src() { tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/test$$ trap "rm -f $tempfile" 0 1 2 5 15 dialog --backtitle "$TITLE" --title "Select $DIRTYPE source directory" --help-button \ --fselect $MEDIA/ 8 48 2> $tempfile case $? in 0) SRC=`cat $tempfile` choose_dest;; 1) umount $MEDIA/cdrom 2>/dev/null;; 2) dir_help;; 255) exit_installer;; esac } choose_dest() { tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/test$$ trap "rm -f $tempfile" 0 1 2 5 15 dialog --backtitle "$TITLE" --title "Select $DIRTYPE destination directory" \ --dselect $ATARGET/ 8 48 2> $tempfile case $? in 0) DEST=`cat $tempfile` confirm_copy;; 1) umount $MEDIA/cdrom 2>/dev/null;; 255) exit_installer;; esac } dir_help() { dialog --backtitle "$TITLE" --title "Directory help" \ --msgbox "\nSpace once to choose directory from list, Space twice to enter chosen directory, Backspace to go up one directory level;\n\nTAB/Shift+TAB (or Cursor Up/Down) to move between boxes, Enter to confirm selection.\n\nDirectories can also be typed." 0 0 test $? = 255 && exit_installer choose_src } confirm_copy() { dialog --backtitle "$TITLE" --title "Confirm copy" --yes-label "Copy" --no-label "Go Back" --colors \ --yesno "\nPlease confirm the $DIRTYPE source directory:\n\n\Z1$SRC\Zn\n\nand destination directory:\n\n\Z1$DEST\Zn\n\nIf these are correct, press 'Copy' to copy files.\n\nPress 'Go Back' to choose again." 0 0 case $? in 0) copy_files copy_another;; 1) choose_src;; 255) exit_installer;; esac } copy_files() { dialog --backtitle "$TITLE" --title "Copying..." \ --infobox "\n\n Copying $DIRTYPE files..." 8 64 [ -d $DEST ] || mkdir -p $DEST cp -a $SRC/* $DEST umount $MEDIA/cdrom 2>/dev/null } copy_another() { dialog --backtitle "$TITLE" --title "Copy another?" \ --yesno "\nWould you like to copy another $DIRTYPE directory?" 8 64 case $? in 0) insert_medium choose_src;; 1) return;; 255) exit_installer;; esac } euae_setup() { dialog --backtitle "$TITLE" --title "UAE setup" \ --yesno "\nWould you like to generate an UAE configuration file? You should edit this file later using a text editor." 8 64 case $? in 0) generate_uaerc;; 1) return;; 255) exit_installer;; esac } generate_uaerc() { # Generate uaerc in stages (preserving original configuration order) # If directories defined, strip '$ATARGET' and prepend '/amiga' [ $ROMDIR ] && ROMDIR="/amiga`echo $ROMDIR | sed "s|$ATARGET||"`" [ $ADFDIR ] && ADFDIR="/amiga`echo $ADFDIR | sed "s|$ATARGET||"`" # First section... sed "s|ROMDIR|$ROMDIR|;s|ADFDIR|$ADFDIR|;s|ROMFILE|$ROMFILE|;s|KEYFILE|$KEYFILE|" < $INSTALLER/proto/uaerc.0 > $LIST/uaerc # Only process OS directory if it's defined if [ $OSDIR ] then # Get list of Amiga directories ('partitions') ls $OSDIR > $LIST/osdirs OSDIR="/amiga`echo $OSDIR | sed "s|$ATARGET||"`" # Middle section: add Amiga drives... # It assumes first directory found has boot priority 1 - not very intelligent DRIVENUM=0 for i in $(cat $LIST/osdirs) do [ $DRIVENUM -eq 0 ] && BOOTPRI=1 || BOOTPRI=0 echo "filesystem2=rw,DH$DRIVENUM:$i:$OSDIR/$i,$BOOTPRI" >> $LIST/uaerc DRIVENUM=`expr $DRIVENUM + 1` done fi # Append second section of uaerc... sed "s|XRES|$XRES|;s|YRES|$YRES|" < $INSTALLER/proto/uaerc.1 >> $LIST/uaerc # Finally, copy uaerc to home directory... cp -a $LIST/uaerc $XAHOME/.uaerc } amiga_end() { dialog --backtitle "$TITLE" --title "Finished copying" --ok-label "Finish" \ --msgbox "\nAmiga files have been copied!\n\nPress 'Finish' for post-installation notes and exit." 11 66 test $? = 255 && exit_installer } post_install() { # Create post-installation notes touch $LIST/postnotes echo -e "X-Amiga (Linux) is currently mounted at $XTARGET\nAmiga file directories are at $ATARGET\n" >> $LIST/postnotes # Check log for errors grep -v "No error reported." $XTARGET/log | grep -i "error" && post_log="errors! Please check the log file..." || post_log="no errors :-)" echo -e "The installer log is located at $XTARGET/log\nThe log reports $post_log\n" >> $LIST/postnotes # Point to locations of grub.conf and initrd [ $BOOTLDR = "None" ] && post_grub="Grub has not been installed.\nYou will need to set up your bootloader in order to boot X-Amiga.\n\nA grub configuration file is at $XTARGET/boot/grub/grub.conf\nAn initrd (contains bootsplash) is at $XTARGET/boot/initrd\n\n" || post_grub="Grub has been installed. If the log reports no errors, your system\nshould boot successfully into X-Amiga." echo -e $post_grub >> $LIST/postnotes } post_notes() { # Display post notes tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/test$$ trap "rm -f $tempfile" 0 1 2 5 15 cat $LIST/postnotes | expand >> $tempfile dialog --clear --title "Post-installation notes" --no-cancel \ --textbox "$tempfile" 0 0 test $? = 255 && exit_installer } the_end() { # Final 'finish' screen dialog --backtitle "$TITLE" --title "Finished installing X-Amiga" --yes-label "Notes" --no-label "Exit" \ --yesno "\nThe X-Amiga installation process is complete.\n\nPress 'Notes' to read post-installation notes.\n\nPress 'Exit' to exit to the console." 11 66 case $? in 0) post_notes the_end;; 1) exit_installer;; 255) exit_installer;; esac } finish_signal() { # Wake up user with jingle... for i in 277.2 415.3 277.2 311.1 349.2 370.0 349.2 311.1 311.1 do beep -f $i -l 80 done } exit_installer() { # Exit cleanly from installer rm -rf $LIST $BUILD umount $MEDIA/cdrom 2>/dev/null cat /etc/issue exit } # # X-Amiga Installer MAIN section # # Gather information for installation welcome detect_hardware list_hardware partition select_drive install_dest amiga_dest select_bootloader select_video select_sound net_tools root_pass view_summary settings_menu error_check # Install Linux OS install_start create_log prep_drive install_packages system_files finish_signal # (Optional) Copy Amiga files, UAE config if [ $AMIGADEST != "None" ] then install_end if [ $AMIGA -eq 1 ] then rom_setup os_setup floppy_setup euae_setup finish_signal amiga_end fi fi # Post install stuff post_install the_end