smeserver-gitutils/git-cvs2git.sh
2023-11-17 09:35:33 +11:00

765 lines
30 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
# This works whether the repo and local files exist of not (it deletes them if necessary)
# However if the remote repo exists, it preserves the README.md file so that edits are not lost
# Also note: I have had difficulty deleting all the link files in the source tree!
#
if [[ -z $1 ]] ; then
echo "************git-cvs2git.sh <modulename> <organization> [<local>]"
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-cvs2git.sh <modulename> <organization> [<local>]"
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
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 ;;
* )
EXTRAPARAMS=$EXTRAPARAMS" "$param ;;
esac
else
break
fi
done
if [ $NOISY ] ; then echo "git-cvs2git.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/$2/$1"
#
# Unless you have changed this, this (below) is my (brian) OpenAI token, but happy to use it here, it costs peanuts!
# unless you delete the repo in between duplicate runs, then the README.md is preserved, so the ChatGPT is only called once.
# but it means you can edit the results on gitea without fear of loosing your edits if the repo is re-created using this script
#
export OPENAI_API_KEY=${smegit_OPENAI_API_KEY}
COMMONREPO=${smegit_COMMONREPO}
# Name is re-initialised later on from the spec file
NAME=$1
# Prepare variable for file in repo to indicate core or contrib.
# and init gitea organisation
# Adjust where we put the repo locally accordingly.
ORGGITEA=$2
if [[ "$2" == "smecontribs" ]]; then
BASEORCONTRIB="contribs10"
PRODUCTBUGZILLA="SME%20Contribs"
else
BASEORCONTRIB="sme10"
PRODUCTBUGZILLA="SME%20Server%2010.X"
fi
# Work out if it is an SMEServer package or a 3rd party one
if [[ "$NAME" =~ ^(smeserver-|e-smith-).* ]]; then
PACKAGETYPE="SMEServer Koozali developed"
else
PACKAGETYPE="3rd Party (Maintained by Koozali)"
fi
# Check that git-lfs is installed
if command -v git-lfs > /dev/null; then
if [ $DEBUG ] ; then echo "************Git LFS is installed" ; fi
else
echo "ERROR********************** Git LFS is not installed ******************"
exit 1
fi
# Check that jq is installed
if command -v jq -V > /dev/null; then
if [ $DEBUG ] ; then echo "************Jq is installed" ; fi
else
echo "ERROR********************** jq is not installed (try EPEL)**************"
exit 1
fi
# Check that lua is installed (needed for change-log)
if command -v lua -V > /dev/null; then
if [ $DEBUG ] ; then echo "************lua is installed" ; fi
else
echo "ERROR********************** lua is not installed (try EPEL)**************"
exit 1
fi
# and check for the special scripts - changelog and BogusDateBot.sh - I think these are available in the
# mockbuild rpm, but beware Bug:12340 - changelog needs an edit to work!
if type -P change-log >/dev/null 2>&1; then
if [ $DEBUG ] ; then echo "************change-log is installed" ; fi
else
echo "ERROR********************change-log is not installed*********** (try installing smeserver-mockbuild)"
exit 1
fi
if [ $DEBUG ] ; then echo "************..and also note bug:12340" ; fi
if type -P BogusDateBot.sh >/dev/null 2>&1; then
if [ $DEBUG ] ; then echo "************BogusDateBot.sh is installed"; fi
else
echo "ERROR********************BogusDateBot.sh is not installed*********** (try installing smeserver-mockbuild)"
exit 1
fi
# Create work directories
cd $WORKDIR
CVSFiles="$WORKDIR/$2/rpms"
#echo $CVSFiles
mkdir -p $CVSFiles
# 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
#
# Clone the CVS repository
#
cd $CVSFiles
# First delete any existing module directory tree
# if there at all
if [ -d "$1" ] ; then
if [ $DEBUG ] ; then echo "************Deleting local CVS files" ; fi
rm -Rf $CVSFiles/$1
fi
# Then get it fully from CVS
cd $CVSFiles
cvs -d:ext:shell.koozali.org:/cvs/$2 $QUIET checkout $1
# Check that the spec file is there
# First bet is the packagename.spec
SPECFILE=$1/$BASEORCONTRIB/$1.spec
ORIGSPECFILE=$SPECFILE
GOTONE=0
if [ ! -f $SPECFILE ] ; then
# See if it is a perl package which has the perl or perl-pear taken off the front
for front in "perl-" "perl-pear-" ; do
reg="^($front).*"
echo "$front $1 $reg"
if [[ "$1" =~ $reg ]]; then
NEWNAME="${1#$front}"
#echo $NEWNAME
SPECFILE="$1/$BASEORCONTRIB/$NEWNAME.spec"
#echo $SPECFILE
if [ -f $SPECFILE ] ; then
GOTONE=1
break
fi
fi
done
# Otherwise, just pull out the first spec file in the directory
cd $1/$BASEORCONTRIB
SPECFILE=$(ls *.spec | head -n 1)
SPECFILE=$1/$BASEORCONTRIB/$SPECFILE
cd $CVSFiles
echo '2nd try: '$SPECFILE
if [ -f $SPECFILE ] ; then
GOTONE=1
ORIGSPECFILE=$SPECFILE
fi
else
GOTONE=1
fi
if [[ $GOTONE -eq 0 ]] ; then
echo "Cannot find .spec file: `pwd`/$ORIGSPECFILE"
exit 1
fi
# Create the local Git repository
GITFiles=$WORKDIR/$ORGGITEA
mkdir -p $GITFiles
cd $GITFiles
# Delete the local first
if [ -d "$1" ] ; then
if [ $DEBUG ] ; then echo "************Deleting local GIT files" ; fi
rm -Rf $GITFiles/$1
fi
# See if it exists on the Gitea host
REPO_NAME=$1
if [ $DEBUG ] ; then echo "check that $GITEAHOST/$ORGGITEA/$REPO_NAME exists" ; fi
READMECONTENTS=
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 $1 already exists!" ; fi
# If so, clone it (just want the README.md)
if [ $DEBUG ] ; then echo "git clone $GITEAHOST/$ORGGITEA/$1.git" ; fi
cd $GITFiles
git clone "$GITEAHOST/$ORGGITEA/$1.git"
if [[ -f $GITFILES/$1/README.md ]] ; then
# Move it and remember its new (temp) name
READMECONTENTS=`mktemp`
mv -f README.md "$READMECONTENTS"
fi
# Now delete the repo, re-create it and clone it in to local
if [ $DEBUG ] ; then echo "Delete $ORGGITEA/$1" ; fi
RESPONSE=$(curl "$checkSSL" "$SILENT4CURL" -o /dev/null -w "%{http_code}" -X 'DELETE' \
"$GITEAHOST/api/v1/repos/$ORGGITEA/$1" \
-H 'accept: application/json' \
-H "Authorization: token $GITEAACCESSTOKEN")
if [[ $RESPONSE == "204" || $RESPONSE == "404" ]] ; then
if [ $DEBUG ] ; then echo "************Repository $ORGGITEA/$1 deleted or does not exist" ; fi
else
echo "************Can NOT delete Repository $ORGGITEA/$1 - results will be unknown - Aborting!"
echo "RESPONSE=$RESPONSE"
exit 1
fi
# Delete all files, links and directories
if [ $DEBUG ] ; then echo "************Deleting local GIT files" ; fi
cd $GITFiles
rm -Rf $GITFiles/$1
else
if [ $DEBUG ] ; then echo "************Repository for $1 does not exist." ; fi
fi
cd $GITFiles
#git init $QUIET $1
#
# Re-create the repo
#
if [ $DEBUG ] ; then echo "************Creating repo for $1 $PACKAGETYPE" ; fi
RESPONSE=$(curl "$checkSSL" "$SILENT4CURL" -X 'POST' \
"$GITEAHOST/api/v1/orgs/$ORGGITEA/repos" \
-H 'accept: application/json' \
-H "Authorization: token $GITEAACCESSTOKEN" \
-H 'Content-Type: application/json' \
-d '{
"auto_init": true,
"default_branch": "master",
"description": "'"$PACKAGETYPE git repo for $1 $2"'",
"gitignores": "",
"issue_labels": "Default",
"license": "Apache-2.0",
"name": "'"$1"'",
"private": false,
"readme": "Default",
"template": false,
"trust_model": "Default Trust Model"
}')
if [ $DEBUG ] ; then echo $RESPONSE ; fi
# and extract the http URL for it
HTTP_URL=`echo $RESPONSE | jq -r '.html_url'`
if [ $DEBUG ] ; then echo $HTTP_URL ; fi
if [[ -z "${HTTP_URL}" ]]; then
echo "ERROR*******Repo for $1 appears NOT to have been created "
echo "$RESPONSE"
exit 1
fi
# And check it now exists
RESPONSE=$(curl "$SILENT4CURL" -o /dev/null -w "%{http_code}" "$GITEAHOST/api/v1/repos/$ORGGITEA/$1")
if [[ "$RESPONSE" == "200" ]]; then
if [ $DEBUG ] ; then echo "************Repository for $1 exists" ; fi
else
echo "ERROR*******Repository for $1 has not been created ($RESPONSE)"
exit 1
fi
# Pull in the auto created or updated files
cd $GITFiles
#GIT_SSL_NO_VERIFY=true git clone "$GITEAHOST/$ORGGITEA/$1.git"
git clone "$GITEAHOST/$ORGGITEA/$1.git"
if [ ! -d $GITFiles/$1 ] ; then
echo "ERROR*******Unable to access the new repo directory for $HTTP_URL $GITFiles/$1"
exit 1
fi
cd $CVSFiles/$1/$BASEORCONTRIB
# Fully populate the directory (gets the tar file - which is not strictly in CVS) and creates the directory source tree
# applying the patches to the base in the tar file.
# Might need to replace this by the code from the makefile if we decide to move "make prep" to git moe likely we'll implement a new one "make gitprep".
make $SILENT4MAKE prep
#echo `pwd`; exit 0
# Extract the directory name for the file tree (it will include the name of the module plus some version information)
# Same trick that we use in the makefile.common - taking the name and verison from the .spec file.
NAME=`ls *.spec|sed 's/\.spec//'`
VERSION=`rpm --queryformat '%{version}\n' --specfile $NAME.spec | head -n 1`
TREEPATH=$NAME-$VERSION
CODEDIR="root"
EXT=$(cat "$(basename $SPECFILE)" | grep -i ^Source | head -n 1 | sed -r 's/^[S|s]ource[0..9]?:\s?//' | xargs basename | sed -E 's/^([^.]*\.)(.*)$/\2/')
#echo $EXT $SPECFILE $(basename $SPECFILE) `pwd`
#exit 0
ARCHIVEFILE=$(cat "$(basename $SPECFILE)" | grep ^Source | head -n 1 | sed -r 's/^[S|s]ource[0..9]?:\s?//' | xargs basename)
ARCHIVEFILE=$(rpm --queryformat "$ARCHIVEFILE\n" --specfile "$(basename $SPECFILE)" | head -n 1)
if [ $DEBUG ] ; then echo $ARCHIVEFILE $EXT $SPECFILE ; fi
# Check that we got the filename (possible define in it not expanded?)
if [ ! -f $ARCHIVEFILE ]; then
# Try another tack
if [ $DEBUG ] ; then echo "************File $ARCHIVE does not exist - trying *.$EXT" ; fi
ARCHIVEFILE=`ls *.$EXT | head -n 1`
if [[ ! -f $ARCHIVEFILE || -z $ARCHIVEFILE ]]; then
echo "ERROR*******Can't identify archive file $ARCHIVEFILE $EXT `pwd`"
exit 1
fi
fi
if [ $DEBUG ] ; then echo "************TreePATH:$TREEPATH and Archivefile:$ARCHIVEFILE `pwd`" ; fi
# pull in all the files we want
cd $GITFiles/$1
# Add file indicating which release and contribs or base - this is matched by the makefile with the contents of the branch file in the common directory
# to give the details of the release (EL7/8/9/ etc)
# This assumes SME10 and contribs10 or sme10 directory names, later releases can update the value in the file and Makefile should still work.
echo $BASEORCONTRIB > contriborbase
# Note that e-smith-backup base module has "Copying" not in all caps - seems to be the only one not in line.
BASESPECFILE=$(basename $SPECFILE)
for fpath in "$BASESPECFILE" "Makefile"
do
if [ $DEBUG ] ; then echo "************Copying $CVSFiles/$1/$BASEORCONTRIB/$fpath" ; fi
if [[ -f $CVSFiles/$1/$BASEORCONTRIB/$fpath ]] ; then
cp -R $CVSFiles/$1/$BASEORCONTRIB/$fpath .
else
echo "ERROR*******Expected to find $fpath in $CVSFiles/$1/$BASEORCONTRIB"
exit 1
fi
done
# and see if the spec file is not according to specification of <packagename>.spec
# if not rename it
if [[ $SPECFILE != $ORIGSPECFILE ]] ; then
if [ $DEBUG ] ; then echo "************Renaming specfile from $(basename $SPECFILE) $(basename $ORIGSPECFILE)" ; fi
mv "$(basename $SPECFILE)" "$(basename $ORIGSPECFILE)"
SPECFILE=$ORIGSPECFILE
fi
if [[ ! "$NAME" =~ ^(smeserver-|e-smith-).* ]]; then
# add in the patches (a 3rd party package)
# it turns out that not all patches end in .patch, so extract the file names out of the spec file as per sources below
PATCHS=$(grep -i -E '^patch[0-9]*:' $(basename $SPECFILE) | cut -d: -f2- | sed 's/ //g')
if [ $DEBUG ] ; then echo "$PATCHS" ; fi
for fpath in $PATCHS; do
# Needs another step incase the extraction from the spec file contains spec variables
fpathfile=$(basename $fpath)
if [ $DEBUG ] ; then echo "$fpathfile" ; fi
translatefpath=$(rpm --queryformat "$fpathfile\n" --specfile $(basename $SPECFILE) | head -n 1)
if [ $DEBUG ] ; then echo "$translatefpath" ; fi
if [[ -f $CVSFiles/$1/$BASEORCONTRIB/$translatefpath ]] ; then
if [ $DEBUG ] ; then echo "************Copying $CVSFiles/$1/$BASEORCONTRIB/$translatefpath" ; fi
cp $CVSFiles/$1/$BASEORCONTRIB/$translatefpath .
else
if [ $DEBUG ] ; then echo "************Not found $CVSFiles/$1/$BASEORCONTRIB/$translatefpath ( $fpathfile )- so not copied" ; fi
fi
done
#for fpath in "*.patch"
#do
#echo "************Copying $CVSFiles/$1/$BASEORCONTRIB/$fpath"
#cp -R $CVSFiles/$1/$BASEORCONTRIB/$fpath .
#done
# See if the spec file needs an extra buildrequires (nothing to do with git! - things have changed since SME10.1)
# if the spec file includes "BuildRequires: perl(ExtUtils::MakeMaker)" and NOT "BuildRequires: perl(ExtUtils::Manifest)" then add the latter
if grep -q "^BuildRequires:.*perl(ExtUtils::MakeMaker)" "$(basename $SPECFILE)" && ! grep -q "^BuildRequires:.*perl(ExtUtils::Manifest)" "$(basename $SPECFILE)"; then
sed -i '/^BuildRequires:.*perl(ExtUtils::MakeMaker)/a BuildRequires: perl(ExtUtils::Manifest)' "$(basename $SPECFILE)"
if [ $DEBUG ] ; then echo "************Added 'BuildRequires: perl(ExtUtils::Manifest)' to the spec file." ; fi
else
if [ $DEBUG ] ; then echo "************No action was taken. The spec file either does not include 'BuildRequires: perl(ExtUtils::MakeMaker)' or already includes 'BuildRequires: perl(ExtUtils::Manifest)'." ; fi
fi
# and similar for another ExtUtils package - ParseXS
if grep -q "^BuildRequires:.*perl(ExtUtils::MakeMaker)" "$(basename $SPECFILE)" && ! grep -q "^BuildRequires:.*perl(ExtUtils::ParseXS)" "$(basename $SPECFILE)"; then
sed -i '/^BuildRequires:.*perl(ExtUtils::MakeMaker)/a BuildRequires: perl(ExtUtils::ParseXS)' "$(basename $SPECFILE)"
if [ $DEBUG ] ; then echo "************Added 'BuildRequires: perl(ExtUtils::ParseXS)' to the spec file." ; fi
else
if [ $DEBUG ] ; then echo "************No action was taken. The spec file either does not include 'BuildRequires: perl(ExtUtils::MakeMaker)' or already includes 'BuildRequires: perl(ExtUtils::ParseXS)'." ; fi
fi
# and similar for another devel package - needs manifest
if grep -q "^BuildRequires:.*perl-devel" "$(basename $SPECFILE)" && ! grep -q "^BuildRequires:.*perl(ExtUtils::Manifest)" "$(basename $SPECFILE)"; then
sed -i '/^BuildRequires:.*perl-devel/a BuildRequires: perl(ExtUtils::Manifest)' "$(basename $SPECFILE)"
if [ $DEBUG ] ; then echo "************Added 'BuildRequires: perl(ExtUtils::Manifest)' to the spec file." ; fi
else
if [ $DEBUG ] ; then echo "************No action was taken. The spec file either does not include 'BuildRequires: perl-devel' or already includes 'BuildRequires: perl(ExtUtils::Manifest)'." ; fi
fi
# Fix the rm in the pear packages - .filemap is no longer part of the download
if grep -q "^rm %{buildroot}/%{peardir}/.filemap" "$(basename $SPECFILE)"; then
sed -i 's/^rm *\%/rm -rf %/' "$(basename $SPECFILE)"
if [ $DEBUG ] ; then echo "************Added 'rm -rf %{buildroot}/%{peardir}/.filemap' to the spec file." ; fi
else
if [ $DEBUG ] ; then echo "************No action was taken. The spec file either does not include 'rm %{buildroot}/%{peardir}/.filemap' or already includes it" ; fi
fi
fi
## and there may be extra files that maybe needed, these can be identified from the "Source" spec in the .spec files
SOURCES=$(grep -i -E '^Source[0-9]*:' $(basename $SPECFILE) | cut -d: -f2- | sed 's/ //g')
if [ $DEBUG ] ; then echo "$SOURCES" ; fi
#SOURCE=$(rpm --queryformat '$SOURCE\n' --specfile $SPECFILE | head -n 1)
for fpath in $SOURCES; do
# Needs another step incase the extraction from the spec file contains spec variables
fpathfile=$(basename $fpath)
if [ $DEBUG ] ; then echo "$fpathfile" ; fi
translatefpath=$(rpm --queryformat "$fpathfile\n" --specfile $(basename $SPECFILE) | head -n 1)
if [ $DEBUG ] ; then echo "$translatefpath" ; fi
if [[ -f $CVSFiles/$1/$BASEORCONTRIB/$translatefpath ]] ; then
if [ $DEBUG ] ; then echo "************Copying $CVSFiles/$1/$BASEORCONTRIB/$translatefpath" ; fi
cp $CVSFiles/$1/$BASEORCONTRIB/$translatefpath .
else
if [ $DEBUG ] ; then echo "************Not found $CVSFiles/$1/$BASEORCONTRIB/$translatefpath ( $fpathfile )- so not copied" ; fi
fi
done
# Take out the logs and rpms from the git save
echo "*.rpm" >> .gitignore
echo "*.log" >> .gitignore
# and the backed up spec file from BogusDateBot.sh
echo "*spec-20*" >>.gitignore
cd $GITFiles/$1
# See if the package is a 3rd party or one of ours - indicated by "smeserver" or "e-smith" in the name
if [[ "$NAME" =~ ^(smeserver-|e-smith-).* ]]; then
# one of ours
if [ $DEBUG ] ; then echo "************Found SMEServer source for $NAME" ; fi
# Create the .gitignore file to ignore the archive
echo "*.$EXT" >> .gitignore
#and copy in the source tree
mkdir -p "$CODEDIR"
if [ $DEBUG ] ; then echo "************Copying $CVSFiles/$1/$BASEORCONTRIB/root `pwd`/$CODEDIR" ; fi
rsync "$QUIET" -a --no-prune-empty-dirs "$CVSFiles/$1/$BASEORCONTRIB/$TREEPATH/root/" "`pwd`/$CODEDIR/"
# copy createlinks to base
if [ -e "$CVSFiles/$1/$BASEORCONTRIB/$TREEPATH/createlinks" ] ; then cp "$CVSFiles/$1/$BASEORCONTRIB/$TREEPATH/createlinks" "`pwd`/." ; fi
# copy anything else in the base directory of $TREEPATH into the additional directory
if [ ! -d "`pwd`/additional" ] ; then mkdir -p "`pwd`/additional" ; fi
rsync "$QUIET" -av --exclude "createlinks" --exclude "root/" "$CVSFiles/$1/$BASEORCONTRIB/$TREEPATH/" "`pwd`/additional/"
# and plug a dummy into any empty directories
find "`pwd`/root"/* -type d -empty -exec touch {}/.gitignore \;
else
# Third party package
# copy over the archive file and make sure the extension is tracked by git-lfs
if [ $DEBUG ] ; then echo "************Found 3rd party package $NAME" ; fi
git lfs install
git lfs track "*.$EXT"
git add .gitattributes
#git config lfs.http://gitea.bjsystems.co.uk/SMEContribs/bugzilla.git/info/lfs.locksverify true
if [[ -f $CVSFiles/$1/$BASEORCONTRIB/$ARCHIVEFILE ]] ; then
if [ $DEBUG ] ; then echo "************Copying archivefile $CVSFiles/$1/$BASEORCONTRIB/$ARCHIVEFILE" ; fi
cp $CVSFiles/$1/$BASEORCONTRIB/$ARCHIVEFILE .
else
if [ $DEBUG ] ; then echo "Unable to find archivefile: $CVSFiles/$1/$BASEORCONTRIB/$ARCHIVEFILE - nothing copied" ; fi
fi
cd $GITFiles/$1
fi
cd $GITFiles/$1
#if [[ $ARCHIVEFILE != "$TREEPATH.tar.gz" ]] ; then
# echo "$ARCHIVEFILE" > archivefilename
#fi
# Take out any bogus dates:
BogusDateBot.sh $(basename $SPECFILE)
# If it is an SME package, take out the patches and then update the release.
if [[ "$NAME" =~ ^(smeserver-|e-smith-).* ]]; then
# Now edit the spec file to remove all those patches and adjust the paths
sed -i '/^Patch/d; /^%patch/d' $(basename $SPECFILE)
# no paths need adjusting at this time!
# - change Source: to new standard of tar.xz
sed -i '/^Source:/s/tar.gz/tar.xz/;s/tgz/tar.xz/' $(basename $SPECFILE)
# Bump the release and add changelog
change-log $(basename $SPECFILE)
# and edit in the reason
# sed - TBD - to look for "fix [SME: ]"
sed -i 's/fix \[SME: \]/Roll up patches and move to git repo \[SME: 12338\]/' $(basename $SPECFILE)
sed -i 's/ME MYSELF <myemail@koozali.org>/cvs2git.sh aka Brian Read <brianr@koozali.org>/' $(basename $SPECFILE)
# package specific changes needed because we use make prep to create the root tree
if [[ $NAME == "e-smith-grub" ]] ; then
sed -i '/^Source1:/d' $(basename $SPECFILE)
sed -i '/^Source2:/d' $(basename $SPECFILE)
sed -i '/^%setup/{n;N;N;N;d}' $(basename $SPECFILE)
sed -i '/\[SME: 12338\]/a - Remove Source1 & Source2 \[SME: 12338\]' $(basename $SPECFILE)
fi
if [[ $NAME == "e-smith-lib" ]] ; then
sed -i '/^%setup/{n;N;d}' $(basename $SPECFILE)
sed -i '/\[SME: 12338\]/a - Remove create e-smith-lib-update event \[SME: 12338\]' $(basename $SPECFILE)
fi
# Add in the autochangelog and autorelease macros into the spec file
# Commented out for now until we have build systems that can install the rpmautospec package (CEntos, Rocky etc V9 only so far)
# sed -i 's/Release:.*/Release: %autorelease/' $(basename $SPECFILE)
# and add in the autochangelog if it is not already there
# sed -i '/^%changelog$/a %autochangelog' $(basename $SPECFILE)
# Note that the Readme.md is updated below once the repo has been created
fi
## Clone the common directory - delete the contents first
#cd $GITFiles/$1
#if [ -d common ]
#then
#find common -delete
#fi
#git clone "${smegit_COMMONREPO}"
## Make sure common directory go created
#if [ ! -e $GITFiles/$1/common ]; then
#echo "ERROR*******No Common directory after git clone"
#exit 1
#fi
## and delete the .git else it pushes back a link to this repo in the new repo
#cd $GITFiles/$1/common
#rm -fr ".git"
## and set the make-archive.sh executible - this needs to be done on any git clone - not sure how or where.
#chmod +x make-archive.sh
# Re-factor the Common directory so that it is outside the repo being created.
# one Common directory for each Organisation
#
# See if it already exists
if [ ! -e $GITFiles/common ]; then
#Get it
cd $GITFiles
git clone "${smegit_COMMONREPO}"
if [ ! -e $GITFiles/common ]; then
echo "ERROR*******No Common Repo found - package $1"
exit 1
fi
else
# Just refresh it
cd $GITFiles/common
git pull $QUIET
fi
# Edit the Readme.md - try to add a link to the wiki for this package - only if it is an SME package
cd $GITFiles/$1
if [ $DEBUG ] ; then echo "************READMECONTENTS:$READMECONTENTS" ; fi
PACKAGENAME=${NAME}
if [[ "$NAME" =~ ^(smeserver-|e-smith-).* ]]; then
# See if we have a previous contents of the README.md
if [[ "$NAME" =~ ^(smeserver-).* ]]; then
PACKAGENAME=${NAME#smeserver-}
fi
# first find the relevant wiki entry
MEDIAWIKI_SITE="https://wiki.koozali.org/api.php"
SEARCH_TERM="$PACKAGENAME"
# Call the API to perform the search and store the JSON response in a variable
RESPONSE=$(curl -s "$MEDIAWIKI_SITE?action=query&format=json&list=search&srsearch=${SEARCH_TERM}&srprop=size%7Cwordcount%7Ctimestamp%7Csnippet&srlimit=10")
# Use jq to extract the titles and pageids of the pages that match the search term (case-insensitive)
RESULTS=$(echo "$RESPONSE" | jq -r '.query.search[] | select(.title | ascii_downcase | contains("'"${SEARCH_TERM}"'" | ascii_downcase)) | .title, .pageid')
# Loop through the results and construct the URL for each page
URLS=$(while read -r TITLE; do \
read -r PAGEID; \
URL="https://wiki.koozali.org/${TITLE}"; \
URL=$(echo $URL | sed 's/ /_/g'); \
echo "<br />${URL}"; \
done <<< "${RESULTS}" )
# and get the first non french (sorry JP!)
WIKILINK=$(while read -r TITLE; do \
read -r PAGEID; \
URL="https://wiki.koozali.org/${TITLE}"; \
URL=$(echo $URL | sed 's/ /_/g'); \
if [[ ! "$URL" =~ 'fr' ]] ; then echo "${URL}"; break; fi \
done <<< "${RESULTS}" )
if [[ "$READMECONTENTS" == "" ]]; then
# nothing previous
# Copy across the Wiki links to the README
if [ ! "$URLS" = "" ]; then
if [ $DEBUG ] ; then echo "************The wiki page(s) for $PACKAGENAME exist." ; fi
echo -en "\n\n## Wiki\n$URLS" >> README.md
fi
# And add bugzilla link
echo -en "\n\n## Bugzilla" >> README.md
echo -en "\nShow list of outstanding bugs: [here](https://bugs.koozali.org/buglist.cgi?component=$1&product=$PRODUCTBUGZILLA&query_format=advanced&limit=0&bug_status=UNCONFIRMED&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&bug_status=CONFIRMED)" >> README.md
# Edit the header to add the logo
#KOOZALILOGO='<img src="http:\/\/vps.bjsystems.co.uk\/KoozaliLogo4GiteaRepo.png" style="vertical-align:bottom">'
KOOZALILOGO='<img src="https:\/\/www.koozali.org\/images\/koozali\/Logo\/Png\/Koozali_logo_2016.png" width="25%" vertical="auto" style="vertical-align:bottom">'
if [[ "$NAME" =~ ^(smeserver-).* ]]; then
sed -i "s/^# smeserver/# $KOOZALILOGO smeserver/" README.md
else
sed -i "s/^# e-smith/# $KOOZALILOGO e-smith/" README.md
fi
# Good to extract some of the wiki here, and load it into the readme,
# OR I could ask GPTChat to write me paragraph on the contrib 8-))
# Set the parameters for the request
if [[ "$NAME" =~ ^(smeserver-).* && "$2" == "smecontribs" ]]; then
prompt="Write me a paragraph on the $PACKAGENAME software contrib for smeserver"
else
prompt="Write me a paragraph about the software $PACKAGENAME"
fi
model="text-davinci-003"
temperature=0.8
# Send the request to the API
response=$(curl "$SILENT4CURL" -X POST https://api.openai.com/v1/engines/$model/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{"prompt": "'"$prompt"'", "temperature": 0.8, "max_tokens": 256}')
# Extract the text from the response
PARAGRAPH=`echo $response | jq -r '.choices[].text'`
# Add it to what was there already
if [ $DEBUG ] ; then echo "************Creating description for $1" ; fi
echo -e "\n\n## Description\n" >> README.md
echo -e "<br />*This description has been generated by an LLM AI system and cannot be relied on to be fully correct.*" >> README.md
echo -e "*Once it has been checked, then this comment will be deleted*" >> README.md
echo -e "<br />$PARAGRAPH" >> README.md
else
# overwrite with previous contents
if [ $DEBUG ] ; then echo "************Picked up previous README contents" ; fi
mv -f $READMECONTENTS ./README.md
fi
else
if [ "$READMECONTENTS" == "" ]; then
# Add in at least a description
prompt="Tell me what the software package $PACKAGENAME does?"
model="text-davinci-003"
temperature=0.8
# Send the request to the API
response=$(curl "$SILENT4CURL" -X POST https://api.openai.com/v1/engines/$model/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{"prompt": "'"$prompt"'", "temperature": 0.8, "max_tokens": 256}')
# Extract the text from the response
PARAGRAPH=`echo $response | jq -r '.choices[].text'`
# Add it to what was there already
if [ $DEBUG ] ; then echo "************Creating description for $1" ; fi
echo -e "\n\n## Description\n" >> README.md
echo -e "<br />*This description has been generated by an LLM AI system and cannot be relied on to be fully correct.*" >> README.md
echo -e "*Once it has been checked, then this comment will be deleted*" >> README.md
echo -e "<br />$PARAGRAPH" >> README.md
else
# overwrite with previous contents
if [ $DEBUG ] ; then echo "************Picked up previous README contents" ; fi
mv -f $READMECONTENTS ./README.md
fi
fi
# Tell repo to use koozali.org bugzilla and wiki - this does not work on CREATE currently - 19Apr2023
if [[ -z $WIKILINK ]] ; then
WIKILINK="https://wiki.koozali.org"
fi
# and then update the repo parameters
RESPONSE=$(curl "$SILENT4CURL" -X 'PATCH' "$GITEAHOST/api/v1/repos/$ORGGITEA/$REPO_NAME" \
-H 'accept: application/json' \
-H "Authorization: token $GITEAACCESSTOKEN" \
-H 'Content-Type: application/json' \
-d '{
"external_tracker": {
"external_tracker_format": "https://bugs.koozali.org/show_bug.cgi?id={index}",
"external_tracker_style": "numeric",
"external_tracker_url": "'"https://bugs.koozali.org/buglist.cgi?component=$REPO_NAME&product=$PRODUCTBUGZILLA"'"
},
"external_wiki": {
"external_wiki_url": "'"$WIKILINK"'"
}
}
')
# should check response here.
if [ $DEBUG ] ; then echo $RESPONSE ; fi
#exit 0
cd $GITFiles/$1
# stage and commit all the files created locally
git add -A
echo "$1 git status" >>gitstatus.log
git status >>gitstatus.log
if [ $DEBUG ] ; then git status ; fi
COMMENT="initial commit of file from CVS for $1 on `date`"
git commit -m "$COMMENT" $QUIET
# push the converted git repository to the remote
git remote remove origin
git remote add origin "$GITEAHOST/$ORGGITEA/$1.git"
#GIT_SSL_NO_VERIFY=true git push --force -u $QUIET origin master
git push --force -u $QUIET origin master
# Now create the version and release tag for these files
RELEASE=`rpm --queryformat '%{release}\n' --specfile $NAME.spec | head -n 1`
# 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 "$COMMENT"
git push origin $TAG $QUIET
echo "Created $1 Repo: $HTTP_URL - Comment:$COMMENT tag:$TAG"
exit 0