From 59a1ad0317d6af2122fdec25116b7e448094cc16 Mon Sep 17 00:00:00 2001 From: Silvan Calarco Date: Sat, 5 Jul 2014 17:50:53 +0200 Subject: [PATCH] autodist,autoport: allow to pass arguments to update-specfile script update-specfile: accept --buildreq multiple arguments to edit build requirements with version --- autodist | 54 +++++++++++++++--- autoport | 12 ++-- etc/autodist/scripts/update-specfile | 82 ++++++++++++++++++++++------ 3 files changed, 120 insertions(+), 28 deletions(-) diff --git a/autodist b/autodist index 21c1724..f8ba819 100755 --- a/autodist +++ b/autodist @@ -18,7 +18,7 @@ ${me[0]} ${me[1]} "$"Batch build tool for bulding a whole distribution and much more."" "$"Usage"": - $me [operations ...] [options ...] [job ...] [-- autospec_args] + $me [operations ...] [options ...] [job ...] [-- autospec_args] [--- script_args] "$"Operations"": -a,--autobuild "$"Start batch build operations (implies -p -u -b -s --severity 1)"" @@ -53,6 +53,7 @@ ${me[0]} ${me[1]} kernel-extra kernel-packages/lirc"" autospec_args "$"Send specified arguments to autospec"" + script_args "$"Send specified arguments to update-specfile script"" " } @@ -91,6 +92,7 @@ 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="/var/run/autodist/autodist.pid" @@ -190,24 +192,37 @@ for ((i=1; i<=$#; i++)); do ;; -*) 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" != "1" ]; then - JOBIDX=${#JOBNAME[@]} - JOBNAME[$JOBIDX]="${!i/\#*}" - [ "${!i/*\#}" != "${!i}" ] && JOBVER[$JOBIDX]="+${!i/*\#}" - else + *) 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 @@ -545,8 +560,31 @@ function launch_pkgs_loop() { [ "$operation" = "update" -o "$operation" = "autoupdate" ] && continue fi fi - $SCRIPT_UPDATE_SPECFILE $spec_dir/$pkg.spec - ;; + if [ -x $SCRIPT_UPDATE_SPECFILE ]; then + $SCRIPT_UPDATE_SPECFILE $spec_dir/$pkg.spec $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 $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 ] && { diff --git a/autoport b/autoport index 5d5052b..9801bac 100755 --- a/autoport +++ b/autoport @@ -23,7 +23,7 @@ ${me[0]} ${me[1]} "$"Batch port and cross-build tool based on autodist."" "$"Usage"": - $me [-a][-f][-x arch1[,arch2],..][-r repository][-d release_repository]{--fix|job ...} + $me [-a][-f][-x arch1[,arch2],..][-r repository][-d release_repository][-s \"script_args\"]{--fix|job ...} -a "$"Automatic mode (use cache) -b "$"Batch port all packages in port repository to sync with base repository @@ -35,6 +35,7 @@ ${me[0]} ${me[1]} -r "$"Work on given repository (default: $PORT_REPOSITORY) -d "$"Release packages to given repository (default: $PORT_REPOSITORY) -h "$"Show this help and exit + -s \"script_args\" "$"Send script_args as arguments for autodist update-specfile script -u changelog "$"Rebuild packages with given changelog -v "$"More verbose output -x "$"Operate in cross build mode @@ -285,6 +286,9 @@ for ((i=1; i<=$#; i++)); do -r) shift PORT_REPOSITORY="${!i}" ;; + -s) shift + SCRIPT_ARGS="${!i}" + ;; -d) shift DEST_REPOSITORY="${!i}" ;; @@ -520,8 +524,8 @@ for TARGET_ARCH in ${TARGET_ARCHS}; do if [ "$REBUILD_MODE" = "1" ]; then echo -n "update" [ "$VERBOSE_MODE" ] && echo " -%% COMMAND: LANG=C LC_ALL=C autodist -u --rebuild -r ${JOB_CURRENT} --severity 2 -- $STAGEOPTS --changelog \"$REBUILD_CHANGELOG\"" - LANG=C LC_ALL=C autodist -u --rebuild -r ${JOB_CURRENT} --severity 2 -- $STAGEOPTS --changelog \"$REBUILD_CHANGELOG\" &>$tmpfile +%% COMMAND: LANG=C LC_ALL=C autodist -u --rebuild -r ${JOB_CURRENT} --severity 2 -- $STAGEOPTS --changelog \"$REBUILD_CHANGELOG\" --- \"$SCRIPT_ARGS\"" + LANG=C LC_ALL=C autodist -u --rebuild -r ${JOB_CURRENT} --severity 2 -- $STAGEOPTS --changelog \"$REBUILD_CHANGELOG\" --- $SCRIPT_ARGS &>$tmpfile [ $? -gt 0 ] && { echo "(FAILED) " autoport_log ${JOB_CURRENT} update failed $tmpfile @@ -534,7 +538,7 @@ for TARGET_ARCH in ${TARGET_ARCHS}; do echo -n "update" [ "$VERBOSE_MODE" ] && echo " %% COMMAND: LANG=C LC_ALL=C autodist -u -r ${JOB_CURRENT} --severity 2 -- $STAGEOPTS --changelog \"automatic port from $PORT_REPOSITORY\"" - LANG=C LC_ALL=C autodist -u -r ${JOB_CURRENT} --severity 2 -- $STAGEOPTS --changelog \"automatic port from $PORT_REPOSITORY\" &>$tmpfile + LANG=C LC_ALL=C autodist -u -r ${JOB_CURRENT} --severity 2 -- $STAGEOPTS --changelog \"automatic port from $PORT_REPOSITORY\" --- $SCRIPT_ARGS &>$tmpfile cat $tmpfile >> $logfile [ $? -gt 0 ] && { echo "(FAILED) " diff --git a/etc/autodist/scripts/update-specfile b/etc/autodist/scripts/update-specfile index 4114d77..0676f1a 100755 --- a/etc/autodist/scripts/update-specfile +++ b/etc/autodist/scripts/update-specfile @@ -1,29 +1,79 @@ +#!/bin/bash +# # Autodist script for updating specfiles # -# Copyright (c) 2007-2012 by Silvan Calarco +# Copyright (c) 2007-2014 by Silvan Calarco # Released with the same license as autodist # -[ "$1" ] || { - echo "Error: update-specfile: specfile not given; aborting." +SPECFILE= +BUILDREQNUM=0 + +for ((i=1; i<=$#; i++)); do + case ${!i} in + --buildreq) let i+=1 + if [ ! "${!i}" ]; then + echo "ERROR: --buildreq requires at least an argument; aborting." + exit 1 + fi + let BUILDREQNUM+=1 + BUILDREQ[$BUILDREQNUM]=${!i} + if [ "${!i+1}" -a "${!i+1:0:1}" != "-" ]; then + let i+=1 + BUILDREQREL[$BUILDREQNUM]=${!i} + if [ ! "${!i+1}" -o "${!i+1:0:1}" = "-" ]; then + echo "ERROR: update-specfile: --buildreq requires one or three arguments; aborting." + exit 1 + fi + let i+=1 + BUILDREQVER[$BUILDREQNUM]=${!i} + fi + ;; + *) if [ ! "$SPECFILE" ]; then + SPECFILE=${!i} + else + echo "ERROR: update-specfile: unrecognized script option: '${!i}'; aborting." + exit 1 + fi + esac +done + +[ "$SPECFILE" ] || { + echo "ERROR: update-specfile: specfile not given; aborting." exit 1 } -[ -e $1 ] || { +[ -e $SPECFILE ] || { echo "Error: update-specfile: file $1 does not exist; aborting." exit 1 } -sed -i "s|^Vendor:.*|Vendor: openmamba|" $1 -sed -i "s|^Distribution:.*|Distribution: openmamba|" $1 -sed -i "s|silvan\.calarco@qilinux\.it|silvan.calarco@mambasoft.it|" $1 -sed -i "/BuildRequires:[[:space:]]*libffmpeg-devel/d" $1 -sed -i "s|\(BuildRequires:[[:space:]]*\)libmysql-devel|\1libmysql5-devel|" $1 -sed -i "s|\(BuildRequires:[[:space:]]*\)libdb42-devel|\1libdb47-devel|" $1 -sed -i "s|\(BuildRequires:[[:space:]]*\)firefox-devel|\1xulrunner-devel|" $1 -sed -i "s|^PreReq:[[:space:]]*/sbin/install-info|Requires(post):%{__install_info}|" $1 -sed -i "s|^PreReq:[[:space:]]*%{__install_info}|Requires(post):%{__install_info}|" $1 -sed -i "s|^PreReq:[[:space:]]*|Requires(pre): |" $1 -sed -i "s|http://.*.dl\.sourceforge\.net/|http://downloads.sourceforge.net/|" $1 -#sed -i "s|^\(Source.*:[[:space:]]*ftp://ftp.kde.org/pub/kde/stable/.*.tar.\)bz2|\1xz|" $1 +# Distribution global changes +sed -i "s|^Vendor:.*|Vendor: openmamba|; + s|^Distribution:.*|Distribution: openmamba|; + /BuildRequires:[[:space:]]*libffmpeg-devel/d; + s|\(BuildRequires:[[:space:]]*\)libmysql-devel|\1libmysql5-devel|; + s|\(BuildRequires:[[:space:]]*\)libdb42-devel|\1libdb47-devel|; + s|\(BuildRequires:[[:space:]]*\)firefox-devel|\1xulrunner-devel|; + s|^PreReq:[[:space:]]*/sbin/install-info|Requires(post):%{__install_info}|; + s|^PreReq:[[:space:]]*%{__install_info}|Requires(post):%{__install_info}|; + s|^PreReq:[[:space:]]*|Requires(pre): |; + s|http://.*.dl\.sourceforge\.net/|http://downloads.sourceforge.net/|" $SPECFILE +#sed -i "s|^\(Source.*:[[:space:]]*ftp://ftp.kde.org/pub/kde/stable/.*.tar.\)bz2|\1xz|" $SPECFILE + +if [ $BUILDREQNUM -gt 0 ]; then + grep "^## AUTOBUILDREQ-END" $SPECFILE > /dev/null || { + echo "ERROR: update-specfile: missing AUTOBUILDREQ block; aborting." + exit 1 + } + for b in `seq 1 $BUILDREQNUM`; do + line=${BUILDREQ[$b]} + if [ "${BUILDREQREL[$b]}" ]; then + line="$line ${BUILDREQREL[$b]} ${BUILDREQVER[$b]}" + fi + sed -i "/^## AUTOBUILDREQ-END/,9999{/BuildRequires:[[:space:]]*${BUILDREQ[$b]}$/d}" $SPECFILE + sed -i "/^## AUTOBUILDREQ-END/,9999{/BuildRequires:[[:space:]]*${BUILDREQ[$b]}[[:space:]]/d}" $SPECFILE + sed -i "/^## AUTOBUILDREQ-END/a BuildRequires: $line" $SPECFILE + done +fi exit 0