#!/bin/bash # # $1 = perl Module e.g. File::MMagic # $2 = Organisation (smeserver, smecontrib or user) - default smeserver # optional (can be in any order) # will use parameters set for local repository else it will use remote # turn on debug regardless of ~/.smegit/config # 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 [ | | ]" 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 []" 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= MODULENAME=$1 ORGGITEA="smeserver" for param in $2 $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 ;; * ) ORGGITEA=$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 $MODULENAME; do words+=($i) ; done RepoName="perl" ShortName= for word in ${words[@]}; do RepoName="$RepoName-$word" if [ $ShortName ] ; then ShortName="$ShortName-$word" else ShortName="$word" fi done if [ $DEBUG ] ; then echo "RepoName=$RepoName" ; fi IFS="${IFS:0:3}" RemoteRepoURL="$GITEAHOST/$ORGGITEA/$RepoName" 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 cpanspec is installed if command -v cpanspec >/dev/null; then if [ $DEBUG ] ; then echo "************cpanspec is installed"; fi else echo "ERROR********************cpanspec is not installed*********** (try installing cpanspec)" exit 1 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 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 # 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 "$MODULENAME" # 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 # Get the tarball file extension 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/') # 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 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 # 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 # # 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 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 # Tell repo to use koozali.org bugzilla and wiki - this does not work on CREATE currently - 19Apr2023 WIKILINK="https://wiki.koozali.org/$RepoName" # and then update the repo parameters RESPONSE=$(curl "$SILENT4CURL" -X 'PATCH' "$GITEAHOST/api/v1/repos/$ORGGITEA/$RepoName" \ -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=$RepoName&product=$PRODUCTBUGZILLA"'" }, "external_wiki": { "external_wiki_url": "'"$WIKILINK"'" } } ') # should check response here. if [ $DEBUG ] ; then echo $RESPONSE ; fi #exit 0 # Pull in the auto created or updated files cd $GITFiles git clone "$GITEAHOST/$ORGGITEA/$RepoName.git" if [ ! -d $GITFiles/$RepoName ] ; then echo "ERROR*******Unable to access the new repo directory for $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/* . # create the Makefile cat > Makefile <<- _EOT # Makefile for source rpm: $RepoName # \$Id: Makefile,v 1.1 2016/02/04 12:24:52 vip-ire Exp $ NAME := $RepoName SPECFILE = \$(firstword \$(wildcard *.spec)) define find-makefile-common for d in common ../common ../../common ; do if [ -f \$\$d/Makefile.common ] ; then if [ -f \$\$d/CVS/Root -a -w \$\$/Makefile.common ] ; then cd \$\$d ; cvs -Q update ; fi ; echo "\$\$d/Makefile.common" ; break ; fi ; done endef MAKEFILE_COMMON := \$(shell \$(find-makefile-common)) ifeq (\$(MAKEFILE_COMMON),) # attept a checkout define checkout-makefile-common test -f CVS/Root && { cvs -Q -d \$\$(cat CVS/Root) checkout common && echo "common/Makefile.common" ; } || { echo "ERROR: I can't figure out how to checkout the 'common' module." ; exit -1 ; } >&2 endef MAKEFILE_COMMON := \$(shell \$(checkout-makefile-common)) endif include \$(MAKEFILE_COMMON) _EOT # 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 "sme11" > contriborbase # and see if the spec file is not according to specification of .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 $perlFiles/$RepoName/$translatefpath ]] ; then if [ $DEBUG ] ; then echo "************Copying $perlFiles/$RepoName/$translatefpath" ; fi cp $perlFiles/$RepoName/$translatefpath . else if [ $DEBUG ] ; then echo "************Not found $perlFiles/$RepoName/$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 # All perl packages are Third party packages # 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 if [[ -f $perlFiles/$RepoName/$ARCHIVEFILE ]] ; then if [ $DEBUG ] ; then echo "************Copying archivefile $perlFiles/$RepoName/$ARCHIVEFILE" ; fi cp $perlFiles/$RepoName/$ARCHIVEFILE . else if [ $DEBUG ] ; then echo "Unable to find archivefile: $perlFiles/$RepoName/$ARCHIVEFILE - nothing copied" ; fi fi cd $GITFiles/$RepoName # Add the BuildRequires now needed by el8(Rocky 8) sed -i -e '/BuildRequires/{a\BuildRequires: perl(inc::Module::Install)' -e ':a;n;ba}' "$SPECFILE" sed -i -e '/BuildRequires/{a\BuildRequires: perl(ExtUtils::Manifest)' -e ':a;n;ba}' "$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 the description from the spec file for this package cd $GITFiles/$RepoName DESCRIPTION=`rpm --queryformat '%{description}\n' --specfile $SPECFILE` # create the README.md cat > README.md <<- _EOT # $RepoName ($MODULENAME) SMEServer Koozali local git repo for $RepoName ## Documentation https://metacpan.org/pod/$MODULENAME ## Bugs CPAN bug report are [here](https://rt.cpan.org/Public/Dist/Display.html?Name=$ShortName) Show list of Koozali outstanding bugs: [here](https://bugs.koozali.org/buglist.cgi?component=$RepoName&product=SME%20Server%2011.X&query_format=advanced&limit=0&bug_status=UNCONFIRMED&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&bug_status=CONFIRMED) ## Description $DESCRIPTION _EOT 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 create of smeserver perl $MODULENAME 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 push --force -u $QUIET origin master # Now create the version and release tag from the specfile VERSION_RELEASE_LONG=`rpm --queryformat '%{version} %{release}\n' --specfile $SPECFILE` VERSION_RELEASE=${VERSION_RELEASE_LONG%%$'\n'*} VERSION=${VERSION_RELEASE% *} VERSION=${VERSION//./_} RELEASE=${VERSION_RELEASE#* } TAG=$VERSION"-"${RELEASE%.*} if [ $DEBUG ] ; then echo "VERSION_RELEASE=$VERSION_RELEASE" echo "VERSION=$VERSION" echo "RELEASE=$RELEASE" echo "TAG=$TAG" fi git pull git tag -a $TAG -m "align tag with version and release from spec file: $TAG" git push origin --tag $TAG $QUIET echo "$COMMENT tag:$TAG" exit 0