home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume7 / dirstack.csh / shdir.make < prev    next >
Encoding:
Text File  |  1987-01-18  |  6.2 KB  |  187 lines

  1. #! /bin/csh -f
  2. #
  3. #-    shdir.make - Directory stack installation script
  4. #-
  5. #-    To try out the function of shdir, use csh  "source" command to
  6. #-    invoke this program since some aliases will need to be defined
  7. #-    in your current environment.
  8. #-
  9. #-    Change the mode to execute and  then execute it  will cause it
  10. #-    to be installed.
  11. #-
  12. #    Author:        Paul Lew, General Systems Group, Salem, NH
  13. #    Last update:    10/14/86  02:26 PM
  14. #
  15. #if ( "${user}" == "lew" ) goto end
  16. #---------------------------------------------------------------#
  17. #    If invoked from csh "source" command, install locally    #
  18. #    else install globally and update .login, .cshrc, and    #
  19. #    .logout file.                        #
  20. #---------------------------------------------------------------#
  21. if ( $?0 ) goto install
  22. #---------------------------------------------------------------#
  23. #           Compile shdir.c first            #
  24. #---------------------------------------------------------------#
  25. if ( ! -e "shdir" ) then
  26.     if ( ! -e shdir.c ) then
  27.         echo "...File shdir.c missing, aborted..."
  28.         goto end
  29.         endif
  30.     echo -n "...Compiling shdir.c "
  31.     cc -s -o shdir shdir.c -ltermcap
  32.     echo "done..."
  33.     endif
  34. #---------------------------------------------------------------#
  35. #    Make sure all the required files are there        #
  36. #---------------------------------------------------------------#
  37. foreach fname (restdir lsdir shdir useshdir)
  38.     if ( ! -e ${fname} ) then
  39.         echo "...${fname} not in directory ${cwd}, aborted..."
  40.         goto end
  41.         endif
  42.     end
  43. #---------------------------------------------------------------#
  44. #        Define aliases in the current shell            #
  45. #---------------------------------------------------------------#
  46. foreach aname (lsdir po s to)
  47.     @ achar = `alias ${aname} | wc -c`
  48.     if ( ${achar} > 0 ) echo "...alias ${aname} will be redefined..."
  49.     end
  50. unset aname achar
  51. alias    lsdir    source ${cwd}/lsdir
  52. alias    po    'popd +\!* > /dev/null; shdir `dirs`'
  53. alias    s    ${cwd}'/shdir -s\!* `dirs` ;if ( ${status} ) pushd +${status} > /dev/null'
  54. alias    to    'pushd \!* > /dev/null ; '"${cwd}"'/shdir `dirs`'
  55. #---------------------------------------------------------------#
  56. #      Make a set of directory stack to demo            #
  57. #---------------------------------------------------------------#
  58. set dirs = (`dirs`)
  59. if ( ${#dirs} < 3 ) then
  60.     cd /usr/lib/uucp
  61.     foreach x (/usr/spool/uucp /usr/spool/uucppublic /etc ${cwd})
  62.         pushd $x > /dev/null
  63.         end
  64.     unset x
  65.     endif
  66. #---------------------------------------------------------------#
  67. #    Modify TERMCAP so he/she will see the result        #
  68. #---------------------------------------------------------------#
  69. switch ( "${TERM}" )
  70.     case vt100:
  71.     case vt102:
  72.     case vt125:
  73.     case vt220:
  74.     case vt240:
  75.     case wy75:
  76.         set noglob
  77.         eval `tset -Q -s`
  78.         unset noglob
  79.         set tc = ('jjkkllmmqqxx' '\E(B' '\E(0')
  80.         foreach te (ac ae as)
  81.         echo "${TERMCAP}" | fgrep -s ":${te}"
  82.         if ( ${status} == 1 ) then
  83.             echo "...${te} added to TERMCAP..."
  84.             setenv TERMCAP "${TERMCAP}${te}=${tc[1]}:"
  85.             endif
  86.         shift tc
  87.         end
  88.         breaksw
  89.     default:
  90.     endsw
  91. #---------------------------------------------------------------#
  92. #             Give a little hint                #
  93. #---------------------------------------------------------------#
  94. cat << cat_eof
  95. ...Now type 's' and move to the directory you want by pressing space bar....
  96. cat_eof
  97. goto end
  98.  
  99. #---------------------------------------------------------------#
  100. #        Final installation starts here            #
  101. #---------------------------------------------------------------#
  102. install:
  103. cat << cat_eof
  104.        **************** GENERAL INFORMATION ****************
  105.  
  106. This is the final installation procedure.  It will move all the
  107. executables to proper directory and also modify your .login, and
  108. .logout file so that directory stack will preserve across logins.
  109. Your .cshrc will also be modified to define aliases.
  110.  
  111. The defualt place to store the executables is: /usr/local/bin so that
  112. it can be shared among users.  Press return on to the question below
  113. if you like to use the default.
  114.  
  115. cat_eof
  116. echo -n "Where do you want to place executables in your system? "
  117. set dir = "$<"
  118. if ( "${dir}" == "" ) set dir = '/usr/local/bin'
  119. if ( ! -d "${dir}" ) then
  120.     mkdir "${dir}"
  121.     if ( ! -d "${dir}" ) then
  122.         echo "...${dir} is not a valid directory, aborted..."
  123.         goto end
  124.         endif
  125.     endif
  126. #---------------------------------------------------------------#
  127. #     Check if dir specified is in the search path        #
  128. #---------------------------------------------------------------#
  129. unset inpath
  130. foreach cpath (${path})
  131.     if ( "${cpath}" == "${dir}" ) then
  132.         set inpath
  133.         break
  134.         endif
  135.     end
  136. if ( ! ${?inpath} ) then
  137.     echo "...Warning: ${dir} not defined in your search path..."
  138.     endif
  139. unset inpath cpath
  140. #---------------------------------------------------------------#
  141. #      Move script to the executables directory        #
  142. #---------------------------------------------------------------#
  143. foreach fname (restdir lsdir shdir useshdir)
  144.     if ( -e "${dir}/${fname}" ) then
  145.         echo "...${dir}/${fname} already exist..."
  146.         continue
  147.         endif
  148.     if ( ! -e ${fname} ) then
  149.         echo "...${fname} not in directory ${cwd}, aborted..."
  150.         goto end
  151.         endif
  152.     if ( ${cwd} == "${dir}" ) continue
  153.     if ( -e "${dir}/${fname}" ) then
  154.         echo "...${dir}/${fname} already exist..."
  155.     else
  156.         /bin/mv ${fname} "${dir}"
  157.         endif
  158.     end
  159. sed -e "s:source /usr/local/bin:source ${dir}:" < ${dir}/lsdir > /tmp/lsdir$$
  160. /bin/mv -f /tmp/lsdir$$ ${dir}/lsdir
  161. /bin/chmod a+rx "${dir}/useshdir"
  162. /bin/chmod a+r-x "${dir}"/{restdir,lsdir}
  163. #---------------------------------------------------------------#
  164. #      Modify .cshrc, .logout to install for my account        #
  165. #---------------------------------------------------------------#
  166. ${dir}/useshdir ${dir}
  167. cat << cat_eof
  168. --------------------------------------------------------------------
  169. If anyone else in your system would like to use shdir, he/she only
  170. need to execute script: useshdir.
  171.  
  172. If you like to have VT100 graphic characters to draw the box, add the
  173. following to your termcap entry after you verify it does support these
  174. features:
  175.  
  176.     :ac=jjkkllmmqqxx:    #alternate graphic characters
  177.     :as=\E(0:        #alternate set start
  178.     :ae=\E(B:        #alternate set end
  179.  
  180.    ******** The installation is now complete, have fun!! ********
  181. cat_eof
  182. #---------------------------------------------------------------#
  183. #              Exit here                #
  184. #---------------------------------------------------------------#
  185. unset added msg
  186. end:
  187.