#! /bin/sh
# $Id: mk_fol_names.install 0.2 1994/10/29 11:31:12 jerry Exp $
### mk_fol_names.install - make links for mk_fol_names script
### Usage: mk_fol_names.install [-v]
##
##  Makes hard links from $progname (mk_fol_names) file to
##  each program listed in $table.  NOTE: REMOVES any existing
##  file or link with the same name!.. you may want to modify
##  to use "mv ... /tmp", instead of "rm -f ...", for safety.
##
##  -v switch turns on verbose mode.
##
##  NOTE: Read the whole script before you use it!  Modify if needed.
# 
#                             NO WARRANTY
# 
#   BECAUSE THIS PROGRAM IS AVAILABLE FREE OF CHARGE, THERE IS NO WARRANTY
# FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
# OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
# PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
# OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
# TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
# PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
# REPAIR OR CORRECTION.
# 
#   IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
# WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
# REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
# INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
# OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
# TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
# YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
# PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGES.


dir=/home/jpeek/bin # Directory where $progname and links are installed
#dir=/tmp/linktest
progname=/home/jpeek/bin/mk_fol_names   # Name of program we're working for

# Table of folder abbreviations and full names, in this syntax:
#   abbrev<TAB>fulname
# Example:
#   mb  mh-book
#   mba mh-book/authors
#   mbr mh-book/revisions
# That table would handle commands amb, amba, ambr, fmb, fmba, fmbr.
table=/home/jpeek/Mail/folder_table

cd "$dir" || exit
if test ! -f $progname; then
    echo "$0 quitting: can't find program $progname." 1>&2
    exit 1
fi

# NOTE: This does NOT remove links that aren't in $table anymore!  Do by hand.
#
# Note: csh_folders and sh_folders are hardcoded. 
# Also, this sed script names link names starting with "a" and "f".
# If you changed mk_fol_names to use other letters, fix "s" commands in script:
links="csh_folders sh_folders
`sed -n '
/^#/d
s/  .*//
h
s/^/a/p
g
s/^/f/p' $table`"

# NOTE: You may want to change this command to preserve old files:
# /bin/rm -f $links 2>&1
/bin/mv -f $links /tmp >/dev/null 2>&1
# temp -v $links

for link in $links
do
    # Verbose option (actually, any $1 makes script verbose):
    case "$1" in
    ?*) echo "Creating link $link" 1>&2 ;;
    esac

    /bin/ln $progname $link ||
        echo "$0: WARNING: 'ln $progname $link' failed?" 1>&2
done
