Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 434 lines (361 sloc) 17.312 kb
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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433
#!/bin/bash

### dar-build [ -a <archs> ] [ -d <dists> ] [ -s <sdists> ] [ -f ] [ -t tag ] <app> ...

source "/usr/share/dar/dar-functions"

daropts ":a:d:fns:t:v" $@
PKGS="$OPTS"

if [ ! -d "$ROOT" ]; then
echo "ERROR: probably in chroot jail" >&2
    exit 1
fi

### Clear important build variables
export -n CC_FLAGS CXX_FLAGS LD_PRELOAD LINGUAS

for arg in $PKGS; do
DARBUILDRC=1

    SPECDIR="$(dirname $arg)"
    app="$(basename $arg .spec)"
    SPECFILE="$PWD/$app.spec"
    MAKEFLAGS="%nil"

    if [ ! -f "$SPECFILE" ]; then SPECFILE="$SPECDIR/$app.spec"; fi
if [ ! -f "$SPECFILE" ]; then SPECFILE="$SPECSDIR/$app.spec"; fi
if [ ! -f "$SPECFILE" ]; then SPECFILE="$PWD/$app/$app.spec"; fi
if [ ! -f "$SPECFILE" ]; then SPECFILE="$SPECDIR/$app/$app.spec"; fi
if [ ! -f "$SPECFILE" ]; then SPECFILE="$SPECSDIR/$app/$app.spec"; fi
if [ ! -f "$SPECFILE" ]; then SPECFILE="$SPECSDIR/$SPECDIR/$app.spec"; fi

if [ "${SPECFILE:0:1}" != "/" ]; then SPECFILE="$PWD/$SPECFILE"; fi

SPECDIR="$(dirname $SPECFILE)"
    SPECFILE="$SPECDIR/$app.spec"

    if [ ! -f "$SPECFILE" ]; then
echo "ERROR: specfile \"$(basename $SPECFILE)\" is not found."
        continue
fi

if [ ! -d "$SPECDIR" ]; then
echo "ERROR: specdir \"$SPECDIR\" is not found."
        continue
fi

# if [ -d "$SPECDIR/.svn/" ]; then
# svn -q up "$SPECDIR/"
# fi

    app="$(rpmconf Name)"

    if [ -z "$app" ]; then
error "Problem with specfile \"$SPECFILE\". (Name is empty)"
        continue
fi

mkdir -p "$PACKAGEDIR/$app/_buildlogs/" "$SPECDIR/"
    ln -sf "$PACKAGEDIR/$app/_buildlogs/" "$SPECDIR/"
    chown -R $BUILD_USER.$BUILD_GROUP "$PACKAGEDIR/$app/"
    chown -R $BUILD_USER.$BUILD_GROUP "$SPECDIR/"
    chmod -R a+r "$SPECDIR/"

    set_dists
    set_exclude_dist
    set_exclusive_dist
    set_source_dists
    set_soapbox
    set_as_root
    set_ccache
    set_distcc

# echo "Building $app package for dists: '$DISTS' and archs: '$ARCHS', tagged: '$TAG'"
    for dist in $DISTS; do
RPMBUILDOPTS=""
        if [ -r "$CONFIGDIR/dists/$dist/config" ]; then
source "$CONFIGDIR/dists/$dist/config"
        else
warning "Configfile $CONFIGDIR/dists/$dist/config missing. Aborting."
            continue
fi

set_tag
        if [ "$TAG" ]; then
TAGS="$TAG"
        fi

if [ "$NODIST" ]; then
DISTTAG="0"
            DISTNAME="nodist"
# ARCHS="noarch"
        fi

if [ ! -d "$CHROOTDIR/$DISTNICK" ]; then
warning "Distribution $DISTNICK has no build environment ($CHROOTDIR/$DISTNICK). Aborting."
            continue
fi

for exclude_dist in $EXCLUDE_DIST; do
if [ "$exclude_dist" == "$DISTNAME" -o "$exclude_dist" == "$DISTNICK" -o "$DISTNAME" == "nodist" ]; then
warning "Distribution $DISTNAME/$DISTARCH is excluded for package $app. Aborting."
                continue 2
            fi
done

