This repository has been archived by the owner on Jun 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
mock-recreate-srpms
executable file
·157 lines (129 loc) · 4.91 KB
/
mock-recreate-srpms
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
#!/usr/bin/bash
# Usage: $0 [ --repo reponame ] output-dir srpm-dir srpm-list-file
#
# Based upon mock_wrapper.sh, recreate_srpm.sh, and populate_srpm_repo.sh
# from https://github.com/fedora-modularity/baseruntime-package-lists
WORK_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $WORK_DIR/conf/config.inc
source $WORK_DIR/utils.inc
if [ $# -ne 3 ]; then
errexit "Usage: $0 [ --repo reponame ] output-dir srpm-dir srpm-list-file"
fi
output_dir="$1"
srpm_dir="$2"
srpm_list_file="$3"
release_ver="${REPONAME}"
set -e
nproc=$(/usr/bin/getconf _NPROCESSORS_ONLN)
vernum=${release_ver}
if [ "${release_ver}" == "rawhide" ]; then
vernum=33
fi
# load list of srpms from input file into array variable
mapfile -t srpm_list < "${srpm_list_file}"
# make sure we have just the basenames of the SRPMs
srpm_basename_list=(${srpm_list[@]##*/})
# Put the correct release in the base
if [ "${REPO_BASE}" == "rawhide" ] ; then
mock_release="fedora-release"
elif [ "${REPO_BASE}" == "eln" ] ; then
mock_release="fedora-release-eln"
else
mock_release="redhat-release"
fi
mock_cfg=${WORK_DIR}/fedora-${release_ver}-srpm.cfg
cat > ${mock_cfg} <<EOF
config_opts['root'] = 'fedora-$release_ver-srpm'
config_opts['target_arch'] = 'x86_64'
config_opts['legal_host_arches'] = ('x86_64')
config_opts['chroot_setup_cmd'] = 'install $mock_release bash bzip2 coreutils cpio diffutils findutils gawk glibc-minimal-langpack grep gzip info make patch redhat-rpm-config rpm-build sed shadow-utils tar unzip util-linux which xz'
config_opts['dist'] = 'fc$vernum' # only useful for --resultdir variable subst
config_opts['extra_chroot_dirs'] = [ '/run/lock', ]
config_opts['releasever'] = '$vernum'
config_opts['package_manager'] = 'dnf'
config_opts['use_bootstrap'] = False
config_opts['rpmbuild_networking'] = True
# Configure bind mounts for the the srpms and output directories
config_opts['plugin_conf']['bind_mount_enable'] = True
config_opts['plugin_conf']['bind_mount_opts']['dirs'].append(('$srpm_dir', '/opt/srpm/srpms/' ))
config_opts['plugin_conf']['bind_mount_opts']['dirs'].append(('$output_dir', '/opt/srpm/output/' ))
config_opts['yum.conf'] = """
[main]
keepcache=1
debuglevel=2
reposdir=/dev/null
logfile=/var/log/yum.log
retries=20
obsoletes=1
gpgcheck=0
assumeyes=1
syslog_ident=mock
syslog_device=
install_weak_deps=0
metadata_expire=0
mdpolicy=group:primary
best=1
# repos
$(cat ${REPO_DIR}/${REPONAME}.x86_64.repo)
"""
EOF
# read script into variable; use ! to bypass "set -e" exit
! read -r -d '' mock_recreate_srpm_script <<'EOF'
#!/usr/bin/bash
if [ $# -ne 1 ]; then
echo "Missing source-rpm argument"
echo "Usage: recreate_srpm.sh source-rpm"
exit 1
fi
srpm="$1"
pkgname=$(rpm -q --nosignature --qf "%{name}" -p ${srpm})
echo "Rebuilding ${pkgname} SRPMs from ${srpm}"
output_dir=$(pwd)
scratch_dir=$(mktemp -d)
pushd ${scratch_dir}
rpm2cpio ${srpm} | cpio -idm
# find dist so we end up with the same names
pkg_release=$(rpm -qp --nosignature --qf "%{release}" ${srpm})
mkdir tmp
rpmbuild -bs \
--build-in-place \
--define "dist BLAHBLAH" \
--define "_sourcedir ${scratch_dir}" \
--define "_srcrpmdir ${scratch_dir}/tmp" \
${pkgname}.spec
tmp_release=$(rpm -qp --nosignature --qf "%{release}" ${scratch_dir}/tmp/*src.rpm)
release_prefix=$(echo ${tmp_release} | awk -F"BLAHBLAH" '{print $1}')
release_suffix=$(echo ${tmp_release} | awk -F"BLAHBLAH" '{print $2}')
this_dist=$(echo "${pkg_release}" | sed -e "s|^${release_prefix}||" -e "s|${release_suffix}$||")
echo "Building SRPM for package ${pkgname} using %{dist}=${this_dist}"
for arch in __ARCH_LIST__; do
mkdir -p ${output_dir}/${arch}/sources
rpmbuild -bs \
--build-in-place \
--target=${arch} \
--define "dist ${this_dist}" \
--define "_sourcedir ${scratch_dir}" \
--define "_srcrpmdir ${output_dir}/${arch}/sources" \
${pkgname}.spec
done
popd # ${scratch_dir}
rm -rf ${scratch_dir}
EOF
# fill in architecture list placeholder with actual list
mock_recreate_srpm_script="${mock_recreate_srpm_script//__ARCH_LIST__/${ARCH_LIST[@]}}"
# make sure target output directory exists
mkdir -p "${output_dir}"
mock -r ${mock_cfg} --init
# Note: the mock configuration bind mounts the srpms and output directories
mock -r ${mock_cfg} --chroot "mkdir -p /opt/srpm/srpms /opt/srpm/output"
mock -r ${mock_cfg} --copyin /dev/stdin /opt/srpm/recreate_srpm.sh \
<<<"${mock_recreate_srpm_script}"
mock -r ${mock_cfg} --copyin /dev/stdin /opt/srpm/srpm-list.txt \
<<<$(printf "/opt/srpm/srpms/%s\n" ${srpm_basename_list[@]})
mock -r ${mock_cfg} --chroot "
cd /opt/srpm/output
chmod a+rx /opt/srpm/recreate_srpm.sh
cat /opt/srpm/srpm-list.txt | xargs --max-procs=${nproc} -I SRPM /opt/srpm/recreate_srpm.sh SRPM
"
# reset ownership of output directory
mock -r ${mock_cfg} --chroot "chown -R mockbuild:mock /opt/srpm/output"