2017-07-13 18:21:56 -05:00
#!/bin/bash
2019-05-11 08:24:17 +02:00
set -ex
2017-07-13 18:21:56 -05:00
2019-05-11 08:24:17 +02:00
osc checkout "$OBS_PROJECT" "$OBS_PACKAGE"
cd "$OBS_PROJECT/$OBS_PACKAGE"
2017-07-13 18:21:56 -05:00
2017-07-13 19:14:19 -05:00
rm *.obscpio
2017-07-13 18:21:56 -05:00
osc service disabledrun
2017-09-01 16:53:14 -05:00
# ensure _servicedata ends with a newline
tail -n1 _servicedata | read -r _ || echo >> _servicedata
2017-07-13 18:21:56 -05:00
osc addremove
2017-09-01 16:54:26 -05:00
2018-01-25 08:59:52 -06:00
# Always produced modified files, but only want to bother if new source.
if osc status | grep _servicedata ; then
echo "new revision found, committing..."
2017-09-01 16:54:26 -05:00
osc commit -m "$(grep -oP 'version: \K.*' *.obsinfo)"
2018-01-25 08:59:52 -06:00
else
echo "new revision not found, reverting local changes..."
osc revert .
2017-09-01 16:54:26 -05:00
fi
2017-10-06 17:03:13 -05:00
2019-05-11 08:24:17 +02:00
if test -z "$OBS_TARGET_PROJECT"; then
OBS_TARGET_PROJECT="$(osc info | grep -oP "Link info:.*?project \K[^\s,]+")"
fi
if test -z "$OBS_TARGET_PACKAGE"; then
OBS_TARGET_PACKAGE="$(osc info | grep -oP "Link info:.*?, package \K[^\s,]+")"
if test -z "$OBS_TARGET_PACKAGE"; then
OBS_TARGET_PACKAGE=$OBS_PACKAGE
fi
fi
2017-10-06 17:03:13 -05:00
# Create submit request if none currently exists.
2017-10-06 17:48:39 -05:00
echo "checking for existing requests to $OBS_TARGET_PROJECT/$OBS_TARGET_PACKAGE..."
2018-01-25 09:55:23 -06:00
# `osc request list` is wholly inadequate for the task. :(
if osc api "/search/request?match=(state/@name='declined'+or+state/@name='new'+or+state/@name='review')+and+action/target/@project='$OBS_TARGET_PROJECT'+and+action/target/@package='$OBS_TARGET_PACKAGE'" |
grep '<collection matches="0">' ; then
2017-10-06 17:40:08 -05:00
osc service wait
2018-01-25 07:54:55 -06:00
# Only bother making a request if there is a diff (always 6 lines since
# binary source tarball dates changed after local run).
2019-05-11 08:24:17 +02:00
if [ "$(osc sr --diff $OBS_TARGET_PROJECT $OBS_TARGET_PACKAGE | tee temp.diff | wc -l)" -gt 6 ] ; then
2018-01-19 15:26:12 -06:00
echo "-> creating request"
cat temp.diff
rm temp.diff
2019-05-11 08:24:17 +02:00
osc sr --yes -m "automatic update" $OBS_TARGET_PROJECT $OBS_TARGET_PACKAGE
2018-01-19 15:26:12 -06:00
else
echo "-> no difference (likely cron job)"
fi
else
echo "-> existing request"
2017-10-06 17:03:13 -05:00
fi