diff --git a/drydocker/generic_functions.sh b/drydocker/generic_functions.sh index 77f84f0..286213b 100644 --- a/drydocker/generic_functions.sh +++ b/drydocker/generic_functions.sh @@ -1,195 +1,202 @@ #!/bin/bash function _install_package_builddep { if [ -x "$(which yum 2>/dev/null)" ]; then yum-builddep -y --disablerepo=openSUSE_Tools $@ elif [ -x "$(which apt-get 2>/dev/null)" ]; then apt-get -y build-dep $@ fi } function package_version_for_osc_project_repo { osc_project=$1 osc_repository=$2 rpm_filename=$(osc ls -b ${osc_project} ${PACKAGE} ${osc_repository} x86_64 2>&1 | grep "^${PACKAGE}" | grep -vE "*\.src\.rpm$" | sort | head -n 1) if [ -z "${rpm_filename}" ]; then echo "0" return fi success=$(osc getbinaries ${osc_project} ${PACKAGE} ${osc_repository} x86_64 ${rpm_filename} >/dev/null 2>&1; echo $?) if [ ${success} -ne 0 ]; then echo "0" return fi version=$(rpm -q --queryformat="%{VERSION}\n" -p binaries/${rpm_filename}) echo ${version} } function project_for_package_version { osc_project=$1 target_version=$2 declare -a projects projects[${#projects[@]}]="Kolab:14" projects[${#projects[@]}]="Kolab:14:Fasttrack" projects[${#projects[@]}]="Kolab:3.4" projects[${#projects[@]}]="Kolab:3.4:Updates" + projects[${#projects[@]}]="Kolab:16" projects[${#projects[@]}]="Kolab:Winterfell" current_version="" current_project="" x=0 while [ ${x} -lt ${#projects[@]} ]; do version=$(package_version_for_osc_project_repo ${projects[${x}]} ${osc_project}) retval=$(rpmdev-vercmp "${version}" "${target_version}" >/dev/null ; echo $?) if [ ${retval} -eq 12 -o ${retval} -eq 0 ]; then retval=$(rpmdev-vercmp "${current_version}" "${version}" >/dev/null ; echo $?) if [ ${retval} -eq 12 -o ${retval} -eq 0 ]; then current_version="${version}" current_project="${projects[${x}]}" fi fi let x++ done echo "${current_project}" } function repository_configuration { set -x version=$(version_for_commit) osc_project=$(project_for_package_version CentOS_7 ${version}) case ${osc_project} in Kolab:3.4*) sed -i -r \ -e 's/enabled=.*/enabled=0/g' \ $(find /etc/yum.repos.d/ -type f -name "Kolab:*.repo" ! -name "Kolab:3.4*.repo") ;; + Kolab:16*) + sed -i -r \ + -e 's/enabled=.*/enabled=0/g' \ + $(find /etc/yum.repos.d/ -type f -name "Kolab:*.repo" ! -name "Kolab:16*.repo") + ;; + Kolab:Winterfell) sed -i -r \ -e 's/enabled=.*/enabled=0/g' \ $(find /etc/yum.repos.d/ -type f -name "Kolab:*.repo" ! -name "Kolab:Winterfell.repo") ;; esac set - -x } function version_for_commit { # Obtain and copy in sources pushd /srv/${PACKAGE}.git >&3 short_rev=$(git rev-parse --short HEAD) long_rev=$(git rev-parse HEAD) set -x branches=$(git branch --contains ${long_rev} | \ sed -r \ -e 's/^\* //g' \ -e 's/^ //g' | \ grep -E "^(master|${PACKAGE}|[a-z0-9-]+([0-9]+\.?))" | \ sort --version-sort -u ) echo "Branches that contain ${COMMIT}:" >&3 echo "${branches}" | sed -e 's/\s/\r\n/g' >&3 if [ ! -z "$(echo ${branches} | sed -e 's/\s/\r\n/g' | grep -E '^master$')" ]; then branch=master else branch=$(echo ${branches} | sed -e 's/\s/\r\n/g' | tail -n 1) fi echo "Branch is '${branch}'" >&3 latest_stable_branch=$(git branch -la | \ sed -r \ -e 's/^\* //g' \ -e 's/^ remotes\/origin\///g' \ -e '/^HEAD/d' | \ grep -E "^(${PACKAGE}|[a-z0-9-]+([0-9]+\.?))" | \ sort --version-sort -u | \ tail -n 1 ) echo "The latest stable branch is '${latest_stable_branch}'" >&3 if [ "${branch}" == "master" ]; then if [ ! -z "${latest_stable_branch}" ]; then master_version=$(echo ${latest_stable_branch} | \ sed -r -e 's/^.*([0-9]+(\.[0-9]+)+)$/\1/g' | \ awk -F. '{$NF+=1; OFS="."; print $0}' ) echo "This puts the version for master at '${master_version}'" >&3 else master_version="" fi stable_version=0 tag_version=$(git tag -l | \ grep -E "${master_version}(\.[0-9]+)+$" | \ sed -r -e 's/^.*([0-9]\.([0-9]+(\.[0-9]+)+))$/\1/g' | \ sed -r -e 's/[^0-9\.]+//g' | \ sort --version-sort -u | \ tail -n 1 | \ awk -F. '{$NF+=1; OFS="."; print $0}' ) if [ -z "${tag_version}" -a -z "${master_version}" ]; then tag_version=$(git tag -l | \ grep -E "(\.[0-9]+)+$" | \ sed -r -e 's/^.*([0-9]\.([0-9]+(\.[0-9]+)+))$/\1/g' | \ sort --version-sort -u | \ tail -n 1 | \ awk -F. '{$NF+=1; OFS="."; print $0}' ) fi else master_version=0 stable_version=$(echo ${latest_stable_branch} | \ sed -r -e 's/^.*([0-9]+(\.[0-9]+)+)$/\1/g' ) echo "This puts the version for stable at ${stable_version}" >&3 tag_version=$(git tag -l | \ grep -E "${stable_version}(\.[0-9]+)+$" | \ sed -r -e 's/^.*([0-9]\.([0-9]+(\.[0-9]+)+))$/\1/g' | \ sort --version-sort -u | \ tail -n 1 | \ awk -F. '{$NF+=1; OFS="."; print $0}' ) fi new_version=$(echo -e "${master_version}\n${stable_version}\n${tag_version}" | \ sort --version-sort -u | \ tail -n 1 ) if [ "${new_version}" == "0" ]; then new_version="0.1" fi echo "Going with new version: '${new_version}'" >&3 set - -x echo "${new_version}" } diff --git a/drydocker/generic_obs.sh b/drydocker/generic_obs.sh index b849dd2..e5c7874 100644 --- a/drydocker/generic_obs.sh +++ b/drydocker/generic_obs.sh @@ -1,182 +1,186 @@ #!/bin/bash source /srv/stick.git/drydocker/generic_functions.sh function obs_build_local { if [ ! -f "/root/.oscrc" ]; then echo "SKIPPED: No ~/.oscrc." >&3 return fi # Figure out the version for the commit new_version=$(version_for_commit) # Figure out the OBS project for the version osc_project=$(project_for_package_version CentOS_7 ${new_version}) pushd /srv >&3 if [ -d "${osc_project}/${PACKAGE}" ]; then rm -rf ${osc_project}/${PACKAGE} fi osc co ${osc_project}/${PACKAGE} >&3 pushd ${osc_project}/${PACKAGE} >&3 # Remove all compressed content not debian.tar.gz find . \ -mindepth 1 \ -maxdepth 1 \ -type f \ -name "*.tar.gz" \ ! -name "debian.tar.gz" \ -delete # Remove _service file rm -rf _service # Obtain and copy in sources pushd /srv/${PACKAGE}.git >&3 echo "Going with new version: '${new_version}'" >&3 echo "About to create /srv/${osc_project}/${PACKAGE}/${PACKAGE}-${new_version}.tar.gz" >&3 if [ ! -f "${PACKAGE}-${new_version}.tar.gz" ]; then git archive \ --prefix=${PACKAGE}-${new_version}/ HEAD | \ gzip -c > \ /srv/${osc_project}/${PACKAGE}/${PACKAGE}-${new_version}.tar.gz else cp ${PACKAGE}-${new_version}.tar.gz \ /srv/${osc_project}/${PACKAGE}/${PACKAGE}-${new_version}.tar.gz fi echo "Creating /srv/${osc_project}/${PACKAGE}/${PACKAGE}-${new_version}.tar.gz completed" >&3 ls -l /srv/${osc_project}/${PACKAGE}/ >&3 popd >&3 # Set .spec version test -f ${PACKAGE}.spec && \ sed -i -r \ -e "s/^Version:(\s*).*$/Version:\1${new_version}/g" \ -e "s/^Release:(\s*).*$/Release:\10.$(date +'%Y%m%d').git${short_rev}%{?dist}/g" \ -e "0,/^Source[0-9]+:\s*.*\.tar\.gz/{s/^Source([0-9]+):(\s*).*$/Source\1:\2${PACKAGE}-${new_version}.tar.gz/}" \ ${PACKAGE}.spec # Set .dsc and .changelog version test -f ${PACKAGE}.dsc && \ sed -i -r \ -e "s/^Version:(\s*([0-9]+:)?).*$/Version:\1${new_version}~dev$(date +'%Y%m%d')-0~kolab1/g" \ -e "s/${PACKAGE}-([0-9\.]+)\.tar\.gz$/${PACKAGE}-${new_version}.tar.gz/g" \ ${PACKAGE}.dsc test -f debian.changelog && \ sed -i -r \ -e "1 s/\(([0-9]+:)?.*\)/(\1${new_version}~dev$(date +'%Y%m%d')-0~kolab1)/g" \ debian.changelog # Echo this through stdin for the sub-command after a while, to # indicate trust. ( sleep 10; echo 2; case ${osc_project} in Kolab:3.4*) sleep 10; echo 2; ;; + + Kolab:16*) + sleep 10; echo 2; + ;; esac; ) | \ osc build \ --no-verify \ --disable-cpio-bulk-download \ --download-api-only \ --local-package \ CentOS_7 \ ${PACKAGE}.spec >&3 2>&3 ; retval=$? popd >&3 popd >&3 return ${retval} } function obs_install_local { if [ ! -f "/root/.oscrc" ]; then echo "SKIPPED: No ~/.oscrc." >&3 return fi # Assume the locally built packages have a lower NEVRA. # # For packages with a higher NEVRA, this will simply result in # nothing. # # For packages that are not installed, this will simply result in # nothing. retval=$(_shell yum_downgrade) # It is OK if the downgrade fails. if [ ${retval} -ne 0 ]; then echo "yum downgrade failed, but that's OK" >&3 fi # Then install all the packages. retval=$(_shell yum_install) return ${retval} } function obs_checkin { if [ ! -f "/root/.oscrc" ]; then echo "SKIPPED: No ~/.oscrc." >&3 return fi if [ ${TEST_OBS} -eq 0 ]; then echo "SKIPPED: osc_checkin (disabled)" >&3 return fi # Also do not check in code if the difference between HEAD and # master is more than 0. pushd /srv/${PACKAGE}.git num_behind=$(git format-patch ${COMMIT}..master | wc -l) if [ ${num_behind} -gt 0 ]; then echo "SKIPPED: osc_checkin (behind master)" >&3 return fi popd # Figure out the version for the commit new_version=$(version_for_commit) # Figure out the OBS project for the version osc_project=$(project_for_package_version CentOS_7 ${new_version}) pushd /srv/${osc_project}/${PACKAGE}/ >&3 retval=$(_shell osc ar) if [ ${retval} -ne 0 ]; then return ${retval} fi retval=$(_shell osc ci -m "${PACKAGE}@${COMMIT}-$(date +'%Y-%m-%d')") if [ ${retval} -ne 0 ]; then return ${retval} fi popd } function yum_downgrade { yum -y downgrade \ /var/tmp/build-root/*/home/abuild/rpmbuild/RPMS/*/*.rpm ; \ return $? } function yum_install { yum -y install \ /var/tmp/build-root/*/home/abuild/rpmbuild/RPMS/*/*.rpm ; \ return $? }