2023-11-17 02:40:43 +01:00
|
|
|
#!/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
|
|
|
|
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
|
2023-11-17 04:49:55 +01:00
|
|
|
REPO_NAME=$1
|
|
|
|
ORGGITEA=$2
|
2023-11-17 02:40:43 +01:00
|
|
|
GITEAUser=${remote_USER}
|
|
|
|
GITEAACCESSTOKEN=${remote_GITEAACCESSTOKEN}
|
|
|
|
GITEAHOST=${remote_GITEAHOST}
|
|
|
|
NOISY=
|
|
|
|
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 ;;
|
|
|
|
* )
|
|
|
|
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
|
2023-11-17 04:49:55 +01:00
|
|
|
RemoteRepoURL="$GITEAHOST/$ORGGITEA/$REPO_NAME"
|
2023-11-17 02:40:43 +01:00
|
|
|
|
|
|
|
# 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
|
2023-11-17 04:49:55 +01:00
|
|
|
if [ -d "$REPO_NAME" ] ; then
|
2023-11-17 02:40:43 +01:00
|
|
|
if [ $DEBUG ] ; then echo "************Deleting local GIT files" ; fi
|
2023-11-17 04:49:55 +01:00
|
|
|
rm -Rf $GITFiles/$REPO_NAME
|
2023-11-17 02:40:43 +01:00
|
|
|
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
|
2023-11-17 04:49:55 +01:00
|
|
|
if [ $DEBUG ] ; then echo "************Repository for $REPO_NAME exists, cloning!" ; fi
|
2023-11-17 02:40:43 +01:00
|
|
|
# If so, clone it (just want the README.md)
|
2023-11-17 04:49:55 +01:00
|
|
|
if [ $DEBUG ] ; then echo "git clone $GITEAHOST/$ORGGITEA/$REPO_NAME.git" ; fi
|
2023-11-17 02:40:43 +01:00
|
|
|
cd $GITFiles
|
2023-11-17 04:49:55 +01:00
|
|
|
git clone "$GITEAHOST/$ORGGITEA/$REPO_NAME.git"
|
2023-11-17 02:40:43 +01:00
|
|
|
else
|
2023-11-17 04:49:55 +01:00
|
|
|
echo "************Repository for $ORGGITEA/$REPO_NAME does not exist. Aborting $RESPONSE"
|
2023-11-17 02:40:43 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-11-17 04:49:55 +01:00
|
|
|
cd $GITFiles/$REPO_NAME
|
2023-11-17 02:40:43 +01:00
|
|
|
# read the existing tags
|
|
|
|
OLDTAGS=$(git tag --list)
|
|
|
|
# delete old tag/s
|
|
|
|
for tag in $OLDTAGS ; do
|
|
|
|
git tag --delete $tag
|
|
|
|
done
|
|
|
|
# Now create the version and release tag from the specfile
|
2023-11-17 04:49:55 +01:00
|
|
|
VERSION_RELEASE=`rpm --queryformat '%{version} %{release}\n' --specfile $REPO_NAME.spec`
|
|
|
|
VERSION=${VERSION_RELEASE% *}
|
|
|
|
RELEASE=${VERSION_RELEASE#* }
|
2023-11-17 02:40:43 +01:00
|
|
|
# Release is not reliable - if you run on Rocky it comes back EL8, centos 7 - EL7
|
|
|
|
# So, we need to just take the build part (first word)
|
|
|
|
TAG=$VERSION"-"${RELEASE%.*}
|
|
|
|
git tag -a $TAG -m "Setting tag to current Version-Release in spec file: $TAG"
|
2023-11-17 04:49:55 +01:00
|
|
|
git push --tags origin $QUIET
|
2023-11-17 02:40:43 +01:00
|
|
|
|
2023-11-17 04:49:55 +01:00
|
|
|
echo "Current $ORGGITEA/REPO_NAME tagged as $TAG - old tags removed"
|
2023-11-17 02:40:43 +01:00
|
|
|
exit 0
|