initial commit of rename-e-smith-pkg.sh
This commit is contained in:
parent
5a4f897d10
commit
ca0dc63f6f
217
rename-e-smith-pkg.sh
Normal file
217
rename-e-smith-pkg.sh
Normal file
@ -0,0 +1,217 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# $1 = Module name e.g. e-smith-dnscache
|
||||
# $2 = Organisation (smeserver or user - defaults to smeserver)
|
||||
# $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
|
||||
echo "************rename-e-smith-pkg.sh <modulename> [<organization> <local>]"
|
||||
exit 0
|
||||
fi
|
||||
clear
|
||||
echo "**************************************************************************************************"
|
||||
echo "* *"
|
||||
echo "* SMEServer - rename-e-smith-pkg.sh $1 $2 $3 `date` *"
|
||||
echo "* *"
|
||||
echo "**************************************************************************************************"
|
||||
|
||||
#
|
||||
# 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
|
||||
|
||||
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"
|
||||
SILENT="-s"
|
||||
if [ $DEBUG ] ; then
|
||||
QUIET=
|
||||
SILENT="-v"
|
||||
fi
|
||||
# Make this null to get curl to check ssl cert
|
||||
checkSSL="-k"
|
||||
|
||||
if [[ $smegit_WORKDIR == ~* ]] ; then
|
||||
# relative to users home dir
|
||||
WORKDIR=$(echo ~)${smegit_WORKDIR:1}
|
||||
else
|
||||
# absolute path
|
||||
WORKDIR=${smegit_WORKDIR}
|
||||
fi
|
||||
|
||||
SOURCEHOST=${remote_GITEAHOST}
|
||||
SOURCEACCESSTOKEN=${remote_GITEAACCESSTOKEN}
|
||||
SOURCEORG="smeserver"
|
||||
TARGETORG=${remote_USER}
|
||||
for param in $2 $3 ; do
|
||||
if [ $param ] ; then
|
||||
if [[ $param == "local" ]] ; then
|
||||
SOURCEHOST=${local_GITEAHOST}
|
||||
SOURCEACCESSTOKEN=${local_GITEAACCESSTOKEN}
|
||||
TARGETORG=${local_USER}
|
||||
else
|
||||
SOURCEORGORG=$param
|
||||
fi
|
||||
else
|
||||
break
|
||||
fi
|
||||
done
|
||||
#Extract <pkg>
|
||||
SOURCEPKG=$1
|
||||
TARGETPKG=${SOURCEPKG/e-smith/smeserver}
|
||||
|
||||
#Check that source package exists
|
||||
if [ $DEBUG ] ; then echo "Check if $SOURCEORG/$SOURCEPKG is there!" ; fi
|
||||
RESPONSE=$(curl $SILENT -o /dev/null -w "%{http_code}" "$SOURCEHOST/api/v1/repos/$SOURCEORG/$SOURCEPKG")
|
||||
if [ "$RESPONSE" == "200" ]; then
|
||||
if [ $DEBUG ] ; then echo "Repository for $SOURCEORG/$SOURCEPKG exists!" ; fi
|
||||
else
|
||||
echo "************Repository for $SOURCEORG/$SOURCEPKG does not exist on $SOURCEHOST ($RESPONSE)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#Check that target package does not exist
|
||||
if [ $DEBUG ] ; then echo "Check if $TARGETORG/$TARGETPKG is there!" ; fi
|
||||
RESPONSE=$(curl $SILENT -o /dev/null -w "%{http_code}" "$SOURCEHOST/api/v1/repos/$TARGETORG/$TARGETPKG")
|
||||
if [ "$RESPONSE" == "200" ]; then
|
||||
echo "Repository for $TARGETORG/$TARGETPKG exists!"
|
||||
while true; do
|
||||
read -p "Do you wish to delete it and continue?(y/n) " yn
|
||||
case $yn in
|
||||
[Yy]* )
|
||||
RESPONSE=$(curl "$checkSSL" "$SILENT" -X 'DELETE' \
|
||||
"$SOURCEHOST/api/v1/repos/$TARGETORG/$TARGETPKG" \
|
||||
-H 'accept: application/json' \
|
||||
-H "Authorization: token $SOURCEACCESSTOKEN" )
|
||||
break;;
|
||||
[Nn]* )
|
||||
echo "************Abandoning Fork of $SOURCEORG/$SOURCEPKG on $SOURCEHOST ($RESPONSE)"
|
||||
exit 1;;
|
||||
* ) echo "Please answer yes or no.";;
|
||||
esac
|
||||
done
|
||||
|
||||
else
|
||||
if [ $DEBUG ] ; then echo "Repository for $TARGETORG/$TARGETPKG does not exist on $SOURCEHOST" ; fi
|
||||
fi
|
||||
|
||||
#Fork e-smith-<pkg> into users repositories as smeserver-<pkg>
|
||||
# - add bugzilla and wiki references
|
||||
|
||||
RESPONSE=$(curl "$SILENT" "$checkSSL" -X 'POST' \
|
||||
"https://src.koozali.org/api/v1/repos/$SOURCEORG/$SOURCEPKG/forks" \
|
||||
-H 'accept: application/json' \
|
||||
-H 'Content-Type: application/json' \
|
||||
-H "Authorization: token $SOURCEACCESSTOKEN"
|
||||
-d '{
|
||||
"name": "'"$TARGETPKG"'",
|
||||
"description": "'"SMEServer Koozali developed git repo for $TARGETPKG base"'"
|
||||
}')
|
||||
if [ $RESPONSE == "202" ] ; then
|
||||
if [ $DEBUG ] ; then echo "$SOURCEPKG successfully forked" ; fi
|
||||
else
|
||||
echo "************Repository $SOURCEORG/$SOURCEPKG NOT forked on $SOURCEHOST ($RESPONSE)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# create a Bugzilla URL
|
||||
PRODUCTBUGZILLA="SME%20Server%2010.X"
|
||||
if [[ "$SOURCEORG" == "smecontribs" ]]; then
|
||||
PRODUCTBUGZILLA="SME%20Contribs"
|
||||
fi
|
||||
|
||||
# find the relevant wiki entry
|
||||
WIKILINK="https://wiki.koozali.org"
|
||||
MEDIAWIKI_SITE="https://wiki.koozali.org/api.php"
|
||||
SEARCH_TERM=${SOURCEPKG/e-smith-/}
|
||||
|
||||
# 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}" )
|
||||
|
||||
RESPONSE=$(curl "$SILENT" "$checkSSL" -X 'PATCH' \
|
||||
"$SOURCEHOST/api/v1/repos/$TARGETORG/$TARGETPKG" \
|
||||
-H 'accept: application/json' \
|
||||
-H "Authorization: token $SOURCEACCESSTOKEN" \
|
||||
-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=$TARGETPKG&product=$PRODUCTBUGZILLA"'"
|
||||
},
|
||||
"external_wiki": {
|
||||
"external_wiki_url": "'"$WIKILINK"'"
|
||||
}
|
||||
}'
|
||||
)
|
||||
|
||||
#Update README.md
|
||||
# - new name
|
||||
# - Bugzilla link to new name whilst keeping old link for Legacy
|
||||
|
||||
#Update Makefile
|
||||
# - NAME := smeserver-<pkg>
|
||||
|
||||
#Rename e-smith-<pkg>.spec as smeserver-<pkg>.spec
|
||||
|
||||
#Update smeserver-<pkg>.spec
|
||||
# - change name to smeserver-<pkg> (%define name)
|
||||
# - add PROVIDES: e-smith-<pkg>
|
||||
# - change all Requires: e-smith* to smeserver*
|
||||
# - change Source: to new standard of tar.gz
|
||||
# - delete archivefilename file
|
||||
# - add changelog entry (Bugzilla #12359)
|
||||
|
||||
#Update createlinks
|
||||
# - if there is an e-smith-<pkg>-update event rename to smeserver-<pkg>-update
|
||||
|
||||
#Convert repository to a Regular Repository (rather than fork)
|
Loading…
Reference in New Issue
Block a user