home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 4 / MA_Cover_4.iso / netbsd / installation / miniroot / miniroot.fs / install < prev    next >
Encoding:
Text File  |  1997-11-30  |  11.4 KB  |  437 lines

  1. #!/bin/sh
  2. #    $NetBSD: install.sh,v 1.17.2.1 1997/11/25 12:43:12 pk Exp $
  3. #
  4. # Copyright (c) 1996 The NetBSD Foundation, Inc.
  5. # All rights reserved.
  6. #
  7. # This code is derived from software contributed to The NetBSD Foundation
  8. # by Jason R. Thorpe.
  9. #
  10. # Redistribution and use in source and binary forms, with or without
  11. # modification, are permitted provided that the following conditions
  12. # are met:
  13. # 1. Redistributions of source code must retain the above copyright
  14. #    notice, this list of conditions and the following disclaimer.
  15. # 2. Redistributions in binary form must reproduce the above copyright
  16. #    notice, this list of conditions and the following disclaimer in the
  17. #    documentation and/or other materials provided with the distribution.
  18. # 3. All advertising materials mentioning features or use of this software
  19. #    must display the following acknowledgement:
  20. #        This product includes software developed by the NetBSD
  21. #        Foundation, Inc. and its contributors.
  22. # 4. Neither the name of The NetBSD Foundation nor the names of its
  23. #    contributors may be used to endorse or promote products derived
  24. #    from this software without specific prior written permission.
  25. #
  26. # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  27. # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  28. # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  29. # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  30. # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  31. # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  32. # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  33. # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  34. # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  35. # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. # POSSIBILITY OF SUCH DAMAGE.
  37. #
  38.  
  39. #    NetBSD installation script.
  40. #    In a perfect world, this would be a nice C program, with a reasonable
  41. #    user interface.
  42.  
  43. FILESYSTEMS="/tmp/filesystems"        # used thoughout
  44. FQDN=""                    # domain name
  45.  
  46. trap "umount /tmp > /dev/null 2>&1" 0
  47.  
  48. MODE="install"
  49.  
  50. # include machine-dependent functions
  51. # The following functions must be provided:
  52. #    md_copy_kernel()    - copy a kernel to the installed disk
  53. #    md_get_diskdevs()    - return available disk devices
  54. #    md_get_cddevs()        - return available CD-ROM devices
  55. #    md_get_ifdevs()        - return available network interfaces
  56. #    md_get_partition_range() - return range of valid partition letters
  57. #    md_installboot()    - install boot-blocks on disk
  58. #    md_labeldisk()        - put label on a disk
  59. #    md_prep_disklabel()    - label the root disk
  60. #    md_welcome_banner()    - display friendly message
  61. #    md_not_going_to_install() - display friendly message
  62. #    md_congrats()        - display friendly message
  63. #    md_native_fstype()    - native filesystem type for disk installs
  64. #    md_native_fsopts()    - native filesystem options for disk installs
  65. #    md_makerootwritable()    - make root writable (at least /tmp)
  66.  
  67. # include machine dependent subroutines
  68. . install.md
  69.  
  70. # include common subroutines
  71. . install.sub
  72.  
  73. # which sets?
  74. THESETS="$ALLSETS"
  75.  
  76. # Good {morning,afternoon,evening,night}.
  77. md_welcome_banner
  78. echo -n "Proceed with installation? [n] "
  79. getresp "n"
  80. case "$resp" in
  81.     y*|Y*)
  82.         echo    "Cool!  Let's get to it..."
  83.         ;;
  84.     *)
  85.         md_not_going_to_install
  86.         exit
  87.         ;;
  88. esac
  89.  
  90. # XXX Work around vnode aliasing bug (thanks for the tip, Chris...)
  91. ls -l /dev > /dev/null 2>&1
  92.  
  93. # Deal with terminal issues
  94. md_set_term
  95.  
  96. # Get timezone info
  97. get_timezone
  98.  
  99. # Make sure we can write files (at least in /tmp)
  100. # This might make an MFS mount on /tmp, or it may
  101. # just re-mount the root with read-write enabled.
  102. md_makerootwritable
  103.  
  104. # Install the shadowed disktab file; lets us write to it for temporary
  105. # purposes without mounting the miniroot read-write.
  106. cp /etc/disktab.shadow /tmp/disktab.shadow
  107.  
  108. while [ "X${ROOTDISK}" = "X" ]; do
  109.     getrootdisk
  110. done
  111.  
  112. # Deal with disklabels, including editing the root disklabel
  113. # and labeling additional disks.  This is machine-dependent since
  114. # some platforms may not be able to provide this functionality.
  115. md_prep_disklabel ${ROOTDISK}
  116.  
  117. # Assume partition 'a' of $ROOTDISK is for the root filesystem.  Loop and
  118. # get the rest.
  119. # XXX ASSUMES THAT THE USER DOESN'T PROVIDE BOGUS INPUT.
  120. cat << \__get_filesystems_1
  121.  
  122. You will now have the opportunity to enter filesystem information.
  123. You will be prompted for device name and mount point (full path,
  124. including the prepending '/' character).
  125.  
  126. Note that these do not have to be in any particular order.  You will
  127. be given the opportunity to edit the resulting 'fstab' file before
  128. any of the filesystems are mounted.  At that time you will be able
  129. to resolve any filesystem order dependencies.
  130.  
  131. __get_filesystems_1
  132.  
  133. echo    "The following will be used for the root filesystem:"
  134. echo    "    ${ROOTDISK}a    /"
  135.  
  136. echo    "${ROOTDISK}a    /" > ${FILESYSTEMS}
  137.  
  138. resp="X"    # force at least one iteration
  139. while [ "X$resp" != X"done" ]; do
  140.     echo    ""
  141.     echo -n    "Device name? [done] "
  142.     getresp "done"
  143.     case "$resp" in
  144.     done)
  145.         ;;
  146.  
  147.     *)
  148.         _device_name=`basename $resp`
  149.  
  150.         # force at least one iteration
  151.         _first_char="X"
  152.         while [ "X${_first_char}" != X"/" ]; do
  153.             echo -n "Mount point? "
  154.             getresp ""
  155.             _mount_point=$resp
  156.             if [ "X${_mount_point}" = X"/" ]; then
  157.                 # Invalid response; no multiple roots
  158.                 _first_char="X"
  159.             else
  160.                 _first_char=`firstchar ${_mount_point}`
  161.             fi
  162.         done
  163.         echo "${_device_name}    ${_mount_point}" >> ${FILESYSTEMS}
  164.         resp="X"    # force loop to repeat
  165.         ;;
  166.     esac
  167. done
  168.  
  169. # configure swap
  170. resp=""        # force at least one iteration
  171. while [ "X${resp}" = X"" ]; do
  172.     echo -n    "Ok to configure ${ROOTDISK}b as a swap device? [] "
  173.     getresp ""
  174.     case "$resp" in
  175.     y*|Y*)
  176.         echo "${ROOTDISK}b    swap" >> ${FILESYSTEMS}
  177.         ;;
  178.     n*|N*)
  179.         ;;
  180.     *)    ;;
  181.     esac
  182. done
  183.  
  184.  
  185. echo    ""
  186. echo    "You have configured the following devices and mount points:"
  187. echo    ""
  188. cat ${FILESYSTEMS}
  189. echo    ""
  190. echo    "Filesystems will now be created on these devices.  If you made any"
  191. echo -n    "mistakes, you may edit this now.  Edit? [n] "
  192. getresp "n"
  193. case "$resp" in
  194.     y*|Y*)
  195.         ${EDITOR} ${FILESYSTEMS}
  196.         ;;
  197.     *)
  198.         ;;
  199. esac
  200.  
  201. # Loop though the file, place filesystems on each device.
  202. echo    "Creating filesystems..."
  203. (
  204.     while read _device_name _mp; do
  205.         if [ "$_mp" != "swap" ]; then
  206.             newfs /dev/r${_device_name}
  207.             echo ""
  208.         fi
  209.     done
  210. ) < ${FILESYSTEMS}
  211.  
  212. # Get network configuration information, and store it for placement in the
  213. # root filesystem later.
  214. cat << \__network_config_1
  215. You will now be given the opportunity to configure the network.  This will
  216. be useful if you need to transfer the installation sets via FTP or NFS.
  217. Even if you choose not to transfer installation sets that way, this
  218. information will be preserved and copied into the new root filesystem.
  219.  
  220. Note, enter all symbolic host names WITHOUT the domain name appended.
  221. I.e. use 'hostname' NOT 'hostname.domain.name'.
  222.  
  223. __network_config_1
  224. echo -n    "Configure the network? [y] "
  225. getresp "y"
  226. case "$resp" in
  227.     y*|Y*)
  228.         resp=""        # force at least one iteration
  229.         if [ -f /etc/myname ]; then
  230.             resp=`cat /etc/myname`
  231.         fi
  232.         echo -n "Enter system hostname: [$resp] "
  233.         while [ "X${resp}" = X"" ]; do
  234.             getresp "$resp"
  235.         done
  236.         hostname $resp
  237.         echo $resp > /tmp/myname
  238.  
  239.         echo -n "Enter DNS domain name: "
  240.         resp=""        # force at least one iteration
  241.         while [ "X${resp}" = X"" ]; do
  242.             getresp ""
  243.         done
  244.         FQDN=$resp
  245.  
  246.         configurenetwork
  247.  
  248.         echo -n "Enter IP address of default route: [none] "
  249.         getresp "none"
  250.         if [ "X${resp}" != X"none" ]; then
  251.             route delete default > /dev/null 2>&1
  252.             if route add default $resp > /dev/null ; then
  253.                 echo $resp > /tmp/mygate
  254.             fi
  255.         fi
  256.  
  257.         echo -n    "Enter IP address of primary nameserver: [none] "
  258.         getresp "none"
  259.         if [ "X${resp}" != X"none" ]; then
  260.             echo "domain $FQDN" > /tmp/resolv.conf
  261.             echo "nameserver $resp" >> /tmp/resolv.conf
  262.             echo "search $FQDN" >> /tmp/resolv.conf
  263.  
  264.             echo -n "Would you like to use the nameserver now? [y] "
  265.             getresp "y"
  266.             case "$resp" in
  267.                 y*|Y*)
  268.                     cp /tmp/resolv.conf \
  269.                         /tmp/resolv.conf.shadow
  270.                     ;;
  271.  
  272.                 *)
  273.                     ;;
  274.             esac
  275.         fi
  276.  
  277.         echo ""
  278.         echo "The host table is as follows:"
  279.         echo ""
  280.         cat /tmp/hosts
  281.         echo ""
  282.         echo "You may want to edit the host table in the event that"
  283.         echo "you need to mount an NFS server."
  284.         echo -n "Would you like to edit the host table? [n] "
  285.         getresp "n"
  286.         case "$resp" in
  287.             y*|Y*)
  288.                 ${EDITOR} /tmp/hosts
  289.                 ;;
  290.  
  291.             *)
  292.                 ;;
  293.         esac
  294.  
  295.         cat << \__network_config_2
  296.  
  297. You will now be given the opportunity to escape to the command shell to
  298. do any additional network configuration you may need.  This may include
  299. adding additional routes, if needed.  In addition, you might take this
  300. opportunity to redo the default route in the event that it failed above.
  301. If you do change the default route, and wish for that change to carry over
  302. to the installed system, execute the following command at the shell
  303. prompt:
  304.  
  305.     echo <ip_address_of_gateway> > /tmp/mygate
  306.  
  307. where <ip_address_of_gateway> is the IP address of the default router.
  308.  
  309. __network_config_2
  310.         echo -n "Escape to shell? [n] "
  311.         getresp "n"
  312.         case "$resp" in
  313.             y*|Y*)
  314.                 echo "Type 'exit' to return to install."
  315.                 sh
  316.                 ;;
  317.  
  318.             *)
  319.                 ;;
  320.         esac
  321.         ;;
  322.     *)
  323.         ;;
  324. esac
  325.  
  326. # Now that the network has been configured, it is safe to configure the
  327. # fstab.
  328. (
  329.     while read _dev _mp; do
  330.         if [ "$_mp" = "/" ]; then
  331.             echo /dev/$_dev $_mp ffs rw 1 1
  332.         elif [ "$_mp" = "swap" ]; then
  333.             echo /dev/$_dev none swap sw 0 0
  334.         else
  335.             echo /dev/$_dev $_mp ffs rw 1 2
  336.         fi
  337.     done
  338. ) < ${FILESYSTEMS} > /tmp/fstab
  339.  
  340. echo    "The fstab is configured as follows:"
  341. echo    ""
  342. cat /tmp/fstab
  343. cat << \__fstab_config_1
  344.  
  345. You may wish to edit the fstab.  For example, you may need to resolve
  346. dependencies in the order which the filesystems are mounted.  You may
  347. also wish to take this opportunity to place NFS mounts in the fstab.
  348. This would be especially useful if you plan to keep '/usr' on an NFS
  349. server.
  350.  
  351. __fstab_config_1
  352. echo -n    "Edit the fstab? [n] "
  353. getresp "n"
  354. case "$resp" in
  355.     y*|Y*)
  356.         ${EDITOR} /tmp/fstab
  357.         ;;
  358.  
  359.     *)
  360.         ;;
  361. esac
  362.  
  363. echo ""
  364. munge_fstab /tmp/fstab /tmp/fstab.shadow
  365. mount_fs /tmp/fstab.shadow
  366.  
  367. mount | while read line; do
  368.     set -- $line
  369.     if [ "$2" = "/" -a "$3" = "nfs" ]; then
  370.         echo "You appear to be running diskless."
  371.         echo -n    "Are the install sets on one of your currently mounted filesystems? [n] "
  372.         getresp "n"
  373.         case "$resp" in
  374.             y*|Y*)
  375.                 get_localdir
  376.                 ;;
  377.             *)
  378.                 ;;
  379.         esac
  380.     fi
  381. done
  382.  
  383. install_sets $ALLSETS $MDSETS
  384.  
  385. # Copy in configuration information and make devices in target root.
  386. (
  387.     cd /tmp
  388.     for file in fstab ifconfig.* hosts myname mygate resolv.conf; do
  389.         if [ -f $file ]; then
  390.             echo -n "Copying $file..."
  391.             cp $file /mnt/etc/$file
  392.             echo "done."
  393.         fi
  394.     done
  395.  
  396.     # Enable rc.conf
  397.     if [ -e /mnt/etc/rc.conf ]; then
  398.         cp /mnt/etc/rc.conf /tmp
  399.         sed 's/^rc_configured=NO/rc_configured=YES/' /tmp/rc.conf \
  400.             > /mnt/etc/rc.conf
  401.     fi
  402.  
  403.     # If no zoneinfo on the installfs, give them a second chance
  404.     if [ ! -e /usr/share/zoneinfo ]; then
  405.         get_timezone
  406.     fi
  407.     if [ ! -e /mnt/usr/share/zoneinfo ]; then
  408.         echo "Cannot install timezone link..."
  409.     else
  410.         echo -n "Installing timezone link..."
  411.         rm -f /mnt/etc/localtime
  412.         ln -s /usr/share/zoneinfo/$TZ /mnt/etc/localtime
  413.         echo "done."
  414.     fi
  415.     if [ ! -x /mnt/dev/MAKEDEV ]; then
  416.         echo "No /dev/MAKEDEV installed, something is wrong here..."
  417.     else
  418.         echo -n "Making devices..."
  419.         pid=`twiddle`
  420.         cd /mnt/dev
  421.         sh MAKEDEV all
  422.         kill $pid
  423.         echo "done."
  424.     fi
  425.     md_copy_kernel
  426.  
  427.     md_installboot ${ROOTDISK}
  428. )
  429.  
  430. unmount_fs /tmp/fstab.shadow
  431.  
  432. # Pat on the back.
  433. md_congrats
  434.  
  435. # ALL DONE!
  436. exit 0
  437.