File: setpath.sh

package info (click to toggle)
djview4 4.12.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,792 kB
  • sloc: cpp: 22,307; ansic: 9,746; sh: 392; makefile: 229; awk: 94; xml: 84
file content (66 lines) | stat: -rwxr-xr-x 1,223 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
#!/bin/bash

# Step 1 -- locate the directory containing this script

progname="`basename $0`"
if [ "$progname" != "$0" ]
then
    # programname contains directory components
    progdir="`dirname $0`"
else
    # must search along path
    tmpvar="$PATH"
    while [ -n "$tmpvar" ]
    do
      IFS=':' read progdir tmpvar <<EOF
$tmpvar
EOF
      test -x "$progdir/$progname" && break
    done
fi
progdir=`cd $progdir ; pwd`
while [ -L "$progdir/$progname" ]
do
    tmpvar=`ls -ld $progdir/$progname`
    tmpvar=`expr "$tmpvar" : '.*-> *\(.*\)'`
    progname=`basename $tmpvar` 
    tmpvar=`dirname $tmpvar` 
    progdir=`cd $progdir ; cd $tmpvar ; pwd` 
done
if [ ! -x "$progdir/$progname" ]
then
   echo 1>&2 "$progname: command not found"
   exit 10
fi

# Step 2 -- check path and manpath

contains() {
  tmpvar=`eval echo '$'$1`
  while [ -n "$tmpvar" ]
  do
    IFS=':' read dir tmpvar <<EOF
$tmpvar
EOF
    [ "$dir" = "$2" ] && exit 0
  done
  false
}


if ! contains PATH $progdir/bin
then
  echo -n 'PATH="'
  test -n "$PATH" && echo -n '$'PATH:
  echo $progdir/bin'"'
  echo export PATH
fi

if ! contains MANPATH $progdir/share/man
then
  echo MANPATH='"$'MANPATH:$progdir/share/man'"'
  echo export MANPATH
fi