/usr/bin/prefix is in libapp-options-perl 1.12-2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | #!/bin/bash
#*********************************************************************
#** prefix
#*********************************************************************
#** @(#)$Id: prefix 7988 2006-10-27 18:39:02Z spadkins $
#*********************************************************************
export OLD_PREFIX=$PREFIX
export PREFIX=${PREFIX:-/usr/local}
if [[ -f "$HOME/.prefixes" ]] # check if multiple environments exist
then
export PREFIXES_FILE=$HOME/.prefixes
else
export PREFIXES_FILE=/etc/prefixes
fi
print_usage ()
{
echo
echo "The prefix script allows you to manage multiple installations of"
echo "a set of software installed on the same machine. It helps in this"
echo "by taking care of the reconfiguration of environment variables"
echo "appropriate for each installation. It is assumed that the"
echo "software for each installation is all under a single directory"
echo "whose name is assigned to an environment variable called PREFIX. "
echo
echo "This arrangement of enabling multiple installations of software"
echo "on a single machine is useful at many times. On a single server,"
echo "it can provide for development, test, and production installations"
echo "of software. Alternatively, on development servers,"
echo "it allows for multiple development \"sandboxes\", one for each"
echo "developer. On production servers, it allows for multiple versions"
echo "of the production software to be installed. One might be the currently"
echo "running software, one the previous software kept online as a fall-back,"
echo "and one a new release of software which is scheduled to be brought"
echo "online soon."
echo
echo "There are three usages of the prefix script:"
echo
echo " (1) The interactive usage should be placed as the last line"
echo " of a user's ".profile". The user must be running the"
echo " Korn shell (ksh) or the Bourne Again shell (bash)."
echo " The user is prompted to enter one of the known PREFIX locations,"
echo " specified in the \$HOME/.prefixes file or the /etc/prefixes file."
echo " During configuration, the \$PREFIX/.prefixrc file is sourced"
echo " in order to accomplish environment-specific configurations."
echo " (2) The non-interactive user configuration does not consult"
echo " \$HOME/.prefixes or /etc/prefixes or prompt the user, but merely"
echo " configures the environment in accordance with the cmd line argument."
echo " (3) The batch command usage is mainly for running commands from"
echo " cron or running commands in another environment without changing"
echo " to that environment."
echo
echo "Usage (1): . prefix (sets up environment)"
echo " (2): . prefix <prefix> (non-interactive setup)"
echo " (3): prefix <prefix> <cmd> <args> (runs cmd configured for PREFIX)"
echo
}
if [[ "$1" = "-?" ]]
then
print_usage
else
export PREFIX_CMD=""
if [[ "$1" != "" ]]
then
export NEW_PREFIX="$1"
export PREFIX_ASK="no"
shift
if [[ $# -gt 0 ]]
then
export PREFIX_CMD="$*"
set -- # clear cmd line args
fi
fi
if [[ "$PREFIX_ASK" != "no" ]]
then
if [[ -f "$PREFIXES_FILE" ]] # check if multiple environments exist
then
export NUM_PREFIXES=$(wc -l < "$PREFIXES_FILE")
if [[ "$NEW_PREFIX" = "" ]]
then
export NEW_PREFIX=$(head -1 "$PREFIXES_FILE")
fi
if [[ "$PREFIX_ASK" != "no" && "$NUM_PREFIXES" -gt 1 ]]
then
echo "========================================================"
echo "SET UP SOFTWARE PREFIX (ROOT DIRECTORY FOR THE SOFTWARE)"
echo "========================================================"
export PS3="Select a directory: "
select NEW_PREFIX in $(sed 's/#.*//' "$PREFIXES_FILE")
do
break
done
if [[ "$NEW_PREFIX" = "" ]]
then
export NEW_PREFIX="$REPLY"
fi
fi
fi
fi
if [[ "$NEW_PREFIX" = "" ]]
then
echo
echo "ERROR: Please specify a PREFIX or create a ~/.prefixes file"
echo " to enable interactive usage."
echo
print_usage
elif [[ ! -d $NEW_PREFIX/. ]]
then
echo
echo "ERROR: Directory [$NEW_PREFIX] does not exist."
echo
print_usage
else
export PREFIX=$NEW_PREFIX
if [[ -t 1 && "$PREFIX_CMD" = "" ]]
then
echo "Configuring Software Prefix [$NEW_PREFIX]."
fi
######################################################
# Remove all PATH references before adding them back
######################################################
export SED_CLEAN_PATH=""
export SED_CLEAN_LIBPATH=""
export SED_CLEAN_MANPATH=""
for AUX_DIR in $(echo "$OLD_PREFIX:$PRE_PREFIX:$POST_PREFIX" | sed -e 's/^/:/' -e 's!:\([^/~]\)!:'$PREFIX'/\1!' -e 's/:/ /g')
do
SED_CLEAN_PATH="$SED_CLEAN_PATH -e s!:$AUX_DIR/bin!!g"
SED_CLEAN_LIBPATH="$SED_CLEAN_LIBPATH -e s!:$AUX_DIR/lib!!g"
SED_CLEAN_MANPATH="$SED_CLEAN_MANPATH -e s!:$AUX_DIR/man!!g -e s!:$AUX_DIR/share/man!!g"
done
# Remove old references from the PATH
export PATH=`echo $PATH | \
sed -e "s/^:*/:/" \
-e "s/:*$/:/" \
-e "s/:::*/:/g" \
$SED_CLEAN_PATH \
-e "s/::*$//" \
-e "s/^::*//"`
# Remove old references from the LD_LIBRARY_PATH
OLD_LD_LIBRARY_PATH="$LD_LIBRARY_PATH"
if [ "$OLD_LD_LIBRARY_PATH" = "" ]
then
OLD_LD_LIBRARY_PATH="/usr/local/lib:/usr/lib:/lib"
fi
export LD_LIBRARY_PATH=""
export LD_LIBRARY_PATH=`echo $OLD_LD_LIBRARY_PATH | \
sed -e "s/^:*/:/" \
-e "s/:*$/:/" \
-e "s/:::*/:/g" \
$SED_CLEAN_LIBPATH \
-e "s/::*$//" \
-e "s/^::*//"`
unset OLD_LD_LIBRARY_PATH
# Remove old references from the LIBPATH
OLD_LIBPATH="$LIBPATH"
if [ "$OLD_LIBPATH" = "" ]
then
OLD_LIBPATH="/usr/local/lib:/usr/lib:/lib"
fi
export LIBPATH=""
export LIBPATH=`echo $OLD_LIBPATH | \
sed -e "s/^:*/:/" \
-e "s/:*$/:/" \
-e "s/:::*/:/g" \
$SED_CLEAN_LIBPATH \
-e "s/::*$//" \
-e "s/^::*//"`
unset OLD_LIBPATH
# Remove old references from the MANPATH
if [ "$MANPATH" = "" ]
then
MANPATH="/usr/local/man:/usr/share/man:/usr/man:/man"
fi
export MANPATH=`echo $MANPATH | \
sed -e "s/^:*/:/" \
-e "s/:*$/:/" \
-e "s/:::*/:/g" \
$SED_CLEAN_MANPATH \
-e "s/::*$//" \
-e "s/^::*//"`
######################################################
# source the environment's .rmsrc file if it exists
######################################################
for AUX_DIR in $(echo $POST_PREFIX | sed -e 's/^/:/' -e 's!:\([^/~]\)!:'$PREFIX'/\1!' -e 's/:/ /g')
do
if [[ -f $AUX_DIR/.prefixrc ]]
then
. $AUX_DIR/.prefixrc
fi
done
if [[ -f $PREFIX/.prefixrc ]]
then
. $PREFIX/.prefixrc
fi
for AUX_DIR in $(echo $PRE_PREFIX | sed -e 's/^/:/' -e 's!:\([^/~]\)!:'$PREFIX'/\1!' -e 's/:/ /g')
do
if [[ -f $AUX_DIR/.prefixrc ]]
then
. $AUX_DIR/.prefixrc
fi
done
######################################################
# source the user's .prefixrc file if it exists
######################################################
if [[ -f ~/.prefixrc ]]
then
. ~/.prefixrc
fi
##########################################################
# Set appropriate defaults for common variables
##########################################################
export AUX_PATH=""
export AUX_LIBPATH=""
export AUX_MANPATH=""
export PREFIX_INCLUDES=""
for AUX_DIR in $(echo $PRE_PREFIX | sed -e 's/^/:/' -e 's!:\([^/~]\)!:'$PREFIX'/\1!' -e 's/:/ /g')
do
AUX_PATH="$AUX_PATH$AUX_DIR/bin:"
AUX_LIBPATH="$AUX_LIBPATH$AUX_DIR/lib:"
AUX_MANPATH="$AUX_MANPATH$AUX_DIR/man:"
PREFIX_INCLUDES="$PREFIX_INCLUDES -I$AUX_DIR/include"
done
PREFIX_INCLUDES="$PREFIX_INCLUDES -I$PREFIX/include"
export AUX_PATHPOST=""
export AUX_LIBPATHPOST=""
export AUX_MANPATHPOST=""
for AUX_DIR in $(echo $POST_PREFIX | sed -e 's/^/:/' -e 's!:\([^/~]\)!:'$PREFIX'/\1!' -e 's/:/ /g')
do
AUX_PATHPOST="$AUX_PATHPOST:$AUX_DIR/bin"
AUX_LIBPATHPOST="$AUX_LIBPATHPOST:$AUX_DIR/lib"
AUX_MANPATHPOST="$AUX_MANPATHPOST:$AUX_DIR/man"
PREFIX_INCLUDES="$PREFIX_INCLUDES -I$AUX_DIR/include"
done
# Add new references into the PATH
export PATH=$AUX_PATH$PREFIX/bin$AUX_PATHPOST:$PATH
# Add new references into the LD_LIBRARY_PATH
if [[ "$LD_LIBRARY_PATH" = "" ]]
then
export LD_LIBRARY_PATH=$AUX_LIBPATH$PREFIX/lib$AUX_LIBPATHPOST
else
export LD_LIBRARY_PATH=$AUX_LIBPATH$PREFIX/lib$AUX_LIBPATHPOST:$LD_LIBRARY_PATH
fi
# Add new references into the LIBPATH
if [[ "$LIBPATH" = "" ]]
then
export LIBPATH=$AUX_LIBPATH$PREFIX/lib$AUX_LIBPATHPOST
else
export LIBPATH=$AUX_LIBPATH$PREFIX/lib$AUX_LIBPATHPOST:$LIBPATH
fi
# Add new references into the MANPATH
if [[ "$MANPATH" = "" ]]
then
# guess at the base MANPATH
MANPATH=$(ls -d /man /*/man /*/*/man 2> /dev/null | tr '\n' ':' | sed 's/:$//')
fi
# Add new references into the MANPATH
if [[ "$MANPATH" = "" ]]
then
export MANPATH=$AUX_MANPATH$PREFIX/share/man:$PREFIX/man$AUX_MANPATHPOST
else
export MANPATH=$AUX_MANPATH$PREFIX/share/man:$PREFIX/man$AUX_MANPATHPOST:$MANPATH
fi
fi
if [[ "$PREFIX_CMD" != "" ]]
then
exec $PREFIX_CMD
fi
fi
set -- # clear cmd line args
unset PREFIXES_FILE
unset PREFIX_CMD
unset PREFIX_ASK
unset NUM_PREFIXES
unset NEW_PREFIX
unset OLD_PREFIX
unset SED_CLEAN_PATH
unset SED_CLEAN_LIBPATH
unset SED_CLEAN_MANPATH
unset AUX_PATH
unset AUX_LIBPATH
unset AUX_MANPATH
unset AUX_DIR
unset AUX_PATHPOST
unset AUX_LIBPATHPOST
unset AUX_MANPATHPOST
|