You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

175 lines
4.9 KiB
Bash

#!/bin/bash
#
# clone the repo into the local relevant directory and run mockbuild on it
# monitor results and log
#
inifilename=$(echo ~)"/.smegit/config"
if [ ! -e $inifilename ] ; then
# Not here, look at system default
if [ ! -e /etc/smegit.ini ] ; then
echo "No ini file found $inifiename or /etc/smegit.ini"
echo "get-repo-and-build.sh <organisation> <reponame> [branch=<branch> <local> <debug>]"
exit 1
else
initfilename="/etc/smegit.ini"
fi
fi
while read -r line || [[ -n "$line" ]]; do
if [[ $line =~ ^\[.*\]$ ]]
then
section=${line#*[}
section=${section%]*}
else
if [[ $line =~ ^[^#]*= ]]
then
key=${line%=*}
value=${line#*=}
declare "${section}_${key}=$value"
fi
fi
done < "$inifilename"
if [[ -z $1 && -z $2 ]] ; then
echo "get-repo-and-build.sh <reponame> <organisation> [<local>]"
exit 0
fi
DEBUG=
GITEAHOST=${remote_GITEAHOST}
ACCESSTOKEN=${remote_GITEAACCESSTOKEN}
ORG_NAME="$2"
REPO_NAME="$1"
BRANCH=
if [ ${smegit_DEBUG} == "true" ] ; then DEBUG=true ; fi
for param in $3 $4 $5 $6; do
if [ $param ] ; then
case $param in
branch=* )
BRANCH="--${param}"
;;
local )
GITEAHOST=${local_GITEAHOST}
ACCESSTOKEN=${local_GITEAACCESSTOKEN}
;;
debug )
DEBUG=true ;;
* )
TARGETORG=$param ;;
esac
else
break
fi
done
SILENT="-s"
QUIET="-q"
if [ $DEBUG ] ; then
echo "found ini file: $inifilename"
SILENT=
QUIET=
fi
if [[ $smegit_WORKDIR == ~* ]] ; then
# relative to users home dir
WORKDIR=$(echo ~)${smegit_WORKDIR:1}
else
# absolute path
WORKDIR=${smegit_WORKDIR}
fi
if [ $DEBUG ] ; then echo "WORKDIR=$WORKDIR" ; fi
GITFiles=$WORKDIR/$ORG_NAME
REPOURL="$GITEAHOST/$ORG_NAME/$REPO_NAME.git"
if [ $DEBUG ] ; then echo "getting $REPO_NAME from $ORG_NAME on $GITEAHOST" ; fi
mkdir -p $GITFiles
touch "$GITFiles/mockbuilds.log"
if [ $DEBUG ] ; then echo $GITFiles ; fi
# one Common directory for each Organisation
#
# See if it already exists
if [ ! -e $GITFiles/common ]; then
#Get it
if [ $DEBUG ] ; then echo "clone common" ; fi
cd $GITFiles
git clone "${smegit_COMMONREPO}" $QUIET
if [ ! -e $GITFiles/common ]; then
echo "ERROR*******No Common Repo found - package $REPO_NAME"
exit 1
fi
else
# Just refresh it
if [ $DEBUG ] ; then echo "refresh common" ; fi
cd $GITFiles/common
git pull
fi
# See if repo exits in git
if [ $DEBUG ] ; then echo "check if $REPO_NAME in $ORG_NAME exists on $GITEAHOST" ; fi
BRANCHES=
if [ $BRANCH ] ; then BRANCHES="/branches/${BRANCH#*=}" ; fi
RESPONSE=$(curl $SILENT -o /dev/null -w "%{http_code}" "$GITEAHOST/api/v1/repos/$ORG_NAME/$REPO_NAME$BRANCHES")
if [ "$RESPONSE" == "200" ]; then
if [ $DEBUG ] ; then echo "Repository for $ORG_NAME/$REPO_NAME exists!" ; fi
else
if [ $DEBUG ] ; then echo "Repository for $ORG_NAME/$REPO_NAME does not exist" ; fi
if [ $BRANCH ] ; then
echo "Can't find the ${BRANCH#*=} branch of $ORG_NAME/$REPO_NAME - exiting"
exit 1
else
while true; do
read -p "Do you wish to run git-cvs2git?(y/n) " yn
case $yn in
[Yy]* )
if [ $DEBUG ] ; then echo "running git-cvs2git.sh" ; fi
logname="git-cvs2git-create-$ORG_NAME-$REPO_NAME-$(date +'%FT%H%M').log"
git-cvs2git.sh "$REPO_NAME" "$ORG_NAME" > $logname
break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
fi
# And check it is now there
if [ $DEBUG ] ; then echo "check if $REPO_NAME in $ORG_NAME exists on $GITEAHOST" ; fi
RESPONSE=$(curl $SILENT -o /dev/null -w "%{http_code}" "$GITEAHOST/api/v1/repos/$ORG_NAME/$REPO_NAME$BRANCHES")
if [ "$RESPONSE" == "200" ]; then
if [ $DEBUG ] ; then echo "Repository for $ORG_NAME/$REPO_NAME created sucessfully!" ; fi
else
echo "git-cvs2git.sh was unable to create $ORG_NAME/$REPO_NAME sucessfully"
exit 1
fi
fi
# Ok, we have a repo!!
cd $GITFiles
if [ $DEBUG ] ; then echo $GITFiles ; fi
# Delete it if these already
if [[ -d $REPO_NAME ]] ; then
# Should delete everything....
if [ $DEBUG ] ; then echo "Deleting all files in $GITFiles/$REPO_NAME" ; fi
rm -rf "$GITFiles/$REPO_NAME"
fi
if [ $DEBUG ] ; then echo "cloning $REPOURL $BRANCH" ; fi
git clone "$REPOURL" $BRANCH $QUIET
cd $GITFiles
if [[ ! -d $GITFiles/$REPO_NAME ]] ; then
echo "git clone has not created the $REPO_NAME directory"
exit 1
fi
cd $GITFiles/$REPO_NAME
# and run mockbuild
if [ $DEBUG ] ; then echo "running make mockbuild" ; fi
logname="mockbuild-$ORG_NAME-$REPO_NAME-$(date +'%FT%H%M').log"
if make mockbuild 2>&1 > $logname ; then
echo "Looks like mockbuild worked for $ORG_NAME/$REPO_NAME"
echo "$(date +'%FT%H%M') Mockbuild worked for $ORG_NAME/$REPO_NAME " >> $GITFiles/mockbuilds.log
else
echo "Mockbuild failed"
echo "$(date +'%FT%H%M') Mockbuild failed for $ORG_NAME/$REPO_NAME " >> $GITFiles/mockbuilds.log
exit 1
fi