forked from kata-containers/kata-containers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-repo-branch.sh
executable file
·191 lines (165 loc) · 4.66 KB
/
create-repo-branch.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
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
#!/bin/bash
#
# Copyright (c) 2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#
[ -z "${DEBUG}" ] || set -o xtrace
set -o errexit
set -o nounset
set -o pipefail
script_dir=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)
script_name="$(basename "${BASH_SOURCE[0]}")"
# shellcheck source=./../scripts/lib.sh
source "${script_dir}/../scripts/lib.sh"
# shellcheck source=scripts/obs-docker.sh
source "${script_dir}/scripts/obs-docker.sh"
readonly home_project="home:katacontainers"
readonly template_pkg="kata-pkg-template"
arch_target=${ARCH:-$(uname -m)}
# shellcheck source=scripts/obs-docker.sh
source "${script_dir}/scripts/obs-pkgs.sh"
pkg_exist() {
local project="$1"
local pkg="$2"
docker_run osc list "${project}" | grep "${pkg}" || return 1
return 0
}
# Array of repositories.
#
# Each element is comprised of multiple parts in the form:
#
# name::project::repository
#
typeset -a repos
read_repos(){
while read -r p; do
[[ "$p" != "#"* ]] || continue
repos+=("${p}")
echo "Adding distro: ${p}"
done < "${script_dir}/distros_${arch_target}"
}
# Array of maintainers
#
# Each element is comprised of multiple parts in the form:
#
# userid::role
#
typeset -a maintainers
read_maintainers(){
while read -r p; do
[[ "$p" != "#"* ]] || continue
maintainers+=("${p}::maintainer")
echo "Adding maintainer: ${p}"
done < "${script_dir}/maintainers"
}
create_repos_xml_nodes() {
for entry in "${repos[@]}"; do
[ -z "$entry" ] && die "found empty entry"
local name
local project
local repositories
name=$(echo "$entry" | awk -F"::" '{print $1;}')
project=$(echo "$entry" | awk -F"::" '{print $2;}')
repositories=$(echo "$entry" | awk -F"::" '{print $3;}')
[ -z "$name" ] && die "no name for entry '$entry'"
[ -z "$project" ] && die "no project for entry '$entry'"
[ -z "$repositories" ] && die "no repository for entry '$entry'"
echo " <repository name=\"${name}\">"
echo "${repositories}"| tr ',' '\n' | while read -r repository; do
echo " <path project=\"${project}\" repository=\"${repository}\"/>"
done
arch_target_obs=${arch_target}
if [ "$arch_target" == "ppc64" ]; then
arch_target_obs="ppc64le"
fi
echo " <arch>${arch_target_obs}</arch>"
echo " </repository>"
done
}
create_maintainers_xml_nodes() {
for entry in "${maintainers[@]}"; do
[ -z "$entry" ] && die "found empty entry"
local userid=$(echo "$entry" | awk -F"::" '{print $1;}')
local role=$(echo "$entry" | awk -F"::" '{print $2;}')
[ -z "$userid" ] && die "no userid for entry '$entry'"
[ -z "$role" ] && die "no role for entry '$entry'"
echo " <person userid=\"${userid}\" role=\"${role}\"/>"
done
}
create_publish_xml_node() {
# publishing is enabled by default, so only update the config
# when we want to disable publishing
if [ "${publish_repo:-true}" == "false" ];then
echo " <publish>"
echo " <disable/>"
echo " </publish>"
fi
}
create_meta_xml() {
project="${1:-}"
branch="${2:-}"
publish_repo="${3:-true}"
[ -n "${project}" ] || die "project is empty"
[ -n "${branch}" ] || die "branch is empty"
read_maintainers
read_repos
cat >meta_project.xml <<EOT
<project name="${project}">
<title>Branch project for Kata Containers branch ${branch}</title>
<description>This project is the Kata Containers branch ${branch}</description>
$(create_publish_xml_node)
$(create_maintainers_xml_nodes)
$(create_repos_xml_nodes)
</project>
EOT
}
usage() {
msg="${1:-}"
exit_code=$"${2:-0}"
cat <<EOT
${msg}
Usage:
${script_name} <kata-branch>
EOT
exit "${exit_code}"
}
main() {
case "${1:-}" in
"-h"|"--help")
usage Help
;;
--ci)
create_ci_subproject=true
publish_repo=false
shift
;;
-*)
die "Invalid option: ${1:-}"
;;
esac
local branch="${1:-}"
[ -n "${branch}" ] || usage "missing branch" "1"
if [ "${create_ci_subproject:-false}" == "true" ];then
release_type="ci"
elif [ "$arch_target" == "ppc64le" ]; then
release_type="alpha"
else
release_type="releases"
fi
project_branch="${home_project}:${release_type}:${arch_target}:${branch}"
create_meta_xml "${project_branch}" "${branch}" "${publish_repo}"
info "Creating/Updating project with name ${project_branch}"
# Update /Create project metadata.
docker_run osc meta prj "${project_branch}" -F meta_project.xml
docker_run osc meta prjconf "${project_branch}" -F projectconfig
for pkg in "${OBS_PKGS_PROJECTS[@]}"; do
if ! pkg_exist "${project_branch}" "${pkg}"; then
echo "Package ${pkg} does not exit in ${project_branch}, creating ..."
docker_run osc branch "${home_project}" "${template_pkg}" "${project_branch}" "${pkg}"
fi
pkg_dir="${project_branch}/${pkg}"
[ -d "${pkg_dir}/.osc" ] || docker_run osc co "${pkg_dir}"
done
}
main $@