home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / unix / riscbsd / 1_1_beta / upgr_11_fs / upgr-11.fs / upgrade < prev   
Encoding:
Text File  |  1995-12-08  |  7.9 KB  |  255 lines

  1. #!/bin/sh
  2. #
  3. # Copyright (c) 1994 Christopher G. Demetriou
  4. # All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions
  8. # are met:
  9. # 1. Redistributions of source code must retain the above copyright
  10. #    notice, this list of conditions and the following disclaimer.
  11. # 2. Redistributions in binary form must reproduce the above copyright
  12. #    notice, this list of conditions and the following disclaimer in the
  13. #    documentation and/or other materials provided with the distribution.
  14. # 3. All advertising materials mentioning features or use of this software
  15. #    must display the following acknowledgement:
  16. #    This product includes software developed by Christopher G. Demetriou.
  17. # 4. The name of the author may not be used to endorse or promote products
  18. #    derived from this software without specific prior written permission
  19. #
  20. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  21. # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  22. # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  23. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  25. # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  29. # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. #
  31. #    $Id: upgrade.sh,v 1.3 1994/10/18 07:03:16 glass Exp $
  32.  
  33. #    NetBSD upgrade script.
  34. #    In a perfect world, this would be a nice C program, with a reasonable
  35. #    user interface.
  36.  
  37. stty erase ^H
  38.  
  39. DT=/etc/disktab                # /etc/disktab
  40. FSTABDIR=/mnt/etc            # /mnt/etc
  41. #DONTDOIT=echo
  42.  
  43. VERSION=1.0
  44. FSTAB=${FSTABDIR}/fstab
  45.  
  46. getresp() {
  47.     read resp
  48.     if [ "X$resp" = "X" ]; then
  49.         resp=$1
  50.     fi
  51. }
  52.  
  53. echo    "Welcome to the NetBSD ${VERSION} upgrade program."
  54. echo    ""
  55. echo    "This program is designed to help you put the new version of NetBSD"
  56. echo    "on your hard disk, in a simple and rational way.  To upgrade, you"
  57. echo    "must have plenty of free space on all partitions which will be"
  58. echo    "upgraded.  If you have at least 1MB free on your root partition,"
  59. echo    "and several free on your /usr patition, you should be fine."
  60. echo    ""
  61. echo    "As with anything which modifies your hard drive's contents, this"
  62. echo    "program can cause SIGNIFICANT data loss, and you are advised"
  63. echo    "to make sure your hard drive is backed up before beginning the"
  64. echo    "upgrade process."
  65. echo    ""
  66. echo    "Default answers are displyed in brackets after the questions."
  67. echo    "You can hit Control-C at any time to quit, but if you do so at a"
  68. echo    "prompt, you may have to hit return.  Also, quitting in the middle of"
  69. echo    "the upgrade may leave your system in an inconsistent (and unusable)"
  70. echo    "state."
  71. echo    ""
  72. echo -n "Proceed with upgrade? [n] "
  73. getresp "n"
  74. case "$resp" in
  75.     y*|Y*)
  76.         echo    "Cool!  Let's get to it..."
  77.         ;;
  78.     *)
  79.         echo    ""
  80.         echo    "OK, then.  Enter 'halt' at the prompt to halt the"
  81.         echo    "machine."
  82.         exit
  83.         ;;
  84. esac
  85.  
  86. # find out what units are possible, and query the user.
  87. driveunits=`ls /dev/[sw]d?a | sed -e 's,/dev/\(...\)a,\1,g'`
  88. if [ "X${driveunits}" = "X" ]; then
  89.     echo    "FATAL ERROR:"
  90.     echo    "No disk devices."
  91.     echo    "This is probably a bug in the install disks."
  92.     echo    "Exiting install program."
  93.     exit
  94. fi
  95.  
  96. echo    ""
  97. echo    "The following disks are supported by this upgrade procedure:"
  98. echo    "    "${driveunits}
  99. echo    "If your system was previously completely contained within the"
  100. echo    "disks listed above (i.e. if your system didn't occupy any space"
  101. echo    "on disks NOT listed above), this upgrade disk can upgrade your"
  102. echo    "system.  If it cannot, hit Control-C at the prompt."
  103. echo    ""
  104. while [ "X${drivename}" = "X" ]; do
  105.     echo -n    "Which disk contains your root partion? "
  106.     getresp
  107.     otherdrives=`echo "${driveunits}" | sed -e s,${resp},,`
  108.     if [ "X${driveunits}" = "X${otherdrives}" ]; then
  109.         echo    ""
  110.         echo    "\"${resp}\" is an invalid drive name.  Valid choices"
  111.         echo    "are: "${driveunits}
  112.         echo    ""
  113.     else
  114.         drivename=${resp}
  115.     fi
  116. done
  117.  
  118. echo    ""
  119. echo    "Root partition is on ${drivename}a."
  120.  
  121. echo    ""
  122. echo    "Would you like to upgrade your file systems to the new file system"
  123. echo -n    "format? [y] "
  124. getresp "y"
  125. case "$resp" in
  126.     n*|N*)
  127.         echo    ""
  128.         echo    "You should upgrade your file systems with 'fsck -c 2'"
  129.         echo    "as soon as is feasible, because the new file system"
  130.         echo    "code is better-tested and more performant."
  131.         upgradefs=NO
  132.         ;;
  133.     *)
  134.         upgradefs=YES
  135.         ;;
  136. esac
  137.  
  138. if [ $upgradefs = YES ]; then
  139.     echo    ""
  140.     echo    "Upgrading the file system on ${drivename}a..."
  141.     
  142.     fsck -p -c 2 /dev/r${drivename}a
  143.     if [ $? != 0 ]; then
  144.         echo    "FATAL ERROR: FILE SYSTEM UPGRADE FAILED."
  145.         echo    "You should probably reboot the machine, fsck your"
  146.         echo    "disk(s), and try the upgrade procedure again."
  147.         exit 1
  148.     fi
  149.     echo    "Done."
  150. fi
  151.  
  152. echo    ""
  153. echo    "Mounting root partition on /mnt..."
  154. mount /dev/${drivename}a /mnt
  155. if [ $? != 0 ]; then
  156.     echo    "FATAL ERROR: MOUNT FAILED."
  157.     echo    "You should verify that your system is set up as you"
  158.     echo    "described, and re-attempt the upgrade procedure."
  159.     exit 1
  160. fi
  161. echo    "Done."
  162.  
  163. if [ $upgradefs = YES ]; then
  164.     echo    ""
  165.     echo -n    "Copying new fsck binary to your hard disk..."
  166.     if [ ! -d /mnt/sbin ]; then
  167.         mkdir /mnt/sbin
  168.     fi
  169.     cp /sbin/fsck /mnt/sbin/fsck
  170.     if [ $? != 0 ]; then
  171.         echo    "FATAL ERROR: COPY FAILED."
  172.         echo    "It in unclear why this error would occur.  It looks"
  173.         echo    "like you may end up having to upgrade by hand."
  174.         exit 1
  175.     fi
  176.     echo    " Done."
  177.  
  178.     echo    ""
  179.     echo    "Re-mounting root partition read-only..."
  180.     mount -u -o ro /dev/${drivename}a /mnt
  181.     if [ $? != 0 ]; then
  182.         echo    "FATAL ERROR: RE-MOUNT FAILED."
  183.         echo    "It in unclear why this error would occur.  It looks"
  184.         echo    "like you may end up having to upgrade by hand."
  185.         exit 1
  186.     fi
  187.     echo    "Done."
  188.  
  189.     echo    ""
  190.     echo    "Upgrading the rest of your file systems..."
  191.     chroot /mnt fsck -p -c 2
  192.     if [ $? != 0 ]; then
  193.         echo    "FATAL ERROR: FILE SYSTEM UPGRADE(S) FAILED."
  194.         echo    "You should probably reboot the machine, fsck your"
  195.         echo    "file system(s), and try the upgrade procedure"
  196.         echo    "again."
  197.         exit 1
  198.     fi
  199.     echo    "Done."
  200.  
  201.     echo    ""
  202.     echo    "Re-mounting root partition read-write..."
  203.     mount -u -o rw /dev/${drivename}a /mnt
  204.     if [ $? != 0 ]; then
  205.         echo    "FATAL ERROR: RE-MOUNT FAILED."
  206.         echo    "It in unclear why this error would occur.  It looks"
  207.         echo    "like you may end up having to upgrade by hand."
  208.         exit 1
  209.     fi
  210.     echo    "Done."
  211. fi
  212.  
  213. echo    ""
  214. echo    "Updating boot blocks on ${drivename}..."
  215. disklabel -r $drivename > /mnt/tmp/${drivename}.label
  216. if [ $? != 0 ]; then
  217.     echo    "FATAL ERROR: READ OF DISK LABEL FAILED."
  218.     echo    "It in unclear why this error would occur.  It looks"
  219.     echo    "like you may end up having to upgrade by hand."
  220.     exit 1
  221. fi
  222. disklabel -R -B $drivename /mnt/tmp/${drivename}.label
  223. if [ $? != 0 ]; then
  224.     echo    "FATAL ERROR: UPDATE OF DISK LABEL FAILED."
  225.     echo    "It in unclear why this error would occur.  It looks"
  226.     echo    "like you may end up having to upgrade by hand."
  227.     exit 1
  228. fi
  229. echo    "Done."
  230.  
  231. echo    ""
  232. echo    "Copying bootstrapping binaries and config files to the hard drive..."
  233. $DONTDOIT cp /mnt/.profile /mnt/.profile.bak
  234. $DONTDOIT tar --exclude etc --one-file-system -cf - . | (cd /mnt ; tar --unlink -xpf - )
  235. $DONTDOIT mv /mnt/etc/rc /mnt/etc/rc.bak
  236. $DONTDOIT cp /tmp/.hdprofile /mnt/.profile
  237.  
  238. echo    ""
  239. echo    "Mounting remaining partitions..."
  240. chroot /mnt mount -at ffs > /dev/null 2>&1
  241. echo    "Done."
  242.  
  243. echo    ""
  244. echo    ""
  245. echo    "OK!  The preliminary work of setting up your disk is now complete,"
  246. echo    "and you can now upgrade the actual NetBSD software."
  247. echo    ""
  248. echo    "Right now, your hard disk is mounted on /mnt.  You should consult"
  249. echo    "the installation notes to determine how to load and install the new"
  250. echo    "NetBSD distribution sets, and how to clean up after the upgrade"
  251. echo    "software, when you are done."
  252. echo    ""
  253. echo    "GOOD LUCK!"
  254. echo    ""
  255.