home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / darwin / darwinx86.iso / private / etc / rc.cdrom < prev    next >
Encoding:
Text File  |  2001-10-01  |  6.5 KB  |  275 lines

  1. #!/bin/sh
  2.  
  3. PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/libexec:/etc:/private/etc ; export PATH
  4. ARCH=`arch`
  5.  
  6. abort () {
  7.     echo "Aborting the installation"
  8.     echo "1: Restart the installation"
  9.     echo "2: Spawn a shell"
  10.     echo "3: Reboot"
  11. }
  12.  
  13. finishup () {
  14.  
  15.     echo "Installation is now complete."
  16.     echo "You may: "
  17.     until [ ! : ]
  18.     do
  19.         echo "1) Reboot"
  20.         echo "2) Spawn a shell"
  21.         echo -n "Your Choice: "
  22.         read CHOICE
  23.         case ${CHOICE} in
  24.             1) reboot 
  25.                break ;;
  26.             2) exec /bin/sh
  27.                break
  28.                ;;
  29.         esac
  30.     done
  31. }
  32.  
  33. # This function will nuke the whole disk and create the 0xAB and 0xA8
  34. # partitions.  $INSTALLDEV and $RAWINSTDEV need to be set to the
  35. # device to nuke, and the corresponding raw device.
  36. partition_disk () {
  37.     # needs help on ppc
  38.     echo "Partitioning disk ${INSTALLDEV}"
  39.     echo "Warning: this will destroy all data on the disk!"
  40.     echo -n "Continue? (y/n) "
  41.     read CONT
  42.  
  43.     if [ ${CONT} != y ]; then
  44.         abort
  45.     fi
  46.  
  47.     fdisk ${RAWINSTDEV} -useBoot0 -useAllSectors -bootPlusUFS
  48.     ;
  49. }
  50.  
  51. # This will look for partitions on the selected disk, and 
  52. # allow the user to select the 0xAB and 0xA8 partitions to
  53. # use.  $INSTALLDEV needs to be set to the device to look for,
  54. # and $BOOTERPART and $ROOTPART will be set to the chosen
  55. # values upon return.
  56. use_partitions () {
  57.     echo ""
  58.     PARTS=`ls -1 ${INSTALLDEV}s*`
  59.  
  60.     echo "The following partitions are available:"
  61.     for devs in ${PARTS}
  62.     do
  63.         echo ${devs}
  64.     done
  65.  
  66.     # Only x86 needs the booter partition
  67.     if [ "${ARCH}" == "i386" ]; then
  68.         BOOTERPART=""
  69.         until [[ ${BOOTERPART} != "" && -b ${BOOTERPART} ]]
  70.         do
  71.             echo "Which will be the booter partition?"
  72.             read BOOTERPART
  73.         done
  74.         
  75.     fi
  76.  
  77.     ROOTPART=""
  78.     until [[ ${ROOTPART} != "" && -b ${ROOTPART} && ${ROOTPART} != ${BOOTERPART} ]]
  79.     do
  80.         echo "Which will be the root partition?"
  81.         read ROOTPART
  82.  
  83.         if [ ${ROOTPART} == ${BOOTERPART} ]; then
  84.             echo "The root partition can't be the same as the booter partition"
  85.         fi
  86.     done
  87.  
  88.     echo "Using: "
  89.     if [ ! -z "${BOOTERPART}" ]; then
  90.         echo "${BOOTERPART} as the booter partition"
  91.     fi
  92.     echo "${ROOTPART} as the root partition"
  93.     ;
  94. }
  95.  
  96. # This just runs fdisk interactivly on the chosen raw install device
  97. run_fdisk () {
  98.     echo "Starting fdisk"
  99.     if [ "${ARCH}" == "i386" ]; then
  100.         fdisk ${RAWINSTDEV}
  101.     elif [ "${ARCH}" == "ppc" ]; then
  102.         /usr/sbin/pdisk
  103.     fi
  104.     ;
  105. }
  106.  
  107. install_booter () {
  108.     if [ "${ARCH}" == "i386" ]; then
  109.         echo "Installing booter on ${BOOTERPART}"
  110.         dd if=/usr/standalone/i386/boot1 of=${BOOTERPART} bs=512 count=1 >>/dev/null 2>&1
  111.         dd if=/usr/standalone/i386/boot of=${BOOTERPART} bs=512 seek=1 >>/dev/null 2>&1
  112.     elif [ "${ARCH}" == "ppc" ]; then
  113.         bless -folder /mnt/System/Library/CoreServices -bootinfo /mnt/usr/standalone/ppc/bootx.bootinfo
  114.     fi
  115.     ;
  116. }
  117.  
  118. install_packages () {
  119.     echo "Creating Filesystem on ${ROOTPART}"
  120.     if [ "${ARCH}" == "i386" ]; then
  121.         newfs ${ROOTPART} >>/dev/null 2>&1
  122.         mount ${ROOTPART} /mnt
  123.     elif [ "${ARCH}" == "ppc" ]; then
  124.         newfs_hfs -v Darwin ${ROOTPART} >> /dev/null 2>&1
  125.         mount -t hfs ${ROOTPART} /mnt
  126.     fi
  127.     echo "Installing packages on ${ROOTPART}"
  128.     cd /mnt 
  129.     /etc/install-debs /System/Installation/packages
  130.  
  131.     if [ -d /System/Installation/unsupported ]; then
  132.         /etc/install-debs /System/Installation/unsupported
  133.     fi
  134.     /etc/install-debs /System/Installation/unsupported
  135.  
  136.     # If the apple_binary directory exists, install the packages in there.
  137.     if [ -d /System/Installation/apple_binary ]; then
  138.         for a in `ls -1 /System/Installation/apple_binary`
  139.         do
  140.             gnutar zxfp /System/Installation/apple_binary/${a}
  141.         done
  142.     fi
  143.  
  144.     # Both of the following two sections should go away...
  145.  
  146.     if [ "${ARCH}" == "i386" ]; then 
  147.         # Copy over the System.config info, since it's 
  148.         # not in a package yet.
  149.         mkdir -p /mnt/private/Drivers/i386/System.config/
  150.         cp /private/Drivers/i386/System.config/Default.table /mnt/private/Drivers/i386/System.config/Default.table
  151.     
  152.         # Thin the kernel because of bugs in boot2
  153.         mv /mnt/mach_kernel /mnt/mach_kernel.fat
  154.         lipo -thin i386 -output /mnt/mach_kernel /mnt/mach_kernel.fat
  155.     fi
  156.  
  157.     cd /
  158.  
  159.     ;
  160. }
  161.  
  162. main() {
  163.     # Get the device the user wants to install onto.
  164.     INSTALLDEV="novalue"
  165.     until [[ ${INSTALLDEV} != "" && -b ${INSTALLDEV} ]]
  166.     do
  167.         echo "The following devices are available for installation:"
  168.         iofindwholemedia
  169.         echo -n "Which device would you like to install Darwin onto? "
  170.         read INSTALLDEV
  171.     
  172.         if [ ${INSTALLDEV} == "shell" ]; then
  173.             exec /bin/sh
  174.         fi
  175.     
  176.         INSTALLDEV=`iofindwholemedia ${INSTALLDEV}`
  177.  
  178.         if [ ! -b ${INSTALLDEV} ]; then
  179.             echo ""
  180.             echo "${INSTALLDEV} doesn't exist, please enter one of the listed devices."
  181.             echo ""
  182.         fi
  183.     done
  184.     
  185.     RAWINSTDEV=`echo ${INSTALLDEV} | sed 's/disk/rdisk/'`
  186.     
  187.     if [ "${ARCH}" == "i386" ]; then 
  188.         if [ `fdisk ${RAWINSTDEV} -isDiskPartitioned` == "Yes" ]; then
  189.             echo ""
  190.             echo "For partitioning the disk, you have the following choices:"
  191.             until [ ! : ]
  192.             do
  193.                 echo "1) Auto-partition the disk (Destroys all disk contents)"
  194.                 echo "2) Manually partition the disk using fdisk"
  195.                 echo "3) Use existing partitions"
  196.                 echo -n "Choice: "
  197.                 read ANSWER
  198.                 case ${ANSWER} in
  199.                     1) partition_disk
  200.                        # Don't ask which to use, since we already know.
  201.                        BOOTERPART="${INSTALLDEV}s1"
  202.                        ROOTPART="${INSTALLDEV}s2"
  203.                        break
  204.                        ;;
  205.                     2) run_fdisk
  206.                        use_partitions
  207.                        break
  208.                        ;;
  209.                     3) use_partitions
  210.                        break
  211.                        ;;
  212.                 esac
  213.             done
  214.         else
  215.             echo ""
  216.             echo "For partitioning the disk, you have the following choices:"
  217.             until [ ! : ]
  218.             do
  219.                 echo "1) Auto-partition the disk (Destroys all disk contents)"
  220.                 echo "2) Manually partition the disk using fdisk"
  221.                 echo -n "Choice: "
  222.                 read ANSWER
  223.                 case ${ANSWER} in
  224.                     1) partition_disk
  225.                        # Don't ask which to use, since we already know.
  226.                        BOOTERPART="${INSTALLDEV}s1"
  227.                        ROOTPART="${INSTALLDEV}s2"
  228.                        break
  229.                        ;;
  230.                     2) run_fdisk
  231.                        use_partitions
  232.                        break
  233.                        ;;
  234.                 esac
  235.             done
  236.         fi
  237.     elif [ "${ARCH}" == "ppc" ]; then
  238.         until [ ! : ]
  239.         do
  240.             echo "Which partition would you like to install into: "
  241.             i=1
  242.             for slice in `ls ${INSTALLDEV}s*`
  243.             do
  244.                 slice_name=`pdisk ${RAWINSTDEV} -partitionName ${i}`
  245.                 slice_type=`pdisk ${RAWINSTDEV} -partitionType ${i}`
  246.                 echo "${i}) ${slice} ${slice_type} ${slice_name}"
  247.                 i=`expr ${i} + 1`
  248.             done
  249.             echo -n "Your choice: "
  250.             read ANSWER
  251.  
  252.             if [ -b "${INSTALLDEV}s${ANSWER}" ]; then
  253.                 ROOTPART="${INSTALLDEV}s${ANSWER}"
  254.                 break;
  255.             fi
  256.         done
  257.     fi
  258.     install_packages
  259.     install_booter
  260.     umount ${ROOTPART}
  261.     finishup
  262.     ;
  263. }
  264.     
  265. # Set the erase character properly
  266. # This is only for telnet consoles...
  267. #stty erase 
  268.  
  269. # Ignore ^C
  270. #trap "" 2
  271.  
  272. main
  273.  
  274. exit
  275.