This repository has been archived by the owner on Feb 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
pre_checkin.sh
executable file
·106 lines (91 loc) · 3.4 KB
/
pre_checkin.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
#!/bin/bash
## pre_checkin.sh script is expected to be called from
## a local copy of the build service image after running
## the _services file, e.g. `osc service disabledrun`
log() { echo ">>> $@" ; }
abort() { log "FATAL: $@" ; exit 1 ; }
endScript() { log "EXITING: $@" ; exit 0 ; }
usage() {
cat <<USAGE
usage:
./pre_checkin.sh [kubic|caasp]
./pre_checkin.sh kubic|caasp [OPTIONS]
options:
--mkchanges Create/update the changes file (mostly used for automation)
If no parameter is given defaults to 'kubic'
USAGE
}
namespace=${1:-kubic}
mkchanges=$2
[ -n "${mkchanges}" ] && [ "${mkchanges}" != "--mkchanges" ] && usage \
&& abort "Bad option"
make_changes_file() {
local previous_commit
local changes_log
local git_log_format="- Commit %h by %an %ae %n%n%w(77,2,2)%B"
if [ -f "${changes_file}" ]; then
previous_commit="$(sed "4q;d" "${changes_file}" | cut -d' ' -f3).."
fi
# Update the changes file
pushd container-images 1> /dev/null
changes_log=$(git log --pretty=format:"${git_log_format}" \
${previous_commit} -- pre_checkin.sh \
"${image}" | sed "1 s/- \(.*$\)/\1/")
popd 1> /dev/null
[ -z "${changes_log}" ] && endScript "Missing new changelog entries"
osc vc ${changes_file} -m "${changes_log}"
}
if [ "${namespace}" == "kubic" ]; then
product='kubic'
baseimage="opensuse/tumbleweed#latest"
distro="openSUSE Kubic"
label_prefix="org.opensuse.kubic"
elif [[ "${namespace}" =~ ^caasp/.* ]]; then
product='caasp'
baseimage="suse/sle15#15.1"
distro="SLES15 SP1"
label_prefix="com.suse.caasp"
else
usage
abort "Unknown product. Product needs to match 'kubic|caasp/.*'"
fi
set -e
for file in *kiwi.ini; do
image="${file%%.kiwi.ini}"
changes_file="${product}-${image}.changes"
kiwi_file="${product}-${image}.kiwi"
extra_packages=""
extra_packages_file="${product}-extra-packages"
extra_bootstrap_packages_file="${product}-extra-bootstrap-packages"
# Create a list of extra packages
if [ -f "${extra_packages_file}" ]; then
while read -r package; do
extra_packages+=" <package name=\"${package}\"\/>\n"
done < "${extra_packages_file}"
fi
# Create a list of extra bootstrap packages
if [ -f "${extra_bootstrap_packages_file}" ]; then
extra_bootstrap_packages+=" <packages type=\"bootstrap\">\n"
while read -r package; do
extra_bootstrap_packages+=" <package name=\"${package}\"\/>\n"
done < "${extra_bootstrap_packages_file}"
extra_bootstrap_packages+=" </packages>"
fi
# update the changes file, mostly used for automation in Concourse CI
[ -n "${mkchanges}" ] && make_changes_file
# create *.kiwi file from *kiwi.ini template
cp "${file}" "${kiwi_file}"
sed -i -e "s@_BASEIMAGE_@${baseimage}@g" \
-e "s@_DISTRO_@${distro}@g" \
-e "s@_NAMESPACE_@${namespace}@g" \
-e "s@_PRODUCT_@${product}@g" \
-e "s@_LABEL_PREFIX_@${label_prefix}@g" \
-e "/^<image/i\<!--\n\tThis is an autogenerated \
file from ${file} template.\n\tDo not manually modify \
this file.\n-->\n" \
-e "s@_EXTRA_PACKAGES_@${extra_packages}@g" \
-e "s@_EXTRA_BOOTSTRAP_PACKAGES_@${extra_bootstrap_packages}@g" "${kiwi_file}"
# Remove blank lines
sed -i "/^ *$/d" "${kiwi_file}"
log "${kiwi_file} has been created"
done