add git-getperl
This commit is contained in:
parent
452e84b2ca
commit
c5d71a4da7
595
git-getperl.sh
Executable file
595
git-getperl.sh
Executable file
@ -0,0 +1,595 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# $1 = perl Module e.g. File::MMagic
|
||||
# $2 = Organisation (smeserver, smecontrib or user) - default smeserver
|
||||
# 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-getperl.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-getperl.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-getperl.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
|
||||
# create repo name from perl- module with :: replaced by -
|
||||
IFS=::
|
||||
words=()
|
||||
for i in $1; do words+=($i) ; done
|
||||
RepoName="perl"
|
||||
for word in ${words[@]}; do RepoName="$RepoName-$word" ; done
|
||||
if [ $DEBUG ] ; then echo "RepoName=$RepoName" ; fi
|
||||
IFS="${IFS:0:3}"
|
||||
RemoteRepoURL="$GITEAHOST/$ORGGITEA/$RepoName"
|
||||
|
||||
#
|
||||
# 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}
|
||||
|
||||
# Prepare variable for file in repo to indicate core or contrib.
|
||||
# and init gitea organisation
|
||||
# Adjust where we put the repo locally accordingly.
|
||||
ORGGITEA="smeserver"
|
||||
if [[ "$2" == "smecontribs" ]]; then
|
||||
ORGGITEA=$2
|
||||
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
|
||||
PACKAGETYPE="3rd Party (Maintained by Koozali)"
|
||||
|
||||
# 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
|
||||
perlFiles="$WORKDIR/$ORGGITEA/perl"
|
||||
mkdir -p $perlFiles
|
||||
|
||||
# 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 perl repository
|
||||
#
|
||||
cd $perlFiles
|
||||
# First delete any existing module directory tree
|
||||
# if there at all
|
||||
if [ -d "$RepoName" ] ; then
|
||||
if [ $DEBUG ] ; then echo "************Deleting local CVS files" ; fi
|
||||
rm -Rf $perlFiles/$RepoName
|
||||
fi
|
||||
|
||||
# Then get it fully from CVS
|
||||
mkdir -p $perlFiles/$RepoName
|
||||
cd $perlFiles/$RepoName
|
||||
cpanspec "$1"
|
||||
|
||||
# Check that the spec file is there
|
||||
# First bet is the packagename.spec
|
||||
SPECFILE=$RepoName.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 $RepoName $reg"
|
||||
if [[ "$RepoName" =~ $reg ]]; then
|
||||
NEWNAME="${RepoName#$front}"
|
||||
#echo $NEWNAME
|
||||
SPECFILE="$NEWNAME.spec"
|
||||
#echo $SPECFILE
|
||||
if [ -f $SPECFILE ] ; then
|
||||
GOTONE=1
|
||||
break
|
||||
fi
|
||||
fi
|
||||
done
|
||||
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 "$RepoName" ] ; then
|
||||
if [ $DEBUG ] ; then echo "************Deleting local GIT files" ; fi
|
||||
rm -Rf $GITFiles/$RepoName
|
||||
fi
|
||||
|
||||
# See if it exists on the Gitea host
|
||||
if [ $DEBUG ] ; then echo "check that $GITEAHOST/$ORGGITEA/$RepoName exists" ; fi
|
||||
READMECONTENTS=
|
||||
RESPONSE=$(curl $checkSSL $SILENT4CURL -o /dev/null -w "%{http_code}" "$GITEAHOST/api/v1/repos/$ORGGITEA/$RepoName")
|
||||
if [ "$RESPONSE" == "200" ]; then
|
||||
if [ $DEBUG ] ; then echo "************Repository for $RepoName already exists!" ; fi
|
||||
# If so, clone it (just want the README.md)
|
||||
if [ $DEBUG ] ; then echo "git clone $GITEAHOST/$ORGGITEA/$RepoName.git" ; fi
|
||||
cd $GITFiles
|
||||
git clone "$GITEAHOST/$ORGGITEA/$RepoName.git"
|
||||
if [[ -f $GITFILES/$RepoName/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/$RepoName" ; fi
|
||||
RESPONSE=$(curl "$checkSSL" "$SILENT4CURL" -o /dev/null -w "%{http_code}" -X 'DELETE' \
|
||||
"$GITEAHOST/api/v1/repos/$ORGGITEA/$RepoName" \
|
||||
-H 'accept: application/json' \
|
||||
-H "Authorization: token $GITEAACCESSTOKEN")
|
||||
if [[ $RESPONSE == "204" || $RESPONSE == "404" ]] ; then
|
||||
if [ $DEBUG ] ; then echo "************Repository $ORGGITEA/$RepoName deleted or does not exist" ; fi
|
||||
else
|
||||
echo "************Can NOT delete Repository $ORGGITEA/$RepoName - 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/$RepoName
|
||||
else
|
||||
if [ $DEBUG ] ; then echo "************Repository for $RepoName does not exist." ; fi
|
||||
fi
|
||||
|
||||
cd $GITFiles
|
||||
#git init $QUIET $1
|
||||
|
||||
#
|
||||
# Re-create the repo
|
||||
#
|
||||
if [ $DEBUG ] ; then echo "************Creating repo for $RepoName $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 $RepoName $ORGGITEA"'",
|
||||
"gitignores": "",
|
||||
"issue_labels": "Default",
|
||||
"license": "Apache-2.0",
|
||||
"name": "'"$RepoName"'",
|
||||
"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 $RepoName 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/$RepoName")
|
||||
if [[ "$RESPONSE" == "200" ]]; then
|
||||
if [ $DEBUG ] ; then echo "************Repository for $RepoName exists" ; fi
|
||||
else
|
||||
echo "ERROR*******Repository for $RepoName 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/$RepoName.git"
|
||||
git clone "$GITEAHOST/$ORGGITEA/$RepoName.git"
|
||||
|
||||
if [ ! -d $GITFiles/$RepoName ] ; then
|
||||
echo "ERROR*******Unable to access the new repo directory for $HTTP_URL $GITFiles/$RepoName"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 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".
|
||||
cd $GITFiles/$RepoName
|
||||
cp $perlFiles/$RepoName/* .
|
||||
|
||||
# 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 "sme10" > contriborbase
|
||||
|
||||
# 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
|
||||
|
||||
## 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/$RepoName/$BASEORCONTRIB/$translatefpath ]] ; then
|
||||
if [ $DEBUG ] ; then echo "************Copying $CVSFiles/$RepoName/$BASEORCONTRIB/$translatefpath" ; fi
|
||||
cp $CVSFiles/$RepoName/$BASEORCONTRIB/$translatefpath .
|
||||
else
|
||||
if [ $DEBUG ] ; then echo "************Not found $CVSFiles/$RepoName/$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/$RepoName
|
||||
# See if the package is a 3rd party or one of ours - indicated by "smeserver" or "e-smith" in the name
|
||||
if [[ "$RepoName" =~ ^(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/$RepoName/$BASEORCONTRIB/root `pwd`/$CODEDIR" ; fi
|
||||
rsync "$QUIET" -a --no-prune-empty-dirs "$CVSFiles/$RepoName/$BASEORCONTRIB/$TREEPATH/root/" "`pwd`/$CODEDIR/"
|
||||
# copy createlinks to base
|
||||
if [ -e "$CVSFiles/$RepoName/$BASEORCONTRIB/$TREEPATH/createlinks" ] ; then cp "$CVSFiles/$RepoName/$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/$RepoName/$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/$RepoName/$BASEORCONTRIB/$ARCHIVEFILE ]] ; then
|
||||
if [ $DEBUG ] ; then echo "************Copying archivefile $CVSFiles/$RepoName/$BASEORCONTRIB/$ARCHIVEFILE" ; fi
|
||||
cp $CVSFiles/$RepoName/$BASEORCONTRIB/$ARCHIVEFILE .
|
||||
else
|
||||
if [ $DEBUG ] ; then echo "Unable to find archivefile: $CVSFiles/$RepoName/$BASEORCONTRIB/$ARCHIVEFILE - nothing copied" ; fi
|
||||
fi
|
||||
cd $GITFiles/$RepoName
|
||||
fi
|
||||
|
||||
cd $GITFiles/$RepoName
|
||||
|
||||
# Take out any bogus dates:
|
||||
#BogusDateBot.sh $(basename $SPECFILE)
|
||||
|
||||
|
||||
# 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 $RepoName"
|
||||
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/$RepoName
|
||||
if [ $DEBUG ] ; then echo "************READMECONTENTS:$READMECONTENTS" ; fi
|
||||
PACKAGENAME=${NAME}
|
||||
if [[ "$RepoName" =~ ^(smeserver-|e-smith-).* ]]; then
|
||||
# See if we have a previous contents of the README.md
|
||||
if [[ "$RepoName" =~ ^(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=$RepoName&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 [[ "$RepoName" =~ ^(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 [[ "$RepoName" =~ ^(smeserver-).* && "$ORGGITEA" == "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 $RepoName" ; 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 $RepoName" ; 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/$RepoName
|
||||
# stage and commit all the files created locally
|
||||
git add -A
|
||||
echo "$RepoName git status" >>gitstatus.log
|
||||
git status >>gitstatus.log
|
||||
if [ $DEBUG ] ; then git status ; fi
|
||||
COMMENT="initial commit of file from CVS for $RepoName 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/$RepoName.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 $SPECFILE | 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 $RepoName Repo: $HTTP_URL - Comment:$COMMENT tag:$TAG"
|
||||
exit 0
|
Loading…
Reference in New Issue
Block a user