-
Notifications
You must be signed in to change notification settings - Fork 246
/
cmspkg-clone
executable file
·118 lines (114 loc) · 4.46 KB
/
cmspkg-clone
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
#!/bin/bash -e
echo "============================================="
date
echo "============================================="
[ "$1" = "" ] && exit 1
CLONE_DIR=$1
mkdir -p $CLONE_DIR
cd $CLONE_DIR
if [ ! -d cmspkg ] ; then
git clone https://github.com/cms-sw/cmspkg.git
fi
pushd cmspkg
git pull --rebase
popd
mdir=$(echo $CLONE_DIR | cut -d/ -f1,2)
df -h $mdir
mkdir -p $CLONE_DIR/cmssw $CLONE_DIR/cmssw/repos/.obj_store/RPMS
CMSREP="curl -L -s http://cmsrep.cern.ch/cmssw/repos"
if [ "X${REPOSITORY}" = "X" ] ; then
echo "Starting cleanup process ..."
REPOSITORY=$(${CMSREP} | grep 'alt="\[DIR\]' | grep -v 'Parent Directory' | sed 's|.*href=.||;s|/.>.*||' | grep -v tmp | sort | uniq | tr '\n' ' ')
echo "Found repositories: $REPOSITORY"
echo "Searching for obsolete repositories ...."
if [ "X${REPOSITORY}" != "X" ] ; then
if [ -d $CLONE_DIR/cmssw/repos ] ; then
for repo_dir in $(find $CLONE_DIR/cmssw/repos -mindepth 1 -maxdepth 1 -type d | grep -v '/\.obj_store') ; do
repo=$(basename $repo_dir)
if [ "${EXCLUDE_REPO}" != "" ] ; then
if [ $(echo $repo | grep "^${EXCLUDE_REPO}$" | wc -l) -gt 0 ] ; then
if [ -d $CLONE_DIR/cmssw/repos/$repo ] ; then
echo "Deleting excluded repository $repo"
rm -rf $CLONE_DIR/cmssw/repos/$repo
fi
continue
fi
fi
if [ $(echo "$REPOSITORY" | tr ' ' '\n' | grep "^$repo\$" | wc -l) -eq 1 ] ; then
ARCHS=$(${CMSREP}/${repo} | grep 'alt="\[DIR\]' | grep -v 'Parent Directory' | sed 's|.*href=.||;s|/.>.*||' | sort | uniq)
for arch_dir in $(find ${repo_dir} -mindepth 1 -maxdepth 1 -type d) ; do
arch=$(basename ${arch_dir})
if [ "${arch}" = "drivers" ] ; then continue; fi
if [ $(echo "$ARCHS" | grep "^$arch\$" | wc -l) -eq 0 ] ; then
echo " Deleting ${repo}/${arch}"
rm -rf ${arch_dir}
touch $CLONE_DIR/cmssw/repos/.obj_store/RPMS/${arch}
else
echo " Keeping ${repo}/${arch}"
fi
done
continue
fi
for arch in $(find ${repo_dir} -mindepth 1 -maxdepth 1 -type d | sed 's|.*/||') ; do
touch $CLONE_DIR/cmssw/repos/.obj_store/RPMS/${arch}
done
echo " Deleting ${repo}"
rm -rf $repo_dir
done
fi
fi
if [ "${CMSPKG_DELETE_UNUSED}" != "false" ] ; then
echo "Searching for obsolete RPMS in Object Store"
for arch_dir in $(find $CLONE_DIR/cmssw/repos/.obj_store/RPMS -mindepth 1 -maxdepth 1 -mtime -1 -type d) ; do
DEL_FILES=0
arch=$(basename ${arch_dir})
echo " Checking architecture ${arch}"
for rpm in $(find ${arch_dir} -mindepth 3 -maxdepth 3 -name '*.rpm' -type f) ; do
[ $(ls -l $rpm | awk '{print $2}') -gt 1 ] && continue
let DEL_FILES=$DEL_FILES+1
echo " Remove($DEL_FILES): $rpm"
rm -f "$rpm"
done
echo " Deleted obsolete files: ${arch}: $DEL_FILES"
if [ $DEL_FILES -gt 0 ] ; then
echo " Cleaning up empty directories"
for depth in 2 1 ; do
for dir in $(find ${arch_dir} -mindepth ${depth} -maxdepth ${depth} -type d -empty) ; do
echo " Deleting empty store: $dir"
rm -rf $dir
done
done
fi
done
fi
fi
echo "Starting backup process ...."
TOTAL_REPOS=0
ERR=0
for repo in $(echo ${REPOSITORY} | tr ' ' '\n' | grep -v '^cms.week[0-9].PR_[0-9a-f]\{8\}$') ; do
if [ "${EXCLUDE_REPO}" != "" ] ; then
if [ $(echo $repo | grep "^${EXCLUDE_REPO}$" | wc -l) -gt 0 ] ; then
if [ -d $CLONE_DIR/cmssw/repos/$repo ] ; then
echo "Deleting excluded repository $repo"
rm -rf $CLONE_DIR/cmssw/repos/$repo
fi
continue
fi
fi
ARCHS="${ARCHITECTURE}"
if [ "X${ARCHS}" = "X" ] ; then
ARCHS=$(${CMSREP}/${repo} | grep 'alt="\[DIR\]' | grep -v 'Parent Directory' | sed 's|.*href=.||;s|/.>.*||' | grep '^[a-z][a-zA-Z0-9]*_[a-z][a-zA-Z0-9]*_[a-z][a-zA-Z0-9]*$' | sort)
fi
for arch in $ARCHS ; do
echo "Checking $repo $arch"
$CLONE_DIR/cmspkg/client/cmspkg.py ${CMSPKG_CLONE_OPTS} --use-dev --use-store -p $CLONE_DIR/cmssw -a $arch -r $repo -j 4 clone || ERR=1
let TOTAL_REPOS=$TOTAL_REPOS+1
echo "ERR:$ERR, Repository cloned: $TOTAL_REPOS"
if [ -d $CLONE_DIR/cmssw/repos/.obj_store/RPMS/${arch} ] ; then
touch $CLONE_DIR/cmssw/repos/.obj_store/RPMS/${arch}
fi
done
done
echo "Total Repos cloned: $TOTAL_REPOS"
df -h $mdir
exit $ERR