-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync.sh
executable file
·135 lines (120 loc) · 3.21 KB
/
sync.sh
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
#!/bin/bash
# Ruoshi Sun
# 2024-01-24
if [ ! -z "$(git diff main derp sync.sh)" ]; then
echo "Error: sync.sh out of sync across branches"
echo "See README.md for instructions"
exit 1
fi
#-------------------------------
# Global variables and functions
#-------------------------------
HERE=$(realpath $(dirname $0))
COLUMNS=80
# files to be excluded in easyblock dir
EXCLUDE="__init__.py
__pycache__
*.pyc
*.pyo"
EXCLUDE=$(echo "$EXCLUDE"|sed 's/^/--exclude /'|tr '\n' ' ')
TMP=$(mktemp -d)
DIVIDER=$(printf %"$COLUMNS"s|tr ' ' '-')
# determine YYYYMM for production and derp
YMp=$(basename $(ssh -A login.hpc.virginia.edu realpath /apps))
YMd=$(date -d "${YMp}01 + 6 month" +%Y%m)
function sync() {
# collect all files in a temp dir first and then bulk rsync later to capture deleted modules
cd $SOFTWAREDIR/$1
find . -mindepth $2 -maxdepth $2 -type f \( -name *.eb -or -name *.patch \) \
-exec rsync -qa {} $TMP \;
}
# check args
if [ $# -eq 0 ]; then
echo "Usage: `basename $0` p|d [dry]"
echo " p = production"
echo " d = derp"
exit 1
fi
if [ $# -ge 2 ]; then
# dry run
echo "DRY RUN - no changes will be made in $HERE"
RSYNCFLAG=-na
else
RSYNCFLAG=-qa
fi
#----------------------------
# Initialize branch variables
#----------------------------
module purge
case $1 in
p)
if [ ! $(git branch --show-current) = "main" ]; then
echo "Error: trying to sync production into a branch other than main"
exit 1
fi
EBVER=4.7.1
APPSDIR="/sfs/applications/${YMp}_build"
PYTHON=/usr/bin/python3
;;
d)
if [ ! $(git branch --show-current) = "derp" ]; then
echo "Error: trying to sync derp into a branch other than derp"
exit 1
fi
EBVER=4.7.1
APPSDIR="/sfs/applications/${YMd}_build"
PYTHON=/usr/bin/python3
;;
*)
echo "Invalid option"
exit 1
;;
esac
EBDIR=$APPSDIR/software/EasyBuild/$EBVER
PYVER=$($PYTHON -V|awk '{print $2}') # e.g. 3.6.8
PYVER=${PYVER%.*} # e.g. 3.6
# the trailing slash matters for rsync
EASYBLOCKSDIR=$APPSDIR/software/EasyBuild/$EBVER/lib/python${PYVER}/site-packages/easybuild/easyblocks/
SOFTWAREDIR=$APPSDIR/software/standard
for i in $APPSDIR $EBDIR $EASYBLOCKSDIR $SOFTWAREDIR; do
if [ ! -d $i ]; then
echo "Error: $i is not a valid directory"
exit 1
fi
done
# Configuration
echo $DIVIDER
echo "EasyBuild: $EBDIR"
echo "Easyconfigs: $SOFTWAREDIR"
echo "Easyblocks: $EASYBLOCKSDIR"
echo $DIVIDER
# easyconfigs
echo -n "Syncing installed easyconfigs and patches... "
sync core 4
sync compiler 6
sync mpi 8
sync toolchains 4
sync container 6
rsync $RSYNCFLAG --delete $TMP/ $HERE/easyconfigs
rm -rf $TMP
echo "Done."
echo $DIVIDER
# easyblocks
echo -n "Syncing easyblocks... "
rsync $RSYNCFLAG $EXCLUDE "$EASYBLOCKSDIR" $HERE/easyblocks
echo "Done."
echo $DIVIDER
cd $HERE
DATE=$(date -Iseconds)
if [ $# -eq 1 ]; then
if [ ! -z "$(git status -s)" ]; then
echo "Pushing to GitHub... "
git add -A
git commit -m $DATE
git push
else
echo "No changes in repo"
fi
fi
echo $DIVIDER
echo "Completed on $DATE."