if [ "$EXCLUSIVE_DIST" ]; then
EXCLUSIVE=0
            for exclusive_dist in $EXCLUSIVE_DIST; do
if [ "$exclusive_dist" == "$DISTNAME" -o "$exclusive_dist" == "$DISTNICK" -o "$DISTNAME" == "nodist" ]; then
EXCLUSIVE=1
                fi
done
if [ $EXCLUSIVE -ne 1 ]; then
warning "Distribution $DISTNAME/$DISTARCH is excluded for package $app. Aborting."
                continue
fi
fi

        ### Cleaning up nodebug shit
# perl -pi -e 's|-O2 -g|-O2|' $CHROOTDIR/$DISTNICK/usr/lib/rpm/{macros,*/macros,rpmrc}

        ### Export RPMVER to rpmconf
        export RPMVER="$(chroot $CHROOTDIR/$DISTNICK /bin/su -lm $BUILD_USER -c "rpm --version" | cut -d' ' -f3)"

        set_archs

        ### TODO: Check if etc/rpm/macros exists with proper content

        for arch in $ARCHS; do
VERSION="$(rpmconf Version)"
            RELEASE="$(rpmconf Release)"

            NEWSPECFILE="$TEMPDIR/$app-$VERSION-$RELEASE.spec"
            RPMFILE="$app-$VERSION-$RELEASE.$arch.rpm"
            LOGFILE="$app-$VERSION-$RELEASE.$arch"
            LOGFILE_OK="$app-$VERSION-$RELEASE.$arch.ok.log"
            LOGFILE_KO="$app-$VERSION-$RELEASE.$arch.ko.log"
            export MAKEFLAGS="%nil"

            if [ "$arch" == "nosrc" ]; then
DARBUILDRC=0
                break
fi

            ### Check if already build (2 version schemes, multiple disttags)
            for disttag in $DISTNAME $DISTTAG; do
for tag in $TAGS; do
rpmfile="$app-$VERSION-$RELEASE.$arch.rpm"
                    if [ -z "$FORCE_OVERWRITE" -a -f "$PACKAGEDIR/$app/$rpmfile" ]; then
warning "Package \"$PACKAGEDIR/$app/$rpmfile\" already exists."
                        continue 3
                    fi
done
done

if ! download_sources; then
continue
fi

cp -af "$SPECFILE" "$NEWSPECFILE"

            export origspecfile="$SPECFILE" specfile="$NEWSPECFILE" builddir="$BUILDDIR" chrootdir="$CHROOTDIR/$dist"
            export app buildarch="$arch" distarch="$DISTARCH" disttag="$DISTNAME" repotag="$TAG" release="$RELEASE"
            export force="$FORCE_OVERWRITE"
            for script in $CONFIGDIR/scripts/pre-*.sh; do
source "$script"
            done

            ### Start logging
# rm -f "$PACKAGEDIR/$app/$LOGFILE"
            ( echo "----- Build information -----"
                echo "Package name: $app"
                echo "Package version: $VERSION"
                echo "Package release: $RELEASE"
                echo "Packager: $(logname)"
                echo "Distribution: $DISTNAME/$DISTARCH"
                echo "Package arch: $arch"
                echo "Build host: $(uname -n)"
                echo "Build date: $(date)"

                if [ $SOAPBOX -eq 1 -a -f "/lib/libsoapbox.so" -a -f "$CHROOTDIR/$dist/lib/libsoapbox.so" ]; then
echo "Soapbox: enabled"
                else
echo "Soapbox: disabled"
                fi

if [ $AS_ROOT -eq 1 ]; then
echo "BuildAsRoot: enabled (root)"
                    export HOME="/root"
                    export USER="root"
                else
echo "BuildAsRoot: disabled ($BUILD_USER)"
                    export HOME="/home/$BUILD_USER"
                    export USER="$BUILD_USER"
                fi

if [ $USE_DISTCC -ne 0 -a $DISTCC -eq 1 -a -n "$DISTCC_HOSTS" -a -x "$CHROOTDIR/$dist/usr/bin/distcc" -a -d "$CHROOTDIR/$dist/usr/lib/distcc/bin" ]; then
echo "Distcc: enabled"
                    echo "Distcc hosts: $DISTCC_HOSTS"
                else
echo "Distcc: disabled"
                fi

if [ $USE_CCACHE -ne 0 -a $CCACHE -eq 1 -a -x "$CHROOTDIR/$dist/usr/bin/ccache" -a -d "$CHROOTDIR/$dist/usr/lib/ccache/bin" ]; then
echo "Ccache: enabled"
                else
echo "Ccache: disabled"
                fi

            ) &>"$PACKAGEDIR/$app/_buildlogs/$LOGFILE_KO"

            ### Backup PATH
            OLDPATH="$PATH"

            ### Check for Distcc
            if [ $USE_DISTCC -ne 0 -a $DISTCC -eq 1 -a -n "$DISTCC_HOSTS" -a -x "$CHROOTDIR/$dist/usr/bin/distcc" -a -d "$CHROOTDIR/$dist/usr/lib/distcc/bin" ]; then
