-
Notifications
You must be signed in to change notification settings - Fork 0
/
appsync
executable file
·148 lines (128 loc) · 3.24 KB
/
appsync
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
#!/bin/bash
#
# Performs rsync from build to production
# Ruoshi Sun
function print_usage {
echo "Usage: `basename $0` EASYCONFIG"
echo "Usage: `basename $0` vendor APP/VERSION"
}
function print_error {
RED='\e[1;31m'
NC='\e[m'
echo -e "${RED}Error: $1${NC}"
echo
print_usage
exit 1
}
for i in $BUILD_DIR $PROD_DIR; do
if [ ! -d $i ]; then
print_error "Cannot find directory $i. Please update $0."
fi
done
NARGS=$#
if [ $NARGS -eq 0 ]; then
print_usage
exit 0
fi
SOFTWARE="software"
MODFILE="modulefiles"
# Need to use realpath for vendor source and destination
# Do not use /apps or it will overwrite the vendor symlink
if [ $NARGS -eq 2 ]; then
case $1 in
vendor)
SOURCE=/sfs/applications/$1/installation
DEST=/sfs/applications/$1/production
SOFTWARE_PATH=$SOURCE/$SOFTWARE/$2
SOFTWARE_DEST=$DEST/$SOFTWARE/$2
MODFILE_PATH=$SOURCE/$MODFILE/$2.lua
MODFILE_DEST=$DEST/$MODFILE/$2.lua
echo "== Paths"
echo "Software source and destination:"
echo "$SOFTWARE_PATH"
echo "$SOFTWARE_DEST"
echo
echo "Module file source and destination:"
echo "$MODFILE_PATH"
echo "$MODFILE_DEST"
echo
read -p "== Perform rsync now? [y/N]" realrun
if [[ ! $realrun =~ ^[Yy]$ ]]; then
echo "== No changes performed."
exit 0
fi
echo
rsync -av $SOFTWARE_PATH $(dirname $SOFTWARE_DEST)
rsync -av $MODFILE_PATH $MODFILE_DEST
echo "== Done."
exit 0
;;
*)
print_error "invalid category $1."
;;
esac
fi
# standard module
EB=$1
if [ ! -e $EB ]; then
print_error "cannot find easyconfig file $1."
fi
ml easybuild
set -e
set -o pipefail
read -r PREFIX DIR < <(
eb -D $1 | grep '\[x\]' | tail -1 | \
sed -e 's/^.*module: //' -e 's/)$//' | \
awk -F'|' '{print $1,$2}'
)
if [ $? -ne 0 ]; then
print_error "possible error in module installation."
fi
PREFIX="standard/$PREFIX"
DIR="${DIR/\/./\/}"
# add '.' for hidden modulefile
if grep -q "^hidden\s*=\s*True" $EB; then
LUA="${DIR/\///.}.lua"
else
LUA="$DIR.lua"
fi
BUILD_DIR=$(realpath /apps)
YYYYMM_build=$(basename $BUILD_DIR)
echo "BUILD_DIR = $BUILD_DIR"
PROD_DIR=${BUILD_DIR/_build/}
YYYYMM=$(basename $PROD_DIR)
echo "PROD_DIR = $PROD_DIR"
SOFTWARE_PATH=$BUILD_DIR/$SOFTWARE/$PREFIX/$DIR
MODFILE_PATH="$BUILD_DIR/$MODFILE/$PREFIX/$LUA"
echo "== Paths"
echo "Software source and destination:"
echo "$SOFTWARE_PATH"
echo "$PROD_DIR/$SOFTWARE/$PREFIX/$DIR"
echo
echo "Module file source and destination:"
echo "$MODFILE_PATH"
echo "$PROD_DIR/$MODFILE/$PREFIX/`dirname $DIR`"
echo
# check paths of software and module file
for i in $SOFTWARE_PATH $MODFILE_PATH; do
if [ ! -e $i ]; then
print_error "$i not found."
fi
done
echo
read -p "== Perform rsync now? [y/N]" realrun
if [[ ! $realrun =~ ^[Yy]$ ]]; then
echo "== No changes performed."
exit 0
fi
echo "== Performing rsync..."
cd $BUILD_DIR
rsync -avR --delete $SOFTWARE/$PREFIX/$DIR $PROD_DIR && \
rsync -avR $MODFILE/$PREFIX/$LUA $PROD_DIR
# check default symlink
APP=`dirname $DIR`
if [ -e $MODFILE/$PREFIX/$APP/default ]; then
rsync -avR $MODFILE/$PREFIX/$APP/default $PROD_DIR
fi
echo
echo "== Done."