[X2Go-Commits] [buildscripts] 01/01: bin/{sbuild-deb-package, build-rpm-package}: make scripts aware of other architectures.

git-admin at x2go.org git-admin at x2go.org
Wed Sep 6 07:51:51 CEST 2017


This is an automated email from the git hooks/post-receive script.

x2go pushed a commit to branch master
in repository buildscripts.

commit 5e6ab25f95d80177631164957c4e22dfd27da3f1
Author: Mihai Moldovan <ionic at ionic.de>
Date:   Wed Sep 6 07:51:04 2017 +0200

    bin/{sbuild-deb-package,build-rpm-package}: make scripts aware of other architectures.
    
    Adds support for ppc64 (and its derivatives), changes code to be more
    generic and possibly extensible.
    
    The architecture can be selected via the PLATFORM environment variable.
    Valid values are "x86", "ppc64" and "ppc64le" for the time being.
---
 bin/build-rpm-package  | 422 ++++++++++++++++++++++++++++---------------------
 bin/sbuild-deb-package | 118 ++++++++++----
 2 files changed, 332 insertions(+), 208 deletions(-)

diff --git a/bin/build-rpm-package b/bin/build-rpm-package
index 07f2b7a..39243a2 100755
--- a/bin/build-rpm-package
+++ b/bin/build-rpm-package
@@ -65,6 +65,7 @@ test -f "${HOME}/.buildscripts/${PREFIX}.conf" && . "${HOME}/.buildscripts/${PRE
 : ${NO_DELAY:="no"}
 : ${FORCE_BUILD:="no"}
 : ${RPM_BUILD_FOR:="fedora:${FEDORA_DISTROS} epel:${EPEL_DISTROS} opensuse:${OPENSUSE_DISTROS} sle:${SLE_DISTROS}"}
+: ${PLATFORM:="x86"}
 
 # These parts are not user-serviceable.
 TMP_MOCK_CFG_DIR=""
@@ -568,6 +569,65 @@ get_extra_repository () {
 	return 0
 }
 
