smeserver-gitutils/git-get-repo-and-build.sh

151 lines
4.0 KiB
Bash
Raw Normal View History

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"
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> [<local>]"
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
echo "get-repo-and-build.sh <reponame> <organisation> [<local>]"
2023-05-09 05:34:39 +02:00
exit 0
fi
DEBUG=
if [ ${smegit_DEBUG} == "true" ] ; then DEBUG=true ; fi
if [ $DEBUG ] ; then echo "found ini file: $inifilename" ; fi
2023-06-06 11:31:48 +02:00
SILENT="-s"
QUIET="-q"
if [ $DEBUG ] ; then
SILENT=
QUIET=
fi
2023-05-09 05:34:39 +02:00
GITEAHOST=${remote_GITEAHOST}
ACCESSTOKEN=${remote_GITEAACCESSTOKEN}
if [ $3 ] ; then
2023-06-06 11:31:48 +02:00
if [ $3 == "local" ] ; then
GITEAHOST=${local_GITEAHOST}
ACCESSTOKEN=${local_GITEAACCESSTOKEN}
fi
2023-05-09 05:34:39 +02:00
fi
ORG_NAME="$2"
REPO_NAME="$1"
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-05-09 05:34:39 +02:00
GITFiles=$WORKDIR/GITFiles/$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
cd $GITFiles
2023-06-06 11:31:48 +02:00
git clone $QUIET "${smegit_COMMONREPO}"
2023-05-09 05:34:39 +02:00
if [ ! -e $GITFiles/common ]; then
echo "ERROR*******No Common Repo found - package $REPO_NAME"
2023-05-09 05:34:39 +02:00
exit 1
fi
else
# Just refresh it
cd $GITFiles/common
2023-06-06 11:31:48 +02:00
git $QUIET pull
2023-05-09 05:34:39 +02:00
fi
# Now make sure that the make-archive is executible
chmod +x $GITFiles/common/make-archive.sh
# See if repo exits in git
2023-06-06 11:31:48 +02:00
RESPONSE=$(curl $SILENT -o /dev/null -w "%{http_code}" "$GITEAHOST/api/v1/repos/$ORG_NAME/$REPO_NAME")
2023-05-09 05:34:39 +02:00
if [ "$RESPONSE" == "200" ]; then
if [ $DEBUG ] ; then echo "Repository for $ORG_NAME/$REPO_NAME exists!" ; fi
2023-05-09 05:34:39 +02:00
else
if [ $DEBUG ] ; then echo "Repository for $ORG_NAME/$REPO_NAME does not exist" ; fi
logname="git-cvs2git-create-$ORG_NAME-$REPO_NAME-$(date +'%FT%H%M').log"
2023-05-09 05:34:39 +02:00
while true; do
read -p "Do you wish to run git-cvs2git?(y/n) " yn
case $yn in
[Yy]* ) git-cvs2git.sh "$REPO_NAME" "$ORG_NAME" > $logname; break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
# And check it is now there
2023-06-06 11:31:48 +02:00
RESPONSE=$(curl $SILENT -o /dev/null -w "%{http_code}" "$GITEAHOST/api/v1/repos/$ORG_NAME/$REPO_NAME")
2023-05-09 05:34:39 +02:00
if [ "$RESPONSE" == "200" ]; then
if [ $DEBUG ] ; then echo "Repository for $ORG_NAME/$REPO_NAME created sucessfully!" ; fi
2023-05-09 05:34:39 +02:00
else
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
echo $GITFiles
# Delete it if these already
if [[ -d $REPO_NAME ]] ; then
# Should delete everything....
cd $GITFiles/$REPO_NAME
2023-05-09 10:37:35 +02:00
if [ $DEBUG ] ; then echo "Deleting all files in $GITFiles/$REPO_NAME" ; fi
2023-05-09 05:34:39 +02:00
rm -rf "$REPO_NAME"
fi
cd $GITFiles
2023-06-06 11:31:48 +02:00
git $QUIET clone "$REPOURL"
2023-05-09 05:34:39 +02:00
cd $GITFiles
if [[ ! -d $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
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
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"
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