Files
mambasoft d1a093e477 autodist: run update/rebuild after a spec patch keeping Version and Release
A fix-only update patch used to replace the update, so rebuild jobs kept
the published release, skipped build and send and dropped the patch.
2026-11-08 19:51:01 +01:00

1613 lines
65 KiB
Bash
Executable File

#!/bin/bash
#
# Autodist -- batch build tool for RPM based distributions
# Copyright (C) 2006-2026 by Silvan Calarco <silvan.calarco@mambasoft.it>
#
# Released under the terms of the GNU GPL release 3 license
#
. /usr/share/autodist/VERSION
me=(${0##*/} $VERSION)
BASE_REPOSITORY=base
function usage() {
echo "\
${me[0]} ${me[1]}
"$"Copyright (C) 2006-2026 Silvan Calarco <silvan.calarco@mambasoft.it>""
"$"Released under the terms of the GNU GPL v3 license"
echo "
"$"Batch build tool for bulding a whole distribution and much more.""
"$"Usage"":
$me [operations ...] [options ...] [job ...] [-- autospec_args] [--- script_args]
"$"Operations"":
-a,--autobuild "$"Start batch build operations (implies -p -u -b -s --severity 1)""
-p,--prepare "$"Prepare packages (download and prepare for update)""
-u,--update "$"Update packages""
-b,--build "$"Build packages""
-i,--install "$"Install packages on local system""
-s,--send "$"Send packages to repository""
--list-jobs "$"List configured jobs""
--list-pkgs job "$"List packages for specified job""
"$"Options"":
-c,--cleanlogs "$"Clean all logs before starting""
-d,--debug "$"Enable print of debugging information""
-h,--help "$"Print this help, then exit""
-t,--test "$"Just simulate the execution of programs""
-q,--quiet "$"Be quiet (don't display tail of error logs)""
-r,--rebuild "$"Rebuild packages""
-v,--verbose "$"Be verbose""
--force "$"Pass force parameter to autospec""
--force-install "$"Force RPM install with --nodeps (install operation only)""
--repository "$"Pass given repository as base for operations""
--repository-strict "$"Only prepare packages from base repository specified with --repository""
--server num "$"Pass given server number to autospec for send operation""
--severity num "$"Error handling level:
0: don't stop
1: skip current job on error (default)
2: abort on error""
--arch "$"Build packages for specified target architecture""
--user user "$"Pass calling user name for Webbuild social messages""
--rebuild-srpms "$"Rebuild SRPMs when sending""
job "$"Job specification in the form pkg#version, job#version, job/pkg#version, examples:
glibc#2.11.1
kernel-extra
kernel-packages/lirc""
autospec_args "$"Send specified arguments to autospec""
script_args "$"Send specified arguments to update-specfile script""
"
}
[ $# -gt 0 ] || { usage ; exit 1; }
DATE_NOW=`date +%s`
BUILDTIME=`date -Iseconds`
SYSCONFDIR=/etc/autodist
LOCALSTATEDIR=/var/autodist
[ "$USER" = "autodist" ] && USERCONFDIR=$LOCALSTATEDIR || USERCONFDIR=$HOME/.autodist
LOGBASEDIR=$USERCONFDIR/log
# per-process marker read by autodistd (see write_inprogress_marker()),
# removed on exit by every invocation, not only by autodist -a
if [ "$AUTOPORT_REPOSITORY_CONTEXT" ]; then
INPROGRESS_FILE=$LOGBASEDIR/autoport-${AUTOPORT_REPOSITORY_CONTEXT}-inprogress.$$
RUNNING_FILE=$LOGBASEDIR/autoport-${AUTOPORT_REPOSITORY_CONTEXT}-running.$$
else
INPROGRESS_FILE=$LOGBASEDIR/autoupdate-inprogress.$$
RUNNING_FILE=$LOGBASEDIR/autoupdate-running.$$
fi
trap 'rm -f "$INPROGRESS_FILE" "$RUNNING_FILE" "$AUTODISTJSON" "$LEGACYLIST" "$SCHEDULEDLIST"' EXIT
RPMTMPPATH=/var/tmp/autodist
ALL_TEMPFILES=()
SCRIPTDIR=$SYSCONFDIR/scripts
BLACKLIST=$SYSCONFDIR/blacklist
BUILDARCH=`rpm --eval %{_build_cpu}`
TARGETARCH=$BUILDARCH
CONFIGFILE=$SYSCONFDIR/config
SCRIPT_UPDATE_SPECFILE=$SCRIPTDIR/update-specfile
SCRIPT_UPDATE_SPECFILE_CUSTOM=$SCRIPTDIR/update-specfile-custom
AUTOSPEC_CMD="/usr/bin/autospec"
PIDFILE="/run/autodist/autodist.pid"
# Configuration defaults normally overriden in configuration file
AUTOBUILD_MAXNUM=50
# max rotation update checks added after scheduled jobs and rebuilds (empty: no limit)
AUTOBUILD_UPDATECHECK_MAX=
AUTOBUILD_DATEFROM=20070101
AUTODIST_REPOSITORY=
SEND_SERVER=
[ -r $CONFIGFILE ] && . $CONFIGFILE
# init environment especially to have a full PATH when executed by crond with
# system init PATH
. /etc/profile
. /etc/profile.d/*.sh
export PATH
# error handling severity: 0=don't stop; 1=skip; 2=stop
SEVERITY=1
for ((i=1; i<=$#; i++)); do
case ${!i} in
-a|--autobuild) do_autobuild=1;
do_prepare=1;
do_update=1;
do_build=1;
do_send=1;
SEVERITY=1
;;
-c|--cleanlogs) do_cleanlogs=1 ;;
-h|--help) usage
exit 0
;;
-p|--prepare) do_prepare=1 ;;
-u|--update) do_update=1 ;;
-r|--rebuild) rebuild_packages=1 ;;
-b|--build) do_build=1 ;;
-d|--debug) debug=1 ;;
-i|--install) do_install=1 ;;
-s|--send) do_send=1 ;;
-t|--test) simulate=1 ;;
-q|--quiet) quiet=1 ;;
-v|--verbose) verbose=1 ;;
--list-jobs) do_listjobs=1 ;;
--list-pkgs) do_listpkgs=1
let i+=1
[ "${!i}" ] || {
echo "Error: job parameter not given, aborting."
exit 1
}
LISTPKGSJOB="${!i}"
;;
--force) SEND_FORCE="--force"
SEND_FORCE_BUILD="--force-build"
;;
--force-install) SEND_FORCE_INSTALL="--force-install" ;;
--server) let i+=1
[ "${!i}" ] || {
echo "Error: --server parameter not given, aborting."
exit 1
}
SEND_SERVER="${!i}"
;;
--repository) let i+=1
[ "${!i}" ] || {
echo "Error: --repository parameter not given, aborting."
exit 1
}
AUTODIST_REPOSITORY="${!i}"
;;
--repository-strict)
REPOSITORY_STRICT=1
;;
--severity) let i+=1
[ "${!i}" ] || {
echo "Error: --severity parameter not given, aborting."
exit 1
}
SEVERITY=${!i}
;;
--arch) let i+=1
[ "${!i}" ] || {
echo "Error: --arch parameter not given, aborting."
exit 1
}
TARGETARCH=${!i}
;;
--user) let i+=1
[ "${!i}" ] || {
echo "Error: --user parameter not given, aborting."
exit 1
}
WEBBUILD_USER_CMDLINE="${!i}"
;;
--rebuild-srpms)
REBUILD_SRPMS=1
;;
-*) if [ "${!i}" = "--" ]; then
AUTOSPEC_ARGS_MODE=1
SCRIPT_ARGS_MODE=
elif [ "${!i}" = "---" ]; then
SCRIPT_ARGS_MODE=1
AUTOSPEC_ARGS_MODE=
elif [ "$AUTOSPEC_ARGS_MODE" ]; then
AUTOSPEC_ARGS="$AUTOSPEC_ARGS ${!i}"
elif [ "$SCRIPT_ARGS_MODE" ]; then
SCRIPT_ARGS="$SCRIPT_ARGS ${!i}"
else
echo "ERROR: invalid option \`${!i}'; aborting."
exit 1
fi
;;
*) if [ "$AUTOSPEC_ARGS_MODE" ]; then
if [ "${!i/ }" != "${!i}" ]; then
# pass multiple word arguments inside quotation marks
AUTOSPEC_ARGS="$AUTOSPEC_ARGS \"${!i}\""
else
AUTOSPEC_ARGS="$AUTOSPEC_ARGS ${!i}"
fi
elif [ "$SCRIPT_ARGS_MODE" ]; then
if [ "${!i/ }" != "${!i}" ]; then
# pass multiple word arguments inside quotation marks
SCRIPT_ARGS="$SCRIPT_ARGS \"${!i}\""
else
SCRIPT_ARGS="$SCRIPT_ARGS ${!i}"
fi
else
JOBIDX=${#JOBNAME[@]}
JOBNAME[$JOBIDX]="${!i/\#*}"
[ "${!i/*\#}" != "${!i}" ] && JOBVER[$JOBIDX]="+${!i/*\#}"
fi
;;
esac
done
if [ "$do_autobuild" ]; then
if [ -e $PIDFILE ]; then
PIDCHECK=`cat $PIDFILE`
if [ "$PIDCHECK" -a -e /proc/$PIDCHECK -a ! "$DISABLE_PID_CHECK" ]; then
echo "Error: autodist -a already running with PID=$PIDCHECK.Aborting."
exit 0
fi
fi
fi
[ "$AUTODIST_REPOSITORY" ] || AUTODIST_REPOSITORY=devel-autodist
[ "$SEND_SERVER" ] || SEND_SERVER=$AUTODIST_REPOSITORY
SEND_SERVER_CMD="--server $SEND_SERVER"
# perform arch names conversions
case $BUILDARCH in
i386|i486|i686) BUILDARCH=i586 ;;
esac
case $TARGETARCH in
i386|i486|i686) TARGETARCH=i586 ;;
esac
# for webbuild message
function cgi_encodevar() {
local string="${1}"
local strlen=${#string}
local encoded=""
for (( pos=0 ; pos<strlen ; pos++ )); do
c=${string:$pos:1}
case "$c" in
[-_.~a-zA-Z0-9] ) o="${c}" ;;
* ) printf -v o '%%%02x' "'$c"
esac
encoded+="${o}"
done
echo "${encoded}" # You can either set a return variable (FASTER)
# REPLY="${encoded}" #+or echo the result (EASIER)... or both... :p
}
function tempfile() {
local tmpfile
tmpfile=`mktemp -q -t $me.XXXXXXXX` || {
echo "ERROR: cannot create temporary files." >&2
exit 1
}
# register in ALL_TEMPFILES so the trap below cleans up every tempfile
# created so far instead of only the last one (each `trap` call replaces
# the previous handler for the same signal, it does not stack)
ALL_TEMPFILES+=("$tmpfile")
trap 'rm -f "${ALL_TEMPFILES[@]}"' 0 1 2 5 15
> $tmpfile || {
echo "ERROR: cannot write to temporary files." >&2
exit 1
}
echo $tmpfile
}
function version_find_bigger()
{
local VER1 VER2 FPOS CUTVER1 CUTVER2
autodist-vercmp $1 $2
case $? in
0) return 0 ;;
11) return 1 ;;
12) return 2 ;;
esac
echo "!! Warning: autodist-vercmp('$1','$2') returned unexpected value: $?"
return -1
}
function tail_file() {
local elapsedtime elapsedstring elapsedcount phase lastprinttime newtime begintime lines c difftimestep
c=0
lines=0
begintime=`date +%s`
lastlinetime=$begintime
lastprinttime=0
if [ "$do_autobuild" ]; then
difftimestep=1800
else
difftimestep=1
fi
while read line; do
echo "$line" >> $1
let lines+=1
newtime=`date +%s`
let difftime=$newtime-$lastprinttime
case $verbose in
1) echo "$line"
;;
*) if [ $difftime -gt $difftimestep ]; then
let c+=1
lastprinttime=$newtime
let elapsedtime=$newtime-$begintime
[ $elapsedtime -gt 0 ] && let speed=$lines/$elapsedtime
case $c in
1) phase="|" ;;
2) phase="/" ;;
3) phase="-" ;;
4) phase="\\"
let c=0 ;;
esac
elapsedstring="`expr $elapsedtime % 60`s"
elapsedcount=`expr $elapsedtime / 60`
[ $elapsedcount -gt 0 ] && elapsedstring="`expr $elapsedcount % 60`m $elapsedstring"
elapsedcount=`expr $elapsedcount / 60`
[ $elapsedcount -gt 0 ] && elapsedstring="${elapsedcount}h $elapsedstring"
[ ! "$do_autobuild" ] && echo -n -e "\r"
echo -n "$2 $phase ($lines lines, $elapsedstring, $speed l/s)"
fi
;;
esac
done
}
get_job_vector() {
local JTARGET=${1/\/*}
local JPKG=
[ "$JTARGET" != "$1" ] && JPKG="${1/*\/}"
# job names match ignoring "-", "_", "." and "@" (see autodist-jobs)
JOB=(`autodist-jobs -f $AUTODISTJSON -a $TARGETARCH vector $JTARGET`)
if [ ${#JOB[*]} -eq 0 ]; then
# create a default job with given JOB_NAME
JOB=($JTARGET "" "")
elif [ ${#JOB[*]} -eq 1 ]; then
# no variables defined, add an empty job
JOB=(${JOB[*]} "" "")
elif [ "${JPKG}" ]; then
TMPJOB=($JPKG)
for i in `seq 1 ${#JOB[*]}`; do
TMPJOB=(${TMPJOB[*]} "${JOB[$i]}")
done
JOB=(${TMPJOB[*]})
fi
JOB_PKGS=(${JOB[0]//,/ })
JOB_VARNAMES=(${JOB[1]//,/ })
}
function autobuild_log() {
local pkg=$1
local operation=$2
local result=$3
local job=$4
local logfile=$5
local op_start=$6
local op_end=$7
local version=$8
[ "$pkg" -a "$operation" -a "$result" ] || return
# "-" rather than leaving the field empty, so autoupdate-current/-last
# always have the same number of space-separated fields per line
# regardless of whether this call had a logfile/version to report --
# simpler to parse than a sometimes-4, sometimes-5+-field line.
[ "$logfile" ] || logfile=-
[ "$version" ] || version=-
# Normalize raw exit codes to "failed" so autoupdate-current/-last read
# naturally without a lookup table -- except "autoupdate"'s own 2/3/4,
# which are not failures but distinct outcomes of the version check
# itself (newer version found / unknown / already up-to-date).
if [ "$result" != "ok" -a "$result" != "skipped" ]; then
case "$operation-$result" in
autoupdate-2|autoupdate-3|autoupdate-4) ;;
*) result=failed ;;
esac
fi
# Pop $job off autoupdate-queue the first time anything gets logged for
# it, wherever it is: a job leaving the pass without a log entry must
# not keep the following ones queued. Later calls for the same job
# (already in autoupdate-current, also as "job/pkg") are no-ops.
local queue="$LOGBASEDIR/autoupdate-queue"
[ "$job" -a -e "$queue" ] &&
! awk -v j="$job" '$1 == j || index($1, j "/") == 1 { found = 1; exit } END { exit !found }' \
"$LOGBASEDIR/autoupdate-current" 2>/dev/null &&
awk -v j="$job" '!done && $1 == j { done = 1; next } 1' "$queue" > "$queue.tmp" &&
mv -f "$queue.tmp" "$queue"
if [ "$job" -a "$job" != "$pkg" ]; then
echo "$job/$pkg $operation $result $logfile $op_start $op_end $version" >> $LOGBASEDIR/autoupdate-current
else
echo "$pkg $operation $result $logfile $op_start $op_end $version" >> $LOGBASEDIR/autoupdate-current
fi
}
# Overwrites the "job/pkg operation pid" marker autodistd reads. Named
# after $$ (like autoupdate-running.$$) so a concurrent invocation
# doesn't clobber this one's marker.
function write_inprogress_marker() {
local pkg=$1 operation=$2 file=$INPROGRESS_FILE
if [ "$JOB_NAME" -a "$JOB_NAME" != "$pkg" ]; then
echo "$JOB_NAME/$pkg $operation $$" > $file
else
echo "$pkg $operation $$" > $file
fi
}
# Detects a live "autospec -u $1" for the same package under our own user
# (e.g. a manual webbuild session -- webbuild-sudo runs autospec as this
# same user for the main environment, see su -l autodist in webbuild-sudo)
# so a batch pass doesn't step on someone's in-progress manual work.
# /proc/$pid/cmdline (NUL-separated argv, matched exactly for an "-u"/pkg
# pair) is used instead of a `pgrep -f` regex against $pkg directly, since
# package names can contain regex metacharacters (+, .) that would make a
# regex match wrong or over-broad.
function autospec_running_for() {
local target_pkg=$1 pid arg prev
for pid in `pgrep -u "$(id -un)" -f autospec 2>/dev/null`; do
[ "$pid" = "$$" ] && continue
prev=
while IFS= read -r -d '' arg; do
[ "$prev" = "-u" -a "$arg" = "$target_pkg" ] && return 0
prev=$arg
done < /proc/$pid/cmdline 2>/dev/null
done
return 1
}
# first send sub-phase result per log file name: "result logfile start"
declare -A SEND_PREV
function launch_pkgs_loop() {
# This function iterates the passed operation for each package (column) in job
#
# $1: operation (prepare, update, build, send, install)
# $2: options
# $3: job variables (e.g. i386,std)
local JOB_VALUES JOB_ARGS JOB_IDX DEFINES_STRING i a PKGLINE
local cross_target_cpu autodist_crossonly operation
# evaluate job variables
JOB_VALUES=(${3//,/ })
JOB_IDX=$4
[ "$debug" = "1" ] && JOB_ARGS="--debug " || JOB_ARGS=""
[ $JOB_IDX ] || JOB_IDX=0
operation="$1"
passed_arguments="$2"
ret=0
DEFINES_STRING=""
if [ "$TARGETARCH" != "$BUILDARCH" ]; then
TARGET_PLATFORM=`rpm --target ${TARGETARCH} --eval %{_target_platform}`
JOB_ARGS="$JOB_ARGS-A \"${TARGETARCH}\" --root /usr/${TARGET_PLATFORM} "
DEFINES_STRING="--define _host_cpu=\"${TARGETARCH}\",_target_cpu=\"${TARGETARCH}\""
fi
cross_target_cpu=""
autodist_crossonly=""
patch_operation=$operation
# prepare/update pass no job values: use the job-wide setting
[ "$3" ] && continue_on_error= || continue_on_error=$JOB_CONTINUE_ON_ERROR
for i in `seq 1 ${#JOB_VALUES[*]}`; do
[ "${JOB_VALUES[$i-1]}" = "-" ] || \
case ${JOB_VARNAMES[$i-1]} in
%build_and_install)
[ "$operation" = "build" ] && operation=buildinstall
;;
%continue_on_error)
continue_on_error=1
;;
%*)
echo "!! Warning: skipping unknown internal variable: ${JOB_VARNAMES[$i-1]}"
;;
autodist_crossonly)
autodist_crossonly=1
;;
cross_target_cpu)
cross_target_cpu="${JOB_VALUES[$i-1]}"
# don't specify cross_target_cpu for non-cross-target builds
if [ "$cross_target_cpu" = "$TARGETARCH" ]; then
# set cross_target_cpu as don't use
JOB_VALUES[$i-1]="-"
else
[ "$DEFINES_STRING" ] &&
DEFINES_STRING="${DEFINES_STRING}," ||
DEFINES_STRING="--define "
DEFINES_STRING="${DEFINES_STRING}${JOB_VARNAMES[$i-1]}=$cross_target_cpu"
fi
;;
target)
# specific target build was specified, don't build packages containing explicit different target
[ "$BUILDARCH" != "$TARGETARCH" -a "${JOB_VALUES[$i-1]}" != "$TARGETARCH" ] && return 0;
JOB_ARGS="$JOB_ARGS-A \"${JOB_VALUES[$i-1]}\" "
;;
*)
if [ "${JOB_VALUES[$i-1]}" ]; then
[ "$DEFINES_STRING" ] &&
DEFINES_STRING="${DEFINES_STRING}," ||
DEFINES_STRING="--define "
DEFINES_STRING="${DEFINES_STRING}${JOB_VARNAMES[$i-1]}=${JOB_VALUES[$i-1]}"
fi
;;
esac
done
# don't build cross package for the same arch as target arch
[[ ( "$autodist_crossonly" = "1" ) && ( "$cross_target_cpu" = "$TARGETARCH" ) ]] && return 0;
JOB_ARGS="$JOB_ARGS$DEFINES_STRING"
[ "$patch_operation" = "buildinstall" ] && patch_operation=build
[ "$patch_operation" = "autoupdate" -o "$patch_operation" = "rebuild" ] && patch_operation=update
# launch loop for each package
for pkg in ${JOB_PKGS[*]}; do
if [ "$continue_on_error" ] && [[ " ${FAILED_PKGS[*]} " == *" $pkg "* ]]; then
echo "!! Warning: skipping $pkg (failed in earlier phase)."
[ "$do_autobuild" ] && autobuild_log $pkg $operation skipped $JOB_NAME "" `date +%s` `date +%s` $JOB_VER
continue
fi
if autospec_running_for "$pkg"; then
echo "!! Warning: skipping $pkg ($operation) -- autospec -u $pkg is already running."
[ "$do_autobuild" ] && autobuild_log $pkg $operation skipped $JOB_NAME "" `date +%s` `date +%s` $JOB_VER
continue
fi
# build forked by autodistd: its BUILD dir is kept for a resume
if [ -e "$LOGBASEDIR/hold/$pkg" -a "$AUTODIST_IGNORE_HOLD" != "$pkg" ]; then
echo "!! Warning: skipping $pkg ($operation) -- held by autodistd ($LOGBASEDIR/hold/$pkg)."
[ "$do_autobuild" ] && autobuild_log $pkg $operation skipped $JOB_NAME "" `date +%s` `date +%s` $JOB_VER
continue
fi
[ "$quiet" ] || echo "Job: ${pkg} (${operation})" >&2
write_inprogress_marker "$pkg" "$operation"
unset LOGFILE_SUFFIX AUTOUPDATE_SCRIPT_ALREADY_RUN
for a in ${JOB_VALUES[*]}; do
tr_job=`echo $a | tr / _`
LOGFILE_SUFFIX=${LOGFILE_SUFFIX}__$tr_job
done
LOGFILE_SUFFIX=$LOGFILE_SUFFIX.$TARGETARCH
[ "$JOB_NAME" = "${pkg}" ] &&
LOGFILE_PKG_NAME=${pkg}${LOGFILE_SUFFIX} ||
LOGFILE_PKG_NAME=${JOB_NAME}_${pkg}${LOGFILE_SUFFIX}
LOGFILE_PKG=${LOGDIR}/${LOGFILE_PKG_NAME}
# clean previous logs for this package
[ -e ${LOGDIR}/ok/${LOGFILE_PKG_NAME}${LOGFILE_SUFFIX} ] &&
rm -f ${LOGDIR}/ok/${LOGFILE_PKG_NAME}${LOGFILE_SUFFIX}
[ -e ${LOGDIR}/failed/${LOGFILE_PKG_NAME}${LOGFILE_SUFFIX} ] &&
rm -f ${LOGDIR}/failed/${LOGFILE_PKG_NAME}-${LOGFILE_SUFFIX}
case $operation in
autoupdate|update|build|rebuild|buildinstall)
[ -e $spec_dir/$pkg.spec ] || {
case $SEVERITY in
0) ;;
1) echo "!! Error: spec filename must be the same as package name or invalid job name; skipping $pkg package."
[ "$do_autobuild" ] && autobuild_log $pkg $operation 240 $JOB_NAME $LOGDIR/failed/${LOGFILE_PKG_NAME} `date +%s` `date +%s` $JOB_VER
continue ;;
*) echo "!! Error: spec filename must be the same as package name or invalid job name; aborting."
exit 1 ;;
esac
}
# apply patches
SPEC_DATE=`stat $spec_dir/$pkg.spec --printf=%y`
if [ $JOB_IDX -eq 0 -a "$do_autobuild" ]; then
# preserve specfile modification date
if [ -e $AUTOUPDATEDIR/spec-patches-$patch_operation/$pkg.spec.patch ] &&
[[ " $SPEC_PATCHED_PKGS " != *" $pkg "* ]]; then
_spec_vr=`grep -m2 -E "^(Version|Release):" $spec_dir/$pkg.spec`
echo -n "?= "
# Captured into LOGFILE_PKG, not straight into failed/: that clobbered a
# still-relevant previous attempt's log on every apply, even a clean one.
# LOGFILE_PKG moves into failed/ or ok/ as a whole once this op finishes.
patch -p1 $spec_dir/$pkg.spec $AUTOUPDATEDIR/spec-patches-$patch_operation/$pkg.spec.patch 2>&1 | tee $LOGFILE_PKG
if [ ${PIPESTATUS[0]} -ne 0 ]; then
case $SEVERITY in
0) ;;
1) echo "%! Error: could not apply patch to specfile; skipping $pkg package."
mv $LOGFILE_PKG $LOGDIR/failed/
[ "$do_autobuild" ] && autobuild_log $pkg $operation 241 $JOB_NAME $LOGDIR/failed/${LOGFILE_PKG_NAME} `date +%s` `date +%s` $JOB_VER
ret=1
continue ;;
*) echo "!! Error: could not apply patch to specfile; aborting."
exit 1 ;;
esac
fi
SPEC_PATCHED_PKGS="$SPEC_PATCHED_PKGS $pkg"
# a patch keeping Version and Release is only a fix: still run the update or rebuild
if [ "$_spec_vr" != "`grep -m2 -E "^(Version|Release):" $spec_dir/$pkg.spec`" ]; then
[ "$operation" = "update" -o "$operation" = "autoupdate" -o "$operation" = "rebuild" ] && { rm -f $LOGFILE_PKG; continue; }
elif [ "$operation" = "update" -o "$operation" = "autoupdate" -o "$operation" = "rebuild" ]; then
echo "?= Specfile patch keeps Version and Release; running $operation anyway"
rm -f $LOGFILE_PKG
fi
fi
fi
if [ -x $SCRIPT_UPDATE_SPECFILE ]; then
$SCRIPT_UPDATE_SPECFILE $spec_dir/$pkg.spec ${passed_arguments/ *} $SCRIPT_ARGS || {
case $SEVERITY in
0) ;;
1) echo "%! Error: update-specfile script returned $?; skipping $pkg package."
ret=1
continue ;;
*) echo "!! Error: update-specfile script returned $?; aborting."
exit 1 ;;
esac
}
fi
if [ -x $SCRIPT_UPDATE_SPECFILE_CUSTOM ]; then
$SCRIPT_UPDATE_SPECFILE_CUSTOM $spec_dir/$pkg.spec ${passed_arguments/ *} $SCRIPT_ARGS || {
case $SEVERITY in
0) ;;
1) echo "%! Error: update-specfile-custom script returned $?; skipping $pkg package."
ret=1
continue ;;
*) echo "!! Error: update-specfile-custom script returned $?; aborting."
exit 1 ;;
esac
}
fi
;;
esac
[ -e $spec_dir/$pkg.spec ] && {
SPEC_EPOCH=`grep -m1 "^Epoch:" $spec_dir/$pkg.spec | sed "s|Epoch:[[:space:]]*||"`
SPEC_VERSION=`grep -m1 "^Version:" $spec_dir/$pkg.spec | sed "s|Version:[[:space:]]*||"`
SPEC_RELEASE=`grep -m1 "^Release:" $spec_dir/$pkg.spec | sed "s|Release:[[:space:]]*||"`
}
[ -e "$SRCPKGLIST" ] && PKGLINE=`grep "^${pkg} " $SRCPKGLIST` || PKGLINE=
if [ "$PKGLINE" ]; then
eval "$(autodist-distroquery package $(echo "$PKGLINE" | awk '{print $2}') $pkg $TARGETARCH 2>/dev/null)"
BUILDSLINE="${pkg_builds[*]}"
else
BUILDSLINE=
fi
[ -e "$SRCPKGLIST_DELAYED" ] && PKGLINE_DELAYED=`grep "^${pkg} " $SRCPKGLIST_DELAYED` || PKGLINE_DELAYED=
if [ "$PKGLINE_DELAYED" ]; then
eval "$(autodist-distroquery package $(echo "$PKGLINE_DELAYED" | awk '{print $2}') $pkg $TARGETARCH 2>/dev/null)"
BUILDSLINE_DELAYED="${pkg_builds[*]}"
else
BUILDSLINE_DELAYED=
fi
# the delayed list includes the parents: identical lines are the same package
if [ "$PKGLINE_DELAYED" -a "$PKGLINE_DELAYED" != "$PKGLINE" ]; then
set -- $PKGLINE
_ver1=$4
_rel1=$5
set -- $PKGLINE_DELAYED
_ver2=$4
_rel2=$5
_delayed_rep=$2
version_find_bigger ${_ver1} ${_ver2}
_vercmp=$?
if [ $_vercmp -eq 2 ]; then
if [ "$REPOSITORY_STRICT" -a "$_delayed_rep" != "$AUTODIST_REPOSITORY" ]; then
echo "!! Warning: ignoring newer package from delayed repository ($_delayed_rep, ${_ver2} > ${_ver1}) due to --repository-strict"
else
PKGLINE=$PKGLINE_DELAYED
echo "!! Warning: using package from delayed repository (${_ver2} > ${_ver1})"
fi
elif [ $_vercmp -eq 0 ]; then
version_find_bigger ${_rel1} ${_rel2}
_vercmp=$?
if [ $_vercmp -eq 0 ]; then
echo "!! Warning: package with same version (${_ver1}-${_rel1}) exists in delayed repository"
elif [ $_vercmp -eq 2 ]; then
if [ "$REPOSITORY_STRICT" -a "$_delayed_rep" != "$AUTODIST_REPOSITORY" ]; then
echo "!! Warning: ignoring newer package from delayed repository ($_delayed_rep, ${_ver2}-${_rel2} > ${_ver1}-${_rel1}) due to --repository-strict"
else
echo "!! Warning: using package from delayed repository (${_ver2}-${_rel2} > ${_ver1}-${_rel1})"
PKGLINE=$PKGLINE_DELAYED
fi
fi
fi
fi
case $operation in
prepare)
command_opts="-a1"
if [ "$PKGLINE" ]; then
set -- $PKGLINE
REPNAME="$2"
if [ "$REPNAME" != "$AUTODIST_REPOSITORY" -a "$REPOSITORY_STRICT" ]; then
case $SEVERITY in
0) echo "!! Warning: package comes from $REPNAME instead of $AUTODIST_REPOSITORY" ;;
1) echo "!! Error: package comes from $REPNAME instead of $AUTODIST_REPOSITORY; skipping $pkg package."
continue ;;
*) echo "!! Error: package comes from $REPNAME instead of $AUTODIST_REPOSITORY; aborting."
exit 1 ;;
esac
fi
if [ "$REPNAME" ]; then
command_opts="$command_opts --server ${REPNAME}"
fi
else
echo "!! Warning: package $pkg is missing in source packages list"
fi
;;
rebuild) command_opts="-a4 --rebuild" ;;
autoupdate) command_opts="-a2:4" ;;
update)
# skip package in job if up to date
if [ "$PKGLINE" ]; then
set -- $PKGLINE
pkglinever=$4
pkglinerel=$5
# detect specfile/repository mismatch: spec may already be ahead of the
# repository (e.g. during a repository import or after a partial build);
# in that case bumping version/release via autospec -u would produce a
# wrong release tag, so skip the package and warn.
if [ "$SPEC_VERSION" -a "$SPEC_RELEASE" -a \
"$SPEC_VERSION-$SPEC_RELEASE" != "$pkglinever-$pkglinerel" ]; then
echo "!! Warning: skipping ${pkg} package: specfile ($SPEC_VERSION-$SPEC_RELEASE) does not match repository ($pkglinever-$pkglinerel); possible repository transition."
[ "$do_autobuild" ] && autobuild_log $pkg $operation skipped $JOB_NAME "" `date +%s` `date +%s` $JOB_VER
continue
fi
# warning: assuming version is passed first
version_find_bigger "${passed_arguments/ *}" "$pkglinever"
[ $? -eq 1 ] || {
echo "!! Warning: skipping ${pkg} package already up to date ($pkglinever >= ${passed_arguments/ *})."
# echo "%% Adding ${pkg} job to skipped list."
# echo "${pkg} $DATE_NOW 255" >> $SKIPPEDLISTDIR/auto.skip
[ "$do_autobuild" ] && autobuild_log $pkg $operation skipped $JOB_NAME "" `date +%s` `date +%s` $JOB_VER
continue
}
fi
if [ -e $source_dir/$pkg-autoupdate ]; then
echo "?= Running $pkg-autoupdate script with version ${passed_arguments/ *}"
(cd $source_dir; sh ./$pkg-autoupdate ${passed_arguments/ *} >/dev/null)
AUTOUPDATE_SCRIPT_ALREADY_RUN=1
fi
command_opts="-a3:4" ;;
build)
# skip package in job if it is in the repository chain up to the delayed repository
if [ "$PKGLINE_DELAYED" -a "$BUILDSLINE_DELAYED" -a "$do_autobuild" ]; then
set -- $PKGLINE_DELAYED
if [ "$SPEC_VERSION-$SPEC_RELEASE" = "$4-$5" ]; then
echo "!! Warning: skipping ${pkg} package build because $4-$5 is already in the repository chain ($2)."
echo "%% Adding ${pkg} job to skipped list."
echo "${pkg} $DATE_NOW 254" >> $SKIPPEDLISTDIR/auto.skip
[ "$do_autobuild" ] && autobuild_log $pkg $operation skipped $JOB_NAME "" `date +%s` `date +%s` $JOB_VER
continue
fi
fi
# skip package if binary packages at the same version already exist in the target repository
if [ ! "$SEND_FORCE_BUILD" -a "$PKGLINE" -a "$BUILDSLINE" ]; then
set -- $PKGLINE
if [ "$SPEC_VERSION-$SPEC_RELEASE" = "$4-$5" ]; then
case $SEVERITY in
0) echo "!! Warning: skipping ${pkg} build because $SPEC_VERSION-$SPEC_RELEASE already exists in repository."
[ "$do_autobuild" ] && autobuild_log $pkg $operation skipped $JOB_NAME "" `date +%s` `date +%s` $JOB_VER
continue ;;
1) echo "%! Error: skipping ${pkg} build because $SPEC_VERSION-$SPEC_RELEASE already exists in repository; subsequent operations will be skipped."
[ "$do_autobuild" ] && autobuild_log $pkg $operation 242 $JOB_NAME "" `date +%s` `date +%s` $JOB_VER
ret=1
continue ;;
*) echo "!! Error: ${pkg} $SPEC_VERSION-$SPEC_RELEASE already exists in repository; aborting."
exit 1 ;;
esac
fi
fi
command_opts="-a5:6 -b" ;;
buildsrpm)
command_opts="-a5:6 --norpm" ;;
buildinstall)
# skip package in job if up to date
if [ "$PKGLINE" -a "$BUILDSLINE" ]; then
set -- $PKGLINE
pkglinever=$4
pkglinerel=$5
# warning: assuming version is passed first
version_find_bigger "$SPEC_VERSION" "$pkglinever"
[ $? -eq 0 ] && {
version_find_bigger "$SPEC_RELEASE" "$pkglinerel"
if [ $? -ne 1 ]; then
echo "!! Warning: skipping ${pkg} package already up to date ($SPEC_VERSION-$SPEC_RELEASE >= $pkglinever-$pkglinerel)."
continue
fi
}
fi
# skip package in job if it is in the repository chain up to the delayed repository
if [ "$PKGLINE_DELAYED" -a "$BUILDSLINE_DELAYED" -a "$do_autobuild" ]; then
set -- $PKGLINE_DELAYED
if [ "$SPEC_VERSION-$SPEC_RELEASE" = "$4-$5" ]; then
echo "!! Warning: skipping ${pkg} package build because $4-$5 is already in the repository chain ($2)."
continue
fi
fi
command_opts="-a5,6,10,11 --force-install" ;;
send)
# skip package in job if up to date
if [ "$PKGLINE" -a "$BUILDSLINE" -a "$do_autobuild" ]; then
set -- $PKGLINE
pkglinever=$4
pkglinerel=$5
# warning: assuming version is passed first
version_find_bigger "$SPEC_VERSION" "$pkglinever"
[ $? -eq 0 ] && {
version_find_bigger "$SPEC_RELEASE" "$pkglinerel"
if [ $? -ne 1 ]; then
echo "!! Warning: skipping ${pkg} package already up to date ($SPEC_VERSION-$SPEC_RELEASE >= $pkglinever-$pkglinerel)."
continue
fi
}
fi
# skip package in job if it is in the repository chain up to the delayed repository
if [ "$PKGLINE_DELAYED" -a "$BUILDSLINE_DELAYED" -a "$do_autobuild" ]; then
set -- $PKGLINE_DELAYED
if [ "$SPEC_VERSION-$SPEC_RELEASE" = "$4-$5" ]; then
echo "!! Warning: skipping ${pkg} package send because $4-$5 is already in the repository chain ($2)."
continue
fi
fi
# skip package if src.rpm already exists in any repository
if [ ! "$SEND_FORCE" ]; then
srpm_name="${pkg}-${SPEC_VERSION}-${SPEC_RELEASE}.src.rpm"
srpm_already_exists=
for r in ${AUTODIST_REPOSITORIES[*]}; do
[ "$r" = "${SEND_SERVER}" ] && continue
if curl -f -s -o /dev/null -I "$REPS_BASE_URL/$r/SRPMS.base/$srpm_name"; then
echo "!! Warning: skipping ${pkg} send because $srpm_name already exists in repository $r."
srpm_already_exists=1
break
fi
done
[ "$srpm_already_exists" ] && continue
fi
command_opts="-a10" ;;
install) command_opts="-a11" ;;
*)
echo "!! Internal error: unknown operation $operation; aborting."
exit 1
;;
esac
command="$AUTOSPEC_CMD -u $pkg $command_opts $passed_arguments $JOB_ARGS"
OP_START=`date +%s`
# AUTOPORT_REPOSITORY_CONTEXT is set by autoport around each `autodist`
# sub-invocation it makes (prepare/update/build/install), so the live
# tail file names itself after who it actually belongs to instead of
# a bare PID -- multiple of these (plus the main autoupdate batch)
# can be alive at once in the same shared $LOGBASEDIR, all writing
# generically-named current.$$ files otherwise, with nothing besides
# walking /proc to tell them apart.
tmpfile=$RUNNING_FILE
> $tmpfile
tmpfile1=`tempfile`
echo -n "== "`log_date`" $JOB_NAME with args: $JOB_ARGS..." >> $LOGFILE
echo "
=> $command" >> $LOGFILE_PKG
[ "$verbose" ] && echo "== "`log_date`" $JOB_NAME with args: $JOB_ARGS...
=> $command"
if [ "$simulate" ]; then
echo "Command: $command"
else
# eval "$command 2>&1 && echo '0'>$tmpfile1 || echo '1'>$tmpfile1" | tail_file $tmpfile "== $pkg (${JOB_VALUES[*]})..."
(export LANG=en_US.UTF-8; $command 2>&1; echo $? >$tmpfile1) | tail_file $tmpfile "== $pkg (${JOB_VALUES[*]})..."
ret=`cat $tmpfile1 2>/dev/null`
rm -f $tmpfile1
# missing/empty exit status (e.g. disk full) must not be taken as success
[[ "$ret" =~ ^[0-9]+$ ]] || {
echo "autodist: cannot read exit status of $operation for $pkg (disk full?)" >&2
ret=1
}
OP_END=`date +%s`
# "send" runs twice per package (binaries, then sources) writing the
# same log file: append to the first call's log instead of overwriting it.
if [ "$operation" = "send" -a "${SEND_PREV[$LOGFILE_PKG_NAME]}" ]; then
read -r send_prevresult send_prevlogfile send_prevstart <<< "${SEND_PREV[$LOGFILE_PKG_NAME]}"
unset "SEND_PREV[$LOGFILE_PKG_NAME]"
if [ -r "$send_prevlogfile" ]; then
cat "$send_prevlogfile" "$LOGFILE_PKG" > "${LOGFILE_PKG}.merge" &&
mv "${LOGFILE_PKG}.merge" "$LOGFILE_PKG"
rm -f "$send_prevlogfile"
fi
[ "$send_prevresult" != "ok" ] && ret=1
OP_START=$send_prevstart
# one autoupdate-current entry for both sub-phases
if [ "$do_autobuild" ]; then
send_merge_key=$pkg
[ "$JOB_NAME" -a "$JOB_NAME" != "$pkg" ] && send_merge_key="$JOB_NAME/$pkg"
sed -i "\|^$send_merge_key send |d" "$LOGBASEDIR/autoupdate-current"
fi
fi
cat $tmpfile >> $LOGFILE_PKG
if [ $ret -gt 0 ]; then
echo " FAILED (ret=$ret)"
echo " FAILED (ret=$ret)" >> $LOGFILE
[ ! "$quiet" -a ! "$verbose" ] && {
echo "=> $command"
echo
echo " == begin of output log =="
echo
tail -n 40 $tmpfile
echo
echo " == end of output log =="
echo
}
mv $LOGFILE_PKG $LOGDIR/failed/
echo "?= See $LOGDIR/failed/${LOGFILE_PKG_NAME}"
[ "$operation" = "send" ] && SEND_PREV[$LOGFILE_PKG_NAME]="$ret $LOGDIR/failed/$LOGFILE_PKG_NAME $OP_START"
[ "$do_autobuild" ] && autobuild_log $pkg $operation $ret $JOB_NAME $LOGDIR/failed/${LOGFILE_PKG_NAME} $OP_START $OP_END $JOB_VER
[ $SEVERITY -gt 0 -a ! "$continue_on_error" ] && {
rm -f $tmpfile
return $ret
}
if [ "$continue_on_error" ]; then
case $operation in
prepare|autoupdate|update|rebuild)
FAILED_PKGS+=($pkg) ;;
esac
fi
else
echo
echo " OK" >> $LOGFILE
mv $LOGFILE_PKG $LOGDIR/ok/
echo "?= See $LOGDIR/ok/${LOGFILE_PKG_NAME}"
[ "$operation" = "send" ] && SEND_PREV[$LOGFILE_PKG_NAME]="ok $LOGDIR/ok/$LOGFILE_PKG_NAME $OP_START"
[ "$do_autobuild" ] && autobuild_log $pkg $operation ok $JOB_NAME $LOGDIR/ok/${LOGFILE_PKG_NAME} $OP_START $OP_END $JOB_VER
case $operation in
prepare)
[ -e $spec_dir/.$pkg.spec.autodist.prebuild ] && \
rm -f $spec_dir/.$pkg.spec.autodist.prebuild
cp $spec_dir/$pkg.spec $spec_dir/.$pkg.spec.autodist.preupdate
# detect specfile/repository mismatch after fetch: the SRPM in the
# repository may have been updated mid-import, so the freshly
# downloaded specfile can be ahead of the SRCPKGLIST snapshot;
# warn so the upcoming update phase skip is expected.
if [ "$PKGLINE" ]; then
SPEC_VERSION=`grep -m1 "^Version:" $spec_dir/$pkg.spec | sed "s|Version:[[:space:]]*||"`
SPEC_RELEASE=`grep -m1 "^Release:" $spec_dir/$pkg.spec | sed "s|Release:[[:space:]]*||"`
set -- $PKGLINE
if [ "$SPEC_VERSION-$SPEC_RELEASE" != "$4-$5" ]; then
echo "!! Warning: fetched specfile ($SPEC_VERSION-$SPEC_RELEASE) does not match repository snapshot ($4-$5) for $pkg; possible repository transition."
fi
fi
;;
rebuild)
cp $spec_dir/$pkg.spec $spec_dir/.$pkg.spec.autodist.prebuild
;;
update|autoupdate)
cp $spec_dir/$pkg.spec $spec_dir/.$pkg.spec.autodist.prebuild
SPEC_EPOCH=`grep -m1 "^Epoch:" $spec_dir/$pkg.spec | sed "s|Epoch:[[:space:]]*||"`
SPEC_VERSION=`grep -m1 "^Version:" $spec_dir/$pkg.spec | sed "s|Version:[[:space:]]*||"`
SPEC_RELEASE=`grep -m1 "^Release:" $spec_dir/$pkg.spec | sed "s|Release:[[:space:]]*||"`
if [ "$PKGLINE" ]; then
set -- $PKGLINE
echo "?= Specfile updated from version $4-$5 to $SPEC_VERSION-$SPEC_RELEASE"
if [ "`echo $SPEC_VERSION | grep -i alpha`" -o \
"`echo $SPEC_VERSION | grep -i beta`" -o \
"`echo $SPEC_VERSION | grep -i rc`" -o \
"`echo $SPEC_VERSION | grep -i pre`" -o \
"`echo $SPEC_VERSION | grep -i pl`" ]; then
if [ ! "`echo $4 | grep -i alpha`" -a \
! "`echo $4 | grep -i beta`" -a \
! "`echo $4 | grep -i rc`" -a \
! "`echo $4 | grep -i pre`" -a \
! "`echo $4 | grep -i pl`" ]; then
echo "!! Looks like an update to an unstable release; skipping."
[ $SEVERITY -gt 0 ] && {
rm -f $tmpfile
return 3
}
fi
fi
if [ "$4" != "$SPEC_VERSION" -a -e $source_dir/$pkg-autoupdate -a ! "$AUTOUPDATE_SCRIPT_ALREADY_RUN" ]; then
echo "?= Running $pkg-autoupdate script with version ${passed_arguments/ *}"
(cd $source_dir; sh ./$pkg-autoupdate ${passed_arguments/ *} >/dev/null)
AUTOUPDATE_SCRIPT_ALREADY_RUN=1
fi
fi
;;
buildinstall|send)
if [ $JOB_IDX -eq $JOB_LAST -a "$do_autobuild" ]; then
# remove specfile patches
autodist-tool makepatch $pkg remove
# remove new patches added in sources
PATCHES=`diff $spec_dir/$pkg.spec $spec_dir/.$pkg.spec.autodist.preupdate | grep "> Patch" | sed "s|.*[[:space:]]\([^[:space:]]*\)|\1|"`
for p in $PATCHES; do
[ -e $SOURCESDIR/$p ] && rm -f $SOURCESDIR/$p
done
fi
if [ "$operation" = "buildinstall" -o "${passed_arguments/--norpm}" != "${passed_arguments}" ]; then
# send operation: check for --norpm (source send) to avoid sending notification twice
SPEC_VERSION=`grep -m1 "^Version:" $spec_dir/$pkg.spec | sed "s|Version:[[:space:]]*||"`
[ "$WEBBUILD_USER" -a "$DISTROQUERY_API_URL" ] && {
if [ "$WEBBUILD_USER_CMDLINE" ]; then
autodist-distroquery social-log post "$WEBBUILD_USER" \
"(invoked by $WEBBUILD_USER_CMDLINE) sent <b>$pkg $SPEC_VERSION-$SPEC_RELEASE</b> for ${TARGETARCH} to <b>$SEND_SERVER</b>" \
"" "" "false" "$WEBBUILD_EMAIL" 2>/dev/null
else
autodist-distroquery social-log post "$WEBBUILD_USER" \
"sent <b>$pkg $SPEC_VERSION-$SPEC_RELEASE</b> for ${TARGETARCH} to <b>$SEND_SERVER</b>" \
"" "" "false" "$WEBBUILD_EMAIL" 2>/dev/null
fi
}
fi
;;
esac
fi
rm -f $tmpfile
fi
done
return $ret
}
function launch_job_loop() {
# Iterates launch_pkgs_loop for each of the lines of current job
# (defined from JOB_FIRST to JOB_LAST)
# This is needed for build, send and install operations
numerr=0
for j in `seq $JOB_FIRST $JOB_LAST`; do
launch_pkgs_loop "$1" "$2" "${JOBS[$j]}" $j
if [ $? -gt 0 ]; then
numerr=$(($numerr + 1))
[ "$continue_on_error" ] || return $numerr;
fi
done
return $numerr
}
function log_date() {
echo -n `date +%Y%m%d@%H%M%S`
}
[ -e $LOGBASEDIR ] || {
mkdir -p $LOGBASEDIR/prepare/{ok,failed}
mkdir -p $LOGBASEDIR/update/{ok,failed}
mkdir -p $LOGBASEDIR/build/{ok,failed}
mkdir -p $LOGBASEDIR/install/{ok,failed}
mkdir -p $LOGBASEDIR/send/{ok,failed}
}
#
# Main
#
# jobs, legacy list etc. from the distroquery API, saved once for the whole run
AUTODISTJSON=`mktemp -q -t $me.XXXXXXXX`
autodist-jobs dump > $AUTODISTJSON || {
echo "!! Error: unable to get the autodist configuration from the API; aborting." >&2
exit 1
}
if [ "$do_listjobs" ]; then
autodist-jobs -f $AUTODISTJSON -a $TARGETARCH list
exit 0
fi
if [ "$do_listpkgs" ]; then
autodist-jobs -f $AUTODISTJSON -a $TARGETARCH packages $LISTPKGSJOB || echo ${LISTPKGSJOB/\/*}
exit 0
fi
eval `autospec -q --eval="srpms_dir"`
eval `autospec -q --eval="rpms_dir"`
eval `autospec -q --eval="spec_dir"`
eval `autospec -q --eval="source_dir"`
eval `autospec -q --eval="tmppath_dir"`
for a in $LOGBASEDIR/{,prepare/{,ok,failed},update/{,ok,failed},build/{,ok,failed},install/{,ok,failed},send/{,ok,failed}}; do
[ ! -w $a ] && {
echo "!! Error: directory $a is missing or read-only; aborting."
exit 1
}
[ "$do_cleanlogs" ] && {
find $a -type f -exec rm -f {} \;
}
done
AUTOUPDATEDIR=${LOCAL_REPS_BASE_DIR}/$AUTODIST_REPOSITORY/autoupdate/
[ -r $AUTOUPDATEDIR ] || {
AUTOUPDATEDIR=$USERCONFDIR/$AUTODIST_REPOSITORY/autoupdate
mkdir -p $AUTOUPDATEDIR
}
SOURCESDIR=$AUTOUPDATEDIR/sources/
SUCCESSLISTDIR=$AUTOUPDATEDIR
SKIPPEDLISTDIR=$AUTOUPDATEDIR
SRCPKGLIST=`tempfile`
autodist-distroquery repository-srclist $AUTODIST_REPOSITORY > "$SRCPKGLIST" || \
echo "Warning: unable to fetch source packages list for $AUTODIST_REPOSITORY">&2
if [ "$AUTODIST_DELAYED_REPOSITORY" ]; then
SRCPKGLIST_DELAYED=`tempfile`
autodist-distroquery repository-srclist $AUTODIST_DELAYED_REPOSITORY > "$SRCPKGLIST_DELAYED" || \
echo "Warning: unable to fetch source packages list for $AUTODIST_DELAYED_REPOSITORY">&2
fi
LEGACYLIST=`mktemp -q -t $me.XXXXXXXX`
autodist-jobs -f $AUTODISTJSON legacy > $LEGACYLIST
echo "%% Autodist started with PID $$ @ `LANG=C date`"
# autobuild: add jobs ordered by oldest builds
if [ "$do_autobuild" = "1" ]; then
# clean up PIDFILE plus every tempfile registered so far (not just
# SRCPKGLIST/SRCPKGLIST_DELAYED by name), since srctmpfile/pkgtmpfile
# are created after this trap is installed
trap 'rm -f "$PIDFILE" "${ALL_TEMPFILES[@]}"; exit 1' SIGQUIT SIGINT SIGKILL SIGTERM
# autoupdate-queue tracks not-yet-started jobs (see autobuild_log() and
# the main jobs loop below); remove it however this process ends, so a
# stale file never survives to be misread by a later run or by
# autodistd. Covers normal exit and any exit() call the script makes on
# error, plus the exit 1 from the trap above -- can't cover a bare
# SIGKILL from outside, nothing can.
trap 'rm -f "$LOGBASEDIR/autoupdate-queue" "$INPROGRESS_FILE" "$RUNNING_FILE" "$AUTODISTJSON" "$LEGACYLIST" "$SCHEDULEDLIST"' EXIT
echo $$ > $PIDFILE
[ -s "$SRCPKGLIST" ] || {
echo "ERROR: empty or missing sources packages list for $AUTODIST_REPOSITORY; aborting."
exit 1
}
# jobs scheduled by hand (autodist-tool schedule, the web editor): "JOB [VERSION]"
SCHEDULEDLIST=`mktemp -q -t $me.XXXXXXXX`
autodist-jobs scheduled > $SCHEDULEDLIST || {
echo "!! Error: unable to get the scheduled jobs from the API; aborting." >&2
exit 1
}
srctmpfile=`tempfile`
{ awk '{print $1, "+" ($2 == "" ? "0" : $2), "0"}' $SCHEDULEDLIST; cat $AUTOUPDATEDIR/*.in 2>/dev/null; } |
awk '{print $1, "-", "0", $2, "-", $3}' > $srctmpfile
# order by latest build, the one in the delayed repository included
if [ -s "$SRCPKGLIST_DELAYED" ]; then
awk 'NR==FNR { d[$1]=$6; next } d[$1] > $6 { $6=d[$1] } 1' "$SRCPKGLIST_DELAYED" "$SRCPKGLIST"
else
cat $SRCPKGLIST
fi | sort --key=6 >> $srctmpfile
pkgtmpfile=`tempfile`
[ "$pkgtmpfile" ] || {
echo "ERROR: cannot create temporary files; aborting."
exit 1
}
## when autobuilding always rebuild packages
#SEND_FORCE_BUILD="--force-build"
AUTOBUILD_NUMADDED=0
BUILDDATE=0
PKGCOUNT=`wc -l $srctmpfile | awk '{ print $1 }'`
SKIPPEDCOUNT=0
BLACKLISTCOUNT=0
SUCCESSLISTCOUNT=0
REBUILDOLDCOUNT=0
UPDATECHECKCOUNT=0
> $pkgtmpfile
# cat $srctmpfile | sort --key=3 | \
while read line; do
set -- $line
PKGNAME=${1}
SOURCEREP=${2}
EPOCH=${3}
VERSION=${4}
RELEASE=${5}
BUILDDATE=${6}
# skip duplicates
grep "^$PKGNAME " $pkgtmpfile >/dev/null && continue
# check blacklist
awk '{ print $1 }' $BLACKLIST | grep "^$PKGNAME$" >/dev/null && {
BLACKLISTCOUNT=`expr $BLACKLISTCOUNT + 1`
# echo "?= Job $PKGNAME is in the blacklist; skipping"
continue
}
if [ "${VERSION:0:1}" != "+" ]; then
if [ $REBUILDOLDCOUNT -lt $AUTODIST_REBUILDOLD_MAX -a $BUILDDATE -ge $AUTODIST_REBUILDOLD_FROMDATE ]; then
# rebuilt oldest packages
REBUILDOLDCOUNT=$(($REBUILDOLDCOUNT + 1))
VERSION=+0
else
# rotation update checks: stop once both their limit and rebuild-old are reached
if [ "$AUTOBUILD_UPDATECHECK_MAX" ] && [ $UPDATECHECKCOUNT -ge $AUTOBUILD_UPDATECHECK_MAX ]; then
[ $REBUILDOLDCOUNT -ge $AUTODIST_REBUILDOLD_MAX ] && break
continue
fi
# check skippedlist (but ignore for scheduled updates)
SKIPPEDLINE=`awk '{ print $1" "$2 }' $SKIPPEDLISTDIR/*.skip | grep -m1 "^$PKGNAME "`
if [ "$SKIPPEDLINE" ]; then
set -- $SKIPPEDLINE
SKIPPEDTIME=$2
SKIPPEDDAYS=`expr \( $DATE_NOW - $SKIPPEDTIME \) / 86400`
if [ "$SKIPPEDDAYS" -le "$AUTOBUILD_SKIP_DAYS" ]; then
SKIPPEDCOUNT=`expr $SKIPPEDCOUNT + 1`
#echo "?= Package $PKGNAME has been in the skippedlist for $SKIPPEDDAYS days; skipping"
continue
else
sed -i "/^$PKGNAME /d" $SKIPPEDLISTDIR/*.skip
fi
fi
fi
fi
if [ "${VERSION:0:1}" != "+" ]; then
# check legacylist
awk '{ print $1 }' $LEGACYLIST | grep "^$PKGNAME$" >/dev/null && {
echo "?= Job $PKGNAME is in the legacy list; skipping automatic update"
echo "$PKGNAME $DATE_NOW 100" >> $SKIPPEDLISTDIR/auto.skip
continue
}
fi
# manually or from lists scheduled jobs
if [ "${VERSION:0:1}" == "+" -a "$VERSION" != "+0" ]; then
TRVER=`echo ${VERSION:1} | tr - .`
get_job_vector $PKGNAME
NEED_REBUILD=0
if [ ${#JOB_PKGS[*]} -gt 1 ]; then
# jobs are not fully rebuilt
for j in ${JOB_PKGS[*]}; do
REPVER=`grep "^$j " $SRCPKGLIST | gawk '{ print $4 }'`
version_find_bigger "$TRVER" "$REPVER"
[ $? -eq 1 ] && NEED_REBUILD=1
done
else
# single packages are rebuilt if scheduled
NEED_REBUILD=1
fi
if [ "$NEED_REBUILD" = "0" ]; then
echo "?= Job $PKGNAME is already up to date; skipping"
continue
fi
elif [ "$VERSION" != "+0" ]; then
# check successlist
SUCCESSLINE=`awk '{ print $1" "$2 }' $SUCCESSLISTDIR/*.success | grep -m1 "^$PKGNAME "`
if [ "$SUCCESSLINE" ]; then
set -- $SUCCESSLINE
SUCCESSTIME=$2
[ "$SUCCESSTIME" ] || SUCCESSTIME=0
SUCCESSDAYS=`expr \( $DATE_NOW - $SUCCESSTIME \) / 86400`
if [ "$SUCCESSDAYS" -le "$AUTOBUILD_SUCCESS_DAYS" ]; then
SUCCESSLISTCOUNT=`expr $SUCCESSLISTCOUNT + 1`
#echo "?= Job $PKGNAME has been in the successlist for $SUCCESSDAYS days; skipping"
continue
else
sed -i "/^$PKGNAME /d" $SUCCESSLISTDIR/*.success
fi
fi
fi
[ $AUTOBUILD_NUMADDED -ge $AUTOBUILD_MAXNUM ] && break
# FIXME: hardcoded skipped packages
#[ "${PKGNAME:0:5}" = "java-" -o "${PKGNAME:0:7}" = "apache-" -o \
# "${PKGNAME:0:8}" = "jakarta-" -o "${PKGNAME:0:6}" = "compiz" ] && continue
if [ $BUILDDATE -ge $AUTOBUILD_DATEFROM -o $BUILDDATE -eq 0 ]; then
AUTOBUILD_NUMADDED=`expr $AUTOBUILD_NUMADDED + 1`
[ "${VERSION:0:1}" != "+" ] && UPDATECHECKCOUNT=$(($UPDATECHECKCOUNT + 1))
echo "$PKGNAME $VERSION" >> $pkgtmpfile
fi
done < $srctmpfile
echo "%% Total pkgs: $PKGCOUNT, skipped list: $SKIPPEDCOUNT, blacklist: $BLACKLISTCOUNT, success list: $SUCCESSLISTCOUNT, rebuild-old list: $REBUILDOLDCOUNT, update checks: $UPDATECHECKCOUNT, last build date: $BUILDDATE"
while read line; do
set -- $line
PKGNAME=${1}
VERSION=${2}
JOBVER[${#JOBNAME[@]}]=$VERSION
JOBNAME[${#JOBNAME[@]}]=$PKGNAME
done < $pkgtmpfile
echo -n "%% autoupdate jobs: "
# autoupdate-queue mirrors this same list, one "name version" per line
# (same order), for autodistd/API consumers that want the pending queue
# without parsing this log line -- see autobuild_log() for where each
# entry gets popped off once its job has real progress to show.
> $LOGBASEDIR/autoupdate-queue
for i in `seq 1 ${#JOBNAME[@]}`; do
echo -n "${JOBNAME[$i-1]}(${JOBVER[$i-1]}) "
echo "${JOBNAME[$i-1]} ${JOBVER[$i-1]}" >> $LOGBASEDIR/autoupdate-queue
done
echo
rm -f $pkgtmpfile $srctmpfile
[ -e $LOGBASEDIR/autoupdate-current ] && mv $LOGBASEDIR/autoupdate-current $LOGBASEDIR/autoupdate-last
fi
OPERATION_ERRORS=0
echo "%% ${#JOBNAME[*]} job(s) scheduled"
echo "%% Starting main jobs loop"
# analyze a finished job's new failures with the configured AI agent, if any;
# failures already analyzed before are left to agent_end_of_pass()
function agent_for_job() {
[ "$do_autobuild" = "1" -a "$1" ] && type -p autodist-agent >/dev/null || return 0
autodist-agent --mode update --job "$1" --pass "$BUILDTIME" --new-only
}
# spend the agent runs left in this pass on the deferred failures, in queue order
function agent_end_of_pass() {
[ "$do_autobuild" = "1" ] && type -p autodist-agent >/dev/null || return 0
autodist-agent --mode update --pass "$BUILDTIME"
}
AGENT_PREV_JOB=
for JOB_NUM in `seq 1 ${#JOBNAME[*]}`; do
# previous job is done here, however it ended (several paths `continue`)
agent_for_job "$AGENT_PREV_JOB"
JOB_NAME=${JOBNAME[$JOB_NUM-1]}
JOB_VER=${JOBVER[$JOB_NUM-1]}
JOB_VER=`echo $JOB_VER | tr - .`
# resolve JOB_NAME from autodist.json
get_job_vector $JOB_NAME
JOB_NAME=${JOB_NAME/*\/}
AGENT_PREV_JOB=$JOB_NAME
[ "$quiet" ] || echo "== =======================$JOB_NAME============================="
SPEC_PATCHED_PKGS=
echo -n "%% Doing $JOB_NAME (VER=$JOB_VER"
for k in ${JOB_VARNAMES[*]}; do
echo -n " %${k}"
done
echo ") job"
DATE_NOW=`date +%s`
FAILED_PKGS=()
JOBS=()
for k in `seq 3 ${#JOB[*]}`; do
JOBS=(${JOBS[*]} "${JOB[$k-1]}")
done
# %continue_on_error from the first job line, for phases not run per job line
JOB_CONTINUE_ON_ERROR=
JOB_FIRST_VALUES=(${JOBS[0]//,/ })
for k in `seq 1 ${#JOB_VARNAMES[*]}`; do
[ "${JOB_VARNAMES[$k-1]}" = "%continue_on_error" -a "${JOB_FIRST_VALUES[$k-1]}" \
-a "${JOB_FIRST_VALUES[$k-1]}" != "-" ] && JOB_CONTINUE_ON_ERROR=1
done
JOB_NUMBER=${#JOBS[*]}
JOB_FIRST=0
JOB_LAST=`expr $JOB_NUMBER - 1`
if [ "$do_prepare" ]; then
LOGDIR=$LOGBASEDIR/prepare
LOGFILE=$LOGDIR/last
> $LOGFILE
echo "%% Starting PREPARE operation @ `LANG=C date`"
echo "%% "`log_date`" Starting PREPARE operation" > $LOGFILE
launch_pkgs_loop prepare "$AUTOSPEC_ARGS" || {
if [ ! "$continue_on_error" ]; then
case $SEVERITY in
0) ;;
1) echo "%! Error during package prepare; skipping $JOB_NAME job."
OPERATION_ERRORS=`expr $OPERATION_ERRORS + 1`
continue ;;
*) echo "!! Error during package prepare; aborting."
exit 255 ;;
esac
fi
}
if [ ! "$do_update" -a "$do_autobuild" = "1" ]; then
[ "${AUTOSPEC_ARGS/--changelog}" = "${AUTOSPEC_ARGS}" ] &&
AUTOSPEC_CHANGELOG="--changelog \"automatic rebuild by autodist\"" || AUTOSPEC_CHANGELOG=
launch_pkgs_loop rebuild "$AUTOSPEC_ARGS $AUTOSPEC_CHANGELOG" || {
if [ ! "$continue_on_error" ]; then
case $SEVERITY in
0) ;;
1) echo "%! Error during package update for rebuild; skipping $JOB_NAME job."
OPERATION_ERRORS=`expr $OPERATION_ERRORS + 1`
continue ;;
*) echo "!! Error during package update for rebuild; aborting."
exit 255 ;;
esac
fi
}
fi
fi
if [ "$do_update" ]; then
LOGDIR=$LOGBASEDIR/update
LOGFILE=$LOGDIR/last
echo "%% Starting UPDATE operation @ `LANG=C date`"
echo "%% "`log_date`" Starting UPDATE operation" > $LOGFILE
if [ "${JOB_VER:0:1}" != "+" -o "${JOB_VER}" = "+0" ]; then
ret=1
# don't update when --rebuild is passed
if [ ! "$rebuild_packages" ]; then
# check legacylist
awk '{ print $1 }' $LEGACYLIST | grep "^$JOB_NAME$" >/dev/null && {
echo "?= Job $JOB_NAME is in the legacy list; forcing rebuild"
} || {
[ "${AUTOSPEC_ARGS/--changelog}" = "${AUTOSPEC_ARGS}" ] &&
AUTOSPEC_CHANGELOG="--changelog \"automatic update by autodist\"" || AUTOSPEC_CHANGELOG
launch_pkgs_loop autoupdate "$AUTOSPEC_ARGS $AUTOSPEC_CHANGELOG $SEND_FORCE"
ret=$?
}
fi
if [ $ret != 0 ]; then
if [ ! "$continue_on_error" ]; then
if [ ! "$rebuild_packages" -a "${JOB_VER}" != "+0" ]; then
[ $ret -ge 2 -a "$do_autobuild" ] && {
echo "%% Adding $JOB_NAME job to skipped list."
echo "$JOB_NAME $DATE_NOW $ret" >> $SKIPPEDLISTDIR/auto.skip
}
case $SEVERITY in
0) ;;
1) echo "%! Error during package update; skipping $JOB_NAME job."
OPERATION_ERRORS=`expr $OPERATION_ERRORS + 1`
continue ;;
*) echo "!! Error during package update; aborting."
exit 255 ;;
esac
else
echo "%% Rebuilding package(s)"
[ "${AUTOSPEC_ARGS/--changelog}" = "${AUTOSPEC_ARGS}" ] &&
AUTOSPEC_CHANGELOG="--changelog \"automatic rebuild by autodist\"" || AUTOSPEC_CHANGELOG=
launch_pkgs_loop rebuild "$AUTOSPEC_ARGS $AUTOSPEC_CHANGELOG" || {
case $SEVERITY in
0) ;;
1) echo "%! Error during package update for rebuild; skipping $JOB_NAME job."
OPERATION_ERRORS=`expr $OPERATION_ERRORS + 1`
continue ;;
*) echo "!! Error during package update for rebuild; aborting."
exit 255 ;;
esac
}
fi
fi
fi
else
## skip package in job if up to date
#for j in ${JOB_PKGS[*]}; do
# REPVER=`grep "^$j " $SRCPKGLIST | gawk '{ print $2 }'`
# version_find_bigger "$TRVER" "$REPVER"
# [ $? -eq 1 ] && NEED_REBUILD=1
# done
echo "%% Updating to version ${JOB_VER:1}"
# WARNING: JOB_VER must be passed to launch_pkgs_loop as the first string in the second parameter
[ "${AUTOSPEC_ARGS/--changelog}" = "${AUTOSPEC_ARGS}" ] &&
AUTOSPEC_CHANGELOG="--changelog \"automatic version update by autodist\"" || AUTOSPEC_CHANGELOG=
launch_pkgs_loop update "${JOB_VER:1} $AUTOSPEC_ARGS $AUTOSPEC_CHANGELOG $SEND_FORCE" || {
if [ ! "$continue_on_error" ]; then
if [ ! "$rebuild_packages" ]; then
case $SEVERITY in
0) ;;
1) echo "%! Error during update; skipping $JOB_NAME job."
OPERATION_ERRORS=`expr $OPERATION_ERRORS + 1`
continue ;;
*) echo "!! Error during update; aborting."
exit 255 ;;
esac
fi
fi
if [ "$rebuild_packages" ]; then
[ "${AUTOSPEC_ARGS/--changelog}" = "${AUTOSPEC_ARGS}" ] &&
AUTOSPEC_CHANGELOG="--changelog \"automatic rebuild by autodist\"" || AUTOSPEC_CHANGELOG=
launch_pkgs_loop rebuild "$AUTOSPEC_ARGS $AUTOSPEC_CHANGELOG" || {
if [ ! "$continue_on_error" ]; then
case $SEVERITY in
0) ;;
1) echo "%! Error during package update for rebuild; skipping $JOB_NAME job."
OPERATION_ERRORS=`expr $OPERATION_ERRORS + 1`
continue ;;
*) echo "!! Error during package update for rebuild; aborting."
exit 255 ;;
esac
fi
}
fi
}
fi
fi
if [ "$do_build" ]; then
LOGDIR=$LOGBASEDIR/build
LOGFILE=$LOGDIR/last
echo "%% Starting BUILD operation @ `LANG=C date`"
echo "%% "`log_date`" Starting BUILD operation" > $LOGFILE
launch_job_loop build "$AUTOSPEC_ARGS $SEND_FORCE_BUILD $SEND_SERVER_CMD" || {
case $SEVERITY in
0) ;;
1) echo "%! Error during build; skipping $JOB_NAME job."
OPERATION_ERRORS=`expr $OPERATION_ERRORS + 1`
continue ;;
*) echo "!! Error during build; aborting."
exit 255 ;;
esac
}
fi
if [ "$do_install" ]; then
LOGDIR=$LOGBASEDIR/install
LOGFILE=$LOGDIR/last
> $LOGFILE
echo "%% Starting INSTALL operation @ `LANG=C date`"
echo "%% "`log_date`" Starting INSTALL operation" > $LOGFILE
launch_job_loop install "$AUTOSPEC_ARGS $SEND_FORCE $SEND_FORCE_INSTALL" || {
case $SEVERITY in
0) ;;
1) echo "%! Error during installation; skipping $JOB_NAME job."
OPERATION_ERRORS=`expr $OPERATION_ERRORS + 1`
continue ;;
*) echo "!! Error during installation; aborting."
exit 255 ;;
esac
}
fi
if [ "$do_send" ]; then
LOGDIR=$LOGBASEDIR/send
LOGFILE=$LOGDIR/last
> $LOGFILE
echo "%% Starting SEND operation @ `LANG=C date`"
echo "%% "`log_date`" Starting SEND operation" > $LOGFILE
launch_job_loop send "$AUTOSPEC_ARGS --nosrpm $SEND_SERVER_CMD" || {
case $SEVERITY in
0) ;;
1) echo "%! Error sending packages; skipping $JOB_NAME job."
continue ;;
*) echo "!! Error sending packages; aborting."
exit 1 ;;
esac
}
# avoid calling autospec with --nosrpm --norpm (not working as expected and not useful)
if [ "${AUTOSPEC_ARGS/--nosrpm}" = "$AUTOSPEC_ARGS" ]; then
if [ $REBUILD_SRPMS ]; then
echo "== rebuilding and sending source rpms"
launch_pkgs_loop buildsrpm "$AUTOSPEC_ARGS --norpm"
else
echo "== sending source rpms"
fi
launch_pkgs_loop send "$AUTOSPEC_ARGS --norpm $SEND_SERVER_CMD"
if [ $? -gt 0 ]; then
case $SEVERITY in
0) ;;
1) echo "%! Error sending sources; skipping $JOB_NAME job."
continue ;;
*) echo "!! Error sending sources; aborting."
exit 1 ;;
esac
else
# remove specfile patches
if [ "$do_autobuild" ]; then
autodist-tool makepatch $JOB_NAME remove
fi
fi
fi
fi
# if we are here the job was completed; remove manual entry, if any, and add to successlist
[ "$do_autobuild" ] && {
sed -i "/^$JOB_NAME .*/d" $AUTOUPDATEDIR/*.in
# job names match ignoring the -_.@ difference
awk '{ print $1 }' $SCHEDULEDLIST | tr -- '-.@' '___' | grep -qx "`echo $JOB_NAME | tr -- '-.@' '___'`" &&
autodist-jobs unschedule $JOB_NAME
echo "$JOB_NAME $DATE_NOW" >> $SUCCESSLISTDIR/auto.success
}
done
agent_for_job "$AGENT_PREV_JOB"
agent_end_of_pass
[ "$do_autobuild" = "1" ] && rm -f $PIDFILE
rm -f $SRCPKGLIST $SRCPKGLIST_DELAYED
echo "%! $OPERATION_ERRORS error(s)"
echo "%% All jobs done @ `LANG=C date`"
exit $OPERATION_ERRORS