-
Notifications
You must be signed in to change notification settings - Fork 4
/
zanata-package-repo-dnf
executable file
·233 lines (210 loc) · 6.6 KB
/
zanata-package-repo-dnf
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#!/bin/bash -eu
LANG=C
### NAME
### zanata-package-repo-dnf - Release package in repo-dnf
###
### SYNOPSIS
### zanata-package-repo-dnf [Options] <module> <version-release>
### zanata-package-repo-dnf [Options] -a <module>
###
### ARGUMENTS
### module: module to upload to fedorarepo. It is also the Fedora package name.
###
### version-release: (Required if -a is not specified)
### Version and SPEC release field. For example, 3.7.2-2
### This is mandatory when bumping SPEC release number.
###
### OPTIONS
### -h: Show this help.
###
### -a: Automatic detected.
### Version will be detected from latest tag from git.
### And release is 1.
###
### -b: Straight to build
### Go straight to build.
### No remote directory sync.
###
### -n: New repo metadata
### This means run createrepo without option '--update'.
###
### DESCRIPTION
### This program builds and submits the latest Zanata modules
### that are not yet in supported yum/dnf repo.
###
### This program uses rsync to do the sync.
### So make sure both ends support rsync.
###
## Default Environment Variable
ScriptDir=$(dirname $(realpath $0))
FunctionScriptFile=${ScriptDir}/zanata-functions
source "$FunctionScriptFile"
trap exit_print_error EXIT
source "${ScriptDir}/zanata-rpm-functions"
### ENVIRONMENT
### REMOTE_USERNAME
### Required if your remote username is different from $USER
### Default: ${USER}
: ${REMOTE_USER:=${USER}}
###
### REMOTE_HOST
### Host that host for yum/dnf repo
### Default: fedorapeople.org
: ${REMOTE_HOST:=fedorapeople.org}
###
### REMOTE_DIR
### The remote directory that hold repo
### Default: /srv/repos/Zanata_Team/zanata
: ${REMOTE_DIR:=/srv/repos/Zanata_Team/zanata}
###
### LOCAL_DIR
### The local directory that mirror the remote directory
: ${LOCAL_DIR:=${WORK_ROOT}/dnf/zanata}
###
### RSYNC_OPTIONS
### Options that will be passed to rsync
### Default: "--cvs-exclude --recursive --verbose --links --update --compress --exclude '*.core' --stats --progress --archive --keep-dirlinks"
: ${RSYNC_OPTIONS:=--cvs-exclude --recursive --verbose --links --update --compress --exclude '*.core' --stats --progress --archive --keep-dirlinks}
###
### EPEL_VERSIONS
### Fedora or epel releases to be build
### Default: "7 6"
: ${EPEL_VERSIONS:="7 6"}
###
### RESULT_DIR
### The directory for mock output
### Default: "${HOME}/mock/zanata"
: ${RESULT_DIR:=${HOME}/mock/zanata}
###
### CREATEREPO_OPTS
### Options for createrepo
### Default: "-vd --delta -s sha"
: ${CREATEREPO_OPTS:=-vd --delta -s sha}
ProgramName=$(basename $0)
mkdir -p "${RESULT_DIR}"
CACHE_DIR="${WORK_ROOT}/${ProgramName}"
mkdir -p "${CACHE_DIR}"
##=== function definitions Start ===
function fedora_release_to_dist_tag(){
local fedoraRelease=$1
if [[ $fedoraRelease == epel* ]];then
sed -e 's/epel-/el/' <<< "${fedoraRelease}"
fi
}
function update_dnf_repo_dir(){
local baseDir=$1
local repoDir=$2
local opts=""
pushd "$baseDir" 1>/dev/null
if [ $NewRepoMetadata -eq 0 ];then
opts="--update"
fi
print_status " createrepo $opts $CREATEREPO_OPTS $repoDir"
createrepo $opts $CREATEREPO_OPTS "$repoDir"
popd 1>/dev/null
}
##=== function definitions End ===
##=== parsing Start ===
print_status -t parsing -s "Start"
Version=
SpecRelease=
AutoDetect=0
StartFrom=
NewRepoMetadata=0
while getopts "habn" opt;do
case $opt in
h )
zanata_script_help $0
exit ${EXIT_OK}
;;
a )
AutoDetect=1
;;
b )
StartFrom="build"
;;
n )
NewRepoMetadata=1
;;
* )
exit_if_failed ${EXIT_FATAL_INVALID_OPTIONS} ${EXIT_FATAL_INVALID_OPTIONS} "$opt"
;;
esac
done
shift $((OPTIND-1))
## Get Module
branch_prepare RELEASING "$@"
shift $ShiftOffset
print_status " Module=$Module"
## Get Package name
case $Module in
zanata-platform )
PackageName=zanata-cli-bin
;;
* )
PackageName=$Module
;;
esac
## Get Version
if [ ${AutoDetect} -eq 0 ];then
if [ -z "$1" ];then
zanata_script_help $0
EXIT_MSG="Requires version-release. Please either specify version-release or use option -a"
exit ${EXIT_FATAL_INVALID_OPTIONS}
fi
VersionRelease=$1
EXIT_MSG="VersionRelease $VersionRelease is invalid"
SpecRelease=$(sed -n 's/.*-\([0-9]*\)$/\1/p' <<<$VersionRelease)
EXIT_MSG=
test -n "$SpecRelease"
exit_if_failed "$?" ${EXIT_FATAL_INVALID_OPTIONS} "Failed to get SPEC release from ${VersionRelease}"
Version=$(sed -e 's/-'$SpecRelease'$//' <<<$VersionRelease)
test -n "$Version"
exit_if_failed "$?" ${EXIT_FATAL_INVALID_OPTIONS} "Failed to get version from ${VersionRelease}"
else
## Auto detect version
Version=$(detect_module_version ${Module})
print_status " ${Module} version: $Version"
test -n "$Version"
exit_if_failed "$?" ${EXIT_FATAL_FAIL} "Failed to get version from ${Module} git repo"
SpecRelease=1
fi
print_status " Version=$Version"
print_status " SpecRelease=$SpecRelease"
##=== prepare Start ===
print_status -t prepare -s "Start"
## Check depending programs
print_status " check depending programs"
ExitStatus=${EXIT_OK}
for dep in rpmbuild createrepo docker; do
if ! which $dep &>/dev/null ; then
ExitStatus=${EXIT_FATAL_MISSING_DEPENDENCY}
EXIT_MSG+=" $dep"
fi
done
exit_if_failed "${ExitStatus}" ${EXIT_FATAL_MISSING_DEPENDENCY} "$EXIT_MSG"
## Ensure work space
mkdir -p "${LOCAL_DIR}"
cd ${LOCAL_DIR}
if [ -z "${StartFrom}" ];then
print_status " Sync remote directory to local"
rsync ${RSYNC_OPTIONS} --delete ${REMOTE_USER}@${REMOTE_HOST}:${REMOTE_DIR}/ .
fi
##=== spec Start ===
SpecFilename="${PackageName}.spec"
if [ -z "${StartFrom}" ];then
print_status -t "spec-update" -s "Start"
spec_update ${SpecFilename} ${Version} ${SpecRelease} "${MAINTAINER_EMAIL}"
print_status " spectool: Downloading source file(s)"
spectool -g -S "${SpecFilename}" -C ${CACHE_DIR}
fi
##=== RPM build and Repo update Start ===
## For each EPEL versions
for ev in ${EPEL_VERSIONS}; do
print_status -t "$ev" -s "Start"
docker run --rm --name zanata-epel${ev}-builder -v ${LOCAL_DIR}:/repo:Z docker.io/zanata/centos-repo-builder:${ev} $SpecFilename
done
##=== repo-upload Start ===
print_status -t "repo-upload" -s "Start"
rsync ${RSYNC_OPTIONS} --delete * ${REMOTE_USER}@${REMOTE_HOST}:${REMOTE_DIR}
## Done