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
/
buildroot-generator
executable file
·117 lines (105 loc) · 4.69 KB
/
buildroot-generator
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
#!/bin/bash
# Given a list of packages, generate their buildoort
# buildroot means what it would take to build not only that
# package, but all the packages to build the packages.
#
#####
# Variables
#####
WORK_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $WORK_DIR/conf/config.inc
TIMESTAMP=$(date +%Y-%m-%d-%H:%M)
# BINARY VARIABLES
: ${VERBOSE:="FALSE"}
: ${LAYERS:="TRUE"}
#####
# Work through everything one arch at a time
#####
#for this_arch in ${ARCH_LIST[@]}
#do
generate_arch_buildroot(){
#####
# Setup
#####
WORK_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $WORK_DIR/conf/config.inc
this_arch=$1
TIMESTAMP=$2
#
declare -A SOURCE_LIST
ORIGINAL_LIST=()
BINARY_LIST=()
SOURCE_LIST=()
LAYER=1
PACKAGE_LIST_FILE="${PACKAGE_LIST_HEAD}.${this_arch}"
PACKAGE_NVR_LIST_FILE="${PACKAGE_NVR_LIST_HEAD}.${this_arch}"
SOURCE_LIST_FILE="${SOURCE_LIST_HEAD}.${this_arch}"
SOURCE_NVR_LIST_FILE="${SOURCE_NVR_LIST_HEAD}.${this_arch}"
DATA_DIR="${DATA_DIR_BASE}/${this_arch}"
DNF_OPTIONS=" --forcearch=${this_arch} -c ${REPO_DIR}/${REPONAME}.${this_arch}.repo ${DNF_OPTIONS_NOCONF_BASE}"
if [ -d ${DATA_DIR}/${NEW_DIR} ] ; then
rm -f ${DATA_DIR}/${NEW_DIR}/*
else
mkdir -p ${DATA_DIR}/${NEW_DIR}
fi
echo "${TIMESTAMP}" > ${DATA_DIR}/${NEW_DIR}/${BR_TIMESTAMP_FILENAME}
# We have to build them all for each arch, let's put them all in from the start
cp ${PACKAGELIST_DIR}/${PACKAGE_LIST_HEAD}.all-arches ${DATA_DIR}/${NEW_DIR}/${PACKAGE_LIST_FILE}
cp ${PACKAGELIST_DIR}/${PACKAGE_NVR_LIST_HEAD}.all-arches ${DATA_DIR}/${NEW_DIR}/${PACKAGE_NVR_LIST_FILE}
cp ${PACKAGELIST_DIR}/${SOURCE_LIST_HEAD}.all-arches ${DATA_DIR}/${NEW_DIR}/${SOURCE_LIST_FILE}
cp ${PACKAGELIST_DIR}/${SOURCE_NVR_LIST_HEAD}.all-arches ${DATA_DIR}/${NEW_DIR}/${SOURCE_NVR_LIST_FILE}
#####
# Work
#####
echo "${this_arch} Creating BuildRoot "
# Load Original Source List
echo " ${this_arch} - Building initial Source List"
for this_source in $(cat ${PACKAGELIST_DIR}/${SOURCE_LIST_HEAD}.all-arches)
do
if [[ ! " ${SOURCE_LIST[@]} " =~ " ${this_source} " ]]; then
SOURCE_LIST[${this_source}]=1
fi
done
# Loop through until we no longer add sources
number_sources=${#SOURCE_LIST[@]}
number_new_sources=${number_sources}
while [ ${number_new_sources} -ge 1 ]
do
printf "%-12s %-9s %-21s %-16s\n" " ${this_arch}" "Layer: ${LAYER}" "Number Sources: ${number_sources}" "New Sources: ${number_new_sources}"
let LAYER=${LAYER}+1
# Get list of binaries needed to build the current source list
BINARY_LIST=($(dnf ${DNF_OPTIONS} repoquery --srpm --qf %{name} --requires --resolve ${!SOURCE_LIST[@]} 2>/dev/null))
# Add all the sources of those binaries to the current source list
this_source_name=($(dnf ${DNF_OPTIONS} repoquery --qf '%{source_name}' ${BINARY_LIST[@]} 2>/dev/null | grep -v -i -e '^None$' -e '^(none)$' -e 'Subscription Management'))
for this_source in ${this_source_name[@]}
do
if [ ! -v SOURCE_LIST[${this_source}] ]; then
SOURCE_LIST[${this_source}]=1
fi
done
# Get what it would require to install the binaries needed to build the source list, and add their sources to the list
this_source_name=($(dnf ${DNF_OPTIONS} repoquery --qf '%{source_name}' $(dnf ${DNF_OPTIONS} repoquery --qf %{name} --requires --resolve --recursive ${BINARY_LIST[@]} 2>/dev/null ) 2>/dev/null | grep -v -i -e '^None$' -e '^(none)$' -e 'Subscription Management'))
for this_source in ${this_source_name[@]}
do
if [ ! -v SOURCE_LIST[${this_source}] ]; then
SOURCE_LIST[${this_source}]=1
fi
done
new_number_sources=${#SOURCE_LIST[@]}
let number_new_sources=${new_number_sources}-${number_sources}
number_sources=${new_number_sources}
done
# Write it all out
echo " ${this_arch} Writting everything to disk"
printf "%s\n" "${!SOURCE_LIST[@]}" | sort -u -o ${DATA_DIR}/${NEW_DIR}/${BR_SOURCE_PKGNAMES_FILENAME}
printf "%s\n" "${BINARY_LIST[@]}" | sort -u -o ${DATA_DIR}/${NEW_DIR}/${BR_BINARY_PKGNAMES_FILENAME}
dnf ${DNF_OPTIONS} repoquery --srpm --qf "%{name}-%{version}-%{release}.%{arch}" ${!SOURCE_LIST[@]} 2>/dev/null | sort -u -o ${DATA_DIR}/${NEW_DIR}/${BR_SOURCE_NVRS_FILENAME}
dnf ${DNF_OPTIONS} repoquery --qf "%{name}-%{version}-%{release}.%{arch}" ${BINARY_LIST[@]} 2>/dev/null | grep -v .src$ | sort -u -o ${DATA_DIR}/${NEW_DIR}/${BR_BINARY_NVRS_FILENAME}
# finish with this arch
echo "${this_arch} Finished"
}
#done
export -f generate_arch_buildroot
printf '%s\n' "${ARCH_LIST[@]}" | xargs --max-procs=4 -I THIS_ARCH \
bash -c "generate_arch_buildroot -r "${REPONAME}" -p "${PACKAGELIST_DIR}" THIS_ARCH ${TIMESTAMP} "
exit 0