-
Notifications
You must be signed in to change notification settings - Fork 0
/
apprm
executable file
·243 lines (215 loc) · 5.59 KB
/
apprm
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
#!/bin/bash
# Remove app
#
# Ruoshi Sun
# 2021-06-17 YYYYMM aliases
# 2021-03-24 central container dir
# 2020-02-13
BUILD=build
DERPBUILD=derp-build
APPDIR=/sfs/applications
SOFTWARE=software
MODFILE=modulefiles
CONTAINERDIR=/share/resources/containers/singularity
ARCHIVEDIR=$CONTAINERDIR/archive
function print_usage {
cat <<EOF
Usage: `basename $0` YYYYMM CATEGORY [...] SOFTWARE/VERSION
where:
YYYYMM = r|b|db|d|prod|dev|all|"<custom list>"
r = rivanna
b = build
db = derp-build
d = derp
prod = r + b
dev = db + d
all = r + b + db + d
CATEGORY = core|toolchains|compiler|mpi|container
core SOFTWARE/VERSION
toolchains SOFTWARE/VERSION
compiler COMPILER/VERSION SOFTWARE/VERSION
mpi COMPILER/VERSION MPI_NAME/VERSION SOFTWARE/VERSION
container singularity/VERSION SOFTWARE/VERSION
vendor SOFTWARE/VERSION
Example: `basename $0` all core java/1.8.0
`basename $0` \"202003_build 202003\" mpi gcc/7.1.0 openmpi/3.1.0 metis/5.1.0
EOF
}
function print_error {
RED='\e[1;31m'
NC='\e[m'
echo -e "${RED}Error: $1${NC}"
echo
print_usage
exit 1
}
function getym {
if [ "$(hostname)" = "$1" ]; then
echo $(basename $(realpath /apps) | sed 's/_build//')
else
echo $(basename $(ssh $1 realpath /apps) | sed 's/_build//')
fi
}
function recursive_rmdir {
# remove empty directory
while [ ! "$(ls -A .)" ] ; do
dir=$(basename `pwd`)
cd ..
echo "empty directory $dir"
rmdir $dir
done
}
# must have at least 3 arguments
NARGS=$#
if [ $NARGS -lt 3 ]; then
print_usage
exit 0
fi
if [ ! -e $APPDIR ]; then
print_error "$APPDIR not found. Please update $0."
fi
# store list of YYYYMMs
case $1 in
b)
YYYYMMs="$(getym $BUILD)_build"
;;
r)
YYYYMMs=$(getym $BUILD)
;;
db)
YYYYMMs="$(getym $DERPBUILD)_build"
;;
d)
YYYYMMs=$(getym $DERPBUILD)
;;
prod)
YYYYMM=$(getym $BUILD)
YYYYMMs="${YYYYMM}_build $YYYYMM"
;;
dev)
YYYYMM=$(getym $DERPBUILD)
YYYYMMs="${YYYYMM}_build $YYYYMM"
;;
all)
YYYYMMp=$(getym $BUILD)
YYYYMMd=$(getym $DERPBUILD)
YYYYMMs="${YYYYMMp}_build $YYYYMMp ${YYYYMMd}_build $YYYYMMd"
;;
*)
YYYYMMs="$1"
esac
shift
# loop over YYYYMM
for YYYYMM in $YYYYMMs; do
echo "[$YYYYMM]"
# parse args
case $1 in
core|toolchains)
if [ $NARGS -ne 3 ]; then
print_error "incorrect number of arguments."
fi
PREFIX="standard/$1"
DIR=$2
;;
compiler|container)
if [ $NARGS -ne 4 ]; then
print_error "incorrect number of arguments."
fi
PREFIX="standard/$1/$2"
if [ ! -e $APPDIR/$YYYYMM/$SOFTWARE/standard/$1/$2 ]; then
print_error "$1 $2 not found in $YYYYMM."
fi
DIR=$3
;;
mpi)
if [ $NARGS -ne 5 ]; then
print_error "incorrect number of arguments."
fi
PREFIX="standard/$1/$2/$3"
if [ ! -e $APPDIR/$YYYYMM/$SOFTWARE/standard/$1/$2 ]; then
print_error "compiler $2 not found in $YYYYMM."
fi
if [ ! -e $APPDIR/$YYYYMM/$SOFTWARE/standard/$1/$2/$3 ]; then
print_error "$1 $3 not found in $YYYYMM."
fi
DIR=$4
;;
vendor)
if [ $NARGS -ne 3 ]; then
print_error "incorrect number of arguments."
fi
PREFIX=$1
DIR=$2
;;
*)
print_error "invalid category $1."
;;
esac
SOFTWARE_PATH=$APPDIR/$YYYYMM/$SOFTWARE/$PREFIX/$DIR
EBFILE="$SOFTWARE_PATH/easybuild/*.eb"
# check if installation is complete
VERSION=`basename $DIR`
if [ ! -e $EBFILE ]; then
echo "$EBFILE not found. Perhaps due to incomplete installation."
else
# test for hidden module
if grep -q "^hidden\s*=\s*True" $EBFILE; then
VERSION=".$VERSION"
fi
fi
# module files are not stored in separate version directories
MODFILE_PATH="$APPDIR/$YYYYMM/$MODFILE/$PREFIX/$DIR"
MODFILE_PATH="${MODFILE_PATH%/*}"
# check if software path exists
# do not check module path now, since it may not exist
if [ ! -e $SOFTWARE_PATH ]; then
print_error "$SOFTWARE_PATH not found."
fi
# begin removal process
echo "== To be removed"
echo "Software:"
echo $SOFTWARE_PATH
ls -A $SOFTWARE_PATH
echo
echo "Module file:"
echo $MODFILE_PATH
ls -A $MODFILE_PATH/$VERSION.* 2> /dev/null
# confirm before removing
echo
read -p "== Remove? [y/N]" yn
if [[ ! $yn =~ ^[Yy]$ ]]; then
echo "== No changes performed."
exit 0
fi
echo "== Removing..."
# rm software
cd $SOFTWARE_PATH
echo "software files"
ls -A1 . | xargs rm -rf # takes care of any hidden files
recursive_rmdir
# rm module file
if [ -e $MODFILE_PATH ]; then
cd $MODFILE_PATH
echo "module files"
if [ "$(ls -A $VERSION.* 2> /dev/null)" ]; then
rm $VERSION.*
fi
recursive_rmdir
else
echo "$MODFILE_PATH does not exist"
fi
# rm container from $CONTAINERDIR
if [ "$1" = "container" ]; then
echo
ls -A $CONTAINERDIR/${DIR/\//-}.{sif,simg,img} 2> /dev/null
read -p "Archive container? [y/N]" yn
if [[ $yn =~ ^[Yy]$ ]]; then
[ -e $SIF ] && mv -i $CONTAINERDIR/${DIR/\//-}.{sif,simg,img} $ARCHIVEDIR
else
echo "== No changes made in $CONTAINERDIR"
exit 0
fi
fi
echo "== Done."
echo
done