#!/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 []" 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 []" exit 0 fi DEBUG= if [ ${smegit_DEBUG} == "true" ] ; then DEBUG=true ; fi if [ $DEBUG ] ; then echo "found ini file: $inifilename" ; fi SILENT="-s" QUIET="-q" if [ $DEBUG ] ; then SILENT= QUIET= fi GITEAHOST=${remote_GITEAHOST} ACCESSTOKEN=${remote_GITEAACCESSTOKEN} if [ $3 ] ; then if [ $3 == "local" ] ; then GITEAHOST=${local_GITEAHOST} ACCESSTOKEN=${local_GITEAACCESSTOKEN} fi 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 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 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 cd $GITFiles/common git pull fi # Now make sure that the make-archive is executible chmod +x $GITFiles/common/make-archive.sh # See if repo exits in git RESPONSE=$(curl $SILENT -o /dev/null -w "%{http_code}" "$GITEAHOST/api/v1/repos/$ORG_NAME/$REPO_NAME") 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 while true; do read -p "Do you wish to run git-cvs2git?(y/n) " yn case $yn in [Yy]* ) 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 # And check it is now there RESPONSE=$(curl $SILENT -o /dev/null -w "%{http_code}" "$GITEAHOST/api/v1/repos/$ORG_NAME/$REPO_NAME") 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 git clone "$REPOURL" $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 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