173 lines
4.6 KiB
Bash
Executable File
173 lines
4.6 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# $1 = Module name e.g. smeserver-ddclient
|
|
# $2 = Organisation (smeserver or smecontrib)e
|
|
# optional (can be in any order)
|
|
# <local> will use parameters set for local repository else it will use remote
|
|
# <debug> turn on debug regardless of ~/.smegit/config
|
|
# <noisy> print a line showing how it was called
|
|
# Module name must exist
|
|
#
|
|
|
|
if [[ -z $1 ]] ; then
|
|
echo "************git-retag.sh <modulename> <organization> [<local> | <debug>]"
|
|
exit 0
|
|
fi
|
|
|
|
#Needs /usr/bin/rpmspec
|
|
if command -v /usr/bin/rpmspec > /dev/null; then
|
|
if [ $DEBUG ] ; then echo "************rpmspec is installed" ; fi
|
|
else
|
|
echo "ERROR********************** rpmspec is not installed ******************"
|
|
exit 1
|
|
fi
|
|
|
|
|
|
#
|
|
# Pull in parameters from a config file ~/.smegit/config
|
|
#
|
|
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 "git-retag.sh <modulename> <organization> [<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"
|
|
DEBUG=
|
|
if [ ${smegit_DEBUG} == "true" ] ; then DEBUG=true ; fi
|
|
|
|
REPO_NAME=$1
|
|
ORGGITEA=$2
|
|
GITEAUser=${remote_USER}
|
|
GITEAACCESSTOKEN=${remote_GITEAACCESSTOKEN}
|
|
GITEAHOST=${remote_GITEAHOST}
|
|
NOISY=
|
|
CLEAN=
|
|
EXTRAPARAMS=
|
|
for param in $3 $4 $5 $6 ; do
|
|
if [ $param ] ; then
|
|
case $param in
|
|
local )
|
|
GITEAUser=${local_USER}
|
|
GITEAACCESSTOKEN=${local_GITEAACCESSTOKEN}
|
|
GITEAHOST=${local_GITEAHOST}
|
|
;;
|
|
debug )
|
|
DEBUG=true ;;
|
|
noisy )
|
|
NOISY=true ;;
|
|
clean )
|
|
CLEAN=true ;;
|
|
* )
|
|
echo "Unkown parameter: $param"
|
|
exit 1
|
|
;;
|
|
esac
|
|
else
|
|
break
|
|
fi
|
|
done
|
|
|
|
if [ $NOISY ] ; then echo "git-retag.sh $1 $2 $3 $4 $5 $6" ; fi
|
|
if [ $DEBUG ] ; then echo "************found ini file: $inifilename" ; fi
|
|
# Make this null if you want lots of output. Still quite a bit anyway
|
|
QUIET="-q"
|
|
SILENT4CURL="-s"
|
|
SILENT4MAKE="-s"
|
|
if [ $DEBUG ] ; then
|
|
QUIET=
|
|
SILENT4CURL="-v"
|
|
SILENT4MAKE=
|
|
fi
|
|
# Make this null to get curl to check ssl cert
|
|
checkSSL="-k"
|
|
|
|
LOCALUser=${local_USER}
|
|
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
|
|
RemoteRepoURL="$GITEAHOST/$ORGGITEA/$REPO_NAME"
|
|
|
|
# Make sure credentials taken from store
|
|
# The first time you pull or push it will ask for credentials and then save them in a file.
|
|
git config --global credential.helper store
|
|
|
|
# Create the local Git repository
|
|
GITFiles=$WORKDIR/$ORGGITEA
|
|
mkdir -p $GITFiles
|
|
cd $GITFiles
|
|
|
|
# Delete the local first
|
|
if [ -d "$REPO_NAME" ] ; then
|
|
if [ $DEBUG ] ; then echo "************Deleting local GIT files" ; fi
|
|
rm -Rf $GITFiles/$REPO_NAME
|
|
fi
|
|
|
|
# See if it exists on the Gitea host
|
|
if [ $DEBUG ] ; then echo "check that $GITEAHOST/$ORGGITEA/$REPO_NAME exists" ; fi
|
|
RESPONSE=$(curl $checkSSL $SILENT4CURL -o /dev/null -w "%{http_code}" "$GITEAHOST/api/v1/repos/$ORGGITEA/$REPO_NAME")
|
|
if [ "$RESPONSE" == "200" ]; then
|
|
if [ $DEBUG ] ; then echo "************Repository for $REPO_NAME exists, cloning!" ; fi
|
|
# If so, clone it (just want the README.md)
|
|
if [ $DEBUG ] ; then echo "git clone $GITEAHOST/$ORGGITEA/$REPO_NAME.git" ; fi
|
|
cd $GITFiles
|
|
git clone "$GITEAHOST/$ORGGITEA/$REPO_NAME.git"
|
|
else
|
|
echo "************Repository for $ORGGITEA/$REPO_NAME does not exist. Aborting $RESPONSE"
|
|
exit 1
|
|
fi
|
|
|
|
cd $GITFiles/$REPO_NAME
|
|
if [ $CLEAN ] ; then
|
|
# read the existing tags
|
|
OLDTAGS=$(git tag --list)
|
|
# delete old tag/s
|
|
for tag in $OLDTAGS ; do
|
|
git tag --delete $tag
|
|
git push origin --delete $tag
|
|
git push --tags
|
|
done
|
|
fi
|
|
# Now create the version and release tag from the specfile
|
|
VERSION_RELEASE_LONG=`rpm --queryformat '%{version} %{release}\n' --specfile $REPO_NAME.spec`
|
|
VERSION_RELEASE=${VERSION_RELEASE_LONG%%$'\n'*}
|
|
VERSION=${VERSION_RELEASE% *}
|
|
RELEASE=${VERSION_RELEASE#* }
|
|
TAG=$VERSION"-"${RELEASE%.*}
|
|
if [ $DEBUG ] ; then
|
|
echo "VERSION_RELEASE=$VERSION_RELEASE"
|
|
echo "VERSION=$VERSION"
|
|
echo "RELEASE=$RELEASE"
|
|
echo "TAG=$TAG"
|
|
fi
|
|
git pull
|
|
git tag -a $TAG -m "Setting tag to current Version-Release in spec file: $TAG"
|
|
git push origin --tag $TAG $QUIET
|
|
|
|
echo "Current $ORGGITEA/$REPO_NAME tagged as $TAG - old tags removed"
|
|
exit 0
|