Minor fixes & improvements for ISO builds
[ta/build-tools.git] / build_rpms.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 -x
17 set -e
18 set -o pipefail
19
20 usage() {
21     echo "Builds all git repositories under give search dirs"
22     echo "Usage: $0 -m <manifest-dir> -w <work-dir> -r <rpmbuilder-dir> <rpm-create-search-dir> [<rpm-create-search-dir>..]"
23     exit 1
24 }
25
26 while getopts "m:w:r:" OPT; do
27     case $OPT in
28     m)
29         export MANIFEST_PATH=$(readlink -f $OPTARG)
30         ;;
31     w)
32         export WORK=$OPTARG
33         ;;
34     r)
35         export RPMBUILDER_PATH=$(readlink -f $OPTARG)
36         ;;
37     *)
38         usage
39         ;;
40     esac
41 done
42
43 [ -z "$MANIFEST_PATH" ] && usage
44 [ -z "$RPMBUILDER_PATH" ] && usage
45 [ -z "$WORK" ] && usage
46
47 shift "$((OPTIND-1))"
48 search_paths="$@"
49 [ "$#" -eq 0 ] && usage
50 for p in $search_paths; do
51     [ ! -d "$p" ] && usage
52 done
53
54 scriptdir="$(dirname $(readlink -f ${BASH_SOURCE[0]}))"
55 source $scriptdir/lib.sh
56
57 projects_to_build=$(find $search_paths -name .git -printf "%h\n" | sort)
58
59 work=$WORKTMP/rpms
60 rm -rf $work
61 mkdir -p $work
62
63 $scriptdir/create_mock_config.sh $BUILD_CONFIG_INI $work/mock_config
64
65 CENTOS_SOURCES="$(_read_build_config rpm centos_sources)" \
66 $RPMBUILDER_PATH/makebuild.py \
67     -m $work/mock_config/mock.cfg \
68     -w $work \
69     $projects_to_build #-v --nowipe
70
71 echo "### Built RPMS #######################################"
72 find $work/projects/ -type f -name '*.rpm' | xargs ls -l
73 echo "### Built RPM details ##########################################"
74 for rpm in $(find $work/projects/ -type f -name '*.rpm'); do
75     echo "=== $rpm ========================"
76     rpm -qip $rpm
77 done
78
79 _add_rpms_to_localrepo $(find $work/buildrepository/mock -name '*.rpm')
80