File: mklinks

package info (click to toggle)
plplot 5.10.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 26,280 kB
  • ctags: 13,512
  • sloc: ansic: 83,001; xml: 27,081; ada: 18,878; cpp: 15,966; tcl: 11,651; python: 7,075; f90: 7,058; ml: 6,974; java: 6,665; perl: 5,029; sh: 2,210; makefile: 199; lisp: 75; sed: 25; fortran: 7
file content (273 lines) | stat: -rwxr-xr-x 7,036 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#!/bin/sh

#*************************************************************************
#
# $Id: mklinks 5349 2004-02-14 10:00:16Z rlaboiss $
#
# mklinks - makes (or removes) soft-links from distribution directory to
#           more appropriate places (typically under /usr/local).
#
# Maurice LeBrun (mjl@dino.ph.utexas.edu)
# IFS, University of Texas at Austin
# May 17, 1994
#
# Arguments: 
#	-a	Add soft links
#	-n	Print commands without executing
#	-r	Remove soft links
#
# Anything else results in a short help message being printed.
#
# I wrote this script to simplify the business of installing software
# distributions.  With a lot of packages continuing to evolve at a pretty
# good clip, it helps to be able to update without too much hassle.  Also,
# it is best to provide a fairly consistent organization of the files on
# disk, one that fits into just about anyone's system management scheme.
# The method I use works whether you are system manager or just some poor
# slob user :-).
#
# The idea is to type "make install" in the build directory, with the
# install target set to some empty directory.  A good choice is
# /usr/local/<pkg><ver>, where <pkg> is the software package name and
# <ver> is the version.  This way you can have multiple versions of the
# package installed, with only one of them easily accessible.  Or you can
# leave out the version number.
#
# By softlinking the package distribution files into the usual /usr/local
# areas you (a) avoid requiring a change in PATH to get at the binaries,
# (b) avoid requiring changes to makefiles to get include and lib
# settings, (c) avoid requiring changes to MANPATH settings to allow
# access to the man pages, and (d) have an easy way to do upgrades or
# degrades.
#
# The main difficulty as I see it with using softlinks from /usr/local
# areas into /usr/local/bin, /usr/local/lib, /usr/local/include, and
# /usr/local/man, is that once created, the softlinks are hard to get rid
# of.  If you decide to delete the package, you must manually delete the
# softlinks as well.  Switching between versions is an onerous task,
# especially if you want to back down to a previous revision.  Therefore,
# a fundamental capability of this script is to allow easy removal of all
# created softlinks (-r option).
#
# Note: the default is to only link librarys under lib into the target
# dir, since some packages store lots of data files under lib/.
#
#*************************************************************************

# Miscellaneous settings

NAME=$0			# Name of script
CWD=`pwd`		# Current directory
LINK_MAN=1		# Install man pages (set to null to disable)
LINK_LIB_ALL=0		# Link lib/* rather than just lib/lib*

# Infer package name from directory name
# Not all systems have "basename" so use sed for this.

PKG=`echo $CWD | sed 's%/.*/%%'`

# Get base target directory -- the links will go into $INSTALL_DIR/bin,
# $INSTALL_DIR/lib, etc.  Since the package is typically in
# /usr/local/<pkg>, INSTALL_DIR is just one directory up.  Use an absolute
# path name rather than relative (..) since it's less confusing.

INSTALL_DIR=`echo $CWD | sed 's%/[^/][^/]*$%%'`

# Per-package defaults:
#    PKG_NAME		Name of package, for help/error messages
#    REFERENCE_FILE	Name of an installed file to assist internal logic

case "$PKG" in

    perl* )
	PKG_NAME="perl"
	REFERENCE_FILE="$INSTALL_DIR/bin/perl"
    ;;

    plplot* )
	PKG_NAME="PLplot"
	REFERENCE_FILE="$INSTALL_DIR/bin/plrender"
    ;;

    python* )
	PKG_NAME="Python"
	REFERENCE_FILE="$INSTALL_DIR/bin/python"
	LINK_LIB_ALL=1
    ;;

    tcl*|tk* )
	PKG_NAME="Tcl/TK/etc"
	REFERENCE_FILE="$INSTALL_DIR/bin/tclsh"
	LINK_LIB_ALL=1
    ;;

    * )
	echo "Unrecognized package; aborting"
	exit
    ;;
