forked from kronosnet/ci-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ci-rpm-repos
executable file
·183 lines (148 loc) · 3.33 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
174
175
176
177
178
179
180
181
182
183
#!/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 . -maxdepth 1 -type d -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/
cat > $rpmdir/opensuse-readme.repo << EOF
OpenSUSE users, please browse the kronosnet/ folder for appropriate builds for your deployment.
You can use zypper to enable those repositories.
For example use the following command to add the repository:
zypper add https://ci.kronosnet.org/builds/kronosnet/opensuse-tumbleweed-x86-64/main/latest/ kronosnet
and to enable and autorefresh:
zypper mr -e -f -G kronosnet
please be aware the repositories are not signed.
EOF
for i in $(ls | grep -v repo); do
# project level
cd $i
for x in $(ls | grep -v opensuse | 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
cd $rpmdir/
for i in main-repo main-kernel-repo next-stable-repo next-stable-kernel-repo; do
cd $i
for x in $(ls); do
echo "Creating $i-$x repo file"
cat > $rpmdir/$i-$x.repo << EOF
[$i-$x]
name=$i-$x
baseurl=https://ci.kronosnet.org/builds/$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