if [ -z "$CPUNR" ]; then
CPUNR="$(( $(echo $DISTCC_HOSTS | wc -w) * 2 ))"
                fi
if [ "$FORCE_VERBOSE" ]; then
export DISTCC_VERBOSE="1"
                fi
if [ -d /root/.distcc/state/ ]; then
rmdir /root/.distcc/state/ &>/dev/null
                fi
if [ $USE_ROOT -ne 1 -o $AS_ROOT -ne 1 ]; then
chown $BUILD_USER.$BUILD_USER $CHROOTDIR/$dist/root/.distcc/
# ln -sf $CHROOTDIR/$dist/home/$BUILD_USER/.distcc/state /root/.distcc/
# else
# ln -sf $CHROOTDIR/$dist/root/.distcc/state /root/.distcc/
                fi
ln -sf $CHROOTDIR/$dist/root/.distcc/state /root/.distcc/
                export DISTCC_LOG="$TEMPDIR/distcc-$LOGFILE"
                rm -f "$DISTCC_LOG"
                export MAKEFLAGS="-j$CPUNR CC='$DISTCC_CC' CXX='$DISTCC_CXX' GXX='$DISTCC_CXX'"
                export DISTCC_HOSTS CC="$DISTCC_CC" CXX="$DISTCC_CXX" GXX="$DISTCC_CXX"
                export PATH="/usr/lib/distcc/bin:$PATH"
            else
if [ "$CPUNR" -a $CPUNR -ne 0 -a $CPUNR -ne 1 ]; then
export MAKEFLAGS="-j$CPUNR"
                else
export MAKEFLAGS="-j1"
                fi
export -n DISTCC_HOSTS CC CXX GXX
            fi

            ### Check for Ccache
            if [ $USE_CCACHE -ne 0 -a $CCACHE -eq 1 -a -x "$CHROOTDIR/$dist/usr/bin/ccache" -a -d "$CHROOTDIR/$dist/usr/lib/ccache/bin" ]; then
export CCACHE_DIR="$TEMPDIR/ccache-$dist"
                export -n CCACHE_RECACHE
                export PATH="/usr/lib/ccache/bin:$PATH"
                mkdir -p "$CCACHE_DIR"
            else
export CCACHE_RECACHE="1"
            fi

            ### Disable ExtUtils::AutoInstall in perl packages
            export PERL_AUTOINSTALL="--skipdeps --skip"
            export PERL_EXTUTILS_AUTOINSTALL="--skipdeps --skip"

            ### Remove buildroot
            rm -rf "$TEMPDIR/root-$app-$VERSION"

            ### Prepare rpm options
            if [ "$FORCE_VERBOSE" ]; then
RPMBUILDOPTS="$RPMBUILDOPTS -vv"
            fi

if [ "$FORCE_VERBOSE" == "yes" ]; then
echo "Building $dist/$arch [$SPECDIR/_buildlogs/$LOGFILE]."
            fi

            ### Check for Soapbox
            if [ "$SOAPBOX" == "1" -a -f "/lib/libsoapbox.so" -a -f "$CHROOTDIR/$dist/lib/libsoapbox.so" ]; then