esac

# Account for differences in /bin/sh semantics wrt soft links.

IF_SOFT="-h"
if test `uname` = "AIX"; then
    IF_SOFT="-L"
fi

# Define a symbol for echo to save a little bit of space.

e=echo

#*************************************************************************

# Spits out help message, then exits

help () {

$e "Usage: $NAME [-n] [-a | -r]"
$e "       Creates (-a) or removes (-r) soft links to $PKG_NAME files."
$e "       Currently configured to put soft links under $INSTALL_DIR."
$e ""
$e "       If -n is specified, commands are printed with no action taken."
$e "       The -n flag must come first, if specified."
    exit 1
}

#*************************************************************************

# Adds one or many soft-links.  Creates directory if necessary.
# $1 - subdir name
# $2 - file spec

add_link () {

    if test -d "$CWD/$1"; then

	if test ! -d "$INSTALL_DIR/$1"; then
	    if test "$DO_NOTHING"; then
		echo "mkdir -p $INSTALL_DIR/$1"
	    else
		mkdir -p $INSTALL_DIR/$1
	    fi
	fi

	# Do filename globbing here so we can catch cases where no
	# filenames match.

	for file in $CWD/$1/$2; do
	    if test -r $file; then
		if test "$DO_NOTHING"; then
		    echo "ln -s $file  $INSTALL_DIR/$1"
		else
		    ln -s $file $INSTALL_DIR/$1
		fi
	    fi
	done
    fi
}

#*************************************************************************

# Removes a single soft-link
# $1 - link name (relative to $INSTALL_DIR)

rm_link () {

    if test $IF_SOFT "$INSTALL_DIR/$1"; then
	if test "$DO_NOTHING"; then
	    echo "rm $INSTALL_DIR/$1"
	else
	    rm $INSTALL_DIR/$1
	fi
    fi
}

#*************************************************************************

# Removes multiple soft-links
# $1 through $# - link specs (relative to $INSTALL_DIR)

rm_links () {
    for file in $*; do
	rm_link $file
    done
}

#*************************************************************************

# Add links

Add () {

# Bomb out if we're not starting clean

    if test $IF_SOFT "$REFERENCE_FILE"; then
	echo "Must remove old links first -- use \"$NAME -r\"."
	exit 1
    fi

# Set up links

    echo "Adding links from $CWD to $INSTALL_DIR"

    add_link "bin"	"*"
    add_link "include"	"*.h"

    if test "$LINK_LIB_ALL" = 1; then
	add_link "lib"	"*"
    else
	add_link "lib"	"lib*"
    fi

    if test "$LINK_MAN"; then
	add_link "man/man1" "*.1"
	add_link "man/man3" "*.3"
	add_link "man/mann" "*.n"
    fi
}

#*************************************************************************

# Remove links

Remove () {

# Bomb out if links already removed.

    if test ! $IF_SOFT "$REFERENCE_FILE"; then
	echo 'Soft links already removed.'
	exit 1
    fi

# Delete links
# Here we reglob to determine what links need deleting.  Note that in each
# case, we check to make sure it really is a soft link.

    echo "Removing links from $CWD to $INSTALL_DIR"

    rm_links bin/* lib/* include/*.h

    if test "$LINK_MAN"; then
	rm_links man/man1/*.1 man/man3/*.3 man/mann/*.n
    fi
}

#*************************************************************************

# Call the necessary function to do the job.

if test "$1" = "-n"; then
    DO_NOTHING=1
    shift
fi

if test "$1" = '-a'; then
    Add

elif test "$1" = '-r'; then
    Remove

else
    help
fi
exit 0