2023-05-09 05:34:39 +02:00
#!/bin/bash
#
# $1 = Module name e.g. smeserver-ddclient
# $2 = Organisation (smeserver or smecontrib)e
# $3 = "local" will use parameters set for local repository else it will use remote
# 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
2023-05-10 02:17:35 +02:00
echo "************git-cvs2git.sh <modulename> <organization> [<local>]"
2023-05-09 05:34:39 +02:00
exit 0
fi
clear
echo "**************************************************************************************************"
echo "* *"
2023-05-10 02:17:35 +02:00
echo " * SMEServer - git-cvs2git $1 $2 $3 `date` * "
2023-05-09 05:34:39 +02:00
echo "* *"
echo "**************************************************************************************************"
#
# Pull in parameters from a config file ~/.smegit/config
#
inifilename = $( echo ~) "/.smegit/config"
if [ ! -e $inifilename ] ; then
2023-05-10 02:17:35 +02:00
# 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
2023-05-09 05:34:39 +02:00
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 "
2023-05-11 07:29:55 +02:00
DEBUG =
2023-05-09 05:34:39 +02:00
if [ ${ smegit_DEBUG } = = "true" ] ; then DEBUG = true ; fi
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo " ************found ini file: $inifilename " ; fi
2023-05-09 05:34:39 +02:00
# Make this null if you want lots of output. Still quite a bit anyway
QUIET = "-q"
2023-05-09 09:46:24 +02:00
curlsilent = "-s"
2023-05-22 03:37:20 +02:00
suppress = " > /dev/null 2>&1"
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then
QUIET =
2023-05-11 07:29:55 +02:00
curlsilent = "-v"
2023-05-22 03:37:20 +02:00
suppress =
2023-05-09 09:46:24 +02:00
fi
2023-05-09 05:34:39 +02:00
# Make this null to get curl to check ssl cert
checkSSL = "-k"
LOCALUser = ${ local_USER }
2023-05-10 02:17:35 +02:00
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
GITEAUser = ${ remote_USER }
GITEAACCESSTOKEN = ${ remote_GITEAACCESSTOKEN }
GITEAHOST = ${ remote_GITEAHOST }
if [ $3 ] ; then
if [ $3 = = "local" ] ; then
GITEAUser = ${ local_USER }
GITEAACCESSTOKEN = ${ local_GITEAACCESSTOKEN }
GITEAHOST = ${ local_GITEAHOST }
fi
2023-05-09 07:16:55 +02:00
fi
2023-05-09 05:34:39 +02:00
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
cd $WORKDIR
CVSFiles = " $WORKDIR / $2 /rpms "
#echo $CVSFiles
mkdir -p $CVSFiles
# Check that git-lfs is installed
if command -v git-lfs > /dev/null; then
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo "************Git LFS is installed" ; fi
2023-05-09 05:34:39 +02:00
else
echo "ERROR********************** Git LFS is not installed ******************"
exit 1
fi
# Check that jq is installed
if command -v jq -V > /dev/null; then
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo "************Jq is installed" ; fi
2023-05-09 05:34:39 +02:00
else
echo "ERROR********************** jq 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
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo "************change-log is installed" ; fi
2023-05-09 05:34:39 +02:00
else
echo "ERROR********************change-log is not installed*********** (try installing smeserver-mockbuild)"
fi
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo "************..and also note bug:12340" ; fi
2023-05-09 05:34:39 +02:00
if type -P BogusDateBot.sh >/dev/null 2>& 1; then
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo "************BogusDateBot.sh is installed" ; fi
2023-05-09 05:34:39 +02:00
else
echo "ERROR********************BogusDateBot.sh is not installed*********** (try installing smeserver-mockbuild)"
fi
# 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.
2023-05-25 10:10:03 +02:00
git config --global credential.helper store
2023-05-09 05:34:39 +02:00
#
# Clone the CVS repository
#
cd $CVSFiles
# First delete any existing module directory tree
# if there at all
if [ -d " $1 " ] ; then
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo "************Deleting local CVS files" ; fi
2023-05-09 10:33:32 +02:00
rm -Rf $CVSFiles /$1
2023-05-09 05:34:39 +02:00
fi
# Then get it fully from CVS
cd $CVSFiles
2023-05-22 03:37:20 +02:00
cvs -d:ext:shell.koozali.org:/cvs/$2 $QUIET checkout $1
2023-05-09 05:34:39 +02:00
# 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
2023-05-12 03:29:42 +02:00
if [ [ " $2 " = = "smecontribs" ] ] ; then
2023-05-09 05:34:39 +02:00
BASEORCONTRIB = "contribs10"
PRODUCTBUGZILLA = "SME%20Contribs"
else
BASEORCONTRIB = "sme10"
PRODUCTBUGZILLA = "SME%20Server%2010.X"
fi
# 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 /GITFiles/$ORGGITEA
mkdir -p $GITFiles
cd $GITFiles
# Delete the local first
if [ -d " $1 " ] ; then
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo "************Deleting local GIT files" ; fi
2023-05-09 10:33:32 +02:00
rm -Rf $GITFiles /$1
2023-05-09 05:34:39 +02:00
fi
# See if it exists on the Gitea host
REPO_NAME = $1
2023-05-12 03:34:36 +02:00
if [ $DEBUG ] ; then echo " check that $GITEAHOST / $ORGGITEA / $REPO_NAME exists " ; fi
2023-05-11 07:29:55 +02:00
RESPONSE = $( curl $checkSSL $curlsilent -o /dev/null -w "%{http_code}" " $GITEAHOST /api/v1/repos/ $ORGGITEA / $REPO_NAME " )
2023-05-09 05:34:39 +02:00
if [ " $RESPONSE " = = "200" ] ; then
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo " ************Repository for $1 already exists! " ; fi
2023-05-09 05:34:39 +02:00
# If so, clone it (just want the README.md)
# And Clone it
2023-05-11 07:29:55 +02:00
if [ $DEBUG ] ; then echo " git clone $GITEAHOST / $ORGGITEA / $1 .git " ; fi
2023-05-09 05:34:39 +02:00
cd $GITFiles
2023-05-25 10:10:03 +02:00
git clone " $GITEAHOST / $ORGGITEA / $1 .git "
2023-05-09 05:34:39 +02:00
#GIT_SSL_NO_VERIFY=true git clone "$GITEAHOST/$ORGGITEA/$1.git"
NOREPO = 0
else
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo " ************Repository for $1 does not exist. " ; fi
2023-05-09 05:34:39 +02:00
NOREPO = 1
fi
# then pull in the README
READMECONTENTS = "" ;
cd $GITFiles
if [ -d " $1 " ] ; then
cd $GITFiles /$1
# Retain the contents of the README.md (incase its been editted, and saving multiple GPT accesses)
2023-05-12 03:29:42 +02:00
if [ -f README.md ] ; then
2023-05-09 05:34:39 +02:00
# Move it and remember its new (temp) name
READMECONTENTS = ` mktemp`
mv -f README.md " $READMECONTENTS "
fi
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo " ************Saved README: $READMECONTENTS " ; fi
2023-05-09 05:34:39 +02:00
# Delete all files, links and directories
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo "************Deleting local GIT files" ; fi
cd $GITFiles
2023-05-09 10:33:32 +02:00
rm -Rf $GITFiles /$1
2023-05-09 05:34:39 +02:00
fi
cd $GITFiles
#git init $QUIET $1
2023-06-01 01:07:39 +02:00
# 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
# Now delete the repo, re-create it and clone it in to local
2023-05-11 07:29:55 +02:00
if [ $DEBUG ] ; then echo " Delete $ORGGITEA / $1 " ; fi
2023-06-01 01:07:39 +02:00
RESPONSE = $( curl " $checkSSL " " $curlsilent " -X 'DELETE' \
2023-05-09 05:34:39 +02:00
" $GITEAHOST /api/v1/repos/ $ORGGITEA / $1 " \
-H 'accept: application/json' \
2023-06-01 01:07:39 +02:00
-H " Authorization: token $GITEAACCESSTOKEN " )
if [ [ $RESPONSE = = "204" ] ] ; 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
2023-05-09 05:34:39 +02:00
# and check if it is here.
2023-05-11 07:29:55 +02:00
if [ $DEBUG ] ; then echo " Check if $ORGGITEA / $1 is there! " ; fi
2023-05-09 09:46:24 +02:00
RESPONSE = $( curl $curlsilent -o /dev/null -w "%{http_code}" " $GITEAHOST /api/v1/repos/ $ORGGITEA / $1 " )
2023-05-09 05:34:39 +02:00
if [ " $RESPONSE " = = "200" ] ; then
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo " ************Repository for $1 exists! " ; fi
2023-05-09 05:34:39 +02:00
GOTREPO = 0
else
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo " ************Repository for $1 does not exist " ; fi
2023-05-09 05:34:39 +02:00
GOTREPO = 1
fi
#
2023-06-01 01:07:39 +02:00
# Create the repo
2023-05-09 05:34:39 +02:00
#
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo " ************Creating repo for $1 $PACKAGETYPE " ; fi
2023-06-01 01:07:39 +02:00
RESPONSE = $( curl " $checkSSL " " $curlsilent " -X 'POST' " $GITEAHOST /api/v1/orgs/ $ORGGITEA /repos " \
2023-05-09 05:34:39 +02:00
-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"
} ' )
2023-06-01 01:07:39 +02:00
if [ $DEBUG ] ; then echo $RESPONSE ; fi
2023-05-09 05:34:39 +02:00
2023-06-01 01:07:39 +02:00
# and extract the http URL for it
HTTP_URL = ` echo $RESPONSE | jq -r '.html_url' `
2023-05-09 05:34:39 +02:00
2023-06-01 01:07:39 +02:00
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
2023-05-09 05:34:39 +02:00
# And check it now exists
RESPONSE = $( curl -s -o /dev/null -w "%{http_code}" " $GITEAHOST /api/v1/repos/ $ORGGITEA / $1 " )
2023-05-12 03:29:42 +02:00
if [ [ " $RESPONSE " = = "200" ] ] ; then
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo " ************Repository for $1 exists " ; fi
2023-05-09 05:34:39 +02:00
else
2023-06-01 01:07:39 +02:00
echo " ERROR*******Repository for $1 has not been created ( $RESPONSE ) "
2023-05-09 05:34:39 +02:00
exit 1
fi
# Pull in the auto created or updated files
cd $GITFiles
#GIT_SSL_NO_VERIFY=true git clone "$GITEAHOST/$ORGGITEA/$1.git"
2023-05-25 10:10:03 +02:00
git clone " $GITEAHOST / $ORGGITEA / $1 .git "
2023-05-09 05:34:39 +02:00
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".
2023-05-25 10:10:03 +02:00
make prep
2023-05-09 05:34:39 +02:00
# 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)
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo $ARCHIVEFILE $EXT $SPECFILE ; fi
2023-05-09 05:34:39 +02:00
# Check that we got the filename (possible define in it not expanded?)
if [ ! -f $ARCHIVEFILE ] ; then
# Try another tack
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo " ************File $ARCHIVE does not exist - trying *. $EXT " ; fi
2023-05-09 05:34:39 +02:00
ARCHIVEFILE = ` ls *.$EXT | head -n 1`
2023-05-12 03:29:42 +02:00
if [ [ ! -f $ARCHIVEFILE || -z $ARCHIVEFILE ] ] ; then
2023-05-09 05:34:39 +02:00
echo " ERROR*******Can't identify archive file $ARCHIVEFILE $EXT `pwd` "
exit 1
fi
fi
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo " ************TreePATH: $TREEPATH and Archivefile: $ARCHIVEFILE `pwd` " ; fi
2023-05-09 05:34:39 +02:00
# 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
2023-05-22 03:37:20 +02:00
if [ $DEBUG ] ; then echo " ************Copying $CVSFiles / $1 / $BASEORCONTRIB / $fpath " ; fi
2023-05-09 05:34:39 +02:00
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
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo " ************Renaming specfile from $( basename $SPECFILE ) $( basename $ORIGSPECFILE ) " ; fi
2023-05-09 05:34:39 +02:00
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' )
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo " $PATCHS " ; fi
2023-05-09 05:34:39 +02:00
for fpath in $PATCHS ; do
# Needs another step incase the extraction from the spec file contains spec variables
fpathfile = $( basename $fpath )
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo " $fpathfile " ; fi
2023-05-09 05:34:39 +02:00
translatefpath = $( rpm --queryformat " $fpathfile \n " --specfile $( basename $SPECFILE ) | head -n 1)
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo " $translatefpath " ; fi
2023-05-09 05:34:39 +02:00
if [ [ -f $CVSFiles /$1 /$BASEORCONTRIB /$translatefpath ] ] ; then
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo " ************Copying $CVSFiles / $1 / $BASEORCONTRIB / $translatefpath " ; fi
2023-05-09 05:34:39 +02:00
cp $CVSFiles /$1 /$BASEORCONTRIB /$translatefpath .
else
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo " ************Not found $CVSFiles / $1 / $BASEORCONTRIB / $translatefpath ( $fpathfile )- so not copied " ; fi
2023-05-09 05:34:39 +02:00
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 ) "
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo "************Added 'BuildRequires: perl(ExtUtils::Manifest)' to the spec file." ; fi
2023-05-09 05:34:39 +02:00
else
2023-05-09 09:46:24 +02:00
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
2023-05-09 05:34:39 +02:00
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 ) "
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo "************Added 'BuildRequires: perl(ExtUtils::ParseXS)' to the spec file." ; fi
2023-05-09 05:34:39 +02:00
else
2023-05-09 09:46:24 +02:00
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
2023-05-09 05:34:39 +02:00
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 ) "
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo "************Added 'BuildRequires: perl(ExtUtils::Manifest)' to the spec file." ; fi
2023-05-09 05:34:39 +02:00
else
2023-05-09 09:46:24 +02:00
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
2023-05-09 05:34:39 +02:00
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 ) "
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo "************Added 'rm -rf %{buildroot}/%{peardir}/.filemap' to the spec file." ; fi
2023-05-09 05:34:39 +02:00
else
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo "************No action was taken. The spec file either does not include 'rm %{buildroot}/%{peardir}/.filemap' or already includes it" ; fi
2023-05-09 05:34:39 +02:00
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' )
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo " $SOURCES " ; fi
2023-05-09 05:34:39 +02:00
#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 )
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo " $fpathfile " ; fi
2023-05-09 05:34:39 +02:00
translatefpath = $( rpm --queryformat " $fpathfile \n " --specfile $( basename $SPECFILE ) | head -n 1)
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo " $translatefpath " ; fi
2023-05-09 05:34:39 +02:00
if [ [ -f $CVSFiles /$1 /$BASEORCONTRIB /$translatefpath ] ] ; then
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo " ************Copying $CVSFiles / $1 / $BASEORCONTRIB / $translatefpath " ; fi
2023-05-09 05:34:39 +02:00
cp $CVSFiles /$1 /$BASEORCONTRIB /$translatefpath .
else
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo " ************Not found $CVSFiles / $1 / $BASEORCONTRIB / $translatefpath ( $fpathfile )- so not copied " ; fi
2023-05-09 05:34:39 +02:00
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-2023*" >>.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
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo " ************Found SMEServer source for $NAME " ; fi
2023-05-09 05:34:39 +02:00
# Create the .gitignore file to ignore the archive
echo " *. $EXT " >> .gitignore
#and copy in the source tree
mkdir -p " $CODEDIR "
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo " ************Copying $CVSFiles / $1 / $BASEORCONTRIB /root `pwd`/ $CODEDIR " ; fi
2023-05-09 05:34:39 +02:00
rsync -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 -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
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo " ************Found 3rd party package $NAME " ; fi
2023-05-25 10:10:03 +02:00
git lfs install
git lfs track " *. $EXT "
git add .gitattributes
2023-05-09 05:34:39 +02:00
#git config lfs.http://gitea.bjsystems.co.uk/SMEContribs/bugzilla.git/info/lfs.locksverify true
if [ [ -f $CVSFiles /$1 /$BASEORCONTRIB /$ARCHIVEFILE ] ] ; then
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo " ************Copying archivefile $CVSFiles / $1 / $BASEORCONTRIB / $ARCHIVEFILE " ; fi
2023-05-09 05:34:39 +02:00
cp $CVSFiles /$1 /$BASEORCONTRIB /$ARCHIVEFILE .
else
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo " Unable to find archivefile: $CVSFiles / $1 / $BASEORCONTRIB / $ARCHIVEFILE - nothing copied " ; fi
2023-05-09 05:34:39 +02:00
fi
cd $GITFiles /$1
fi
cd $GITFiles /$1
2023-05-12 03:29:42 +02:00
if [ [ $ARCHIVEFILE != " $TREEPATH .tar.gz " ] ] ; then
2023-05-09 05:34:39 +02:00
echo " $ARCHIVEFILE " > archivefilename
fi
# Take out any bogus dates:
2023-05-25 10:10:03 +02:00
/usr/bin/BogusDateBot.sh $( basename $SPECFILE )
2023-05-09 05:34:39 +02:00
# 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!
# 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 )
# 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
2023-05-09 07:56:45 +02:00
#git clone "${smegit_COMMONREPO}"
2023-05-09 05:34:39 +02:00
## 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
2023-05-09 07:56:45 +02:00
git clone " ${ smegit_COMMONREPO } "
2023-05-09 05:34:39 +02:00
if [ ! -e $GITFiles /common ] ; then
echo " ERROR*******No Common Repo found - package $1 "
exit 1
fi
else
# Just refresh it
cd $GITFiles /common
2023-05-25 10:10:03 +02:00
git 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
# 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
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo " ************READMECONTENTS: $READMECONTENTS " ; fi
2023-05-09 05:34:39 +02:00
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 } " )
2023-05-12 03:29:42 +02:00
if [ [ " $READMECONTENTS " = = "" ] ] ; then
2023-05-09 05:34:39 +02:00
# nothing previous
# Copy across the Wiki links to the README
if [ ! " $URLS " = "" ] ; then
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo " ************The wiki page(s) for $PACKAGENAME exist. " ; fi
2023-05-09 05:34:39 +02:00
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
2023-05-09 07:16:55 +02:00
if [ [ " $NAME " = ~ ^( smeserver-) .* && " $2 " = = "smecontribs" ] ] ; then
2023-05-09 05:34:39 +02:00
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
2023-05-09 09:46:24 +02:00
response = $( curl " $curlsilent " -X POST https://api.openai.com/v1/engines/$model /completions \
2023-05-09 05:34:39 +02:00
-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
2023-05-22 03:37:20 +02:00
if [ $DEBUG ] ; then echo " ************Creating description for $1 " ; fi
2023-05-09 05:34:39 +02:00
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
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo "************Picked up previous README contents" ; fi
2023-05-09 05:34:39 +02:00
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
2023-05-09 09:46:24 +02:00
response = $( curl " $curlsilent " -X POST https://api.openai.com/v1/engines/$model /completions \
2023-05-09 05:34:39 +02:00
-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
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo " ************Creating description for $1 " ; fi
2023-05-09 05:34:39 +02:00
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
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo "************Picked up previous README contents" ; fi
2023-05-09 05:34:39 +02:00
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
2023-05-09 09:46:24 +02:00
RESPONSE = $( curl " $curlsilent " -X 'PATCH' " $GITEAHOST /api/v1/repos/ $ORGGITEA / $REPO_NAME " \
2023-05-09 05:34:39 +02:00
-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.
2023-05-09 09:46:24 +02:00
if [ $DEBUG ] ; then echo $RESPONSE ; fi
2023-05-09 05:34:39 +02:00
#exit 0
cd $GITFiles /$1
# stage and commit all the files created locally
2023-05-25 10:10:03 +02:00
git add -A
2023-05-09 05:34:39 +02:00
echo " $1 git status " >>gitstatus.log
git status >>gitstatus.log
2023-05-25 10:10:03 +02:00
git status
2023-05-09 05:34:39 +02:00
COMMENT = " initial commit of file from CVS for $1 on `date` "
git commit -m " $COMMENT " $QUIET
# push the converted git repository to the remote
2023-05-25 10:10:03 +02:00
git remote remove origin
git remote add origin " $GITEAHOST / $ORGGITEA / $1 .git "
2023-05-09 05:34:39 +02:00
#GIT_SSL_NO_VERIFY=true git push --force -u $QUIET origin master
2023-05-25 10:10:03 +02:00
git push --force -u $QUIET origin master
2023-05-09 05:34:39 +02:00
# Now create the version and release tag for these files
RELEASE = ` rpm --queryformat '%{release}\n' --specfile $NAME .spec | head -n 1`
TAG = $VERSION -$RELEASE
2023-05-25 10:10:03 +02:00
git tag -a $TAG -m " $COMMENT "
git push origin $TAG
2023-05-09 05:34:39 +02:00
echo " Created $1 Repo: $HTTP_URL - Comment: $COMMENT tag: $TAG "
exit 0