export SOAPBOXPATH="$PACKAGEDIR/$app/_buildlogs:$PACKAGEDIR/$app:$TEMPDIR:$BUILDDIR:/dev/null:/dev/tty:/tmp:/var/lib/rpm/__db:$HOME/.distcc"
                export SOAPBOXLOG="$TEMPDIR/soapbox-$LOGFILE.log"
                rm -f "$SOAPBOXLOG"
                export LD_PRELOAD="/lib/libsoapbox.so"
            fi

BUILDCMD="/usr/bin/rpmbuild -bb --clean $RPMBUILDOPTS --target $arch \
--define \"_smp_mflags $MAKEFLAGS\" \
--define \"_rpmfilename %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm\" \
--define \"_initrddir %{_sysconfdir}/rc.d/init.d\" \
--define \"_rpmdir $PACKAGEDIR/$app\" \
--define \"_sourcedir $SPECDIR\" \
--define \"_builddir $ROOT/build\" \
--define \"_tmppath $TEMPDIR\" \
--define \"_buildroot $TEMPDIR/$app-$VERSION-$RELEASE-root\" \
--define \"debug_package %nil\" \
--define \"dtag $DISTNAME\" \
--define \"dist .$DISTNAME.$TAG\" \
--define \"$DISTNAME 1\" \
--define \"$DISTNICK 1\" \"$NEWSPECFILE\""

            (
                echo "Build command:" $BUILDCMD
                echo "Build path: $PATH"

                echo -e "\n----- Spec file -----"
                cat "$NEWSPECFILE"

                echo -e "\n----- Expanded spec file -----"
                expand_specfile $SPECFILE

                echo -e "\n----- Build log -----"

                ### Check for building as user
                if [ $AS_ROOT -ne 1 ]; then
echo "$BUILDCMD" | setarch $DISTARCH /usr/sbin/chroot "$CHROOTDIR/$dist" /bin/su -lm $BUILD_USER -c "/bin/bash --login -s"
                else
echo "$BUILDCMD" | setarch $DISTARCH /usr/sbin/chroot "$CHROOTDIR/$dist" /bin/bash --login -s
                fi

            ) >>"$PACKAGEDIR/$app/_buildlogs/$LOGFILE_KO" 2>&1
# CHROOT="/usr/bin/compartment --chroot $CHROOTDIR/$dist --user $BUILD_USER --group $BUILD_USER --init /usr/lib/dar/compartment.sh --quiet"

            RC=$?
            export -n LD_PRELOAD

            ### Restore PATH
            export PATH="$OLDPATH"

            ### Finish logging
            ( echo -e "\n----- Return code -----"
                echo "$RC"
                if [ -d "$TEMPDIR/$app-$VERSION-$RELEASE-root" ]; then
echo -e "\n----- Buildroot content -----"
                    find "$TEMPDIR/$app-$VERSION-$RELEASE-root" 2>/dev/null
                fi
if [ -s "$SOAPBOXLOG" ]; then
if [ $RC -eq 0 ]; then
warning "Soapbox violations, see \"$PACKAGEDIR/$app/_buildlogs/$LOGFILE_KO.gz\"."
                    else
warning "Soapbox violations, see log."
                    fi
echo -e "\n----- Actions outside buildroot -----"
                    cat "$SOAPBOXLOG"
                    RC=15
                fi
rm -f "$SOAPBOXLOG"
                echo -e "\n----- End of file -----"
            ) >>"$PACKAGEDIR/$app/_buildlogs/$LOGFILE_KO" 2>&1

            ### Check if an RPM package was successfully built.
            grep -q -E '^Wrote: .*.rpm$' "$PACKAGEDIR/$app/_buildlogs/$LOGFILE_KO"
            RC=$?

            if [ $RC -eq 0 ]; then
DARBUILDRC=0
                mv -f "$PACKAGEDIR/$app/_buildlogs/$LOGFILE_KO" "$PACKAGEDIR/$app/_buildlogs/$LOGFILE_OK"
                rm -f "$PACKAGEDIR/$app/_buildlogs/$LOGFILE_KO.gz"
                if [ "$FORCE_VERBOSE" == "yes" ]; then
echo -e "${_GR}Success${_DE} $app [$dist/$arch], see log [$SPECDIR/_buildlogs/$LOGFILE_OK]"
                fi
