2023-05-09 05:34:39 +02:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# clone the repo into the local relevant directory and run mockbuild on it
|
|
|
|
# monitor results and log
|
|
|
|
#
|
|
|
|
inifilename=$(echo ~)"/.smegit/config"
|
2023-05-10 02:17:35 +02:00
|
|
|
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"
|
2023-07-23 07:17:45 +02:00
|
|
|
echo "get-repo-and-build.sh <organisation> <reponame> [branch=<branch> <local> <debug>]"
|
2023-05-10 02:17:35 +02:00
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
initfilename="/etc/smegit.ini"
|
|
|
|
fi
|
|
|
|
fi
|
2023-05-09 05:34:39 +02:00
|
|
|
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
|
2023-06-06 11:23:05 +02:00
|
|
|
echo "get-repo-and-build.sh <reponame> <organisation> [<local>]"
|
2023-05-09 05:34:39 +02:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
DEBUG=
|
2023-06-13 01:36:51 +02:00
|
|
|
GITEAHOST=${remote_GITEAHOST}
|
|
|
|
ACCESSTOKEN=${remote_GITEAACCESSTOKEN}
|
|
|
|
ORG_NAME="$2"
|
|
|
|
REPO_NAME="$1"
|
2023-07-23 07:17:45 +02:00
|
|
|
BRANCH=
|
2023-05-09 05:34:39 +02:00
|
|
|
if [ ${smegit_DEBUG} == "true" ] ; then DEBUG=true ; fi
|
2023-06-13 01:36:51 +02:00
|
|
|
for param in $3 $4 $5 $6; do
|
|
|
|
if [ $param ] ; then
|
|
|
|
case $param in
|
2023-07-23 07:17:45 +02:00
|
|
|
branch=* )
|
|
|
|
BRANCH="--${param}"
|
|
|
|
;;
|
2023-06-13 01:36:51 +02:00
|
|
|
local )
|
|
|
|
GITEAHOST=${local_GITEAHOST}
|
|
|
|
ACCESSTOKEN=${local_GITEAACCESSTOKEN}
|
|
|
|
;;
|
|
|
|
debug )
|
|
|
|
DEBUG=true ;;
|
|
|
|
* )
|
|
|
|
TARGETORG=$param ;;
|
|
|
|
esac
|
|
|
|
else
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
2023-05-09 05:34:39 +02:00
|
|
|
|
2023-06-06 11:31:48 +02:00
|
|
|
SILENT="-s"
|
|
|
|
QUIET="-q"
|
|
|
|
if [ $DEBUG ] ; then
|
2023-06-13 02:12:49 +02:00
|
|
|
echo "found ini file: $inifilename"
|
2023-06-06 11:31:48 +02:00
|
|
|
SILENT=
|
|
|
|
QUIET=
|
|
|
|
fi
|
2023-05-09 05:34:39 +02:00
|
|
|
|
2023-05-10 02:17:35 +02:00
|
|
|
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
|
2023-06-09 07:06:44 +02:00
|
|
|
GITFiles=$WORKDIR/$ORG_NAME
|
2023-05-09 05:34:39 +02:00
|
|
|
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
|
2023-06-13 02:12:49 +02:00
|
|
|
if [ $DEBUG ] ; then echo "clone common" ; fi
|
2023-05-09 05:34:39 +02:00
|
|
|
cd $GITFiles
|
2023-06-06 11:39:40 +02:00
|
|
|
git clone "${smegit_COMMONREPO}" $QUIET
|
2023-05-09 05:34:39 +02:00
|
|
|
if [ ! -e $GITFiles/common ]; then
|
2023-06-06 11:23:05 +02:00
|
|
|
echo "ERROR*******No Common Repo found - package $REPO_NAME"
|
2023-05-09 05:34:39 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
# Just refresh it
|
2023-06-13 02:12:49 +02:00
|
|
|
if [ $DEBUG ] ; then echo "refresh common" ; fi
|
2023-05-09 05:34:39 +02:00
|
|
|
cd $GITFiles/common
|
2023-06-06 11:39:40 +02:00
|
|
|
git pull
|
2023-05-09 05:34:39 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# See if repo exits in git
|
2023-06-13 02:12:49 +02:00
|
|
|
if [ $DEBUG ] ; then echo "check if $REPO_NAME in $ORG_NAME exists on $GITEAHOST" ; fi
|
2023-07-23 09:28:12 +02:00
|
|
|
BRANCHES=
|
|
|
|
if [ $BRANCH ] ; then $BRANCHES="/branches/${BRANCH#*=}" ; file
|
|
|
|
RESPONSE=$(curl $SILENT -o /dev/null -w "%{http_code}" "$GITEAHOST/api/v1/repos/$ORG_NAME/$REPO_NAME$BRANCHES")
|
2023-05-09 05:34:39 +02:00
|
|
|
if [ "$RESPONSE" == "200" ]; then
|
2023-07-23 09:28:12 +02:00
|
|
|
if [ $DEBUG ] ; then echo "Repository for $ORG_NAME/$REPO_NAME exists!" ; fi
|
2023-05-09 05:34:39 +02:00
|
|
|
else
|
2023-07-23 09:28:12 +02:00
|
|
|
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
|
2023-05-09 05:34:39 +02:00
|
|
|
# And check it is now there
|
2023-07-23 09:28:12 +02:00
|
|
|
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")
|
2023-05-09 05:34:39 +02:00
|
|
|
if [ "$RESPONSE" == "200" ]; then
|
2023-06-06 11:23:05 +02:00
|
|
|
if [ $DEBUG ] ; then echo "Repository for $ORG_NAME/$REPO_NAME created sucessfully!" ; fi
|
2023-05-09 05:34:39 +02:00
|
|
|
else
|
2023-06-06 11:23:05 +02:00
|
|
|
echo "git-cvs2git.sh was unable to create $ORG_NAME/$REPO_NAME sucessfully"
|
2023-05-09 05:34:39 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
# Ok, we have a repo!!
|
|
|
|
cd $GITFiles
|
2023-06-06 12:19:09 +02:00
|
|
|
if [ $DEBUG ] ; then echo $GITFiles ; fi
|
2023-05-09 05:34:39 +02:00
|
|
|
# Delete it if these already
|
|
|
|
if [[ -d $REPO_NAME ]] ; then
|
|
|
|
# Should delete everything....
|
2023-05-09 10:37:35 +02:00
|
|
|
if [ $DEBUG ] ; then echo "Deleting all files in $GITFiles/$REPO_NAME" ; fi
|
2023-06-06 12:19:09 +02:00
|
|
|
rm -rf "$GITFiles/$REPO_NAME"
|
2023-05-09 05:34:39 +02:00
|
|
|
fi
|
2023-07-23 07:17:45 +02:00
|
|
|
if [ $DEBUG ] ; then echo "cloning $REPOURL $BRANCH" ; fi
|
|
|
|
git clone "$REPOURL" $BRANCH $QUIET
|
2023-05-09 05:34:39 +02:00
|
|
|
|
|
|
|
cd $GITFiles
|
2023-06-06 12:19:09 +02:00
|
|
|
if [[ ! -d $GITFiles/$REPO_NAME ]] ; then
|
2023-06-06 11:34:10 +02:00
|
|
|
echo "git clone has not created the $REPO_NAME directory"
|
2023-05-09 05:34:39 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
cd $GITFiles/$REPO_NAME
|
|
|
|
# and run mockbuild
|
2023-06-13 02:12:49 +02:00
|
|
|
if [ $DEBUG ] ; then echo "running make mockbuild" ; fi
|
2023-06-06 11:23:05 +02:00
|
|
|
logname="mockbuild-$ORG_NAME-$REPO_NAME-$(date +'%FT%H%M').log"
|
2023-05-09 05:34:39 +02:00
|
|
|
if make mockbuild 2>&1 > $logname ; then
|
2023-06-06 11:23:05 +02:00
|
|
|
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
|
2023-05-09 05:34:39 +02:00
|
|
|
else
|
|
|
|
echo "Mockbuild failed"
|
2023-06-06 11:23:05 +02:00
|
|
|
echo "$(date +'%FT%H%M') Mockbuild failed for $ORG_NAME/$REPO_NAME " >> $GITFiles/mockbuilds.log
|
2023-05-09 05:34:39 +02:00
|
|
|
exit 1
|
|
|
|
fi
|