-
Notifications
You must be signed in to change notification settings - Fork 11
/
ci-rpm-repos
executable file
·173 lines (142 loc) · 2.9 KB
/
ci-rpm-repos
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
#!/bin/bash
# ENTRY POINT (done)
set -e
project="$1"
branch="$2"
if [ -n "$3" ]; then
extraverdir="/$3"
extraver="-$3"
fi
if [ -z "$project" ]; then
echo "no project specificed"
exit 1
fi
if [ -z "$branch" ]; then
echo "no branch specificed"
exit 1
fi
rpmdir=/var/www/ci.kronosnet.org/builds
clean_dirs() {
echo "Purging 0 byte files"
find $rpmdir/ -type f -size 0 -print -delete
echo "Purging empty dirs"
find $rpmdir/ -type d -empty -print -delete
}
process_pr() {
cd $branch
for i in $(ls); do
echo processing $i
cd $i
createrepo --compress-type=gz .
cd -
done
cd -
cd $rpmdir/$project/pr
find . -type f -mtime +30 -exec rm -rf {} \;
cd -
}
process_publish() {
for i in $(ls | grep -v pr); do
cd $rpmdir/$project/
echo "Processing $i"
cd $i
if [ ! -d ${branch}${extraverdir} ]; then
continue
fi
toplevelbranch=$(basename $branch)${extraver}
rm -f ${toplevelbranch}
ln -sf ${branch}${extraverdir} ${toplevelbranch}
cd $toplevelbranch
# createrepo on latest and update symlinks
lastbuild="$(ls -1 | sort -n | tail -n 1)"
echo "Last build detected: $lastbuild"
cd $lastbuild
createrepo --compress-type=gz .
cd ..
rm -f latest
ln -sf $lastbuild latest
# remove old builds (keep last 5)
builds="$(ls -1 | grep -v latest | sort -n)"
numbuilds="$(echo "$builds" | wc -l)"
if [ "$numbuilds" -gt 5 ]; then
purgenum=$((numbuilds - 5))
candidates="$(echo "$builds" | head -n $purgenum)"
for x in $candidates; do
echo "Removing old build: $x"
rm -rf $x
done
fi
done
# generate repo files
cd $rpmdir/
for i in $(ls | grep -v repo | grep -v stacks); do
# project level
cd $i
for x in $(ls | grep -v "^pr"); do
# builder level
cd $x
for b in $(ls |grep -v origin); do
echo "Creating $i-$b-$x repo file"
cat > $rpmdir/$i-$b-$x.repo << EOF
[$i-$b-$x]
name=$i-$b-$x
baseurl=https://ci.kronosnet.org/builds/$i/$x/$b/latest/
repo_gpgcheck=0
enabled=1
gpgcheck=0
metadata_expire=1d
skip_if_unavailable=True
module_hotfixes=1
priority=1
EOF
done
cd - >/dev/null 2>&1
done
cd .. >/dev/null 2>&1
done
# used for fn testing
cd $rpmdir/stacks
for i in $(ls); do
# stable / next-stable / main level
cd $i
for x in $(ls); do
# rhel release
echo "Creating $i-$x repo file"
cat > $rpmdir/stacks-$i-$x.repo << EOF
[$i-$x]
name=$i-$x
baseurl=https://ci.kronosnet.org/builds/stacks/$i/$x/
repo_gpgcheck=0
enabled=1
gpgcheck=0
metadata_expire=1d
skip_if_unavailable=True
module_hotfixes=1
priority=1
EOF
if [ -h "$x" ]; then
continue
fi
cd $x
createrepo --compress-type=gz .
cd ..
done
cd ..
done
}
(
flock -e 200
clean_dirs
echo "Updating all rpm repos for project: $project branch: $branch extraver: $3"
cd $rpmdir/$project/
case $branch in
pr*)
process_pr
;;
*)
process_publish
;;
esac
rsync -av --delete-after $rpmdir/ jweb:$rpmdir/.
exit 0
) 200>/tmp/ci-rpm-repos.lock