+# Signs RPM packages in a pkg-dist "repository".
+# Takes the distribution, its version (either a real number or a codename)
+# and the architecture.
+sign_packages () {
+	typeset dist="${1:?"Error: no distribution passed to ${FUNCNAME}()."}"
+	typeset codename="${2:?"Error: no codename (distro 'version') passed to ${FUNCNAME}()."}"
+	typeset arch="${3:?"Error: no architecture passed to ${FUNCNAME}()."}"
+
+	typeset gpg_sign_with="${GPG_KEY}"
+
+	[ "${dist}" = "epel" ] && [ "${codename}" = "5" ] && gpg_sign_with="${GPG_KEY_EPEL5}"
+
+	if [ "${dist}" = "opensuse" ] || [ "${dist}" = "sle" ]; then
+		typeset -i tmp_suse_major_version="0"
+		typeset -i tmp_suse_minor_version="0"
+		tmp_suse_major_version="$(get_generic_major_version "${codename}")"
+
+		if [ "${?}" -ne "0" ]; then
+			echo "Unable to extract SUSE version."
+			exit "1"
+		fi
+
+		tmp_suse_minor_version="$(get_generic_minor_version "${codename}")"
+
+		if [ "${?}" -ne "0" ]; then
+			echo "Unable to extract minor SUSE version."
+			exit "1"
+		fi
+
+		[ "${tmp_suse_major_version}" -lt "12" ] && gpg_sign_with="${GPG_KEY_EPEL5}"
+	fi
+
+	typeset rpmmacro_v3sign="%__gpg_sign_cmd %{__gpg} /usr/bin/gpg --force-v3-sigs --digest-algo=sha1 --batch --no-verbose --no-armor --passphrase-fd 3 --no-secmem-warning -u \"%{_gpg_name}\" -sbo %{__signature_filename} %{__plaintext_filename}"
+
+	typeset -i use_v3="0"
+
+	[ "${dist}" = "epel" ] && [ "${codename}" = "5" ] && use_v3="1"
+
+	typeset -a rpmsign_opts
+	rpmsign_opts=( "-v" "-D" "%_gpg_name ${gpg_sign_with}" )
+
+	if [ "${use_v3}" -ne "0" ]; then
+		# References:
+		# /usr/lib/rpm/macros
+		# http://adminotes.blogspot.fr/2011/12/centos-6-rpm-sign-problem-v4-signatures.html
+		rpmsign_opts+=( "-D" "${rpmmacro_v3sign}" )
+	fi
+
+	rpmsign_opts+=( "--addsign" )
+
+	typeset rpmfile=''
+	# -r parameter to read: Backslashes may NOT escape any characters!
+	# -d '': specifies the delimiter to be used - as '' resolves to an empty string followed
+	#        by a NUL character, the delimiter is set to this very NUL (\000) character.
+	find "${PKGDIST}/${dist}/${codename}/${arch}/" -type 'f' -iname '*.rpm' -print0 | while read -r -d '' rpmfile; do rpmsign-unattended "${rpmsign_opts[@]}" "${rpmfile}"; done
+
+	return 0
+}
+
 prepare_workspace() {
 	# make sure our local working copy is up to date...
 	if [ -d "${PROJECT_DIR}/.git" ]; then
@@ -625,8 +685,25 @@ clear_pkgdist() {
 
 				test -z "${CODENAMES}" || grep "${CODENAMES}" <<< "${line}" || break
 
+				typeset -a arches
+				arches=()
+
 				# Yes, "SRPM" is technically not an architecture.
-				for l_ARCH in x86_64 i386 SRPM; do
+				arches+=( "SRPM" )
+
+				case "${PLATFORM}" in
+					("x86")
+						arches+=( "x86_64" "i386" )
+						;;
+					("ppc64")
+						arches+=( "ppc64" )
+						;;
+					("ppc64le")
+						arches+=( "ppc64le" )
+						;;
+				esac
+
+				for l_ARCH in "${arches[@]}"; do
 					# Rename the i386 arch to i586 for OpenSuSE and SLE{S,D}.
 					if [ "${l_DIST}" = "opensuse" ] || [ "${l_DIST}" = "sle" ]; then
 						if [ "${l_ARCH}" = "i386" ]; then
@@ -664,8 +741,25 @@ build_packages() {
 			for l_CODENAME in ${l_CODENAMES}; do
 				test -z "${CODENAMES}" || grep "${CODENAMES}" <<< "${line}" || break
 
-				# FIXME: Builds currently break without this. This should really be merged/transformed into an arch loop.
-				typeset l_ARCH=""
+				typeset -a arches
+				arches=()
+
+				# Yes, "SRPM" is technically not an architecture.
+				arches+=( "SRPM" )
+
+				case "${PLATFORM}" in
+					("x86")
+						arches+=( "x86_64" "i386" )
+						;;
+					("ppc64")
+						arches+=( "ppc64" )
+						;;
+					("ppc64le")
+						arches+=( "ppc64le" )
+						;;
+				esac
+
+				typeset l_ARCH="${arches[0]}"
 
 				# create rpmbuild subdirectories
 				mkdir -p -- "${PKGDIST}/${l_DIST}/${l_CODENAME}/${l_ARCH}/rpmbuild/SOURCES"
@@ -718,28 +812,6 @@ build_packages() {
 
 				cp -- "${PROJECT}.spec" "${PKGDIST}/${l_DIST}/${l_CODENAME}/${l_ARCH}/rpmbuild/SOURCES"
 
-				if [ "x${l_DIST}" = "xfedora" ] || [ "x${l_DIST}" = "xepel" ]; then
-					while [ -d ~mock/"${l_DIST}-${l_CODENAME}-x86_64" ]; do
-						echo "Waiting for some other build to finish..."
-						sleep 30
-					done
-					rm -f -- "${PKGDIST}/${l_DIST}/${l_CODENAME}/x86_64/build.log"
-
-					# Obtain packages from our RPM repository.
-					get_extra_repository "redhat" "${l_DIST}" "${l_CODENAME}" "${COMPONENT}" "${PROJECT}" "x86_64" "${RPM_WANT_EXTRA_REPOS}"
-					if mock --buildsrpm \
-					          ${MOCK_CHROOT_CONFIG} \
-					          --resultdir="${PKGDIST}/${l_DIST}/${l_CODENAME}/rpmbuild/SRPMS" \
-					          --spec "${PKGDIST}/${l_DIST}/${l_CODENAME}/${l_ARCH}/rpmbuild/SOURCES/${PROJECT}.spec" \
-					          --sources "${PKGDIST}/${l_DIST}/${l_CODENAME}/${l_ARCH}/rpmbuild/SOURCES/"; then
-						cat "${PKGDIST}/${l_DIST}/${l_CODENAME}/rpmbuild/SRPMS/build.log"
-						rm -Rf -- "${PKGDIST}/${l_DIST}/${l_CODENAME}/rpmbuild/SRPMS/build.log"
-					else
-						cat "${PKGDIST}/${l_DIST}/${l_CODENAME}/rpmbuild/SRPMS/build.log"
-						exit 1
-					fi
-				fi
-
 				# clean up the Git clone from the temp folder
 				cd && rm -Rf -- "${TEMP_DIR}/${PROJECT}"
 
@@ -747,7 +819,18 @@ build_packages() {
 				### TODO: add changelog entry for this automatic build
 
 				if [ "x${l_DIST}" = "xopensuse" ] || [ "x${l_DIST}" = "xsle" ]; then
-					mkdir -p -- "${PKGDIST}/${l_DIST}/${l_CODENAME}/"{x86_64,i586,SRPM}
+					# Rename the i386 arch to i586 for OpenSuSE and SLE{S,D}.
+					typeset -a arches_copy
+					arches_copy=("${arches[@]}")
+					typeset -i i="0"
+					for ((i = 0; i < ${#arches_copy[@]}; ++i)); do
+						[[ "${arches_copy[i]}" == "i386" ]] && arches_copy[i]="i586"
+					done
+
+					typeset arch=""
+					for arch in "${arches_copy[@]}"; do
+						mkdir -p -- "${PKGDIST}/${l_DIST}/${l_CODENAME}/${arch}"
+					done
 
 					BUILD_RESULT="/home/abuild/rpmbuild/"
 
@@ -795,177 +878,141 @@ build_packages() {
 						fi
 					fi
 				else
-					mkdir -p -- "${PKGDIST}/${l_DIST}/${l_CODENAME}/"{x86_64,i386,SRPM}
+					typeset arch=""
+					for arch in "${arches[@]}"; do
+						mkdir -p -- "${PKGDIST}/${l_DIST}/${l_CODENAME}/${arch}"
+					done
 				fi
 
-				if [ "x${SKIP_ARCH}" != "xx86_64" ] || [ "${IS_NOARCH}" = "yes" ]; then
-					if [ "x${l_DIST}" = "xopensuse" ] || [ "x${l_DIST}" = "xsle" ]; then
-						while ps ax | grep -E "build.*/var/cache/obs-build/${l_DIST}/${l_CODENAME}/x86_64/" | grep "sudo obs"; do
-							echo "Waiting for some other build to finish..."
-							sleep 30
-						done
-
-						# Obtain packages from our RPM repository.
-						get_extra_repository "suse" "${l_DIST}" "${l_CODENAME}" "${COMPONENT}" "${PROJECT}" "x86_64" "${RPM_WANT_EXTRA_REPOS}"
-						if sudo obs-build \
-						             --nosignature \
-						             ${OTHERMIRROR} \
-						             --repo "${DOWNLOAD_URL}" \
-						             --root "/var/cache/obs-build/${l_DIST}/${l_CODENAME}/x86_64/" \
-						             --clean \
-						             "${PKGDIST}/${l_DIST}/${l_CODENAME}/${l_ARCH}/rpmbuild/SOURCES/${PROJECT}.spec"; then
-							mkdir -p -- "${PKGDIST}/${l_DIST}/${l_CODENAME}/x86_64/"
-
-							# -r parameter to read: Backslashes may NOT escape any characters!
-							# -d '': specifies the delimiter to be used - as '' resolves to an empty string followed
-							#        by a NUL character, the delimiter is set to this very NUL (\000) character.
-							find "/var/cache/obs-build/${l_DIST}/${l_CODENAME}/x86_64/${BUILD_RESULT}/RPMS/" -type f \( -iname '*.rpm' -and -not -iname '*.src.rpm' \) -print0 | while read -r -d '' rpmfile; do
-								cp "${rpmfile}" "${PKGDIST}/${l_DIST}/${l_CODENAME}/x86_64/"
-							done
-
-							typeset gpg_sign_with="${GPG_KEY}"
-							[ "${tmp_suse_major_version}" -lt "12" ] && gpg_sign_with="${GPG_KEY_EPEL5}"
-
-							typeset rpmfile=''
-							find "${PKGDIST}/${l_DIST}/${l_CODENAME}/x86_64/" -type 'f' -iname '*.rpm' -print0 | while read -r -d '' rpmfile; do rpmsign-unattended -v -D "%_gpg_name ${gpg_sign_with}" --addsign "${rpmfile}"; done
-
-							# also copy and sign source RPM's
-							# For information on why this weird -print0 | read -r -d '' construction works,
-							# refer to the first instance of this in this script.
-							find "/var/cache/obs-build/${l_DIST}/${l_CODENAME}/x86_64/${BUILD_RESULT}/SRPMS/" -type 'f' -iname '*.rpm' -print0 | while read -r -d '' rpmfile; do
-								cp "${rpmfile}" "$PKGDIST/${l_DIST}/${l_CODENAME}/SRPM/"
+				typeset -i noarch_built="0"
+				for l_ARCH in "${arches[@]}"; do
+					if [ "${l_ARCH}" = "SRPM" ]; then
+						# Build SRPM.
+						typeset base_arch="${arches[1]}"
+						if [ "x${l_DIST}" = "xfedora" ] || [ "x${l_DIST}" = "xepel" ]; then
+							while [ -d ~mock/"${l_DIST}-${l_CODENAME}-${base_arch}" ]; do
+								echo "Waiting for some other build to finish..."
+								sleep 30
 							done
-							find "${PKGDIST}/${l_DIST}/${l_CODENAME}/SRPM/" -type 'f' -iname '*.rpm' -print0 | while read -r -d '' rpmfile; do rpmsign-unattended -v -D "%_gpg_name ${gpg_sign_with}" --addsign "${rpmfile}"; done
-						else
-							exit 1
-						fi
-					else
-						rm -f -- "${PKGDIST}/${l_DIST}/${l_CODENAME}/x86_64/build.log"
-						while [ -d ~mock/"${l_DIST}-${l_CODENAME}-x86_64" ]; do
-							echo "Waiting for some other build to finish..."
-							sleep 30
-						done
-
-						# Obtain packages from our RPM repository.
-						get_extra_repository "redhat" "${l_DIST}" "${l_CODENAME}" "${COMPONENT}" "${PROJECT}" "x86_64" "${RPM_WANT_EXTRA_REPOS}"
-
-						# For information on why this weird -print0 | read -r -d '' construction works,
-						# refer to the first instance of this in this script.
-						find "${PKGDIST}/${l_DIST}/${l_CODENAME}/${l_ARCH}/rpmbuild/SRPMS/" -type 'f' -iname "${PROJECT}-${UPSTREAM_VERSION}-${PKG_SRCRELEASE}.${IS_RELEASE}.git${DATE}.${GITREV}.${COMPONENT}.*.src.rpm" -print0 | while read -r -d '' srpm; do
-							if mock ${MOCK_CHROOT_CONFIG} --resultdir="${PKGDIST}/${l_DIST}/${l_CODENAME}/x86_64" "${srpm}"; then
-								# copy and later sign source RPM
-								cp "${srpm}" "${PKGDIST}/${l_DIST}/${l_CODENAME}/SRPM/"
-
-								# Clean up source RPM files. We copy them manually.
-								find "${PKGDIST}/${l_DIST}/${l_CODENAME}/x86_64" -type 'f' -iname '*.src.rpm' -exec rm -f -- '{}' \;
-
-								if [ "${l_DIST}" = "epel" ] && [ "${l_CODENAME}" = "5" ]; then
-									# References:
-									# /usr/lib/rpm/macros
-									# http://adminotes.blogspot.fr/2011/12/centos-6-rpm-sign-problem-v4-signatures.html
-									RPMMACRO_V3SIGN="%__gpg_sign_cmd %{__gpg} /usr/bin/gpg --force-v3-sigs --digest-algo=sha1 --batch --no-verbose --no-armor --passphrase-fd 3 --no-secmem-warning -u \"%{_gpg_name}\" -sbo %{__signature_filename} %{__plaintext_filename}"
-									typeset rpmfile=''
-									find "${PKGDIST}/${l_DIST}/${l_CODENAME}/x86_64/" -type 'f' -iname '*.rpm' -print0 | while read -r -d '' rpmfile; do rpmsign-unattended -v -D "%_gpg_name ${GPG_KEY_EPEL5}" -D "${RPMMACRO_V3SIGN}" --addsign "${rpmfile}"; done
-									find "${PKGDIST}/${l_DIST}/${l_CODENAME}/SRPM/" -type 'f' -iname '*.rpm' -print0 | while read -r -d '' rpmfile; do rpmsign-unattended -v -D "%_gpg_name ${GPG_KEY_EPEL5}" -D "${RPMMACRO_V3SIGN}" --addsign "${rpmfile}"; done
-								else
-									typeset rpmfile=''
-									find "${PKGDIST}/${l_DIST}/${l_CODENAME}/x86_64/" -type 'f' -iname '*.rpm' -print0 | while read -r -d '' rpmfile; do rpmsign-unattended -v -D "%_gpg_name ${GPG_KEY}" --addsign "${rpmfile}"; done
-									find "${PKGDIST}/${l_DIST}/${l_CODENAME}/SRPM/" -type 'f' -iname '*.rpm' -print0 | while read -r -d '' rpmfile; do rpmsign-unattended -v -D "%_gpg_name ${GPG_KEY}" --addsign "${rpmfile}"; done
-								fi
-								cat "${PKGDIST}/${l_DIST}/${l_CODENAME}/x86_64/build.log"
+							rm -f -- "${PKGDIST}/${l_DIST}/${l_CODENAME}/${base_arch}/build.log"
+
+							# Obtain packages from our RPM repository.
+							get_extra_repository "redhat" "${l_DIST}" "${l_CODENAME}" "${COMPONENT}" "${PROJECT}" "${base_arch}" "${RPM_WANT_EXTRA_REPOS}"
+							if mock --buildsrpm \
+							          ${MOCK_CHROOT_CONFIG} \
+							          --resultdir="${PKGDIST}/${l_DIST}/${l_CODENAME}/${l_ARCH}/" \
+							          --spec "${PKGDIST}/${l_DIST}/${l_CODENAME}/${l_ARCH}/rpmbuild/SOURCES/${PROJECT}.spec" \
+							          --sources "${PKGDIST}/${l_DIST}/${l_CODENAME}/${l_ARCH}/rpmbuild/SOURCES/"; then
+								sign_packages "${l_DIST}" "${l_CODENAME}" "${l_ARCH}"
+
+								cat "${PKGDIST}/${l_DIST}/${l_CODENAME}/${l_ARCH}/build.log"
+								rm -Rf -- "${PKGDIST}/${l_DIST}/${l_CODENAME}/${l_ARCH}/build.log"
 							else
-								cat "${PKGDIST}/${l_DIST}/${l_CODENAME}/x86_64/build.log"
+								cat "${PKGDIST}/${l_DIST}/${l_CODENAME}/${l_ARCH}/build.log"
 								exit 1
 							fi
-						done
-					fi
-				fi
-				if [ "x${SKIP_ARCH}" != "xi386" ]; then
-					if { [ "x${l_DIST}" = "xopensuse" ] || [ "x${l_DIST}" = "xsle" ]; } && [ "${IS_NOARCH}" != "yes" ]; then
-						while ps ax | grep -E "build.*/var/cache/obs-build/${l_DIST}/${l_CODENAME}/i586/" | grep "sudo obs"; do
-							echo "Waiting for some other build to finish..."
-							sleep 30
-						done
-
-						# Obtain packages from our RPM repository.
-						get_extra_repository "suse" "${l_DIST}" "${l_CODENAME}" "${COMPONENT}" "${PROJECT}" "i586" "${RPM_WANT_EXTRA_REPOS}"
-						if linux32 sudo obs-build \
-						                    --nosignature \
-						                    ${OTHERMIRROR} \
-						                    --repo "${DOWNLOAD_URL}" \
-						                    --root "/var/cache/obs-build/${l_DIST}/${l_CODENAME}/i586/" \
-						                    --arch "i586" \
-						                    --clean \
-						                    "${PKGDIST}/${l_DIST}/${l_CODENAME}/${l_ARCH}/rpmbuild/SOURCES/${PROJECT}.spec"; then
-							mkdir -p -- "${PKGDIST}/${l_DIST}/${l_CODENAME}/i586/"
-
-							# For information on why this weird -print0 | read -r -d '' construction works,
-							# refer to the first instance of this in this script.
-							find "/var/cache/obs-build/${l_DIST}/${l_CODENAME}/i586/${BUILD_RESULT}/RPMS/" -type 'f' \( -iname '*.rpm' -and -not -iname '*.src.rpm' \) -print0 | while read -r -d '' rpmfile; do
-								cp "${rpmfile}" "${PKGDIST}/${l_DIST}/${l_CODENAME}/i586/"
+						else
+							while ps ax | grep -E "build.*/var/cache/obs-build/${l_DIST}/${l_CODENAME}/${base_arch}/" | grep "sudo obs"; do
+								echo "Waiting for some other build to finish..."
+								sleep 30
 							done
 
-							typeset gpg_sign_with="${GPG_KEY}"
-							[ "${tmp_suse_major_version}" -lt "12" ] && gpg_sign_with="${GPG_KEY_EPEL5}"
-
-							typeset rpmfile=''
-							find "${PKGDIST}/${l_DIST}/${l_CODENAME}/i586/" -type 'f' -iname '*.rpm' -print0 | while read -r -d '' rpmfile; do rpmsign-unattended -v -D "%_gpg_name ${gpg_sign_with}" --addsign "${rpmfile}"; done
-
-							# copy and later sign source RPM's, if needed (that is, not already generated by x86_64/noarch code above)
-							SEARCH_SRPM="$(find "${PKGDIST}/${l_DIST}/${l_CODENAME}/SRPM" -type 'f' -iname "*.src.rpm" -print)"
-							if [ -z "${SEARCH_SRPM}" ]; then
+							# Obtain packages from our RPM repository.
+							get_extra_repository "suse" "${l_DIST}" "${l_CODENAME}" "${COMPONENT}" "${PROJECT}" "${base_arch}" "${RPM_WANT_EXTRA_REPOS}"
+							if sudo obs-build \
+							             --nosignature \
+							             ${OTHERMIRROR} \
+							             --repo "${DOWNLOAD_URL}" \
+							             --root "/var/cache/obs-build/${l_DIST}/${l_CODENAME}/${base_arch}/" \
+							             --clean \
+							             --stage "-bs" \
+							             "${PKGDIST}/${l_DIST}/${l_CODENAME}/${l_ARCH}/rpmbuild/SOURCES/${PROJECT}.spec"; then
+
+								# Copy and sign source RPM's.
 								# For information on why this weird -print0 | read -r -d '' construction works,
 								# refer to the first instance of this in this script.
-								find "/var/cache/obs-build/${l_DIST}/${l_CODENAME}/i586/${BUILD_RESULT}/SRPMS/" -type 'f' -iname '*.src.rpm' -print0 | while read -r -d '' rpmfile; do
-									cp "${rpmfile}" "${PKGDIST}/${l_DIST}/${l_CODENAME}/SRPM/"
+								find "/var/cache/obs-build/${l_DIST}/${l_CODENAME}/${base_arch}/${BUILD_RESULT}/SRPMS/" -type 'f' -iname '*.rpm' -print0 | while read -r -d '' rpmfile; do
+									cp "${rpmfile}" "${PKGDIST}/${l_DIST}/${l_CODENAME}/${l_ARCH}/"
 								done
-								find "${PKGDIST}/${l_DIST}/${l_CODENAME}/SRPM/" -type 'f' -iname '*.rpm' -print0 | while read -r -d '' rpmfile; do rpmsign-unattended -v -D "%_gpg_name ${gpg_sign_with}" --addsign "${rpmfile}"; done
+
+								sign_packages "${l_DIST}" "${l_CODENAME}" "${l_ARCH}"
+							else
+								exit 1
 							fi
-						else
-							exit 1
 						fi
-					elif [ "${l_DIST}" != "opensuse" ] && [ "${l_DIST}" != "sle" ]; then
-						while [ -d ~mock/"${l_DIST}-${l_CODENAME}-i386" ]; do
-							echo "Waiting for some other build to finish..."
-							sleep 30
-						done
-						rm -f -- "${PKGDIST}/${l_DIST}/${l_CODENAME}/i386/build.log"
-
-						# Obtain packages from our RPM repository.
-						get_extra_repository "redhat" "${l_DIST}" "${l_CODENAME}" "${COMPONENT}" "${PROJECT}" "i386" "${RPM_WANT_EXTRA_REPOS}"
-
-						# For information on why this weird -print0 | read -r -d '' construction works,
-						# refer to the first instance of this in this script.
-						find "${PKGDIST}/${l_DIST}/${l_CODENAME}/${l_ARCH}/rpmbuild/SRPMS/" -type 'f' -iname "${PROJECT}-${UPSTREAM_VERSION}-${PKG_SRCRELEASE}.${IS_RELEASE}.git${DATE}.${GITREV}.${COMPONENT}.*.src.rpm" -print0 | while read -r -d '' srpm; do
-							if nice mock ${MOCK_CHROOT_CONFIG} --resultdir="${PKGDIST}/${l_DIST}/${l_CODENAME}/i386" "${srpm}"; then
-								# only copy and sign source RPM if necessary
-								SIGN_SRPM="0"
-								if [ ! -e "${PKGDIST}/${l_DIST}/${l_CODENAME}/SRPM/$(basename "${srpm}")" ]; then
-									cp "${srpm}" "${PKGDIST}/${l_DIST}/${l_CODENAME}/SRPM/"
-									SIGN_SRPM="1"
+					else
+						if [ -n "${l_ARCH}" ] && [ "x${SKIP_ARCH}" != "x${l_ARCH}" ]; then
+							if [ "x${l_DIST}" = "xopensuse" ] || [ "x${l_DIST}" = "xsle" ]; then
+								# Skip architecture-dependent build, if the package is noarch and we already have a binary package.
+								if [ "${IS_NOARCH}" = "yes" ] && [ "${noarch_built}" -ne "0" ]; then
+									continue
 								fi
 
-								# Clean up source RPM files. We copy them manually.
-								find "${PKGDIST}/${l_DIST}/${l_CODENAME}/i386" -type 'f' -iname '*.src.rpm' -exec rm -f -- '{}' \;
+								# Rename the i386 arch to i586 for OpenSuSE and SLE{S,D}.
+								[[ "${l_ARCH}" == "i386" ]] && l_ARCH="i586"
+
+								while ps ax | grep -E "build.*/var/cache/obs-build/${l_DIST}/${l_CODENAME}/${l_ARCH}/" | grep "sudo obs"; do
+									echo "Waiting for some other build to finish..."
+									sleep 30
+								done
 
-								if [ "${l_DIST}" = "epel" ] && [ "${l_CODENAME}" = "5" ]; then
-									RPMMACRO_V3SIGN="%__gpg_sign_cmd %{__gpg} /usr/bin/gpg --force-v3-sigs --digest-algo=sha1 --batch --no-verbose --no-armor --passphrase-fd 3 --no-secmem-warning -u \"%_gpg_name\" -sbo %{__signature_filename} %{__plaintext_filename}"
-									typeset rpmfile=''
-									find "${PKGDIST}/${l_DIST}/${l_CODENAME}/i386/" -type 'f' -iname '*.rpm' -print0 | while read -r -d '' rpmfile; do rpmsign-unattended -v -D "%_gpg_name ${GPG_KEY_EPEL5}" -D "${RPMMACRO_V3SIGN}" --addsign "${rpmfile}"; done
-									[ "x${SIGN_SRPM}" = "x1" ] && find "${PKGDIST}/${l_DIST}/${l_CODENAME}/SRPM/" -type 'f' -iname '*.rpm' -print0 | while read -r -d '' rpmfile; do rpmsign-unattended -v -D "%_gpg_name ${GPG_KEY_EPEL5}" -D "${RPMMACRO_V3SIGN}" --addsign "${rpmfile}"; done
+								typeset -a obs_command
+								obs_command=( )
+								[[ "${l_ARCH}" == "i586" ]] && obs_command+=( "linux32" )
+								obs_command+=( "sudo" "obs-build" )
+
+								# Obtain packages from our RPM repository.
+								get_extra_repository "suse" "${l_DIST}" "${l_CODENAME}" "${COMPONENT}" "${PROJECT}" "${l_ARCH}" "${RPM_WANT_EXTRA_REPOS}"
+								if "${obs_command[@]}" \
+								             --nosignature \
+								             ${OTHERMIRROR} \
+								             --repo "${DOWNLOAD_URL}" \
+								             --root "/var/cache/obs-build/${l_DIST}/${l_CODENAME}/${l_ARCH}/" \
+								             --arch "${l_ARCH}" \
+								             --clean \
+								             --stage "-bb" \
+								             "${PKGDIST}/${l_DIST}/${l_CODENAME}/SRPM/rpmbuild/SOURCES/${PROJECT}.spec"; then
+									# For information on why this weird -print0 | read -r -d '' construction works,
+									# refer to the first instance of this in this script.
+									find "/var/cache/obs-build/${l_DIST}/${l_CODENAME}/${l_ARCH}/${BUILD_RESULT}/RPMS/" -type f \( -iname '*.rpm' -and -not -iname '*.src.rpm' \) -print0 | while read -r -d '' rpmfile; do
+										cp "${rpmfile}" "${PKGDIST}/${l_DIST}/${l_CODENAME}/${l_ARCH}/"
+									done
+
+									sign_packages "${l_DIST}" "${l_CODENAME}" "${l_ARCH}"
 								else
-									typeset rpmfile=''
-									find "${PKGDIST}/${l_DIST}/${l_CODENAME}/i386/" -type 'f' -iname '*.rpm' -print0 | while read -r -d '' rpmfile; do rpmsign-unattended -v -D "%_gpg_name ${GPG_KEY}" --addsign "${rpmfile}"; done
-									[ "x$SIGN_SRPM" = "x1" ] && find "${PKGDIST}/${l_DIST}/${l_CODENAME}/i386/" -type 'f' -iname '*.rpm' -print0 | while read -r -d '' rpmfile; do rpmsign-unattended -v -D "%_gpg_name ${GPG_KEY}" --addsign "${rpmfile}"; done
+									exit 1
 								fi
-								cat "${PKGDIST}/${l_DIST}/${l_CODENAME}/i386/build.log"
 							else
-								cat "${PKGDIST}/${l_DIST}/${l_CODENAME}/i386/build.log"
-								exit 1
+								while [ -d ~mock/"${l_DIST}-${l_CODENAME}-${l_ARCH}" ]; do
+									echo "Waiting for some other build to finish..."
+									sleep 30
+								done
+								rm -f -- "${PKGDIST}/${l_DIST}/${l_CODENAME}/${l_ARCH}/build.log"
+
+								# Obtain packages from our RPM repository.
+								get_extra_repository "redhat" "${l_DIST}" "${l_CODENAME}" "${COMPONENT}" "${PROJECT}" "${l_ARCH}" "${RPM_WANT_EXTRA_REPOS}"
+
+								# For information on why this weird -print0 | read -r -d '' construction works,
+								# refer to the first instance of this in this script.
+								find "${PKGDIST}/${l_DIST}/${l_CODENAME}/SRPM/" -type 'f' -iname "${PROJECT}-${UPSTREAM_VERSION}-${PKG_SRCRELEASE}.${IS_RELEASE}.git${DATE}.${GITREV}.${COMPONENT}.*.src.rpm" -print0 | while read -r -d '' srpm; do
+									if mock ${MOCK_CHROOT_CONFIG} --resultdir="${PKGDIST}/${l_DIST}/${l_CODENAME}/${l_ARCH}" "${srpm}"; then
+										# Clean up source RPM files. We build them separately.
+										find "${PKGDIST}/${l_DIST}/${l_CODENAME}/${l_ARCH}" -type 'f' -iname '*.src.rpm' -exec rm -f -- '{}' \;
+
+										sign_packages "${l_DIST}" "${l_CODENAME}" "${l_ARCH}"
+
+										cat "${PKGDIST}/${l_DIST}/${l_CODENAME}/${l_ARCH}/build.log"
+									else
+										cat "${PKGDIST}/${l_DIST}/${l_CODENAME}/${l_ARCH}/build.log"
+										exit 1
+									fi
+								done
 							fi
-						done
+
+							noarch_built="1"
+						fi
 					fi
-				fi
+				done
 			done
 		}
 	done
@@ -992,14 +1039,29 @@ upload_packages() {
 
 			test -z "${CODENAMES}" || grep "${CODENAMES}" <<< "${line}" || break
 
+			typeset -a arches
+			arches=()
+
 			# Yes, "SRPM" is technically not an architecture.
-			for l_ARCH in x86_64 i386 SRPM; do
+			arches+=( "SRPM" )
+
+			case "${PLATFORM}" in
+				("x86")
+					arches+=( "x86_64" "i386" )
+					;;
+				("ppc64")
+					arches+=( "ppc64" )
+					;;
+				("ppc64le")
+					arches+=( "ppc64le" )
+					;;
+			esac
+
+			for l_ARCH in "${arches[@]}"; do
 				if [ "x${SKIP_ARCH}" != "x${l_ARCH}" ]; then
 					if [ "${l_DIST}" = "opensuse" ] || [ "${l_DIST}" = "sle" ]; then
 						# Rename the i386 arch to i586 for OpenSuSE and SLE{S,D}.
-						if [ "${l_ARCH}" = "i386" ]; then
-							l_ARCH="i586"
-						fi
+						[[ "${l_ARCH}" = "i386" ]] && l_ARCH="i586"
 
 						# create remote directories in archive
 						0</dev/null ssh -- "${REPOS_SERVER}" "mkdir -p -- '${RPM_REPOS_BASE}/${l_DIST}/${l_CODENAME}/${COMPONENT}/${l_ARCH}/${PROJECT}'"
diff --git a/bin/sbuild-deb-package b/bin/sbuild-deb-package
index 53015ae..acbe6b9 100755
--- a/bin/sbuild-deb-package
+++ b/bin/sbuild-deb-package
@@ -55,6 +55,7 @@ test -f "${HOME}/.buildscripts/${PREFIX}.conf" && . "${HOME}/.buildscripts/${PRE
 : ${FORCE_BUILD:="no"}
 : ${DEB_BUILD_FOR:="debian:${DEBIAN_DISTROS} ubuntu:${UBUNTU_DISTROS} raspbian:${RASPBIAN_DISTROS}"}
 : ${FLAVOR:="native"}
+: ${PLATFORM:="x86"}
 
 # These parts are not user-serviceable.
 typeset -ag temp_cleanup=""
@@ -201,11 +202,23 @@ clear_pkgdist() {
 				# the wrong distribution here...
 				test -z "${CODENAMES}" || grep "${CODENAMES}" <<< "${line}" || break
 
-				typeset arches="amd64 i386"
-
-				[ "${l_DIST}" = "raspbian" ] && arches="armhf"
-
-				for l_ARCH in ${arches}; do
+				typeset -a arches
+				arches=()
+				case "${PLATFORM}" in
+					("x86")
+						arches+=( "amd64" "i386" )
+						;;
+					("ppc64")
+						arches+=( "powerpc" "ppc64" )
+						;;
+					("ppc64le")
+						arches+=( "ppc64el" )
+						;;
+				esac
+
+				[ "${l_DIST}" = "raspbian" ] && arches=( "armhf" )
+
+				for l_ARCH in "${arches[@]}"; do
 					[ "x${SKIP_ARCH}" != "x${l_ARCH}" ] && {
 						mkdir -p -- "${PKGDIST}/${l_DIST}/${l_CODENAME}/${l_ARCH}"
 						rm -f -- "${PKGDIST}/${l_DIST}/${l_CODENAME}/${l_ARCH}/dupload.conf"
@@ -312,7 +325,28 @@ build_packages() {
 				else
 					dch --distribution "${codename}" --force-distribution -l "~git${DATE}.${GITREV}+${numerical_version}.${COMPONENT}." "Development-Snapshot!!! Auto-built ${pretty_dist} ${l_CODENAME} (${numerical_version}) package for ${REPOS_SERVER} repository (Git commit: ${GIT_OBJECT_ID})."
 				fi
-				[ "${l_DIST}" = "raspbian" ] && mkdir -p -- "${PKGDIST}/${l_DIST}/${l_CODENAME}/armhf" || mkdir -p -- "${PKGDIST}/${l_DIST}/${l_CODENAME}/"{amd64,i386}
+
+				typeset -a arches
+				arches=()
+				case "${PLATFORM}" in
+					("x86")
+						arches+=( "amd64" "i386" )
+						;;
+					("ppc64")
+						arches+=( "powerpc" "ppc64" )
+						;;
+					("ppc64le")
+						arches+=( "ppc64el" )
+						;;
+				esac
+
+				[ "${l_DIST}" = "raspbian" ] && arches=( "armhf" )
+
+				typeset cur_arch=""
+				for cur_arch in "${arches[@]}"; do
+					mkdir -p -- "${PKGDIST}/${l_DIST}/${l_CODENAME}/${cur_arch}"
+				done
+
 				OTHERMIRROR=""
 				if [ "x${COMPONENT}" = "x${COMPONENT_NIGHTLY}" ]; then
 					grep -qs "${PROJECT}" <<< "${PACKAGE_WITHOUT_OTHERMIRROR}" || OTHERMIRROR="deb http://${REPOS_SERVER}/${l_DIST} ${l_CODENAME} ${COMPONENT_RELEASE} ${COMPONENT}"
@@ -350,26 +384,42 @@ build_packages() {
 					sbuild_options+=("--extra-repository=${OTHERMIRROR}")
 				fi
 
-				typeset -a sbuild_options_64 sbuild_options_32 sbuild_options_armhf
-				sbuild_options_64=("${sbuild_options[@]}")
-				sbuild_options_32=("${sbuild_options[@]}" "--arch=i386" "--debbuildopts=-B")
+				typeset -a sbuild_options_amd64 sbuild_options_i386 \
+					   sbuild_options_armhf \
+					   sbuild_options_powerpc sbuild_options_ppc64 \
+					   sbuild_options_ppc64le
+				sbuild_options_amd64=("${sbuild_options[@]}")
+				sbuild_options_i386=("${sbuild_options[@]}" "--arch=i386" "--debbuildopts=-B")
 				sbuild_options_armhf=("${sbuild_options[@]}" "--arch=armhf" "--chroot=${codename}-armhf-raspbian-sbuild")
+				sbuild_options_powerpc=("${sbuild_options[@]}")
+				# ppc64 is the more or less experimental Power7+ ppc64 port only available for unstable with experimental packages.
+				sbuild_options_ppc64=("${sbuild_options[@]}" "--arch=ppc64" "--chroot=${codename}-ppc64-sbuild" "--debbuildopts=-B")
+				sbuild_options_ppc64le=("${sbuild_options[@]}")
+
+				typeset base_arch="${arches[0]}"
+				[ "x${SKIP_ARCH}" != "x${base_arch}" ] && grep -Eqs "Architecture.*(all|any|${base_arch})" "${TEMP_DIR}/${PROJECT}/debian/control" && {
+					typeset indirect="sbuild_options_${base_arch}[@]"
+					typeset -a indirect_resolve
+					indirect_resolve=("${!indirect}")
+
+					cd "${PKGDIST}/${l_DIST}/${l_CODENAME}/${base_arch}"
+					nice ${SBUILD} "${indirect_resolve[@]}" "${TEMP_DIR}/${PROJECT}"
+				}
 
-				if [ "${l_DIST}" = "raspbian" ]; then
-					[ "${SKIP_ARCH}" != "armhf" ] && grep -Eqs 'Architecture.*(all|any|armhf)' "${TEMP_DIR}/${PROJECT}/debian/control" && {
-						cd "${PKGDIST}/${l_DIST}/${l_CODENAME}/armhf"
-						nice ${SBUILD} "${sbuild_options_armhf[@]}" "${TEMP_DIR}/${PROJECT}"
-					}
-				else
-					[ "x${SKIP_ARCH}" != "xamd64" ] && grep -Eqs 'Architecture.*(all|any|amd64)' "${TEMP_DIR}/${PROJECT}/debian/control" && {
-						cd "${PKGDIST}/${l_DIST}/${l_CODENAME}/amd64"
-						nice ${SBUILD} "${sbuild_options_64[@]}" "${TEMP_DIR}/${PROJECT}"
-					}
-					[ "x${SKIP_ARCH}" != "xi386" ] && grep -Eqs 'Architecture.*(any|i386)' "${TEMP_DIR}/${PROJECT}/debian/control" && {
-						cd "${PKGDIST}/${l_DIST}/${l_CODENAME}/i386"
-						nice ${SBUILD} "${sbuild_options_32[@]}" "${TEMP_DIR}/${PROJECT}"
-					}
+				base_arch="${arches[1]}"
+				# Clear out the ppc64 arch if not building against unstable to skip this part.
+				# Refer to the first arches comment regarding this.
+				if [[ "${base_arch}" = "ppc64" ]] && [[ "${codename}" != "unstable" ]]; then
+					base_arch=""
 				fi
+				[ -n "${base_arch}" ] && [ "x${SKIP_ARCH}" != "x${base_arch}" ] && grep -Eqs "Architecture.*(any|${base_arch})" "${TEMP_DIR}/${PROJECT}/debian/control" && {
+					typeset indirect="sbuild_options_${base_arch}[@]"
+					typeset -a indirect_resolve
+					indirect_resolve=("${!indirect}")
+
+					cd "${PKGDIST}/${l_DIST}/${l_CODENAME}/${base_arch}"
+					nice ${SBUILD} "${indirect_resolve[@]}" "${TEMP_DIR}/${PROJECT}"
+				}
 			done
 		}
 	done
@@ -398,11 +448,23 @@ upload_packages() {
 			# the wrong distribution here...
 			test -z "${CODENAMES}" || grep "${CODENAMES}" <<< "${line}" || break
 
-			typeset arches="amd64 i386"
-
-			[ "${l_DIST}" = "raspbian" ] && arches="armhf"
-
-			for l_ARCH in ${arches}; do
+			typeset -a arches
+			arches=()
+			case "${PLATFORM}" in
+				("x86")
+					arches+=( "amd64" "i386" )
+					;;
+				("ppc64")
+					arches+=( "powerpc" "ppc64" )
+					;;
+				("ppc64le")
+					arches+=( "ppc64el" )
+					;;
+			esac
+
+			[ "${l_DIST}" = "raspbian" ] && arches=( "armhf" )
+
+			for l_ARCH in "${arches[@]}"; do
 				[ "x${SKIP_ARCH}" != "x${l_ARCH}" ] && {
 					cd "${PKGDIST}/${l_DIST}/${l_CODENAME}/${l_ARCH}"
 					test -f "./dupload.conf" || ln -s -- "${HOME}/.dupload.conf.${PREFIX}" "./dupload.conf"

--
Alioth's /srv/git/code.x2go.org/buildscripts.git//..//_hooks_/post-receive-email on /srv/git/code.x2go.org/buildscripts.git


More information about the x2go-commits mailing list