C++ Library containing a lot of needful things: Stack Trace, Command Line Parser, Resource Handling, Configuration Files, Unix Command Execution, Directories, Regular Expressions, Tokenizer, Function Trace, Standard Extensions.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

resolve-rpmbuilddeps.sh 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #! /bin/bash -ex
  2. ## @id $Id$
  3. ## Resolve RPM Build Dependencies
  4. ## Installs all the required packages
  5. ## Call: ./resolve-rpmbuilddeps 'name of build schroot'
  6. ## e.g. call: ./resolve-rpmbuilddeps opensuse-13.2_x86_64
  7. ## 1 2 3 4 5 6 7 8
  8. ## 45678901234567890123456789012345678901234567890123456789012345678901234567890
  9. INSTALL_TOOL=${INSTALL_TOOL:-$((test -x /usr/bin/zypper && echo zypper install -y) || (test -x /usr/bin/dnf && echo dnf install -y) || (test -x /usr/bin/yum && echo yum install -y) || (test -x /usr/sbin/urpmi && echo urpmi --auto))}
  10. SCHROOTNAME="$1"
  11. PACKAGE_NAME=$(sed -n 's/^ *m4_define(x_package_name, \(.*\)).*/\1/p' configure.ac)
  12. TRAP_CMD="sleep ${SLEEP:-0};"
  13. DEPS=
  14. for f in BUILD BUILDROOT RPMS SPECS SRPMS; do
  15. if ! test -d $f; then
  16. TRAP_CMD+="rm -rf $f;"
  17. mkdir $f
  18. fi
  19. done
  20. if test -e ${PACKAGE_NAME}.spec.in -a ! -e ${PACKAGE_NAME}.spec; then
  21. function pkg_exists() {
  22. (test -x /usr/bin/zypper && zypper search -x "$1" 1>&2 > /dev/null) || \
  23. (test -x /usr/bin/dnf && dnf list -q "$1" 1>&2 > /dev/null) || \
  24. (test -x /usr/bin/yum && yum list -q "$1" 1>&2 > /dev/null) || \
  25. (test -x /usr/sbin/urpmq && urpmq "$1" 1>&2 > /dev/null)
  26. }
  27. function AX_PKG_CHECK() {
  28. local DEV_RPM_DIST_PKG=
  29. local DEV_DIST_PKG=
  30. local pkg=
  31. eval $4
  32. if test -z "$2"; then
  33. pkg=$1
  34. else
  35. pkg=$2
  36. fi
  37. pkg=${DEV_RPM_DIST_PKG:-${DEV_DIST_PKG:-${pkg}}-devel}
  38. if pkg_exists "${pkg}"; then
  39. echo ${pkg}
  40. fi
  41. }
  42. function AX_PKG_REQUIRE() {
  43. local DEV_RPM_DIST_PKG=
  44. local DEV_DIST_PKG=
  45. local pkg=
  46. eval $6
  47. if test -z "$2"; then
  48. pkg=$1
  49. else
  50. pkg=$2
  51. fi
  52. if test -n "$4"; then
  53. for f in $pkg $4; do
  54. if pkg_exists "${f}-devel"; then
  55. pkg=$f
  56. break
  57. fi
  58. done
  59. fi
  60. echo ${DEV_RPM_DIST_PKG:-${DEV_DIST_PKG:-${pkg}}-devel}
  61. }
  62. DEPS+=" $(eval $(sed -n '/^ *AX_PKG_REQUIRE/{s,^ *\(AX_PKG_REQUIRE\) *(\(.*\)).*,\1 \2,;s.\[\([^]]*\)\],\?."\1".g;s,$,;,g;p}' configure.ac))"
  63. DEPS+=" $(eval $(sed -n '/^ *AX_PKG_CHECK/{s,^ *\(AX_PKG_CHECK\) *(\(.*\)).*,\1 \2,;s.\[\([^]]*\)\],\?."\1".g;s,$,;,g;p}' configure.ac))"
  64. for f in $(sed -n 's, *AX_\(RPM\|ALL\)_DEPEND_IFEXISTS(\([^)]*\)).*,\2,p' configure.ac); do
  65. if pkg_exists "${f}"; then
  66. DEPS+=" ${f}"
  67. fi
  68. done
  69. for f in $(sed -n 's, *AX_\(RPM\|ALL\)_DEPEND_IFEXISTS_DEV(\([^)]*\)).*,\2,p' configure.ac); do
  70. if pkg_exists "${f}-devel"; then
  71. DEPS+=" ${f}-devel"
  72. fi
  73. done
  74. for f in $(sed -n 's, *AX_\(RPM\|ALL\)\(_BUILD\)\?_DEPEND(\([^)]*\)).*,\3,p' configure.ac); do
  75. DEPS+=" ${f}"
  76. done
  77. for f in $(sed -n 's, *AX_\(RPM\|ALL\)\(_BUILD\)\?_DEPEND_DEV(\([^)]*\)).*,\3,p' configure.ac); do
  78. DEPS+=" ${f}-devel"
  79. done
  80. TRAP_CMD+="rm ${PACKAGE_NAME}.spec;"
  81. trap "${TRAP_CMD}" INT TERM EXIT
  82. sed 's,@\(\(ALL\|RPM\)_DEPEND_IFEXISTS\|\(ALL\|RPM\)_BUILD_DEPEND\|\(ALL\|RPM\)_DEPEND\)@,,g' ${PACKAGE_NAME}.spec.in | \
  83. sed 's,@[^@]*@,dummytext,g' > ${PACKAGE_NAME}.spec
  84. fi
  85. TGZFILE=$(sed -n '/^Name: */{s///;h};/^Version: */{s///;H;x;s/\n/-/;s/$/.tar.gz/;p}' ${PACKAGE_NAME}.spec)
  86. if ! test -e $TGZFILE; then
  87. TRAP_CMD+="rm ${TGZFILE};"
  88. trap "${TRAP_CMD}" INT TERM EXIT
  89. touch $TGZFILE
  90. fi
  91. if test -n "${SCHROOTNAME}"; then
  92. FILES=$(LANG= schroot -c ${SCHROOTNAME} -- rpmbuild -bb --clean --nobuild --define "_topdir ." --define "_sourcedir ." ${PACKAGE_NAME}.spec 2>&1 | sed -n 's, is needed by.*,,p')
  93. if test -n "${FILES// /}${DEPS// /}"; then
  94. schroot -c ${SCHROOTNAME} -u root -- ${INSTALL_TOOL} ${FILES} ${DEPS}
  95. fi
  96. else
  97. FILES=$(LANG= rpmbuild -bb --clean --nobuild --define "_topdir ." --define "_sourcedir ." ${PACKAGE_NAME}.spec 2>&1 | sed -n 's, is needed by.*,,p')
  98. if test -n "${FILES// /}${DEPS// /}"; then
  99. ${INSTALL_TOOL} ${FILES} ${DEPS}
  100. fi
  101. fi
  102. if test -n "${SCHROOTNAME}"; then
  103. FILES=$(LANG= schroot -c ${SCHROOTNAME} -- rpmbuild -bb --clean --nobuild --define "_topdir ." --define "_sourcedir ." ${PACKAGE_NAME}.spec 2>&1 | sed -n 's, is needed by.*,,p')
  104. else
  105. FILES=$(LANG= rpmbuild -bb --clean --nobuild --define "_topdir ." --define "_sourcedir ." ${PACKAGE_NAME}.spec 2>&1 | sed -n 's, is needed by.*,,p')
  106. fi
  107. if test -n "${FILES// /}"; then
  108. echo "**** ERROR: Cannot install: " $FILES
  109. exit 1
  110. fi
  111. echo "**** Success: All Dependencies Resolved"