diff --git a/drydocker/generic_functions.sh b/drydocker/generic_functions.sh index e830031..5bc4704 100644 --- a/drydocker/generic_functions.sh +++ b/drydocker/generic_functions.sh @@ -1,195 +1,195 @@ #!/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:Development" 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:Development) sed -i -r \ -e 's/enabled=.*/enabled=0/g' \ $(find /etc/yum.repos.d/ -type f -name "Kolab:*.repo" ! -name "Kolab:Development.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' | \ - sed -r -e 's/[^0-9\.]+//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}" }