42 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
osc-init
osc checkout "$OBS_PACKAGE"
cd "$OBS_PACKAGE"
rm *.obscpio
osc service disabledrun
# ensure _servicedata ends with a newline
tail -n1 _servicedata | read -r _ || echo >> _servicedata
osc addremove
if [ "$(osc status | wc -l)" -gt 0 ] ; then
osc commit -m "$(grep -oP 'version: \K.*' *.obsinfo)"
fi
# Create submit request if none currently exists.
OBS_TARGET_PROJECT="$(osc info | grep -oP "Link info:.*?project \K[^\s,]+")"
OBS_TARGET_PACKAGE="$(osc info | grep -oP "Link info:.*?, package \K[^\s,]+")"
echo "checking for existing requests to $OBS_TARGET_PROJECT/$OBS_TARGET_PACKAGE..."
# Limit by user in an attempt to avoid requests sourced from target project.
# Unfortunately the command line provides no mechanism to do so and a full API
# query is rather ungainly compared to this workaround.
if osc request list -U "$OBS_USER" "$OBS_TARGET_PROJECT" "$OBS_TARGET_PACKAGE" |
grep 'No results for package' ; then
osc service wait
# Only bother making a request if there is a diff (always shows 3 lines).
if [ "$(osc sr --diff | tee temp.diff | wc -l)" -gt 3 ] ; then
echo "-> creating request"
cat temp.diff
rm temp.diff
osc sr --yes -m "automatic update"
else
echo "-> no difference (likely cron job)"
fi
else
echo "-> existing request"
fi