Add initial code
[ta/build-tools.git] / create_mock_config.sh
1 #!/bin/bash
2 # Copyright 2019 Nokia
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 set -e
17
18 scriptdir="$(dirname $(readlink -f ${BASH_SOURCE[0]}))"
19 source $scriptdir/lib.sh
20
21 config_ini=${1:-$BUILD_CONFIG_INI}
22 output_repo_files_dir=${2:-$REPO_FILES}
23 output_mock_dir=${2:-$(dirname $RPM_BUILDER_SETTINGS)}
24 [ -f "$config_ini" ] || _abort "Config INI '$config_ini' not found"
25
26 # Create .repo files
27 $LIBDIR/build_step_create_yum_repo_files.sh $config_ini $output_repo_files_dir
28
29 # Create mock config
30 mkdir -p $output_mock_dir
31 cp $LIBDIR/mock/logging.ini $output_mock_dir/
32 cp $LIBDIR/mock/site-defaults.cfg $output_mock_dir/
33 mock_cfg=$output_mock_dir/mock.cfg
34 sed -e "/#REPOSITORIES#/r $output_repo_files_dir/repositories.repo" $LIBDIR/mock/mock.cfg.template > $mock_cfg
35 sed -i \
36   -e "s/#RPM_PACKAGER#/\"$(_read_build_config $config_ini rpm packager)\"/" \
37   -e "s/#RPM_VENDOR#/\"$(_read_build_config $config_ini rpm vendor)\"/" \
38   -e "s/#RPM_LICENSE#/\"$(_read_build_config $config_ini rpm license)\"/" \
39   -e "s/#RPM_RELEASE_ID#/\"$(_read_build_config $config_ini rpm release_id)\"/" \
40   $mock_cfg
41
42 docker_sock=/var/run/docker.sock
43 if [ -S "$docker_sock" ]; then
44   sed -i "/#ADDITIONAL_CONFIG_OPTS#/a config_opts['plugin_conf']['bind_mount_opts']['dirs'].append(('$docker_sock', '$docker_sock'))" $mock_cfg
45 fi
46 if [ -n "$DOCKER_HOST" ]; then
47   sed -i "/#ADDITIONAL_CONFIG_OPTS#/a config_opts['environment']['DOCKER_HOST'] = '${DOCKER_HOST}:2375'" $mock_cfg
48 fi
49
50 # HACK ??
51 # include kernels in order for yum development group to install
52 sed -i -e 's/exclude=kernel/#exclude=kernel/' $mock_cfg
53
54 echo "Wrote mock configuration to: $output_mock_dir"