-
Notifications
You must be signed in to change notification settings - Fork 0
/
revdep
executable file
·68 lines (58 loc) · 1.38 KB
/
revdep
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
#!/bin/bash
# find reverse dependency of module
# Ruoshi Sun
# 2021-04-05 all orders, tree
# 2020-11-24
if [[ $# -eq 0 || $# -gt 2 ]]; then
echo "Usage: `basename $0` APP [VERSION]"
exit 1
fi
DIR=/apps/modulefiles/standard
N=$((${#DIR}+2))
function find_revdep {
RESULT=$(find $DIR -name '*.lua' -exec grep -l "load(\"$1\")" {} \; | cut -c ${N}- | sed 's/.lua$//')
echo "$RESULT"
}
count=1
function recursive_find {
RESULT="$@"
if [ -z "$RESULT" ]; then
echo -ne "Processed leaf $count\r"
count=$((count+1))
else
ALLDIRS=$(echo "$RESULT" | sed 's/\//@/g')
mkdir $ALLDIRS
for i in *; do
cd $i
SEARCH=$(echo $i | awk -F'@' '{printf "%s/%s", $(NF-1), $NF}')
RESULT=$(find_revdep "$SEARCH")
recursive_find "$RESULT"
cd ..
done
fi
}
APP=$1
if [ $# -eq 2 ]; then
VERSION=$2
SEARCH="$APP/$VERSION"
HEADER=$SEARCH
else
SEARCH="$APP/.*"
HEADER=$APP
fi
RESULT=$(find_revdep $SEARCH)
if [ ! -z "$RESULT" ]; then
NDEP=$(echo $RESULT|awk '{print NF}')
echo "Found $NDEP 1st order reverse dependencies"
TMPDIR=$(mktemp -d)
cd $TMPDIR
recursive_find "$RESULT"
echo
echo
ml tree
echo $HEADER
tree $TMPDIR | sed -e 's/@/\//g' -e '1d' -e '$d'
rm -rf $TMPDIR
else
echo "No reverse dependencies"
fi