|
| 1 | +#!/bin/bash |
| 2 | +function print_info |
| 3 | +{ |
| 4 | + echo -e "\e[0;32m$1\033[0m" |
| 5 | +} |
| 6 | + |
| 7 | +function print_error |
| 8 | +{ |
| 9 | + echo -e "\033[0;31m$1\033[0m" |
| 10 | +} |
| 11 | + |
| 12 | +function print_help |
| 13 | +{ |
| 14 | + echo ' |
| 15 | +Creates RPM packages. |
| 16 | +
|
| 17 | +Usage: |
| 18 | + -s only create srpm, nothing will be compiled |
| 19 | + -b build last srpm, the package release number will not be increased |
| 20 | + -h show help |
| 21 | +' |
| 22 | +} |
| 23 | + |
| 24 | +build_only=0 |
| 25 | +srpm_only=0 |
| 26 | + |
| 27 | +while getopts "shb" opt; do |
| 28 | + case ${opt} in |
| 29 | + s) |
| 30 | + srpm_only=1 |
| 31 | + ;; |
| 32 | + [\?|h]) |
| 33 | + print_help |
| 34 | + exit 0 |
| 35 | + ;; |
| 36 | + b) |
| 37 | + build_only=1 |
| 38 | + ;; |
| 39 | + esac |
| 40 | +done |
| 41 | + |
| 42 | +# Load default config |
| 43 | +source default.cfg |
| 44 | +# Load local config file |
| 45 | +if [ -f local.cfg ] |
| 46 | +then |
| 47 | + source local.cfg |
| 48 | +fi |
| 49 | + |
| 50 | +# Get next release version number and increment after |
| 51 | +if [ ! -f version.cfg ] |
| 52 | +then |
| 53 | + echo "RELVER=1" > version.cfg |
| 54 | +fi |
| 55 | +source version.cfg |
| 56 | +if [ "$build_only" -ne "1" ] |
| 57 | +then |
| 58 | + let RELVER+=1 |
| 59 | + echo "RELVER=$RELVER" > version.cfg |
| 60 | +fi |
| 61 | + |
| 62 | +# Clean logfiles |
| 63 | +if [ -f $OUTDIR/build.log ] |
| 64 | +then |
| 65 | + print_info "Cleaning log file" |
| 66 | + rm $OUTDIR/build.log |
| 67 | +fi |
| 68 | + |
| 69 | +# Get the version string |
| 70 | +major=$(grep -e 'SET(CPACK_PACKAGE_VERSION_MAJOR' ../CMakeLists.txt | |
| 71 | + sed 's/.*\([0-9]\).*/\1/') |
| 72 | +minor=$(grep -e 'SET(CPACK_PACKAGE_VERSION_MINOR' ../CMakeLists.txt | |
| 73 | + sed 's/.*\([0-9]\).*/\1/') |
| 74 | +patch=$(grep -e 'SET(CPACK_PACKAGE_VERSION_PATCH' ../CMakeLists.txt | |
| 75 | + sed 's/.*\([0-9]\).*/\1/') |
| 76 | + |
| 77 | +version=$(echo $major.$minor.$patch) |
| 78 | + |
| 79 | +print_info "Building version $version-$RELVER" |
| 80 | + |
| 81 | +if [ "$build_only" -ne "1" ] |
| 82 | +then |
| 83 | + # Current git branch name |
| 84 | + branch=$(git branch --no-color 2> /dev/null | |
| 85 | + sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/') |
| 86 | + |
| 87 | + print_info "Creating source tarball" |
| 88 | + # Create source tarball |
| 89 | + git -C .. archive --format=tar --prefix=qgis-$version/ $BRANCH | bzip2 > sources/qgis-$version.tar.gz |
| 90 | + |
| 91 | + print_info "Creating source package" |
| 92 | + # Create spec file |
| 93 | + cat qgis.spec.template | sed -e s/%{_version}/$version/g \ |
| 94 | + | sed -e s/%{_relver}/$RELVER/g \ |
| 95 | + | tee qgis.spec 1>/dev/null |
| 96 | + # Build source package |
| 97 | + mock --buildsrpm --spec qgis.spec --sources ./sources --define "_relver $RELVER" --define "_version $version" --resultdir=$OUTDIR |
| 98 | + if [ $? -ne 0 ] |
| 99 | + then |
| 100 | + print_error "Creating source package failed" |
| 101 | + exit 1 |
| 102 | + fi |
| 103 | + |
| 104 | + srpm=$(grep -e 'Wrote: .*\.src\.rpm' $OUTDIR/build.log | |
| 105 | + sed 's_Wrote: /builddir/build/SRPMS/\(.*\)_\1_') |
| 106 | + |
| 107 | + print_info "Source package created: $srpm" |
| 108 | +fi |
| 109 | + |
| 110 | +if [ "$srpm_only" -eq "1" ] |
| 111 | +then |
| 112 | + exit 0 |
| 113 | +fi |
| 114 | + |
| 115 | +# Create packages for every ARCH defined in the config file |
| 116 | +for arch in "${ARCHS[@]}" |
| 117 | +do : |
| 118 | + print_info "Building packages for $arch" |
| 119 | + if [ -f $OUTDIR/$arch/build.log ] |
| 120 | + then |
| 121 | + print_info "Cleaning log file" |
| 122 | + rm $OUTDIR/$arch/build.log |
| 123 | + fi |
| 124 | + mkdir $OUTDIR/$arch |
| 125 | + mock -r $arch --rebuild $OUTDIR/$srpm --define "_relver $RELVER" --define "_version $version" --resultdir=$OUTDIR/$arch |
| 126 | + if [ $? -eq 0 ] |
| 127 | + then |
| 128 | + # Add to package list |
| 129 | + packages="$packages $(ls $OUTDIR/$arch/*-$version-$RELVER.*.rpm)" |
| 130 | + else |
| 131 | + print_error "Package creation for $arch failed. Abort" |
| 132 | + exit 1 |
| 133 | + fi |
| 134 | +done |
| 135 | + |
| 136 | +if $NOSIGN |
| 137 | +then |
| 138 | + print_info "Signing packages" |
| 139 | + rpm --resign $packages |
| 140 | +fi |
| 141 | + |
| 142 | +print_info "Done" |
0 commit comments