aboutsummaryrefslogtreecommitdiff
path: root/src/makealias.sh
blob: 43559ba658059e4b13afdc7a95b174a0819e7217 (plain)
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
#!/bin/sh

EXTENSIONS=".pd -help.pd .pd_linux .pd_darwin .pd_freebsd .dll .b_i386 .l_ia64 .l_i386 .d_fat .d_i386 .d_ppc .m_i386" 

ALIASFILE=$1
shift

if [ "x$ALIASFILE" = "x-clean" ]
then
  CLEANMODE=yes
  ALIASFILE=$1
  shift
else
  CLEANMODE=
fi


if [ -e "${ALIASFILE}" ]; then :; else
 echo cannot find alias-file ${ALIASFILE}
 exit 1
fi


debug() {
 :
# echo $@
}

do_makealias() {
 local source
 local dest

 source=$1
 dest=$2

 if [ "x${CLEANMODE}" = "xyes" ]
 then
   if [ -e "${dest}" ]; then
    debug "removing alias ${dest}"
    rm ${dest}
   else
     debug "alias ${dest} does not exist"
   fi
 else
   debug "aliasing ${source} to ${dest}"
   if [ "x${COPYMODE}" = "xyes" ]
   then
    cp ${source} ${dest}
   else
    source=${source##*/}
    ln -s ${source} ${dest}
   fi
 fi
}

do_makealiases() {
  local dir
  local master
  local slave
  local extension

  dir=$1
  master=$2
  shift; shift

  if [ "x${master}" = "x" ]; then
  # no realname provided
    return
  fi

  if [ "x$@" = "x" ]; then
  # no aliases provided...
    return
  fi

  for extension in ${EXTENSIONS}
  do
#   echo "checking aliases for ${dir}/${master}${extension}"
   if [ -f "${dir}/${master}${extension}" ]
   then
     for slave in $@
     do
      do_makealias ${dir}/${master}${extension} ${dir}/${slave}${extension}
     done
   fi
  done
}

for d in $@
do
  if [ -d "$d" ]
  then
    debug "scanning directory $d for aliases"
    cat ${ALIASFILE} | while read line
    do
     do_makealiases $d $line
    done
  else
    echo "skipping non-directory $d"
  fi
done