echo "$app [$dist/$arch] ${SPECFILE/*\/} $LOGFILE_OK" >>/dar/log/dar-build-success.log
                cp -au "$SPECFILE" "$PACKAGEDIR/$app/"

                if [ "$RETAIN_LOGS" == "yes" ]; then
# bzip2 -9 -f "$PACKAGEDIR/$app/_buildlogs/$LOGFILE_OK"
                    gzip -9 --rsyncable -f "$PACKAGEDIR/$app/_buildlogs/$LOGFILE_OK"
                fi

                ### Clean up current and older logfile
                rm -f "$DISTCC_LOG"

                if [ -z "$SOURCE_DISTS" ]; then
SOURCE_DISTS="$DISTNICK"
                fi
else
# log "Failed building package $app for $dist/$arch." >> "$LOGDIR/dar.log"
                error "${_RE}Failed${_DE} $app [$dist/$arch], see log [$SPECDIR/_buildlogs/$LOGFILE_KO]"
                echo "$app [$dist/$arch] ${SPECFILE/*\/} $LOGFILE_KO" >>/dar/log/dar-build-failed.log
# bzip2 -9 -f "$PACKAGEDIR/$app/_buildlogs/$LOGFILE_KO"
                gzip -9 --rsyncable -f "$PACKAGEDIR/$app/_buildlogs/$LOGFILE_KO"
            fi
rm -f "$NEWSPECFILE"
        done
done

RPMFILE="$app-$VERSION-$RELEASE.src.rpm"
    ### Only build when there was a succesful binary build
# if [ -z "$NOSOURCE" -a "$DARBUILDRC" -eq 0 -o ! -f "$PACKAGEDIR/$app/$RPMFILE" ]; then
    if [ -z "$NOSOURCE" -a "$DARBUILDRC" -eq 0 ]; then

if [ -z "$SOURCE_DISTS" ]; then SOURCE_DISTS="$DEFAULT_SOURCE_DISTS"; fi

for dist in $SOURCE_DISTS; do
if [ -r "$CONFIGDIR/dists/$dist/config" ]; then
source "$CONFIGDIR/dists/$dist/config"
            else
warning "Configfile $CONFIGDIR/dists/$dist/config missing. Aborting."
                continue
fi

RPMFILE="$app-$VERSION-$RELEASE.src.rpm"

            NEWSPECFILE="$TEMPDIR/$app.spec"
            cp -af "$SPECFILE" "$NEWSPECFILE"
            export buildarch="src" distarch="$DISTARCH" disttag="$DISTNAME" specfile="$NEWSPECFILE" repotag="$TAG"
            for script in $CONFIGDIR/scripts/pre-*.sh; do
source "$script"
            done

if [ "$FORCE_VERBOSE" == "yes" ]; then
echo "Building source package $app using \"$SPECFILE\" for $dist"
            fi
BUILDCMD="/usr/bin/rpmbuild -bs \
--define \"_rpmfilename %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm\" \
--define \"_srcrpmdir $PACKAGEDIR/$app\" \
--define \"_sourcedir $SPECDIR\" \
--define \"dist .$TAG\" \
\"$NEWSPECFILE\""
            echo "$BUILDCMD" | setarch $DISTARCH /usr/sbin/chroot "$CHROOTDIR/$dist" /bin/su -lm $BUILD_USER -c "/bin/bash --login -s" &>/dev/null
            RC=$?
            if [ $RC -eq 0 ]; then
if [ "$FORCE_VERBOSE" == "yes" ]; then
echo -e "${_BELL}${_GR}Success${_DE} $app [$dist/src], file in [$PACKAGEDIR/$app/]"
                fi
echo "$app [$dist/src] ${SPECFILE/*\/}" >>/dar/log/dar-build-success.log
            else
error "${_BELL}${_RE}Failed${_DE} $app [$dist/src], see log [$SPECDIR/_buildlogs/$LOGFILE]"
                echo "$app [$dist/src] ${SPECFILE/*\/}" >>/dar/log/dar-build-failed.log
            fi

cp -au "$SPECFILE" "$PACKAGEDIR/$app/"
        done

fi
done

exit 0
Something went wrong with that request. Please try again.