2023-05-30 08:34:06 +02:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
2023-06-01 02:36:25 +02:00
|
|
|
# Rename an e-smith package as smeserver and change relevant files
|
2023-05-30 08:34:06 +02:00
|
|
|
# $1 = Module name e.g. e-smith-dnscache
|
2023-06-01 02:36:25 +02:00
|
|
|
# $2-$5 can appear in any order and are optional
|
|
|
|
# = Organisation (smeserver or user - defaults to smeserver)
|
|
|
|
# = "local" will use parameters set for local repository else it will use remote
|
|
|
|
# = "force" will automagically delete an existing repo, otherwise it will prompt
|
|
|
|
# = "debug" run in debug mode
|
2023-05-30 08:34:06 +02:00
|
|
|
# This works whether the repo and local files exist of not (it deletes them if necessary)
|
|
|
|
#
|
|
|
|
|
|
|
|
if [[ -z $1 ]] ; then
|
2023-06-01 03:05:10 +02:00
|
|
|
echo "Rename an e-smith package as smeserver and change relevant files"
|
2023-06-05 01:21:54 +02:00
|
|
|
echo "rename-e-smith-pkg.sh <modulename> [<organization> <local> <force> <debug> <silent>]"
|
2023-06-02 01:17:03 +02:00
|
|
|
echo "<modulename> = Module/package name (e.g. e-smith-dnscache)"
|
|
|
|
echo " can appear in any order and are optional"
|
2023-06-05 01:21:54 +02:00
|
|
|
echo " - <organisation> (any valid organisation - defaults to smeserver)"
|
2023-06-02 01:17:03 +02:00
|
|
|
echo " - <local> will use parameters set for local repository, else it will use remote"
|
|
|
|
echo " - <force> will automagically delete an existing repo, otherwise it will prompt"
|
|
|
|
echo " - <debug> run in debug mode"
|
2023-06-05 01:21:54 +02:00
|
|
|
echo " - <silent> suppress success message"
|
2023-06-01 03:05:10 +02:00
|
|
|
exit 0
|
2023-05-30 08:34:06 +02:00
|
|
|
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
|
|
|
|
if [ $DEBUG ] ; then echo "************found ini file: $inifilename" ; fi
|
|
|
|
|
|
|
|
if [[ $smegit_WORKDIR == ~* ]] ; then
|
|
|
|
# relative to users home dir
|
|
|
|
WORKDIR=$(echo ~)${smegit_WORKDIR:1}
|
|
|
|
else
|
|
|
|
# absolute path
|
|
|
|
WORKDIR=${smegit_WORKDIR}
|
|
|
|
fi
|
|
|
|
|
2023-06-05 01:42:48 +02:00
|
|
|
# Command line parameters
|
|
|
|
#Extract <pkg>
|
|
|
|
SOURCEPKG=$1
|
|
|
|
TARGETPKG=${SOURCEPKG/e-smith/smeserver}
|
|
|
|
|
2023-06-05 00:52:52 +02:00
|
|
|
GITEAHOST=${remote_GITEAHOST}
|
2023-06-05 01:21:54 +02:00
|
|
|
GITEAACCESSTOKEN=${remote_GITEAACCESSTOKEN}
|
2023-05-30 08:34:06 +02:00
|
|
|
SOURCEORG="smeserver"
|
|
|
|
TARGETORG=${remote_USER}
|
2023-06-01 01:20:55 +02:00
|
|
|
DELETEIT=
|
2023-06-02 03:12:56 +02:00
|
|
|
NOOUTPUT=
|
2023-06-05 01:21:54 +02:00
|
|
|
TRANSFER=
|
2023-06-02 03:15:30 +02:00
|
|
|
for param in $2 $3 $4 $5 $6; do
|
2023-05-30 08:34:06 +02:00
|
|
|
if [ $param ] ; then
|
2023-06-01 01:20:55 +02:00
|
|
|
case $param in
|
|
|
|
local )
|
2023-06-05 00:52:52 +02:00
|
|
|
GITEAHOST=${local_GITEAHOST}
|
2023-06-05 01:21:54 +02:00
|
|
|
GITEAACCESSTOKEN=${local_GITEAACCESSTOKEN}
|
2023-06-01 01:20:55 +02:00
|
|
|
TARGETORG=${local_USER} ;;
|
|
|
|
force )
|
2023-06-01 01:41:09 +02:00
|
|
|
DELETEIT=true ;;
|
2023-06-01 01:20:55 +02:00
|
|
|
debug )
|
|
|
|
DEBUG=true ;;
|
2023-06-05 01:21:54 +02:00
|
|
|
silent )
|
2023-06-02 03:15:30 +02:00
|
|
|
NOOUTPUT=true ;;
|
2023-06-05 01:21:54 +02:00
|
|
|
transfer )
|
|
|
|
TRANSFER=true ;;
|
2023-06-01 01:20:55 +02:00
|
|
|
* )
|
|
|
|
SOURCEORGORG=$param ;;
|
|
|
|
esac
|
2023-05-30 08:34:06 +02:00
|
|
|
else
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
2023-06-05 01:56:26 +02:00
|
|
|
|
2023-06-01 01:56:37 +02:00
|
|
|
# Debug settings
|
|
|
|
# Make this null if you want lots of output. Still quite a bit anyway
|
|
|
|
QUIET="--quiet"
|
|
|
|
SILENT="-s"
|
|
|
|
if [ $DEBUG ] ; then
|
|
|
|
QUIET=
|
|
|
|
SILENT="-v"
|
|
|
|
fi
|
|
|
|
# Make this null to get curl to check ssl cert
|
|
|
|
checkSSL="-k"
|
|
|
|
|
2023-05-30 08:34:06 +02:00
|
|
|
#Check that source package exists
|
|
|
|
if [ $DEBUG ] ; then echo "Check if $SOURCEORG/$SOURCEPKG is there!" ; fi
|
2023-06-05 00:52:52 +02:00
|
|
|
RESPONSE=$(curl $SILENT -o /dev/null -w "%{http_code}" "$GITEAHOST/api/v1/repos/$SOURCEORG/$SOURCEPKG")
|
2023-05-30 08:34:06 +02:00
|
|
|
if [ "$RESPONSE" == "200" ]; then
|
|
|
|
if [ $DEBUG ] ; then echo "Repository for $SOURCEORG/$SOURCEPKG exists!" ; fi
|
|
|
|
else
|
2023-06-05 00:52:52 +02:00
|
|
|
echo "************Repository for $SOURCEORG/$SOURCEPKG does not exist on $GITEAHOST ($RESPONSE)"
|
2023-05-30 08:34:06 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
#Check that target package does not exist
|
|
|
|
if [ $DEBUG ] ; then echo "Check if $TARGETORG/$TARGETPKG is there!" ; fi
|
2023-06-05 00:52:52 +02:00
|
|
|
RESPONSE=$(curl $SILENT -o /dev/null -w "%{http_code}" "$GITEAHOST/api/v1/repos/$TARGETORG/$TARGETPKG")
|
2023-05-30 08:34:06 +02:00
|
|
|
if [ "$RESPONSE" == "200" ]; then
|
2023-06-01 01:56:37 +02:00
|
|
|
if [ $DEBUG ] ; then echo "Repository for $TARGETORG/$TARGETPKG exists!" ; fi
|
2023-06-01 01:41:09 +02:00
|
|
|
if [ -z ${DELETEIT} ] ; then
|
|
|
|
while true; do
|
|
|
|
read -p "Do you wish to delete it and continue?(y/n) " yn
|
|
|
|
case $yn in
|
|
|
|
[Yy]* )
|
2023-06-01 01:20:55 +02:00
|
|
|
DELETEIT=true
|
|
|
|
break ;;
|
2023-06-01 01:41:09 +02:00
|
|
|
[Nn]* )
|
2023-06-05 00:52:52 +02:00
|
|
|
echo "************Abandoning Fork of $SOURCEORG/$SOURCEPKG on $GITEAHOST ($RESPONSE)"
|
2023-06-01 01:20:55 +02:00
|
|
|
exit 1 ;;
|
2023-06-01 01:41:09 +02:00
|
|
|
* ) echo "Please answer yes or no.";;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
fi
|
2023-06-01 01:20:55 +02:00
|
|
|
if [ $DELETEIT ] ; then
|
2023-06-01 01:41:09 +02:00
|
|
|
if [ $DEBUG ] ; then echo "Deleting $TARGETORG/$TARGETPKG" ; fi
|
2023-06-01 01:20:55 +02:00
|
|
|
RESPONSE=$(curl "$checkSSL" "$SILENT" -X 'DELETE' \
|
2023-06-05 00:52:52 +02:00
|
|
|
"$GITEAHOST/api/v1/repos/$TARGETORG/$TARGETPKG" \
|
2023-06-01 01:20:55 +02:00
|
|
|
-H 'accept: application/json' \
|
2023-06-05 01:21:54 +02:00
|
|
|
-H "Authorization: token $GITEAACCESSTOKEN" )
|
2023-06-01 01:20:55 +02:00
|
|
|
fi
|
2023-05-30 08:34:06 +02:00
|
|
|
else
|
2023-06-05 00:52:52 +02:00
|
|
|
if [ $DEBUG ] ; then echo "Repository for $TARGETORG/$TARGETPKG does not exist on $GITEAHOST" ; fi
|
2023-05-30 08:34:06 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
#Fork e-smith-<pkg> into users repositories as smeserver-<pkg>
|
|
|
|
# - add bugzilla and wiki references
|
|
|
|
|
|
|
|
# create a Bugzilla URL
|
|
|
|
PRODUCTBUGZILLA="SME%20Server%2010.X"
|
2023-06-04 09:00:24 +02:00
|
|
|
BASEORCONTRIB="base"
|
2023-05-30 08:34:06 +02:00
|
|
|
if [[ "$SOURCEORG" == "smecontribs" ]]; then
|
|
|
|
PRODUCTBUGZILLA="SME%20Contribs"
|
2023-06-04 09:00:24 +02:00
|
|
|
BASEORCONTRIB="contrib"
|
2023-05-30 08:34:06 +02:00
|
|
|
fi
|
|
|
|
|
2023-06-04 09:00:24 +02:00
|
|
|
# migrate the source package over to target with updated fields
|
2023-06-05 06:54:51 +02:00
|
|
|
if [ $DEBUG ] ; then echo "Migrating $SOURCEORG/$SOURCEPKG as $TARGETORG/$TARGETPKG on $GITEAHOST" ; fi
|
|
|
|
RESPONSE=$(curl $SILENT $checkSSL -o /dev/null -w "%{http_code}" -X 'POST' \
|
2023-06-05 00:52:52 +02:00
|
|
|
"$GITEAHOST/api/v1/repos/migrate" \
|
2023-06-03 04:11:10 +02:00
|
|
|
-H 'accept: application/json' \
|
2023-06-05 01:21:54 +02:00
|
|
|
-H "Authorization: token $GITEAACCESSTOKEN" \
|
2023-06-03 04:11:10 +02:00
|
|
|
-H 'Content-Type: application/json' \
|
2023-06-04 10:04:38 +02:00
|
|
|
-d '{
|
2023-06-05 01:21:54 +02:00
|
|
|
"auth_token": "'"$GITEAACCESSTOKEN"'",
|
2023-06-05 00:52:52 +02:00
|
|
|
"clone_addr": "'"$GITEAHOST/$SOURCEORG/$SOURCEPKG.git"'",
|
2023-06-04 09:50:56 +02:00
|
|
|
"description": "'"SMEServer Koozali developed git repo for $TARGETPKG $BASEORCONTRIB"'",
|
|
|
|
"repo_name": "'"$TARGETPKG"'",
|
2023-06-05 00:52:52 +02:00
|
|
|
"repo_owner": "'"$TARGETORG"'"
|
2023-06-04 10:04:38 +02:00
|
|
|
}'
|
2023-06-04 09:00:24 +02:00
|
|
|
)
|
2023-06-05 06:54:51 +02:00
|
|
|
if [[ $RESPONSE != 201 ]] ; then
|
|
|
|
echo "Unable to migrate $SOURCEORG/$SOURCEPKG to $TARGETORG/$TARGETPKG ($RESPOMNSE) - Aborting"
|
|
|
|
exit 1
|
|
|
|
fi
|
2023-06-04 10:04:38 +02:00
|
|
|
|
2023-06-05 00:52:52 +02:00
|
|
|
# Migrate does NOT copy accross the issues and wiki external links
|
|
|
|
# grab WIKILINK from source package
|
2023-06-05 06:04:19 +02:00
|
|
|
if [ $DEBUG ] ; then echo "Retrieving WIKIKLINK from $SOURCEORG/$SOURCEPKG" ; fi
|
2023-06-05 02:18:11 +02:00
|
|
|
WIKILINK=$(curl "$SILENT" "$checkSSL" -X 'GET' \
|
2023-06-05 00:52:52 +02:00
|
|
|
"$GITEAHOST/api/v1/repos/$SOURCEORG/$SOURCEPKG" \
|
|
|
|
-H 'accept: application/json' \
|
|
|
|
-H 'Content-Type: application/json' \
|
2023-06-05 01:21:54 +02:00
|
|
|
-H "Authorization: token $GITEAACCESSTOKEN" | \
|
2023-06-05 00:52:52 +02:00
|
|
|
jq -r ' .external_wiki.external_wiki_url')
|
|
|
|
if [ $DEBUG ] ; then echo "WIKILINK=$WIKILINK" ; fi
|
|
|
|
|
|
|
|
# Update the repo with the changed bugzilla url and original wiki url
|
2023-06-05 06:04:19 +02:00
|
|
|
if [ $DEBUG ] ; then echo "Updating Bug and Wiki links" ; fi
|
2023-06-05 00:52:52 +02:00
|
|
|
RESPONSE=$(curl "$SILENT" "$checkSSL" -X 'PATCH' \
|
2023-06-05 06:04:19 +02:00
|
|
|
"$GITEAHOST/api/v1/repos/$TARGETORG/$TARGETPKG" \
|
|
|
|
-H 'accept: application/json' \
|
|
|
|
-H "Authorization: token $GITEAACCESSTOKEN" \
|
|
|
|
-H 'Content-Type: application/json' \
|
|
|
|
-d '{
|
2023-06-05 00:52:52 +02:00
|
|
|
"has_issues": true,
|
|
|
|
"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"'"
|
|
|
|
},
|
|
|
|
"has_wiki": true,
|
|
|
|
"external_wiki": {
|
|
|
|
"external_wiki_url": "'"$WIKILINK"'"
|
|
|
|
}
|
|
|
|
}'
|
|
|
|
)
|
2023-05-30 08:34:06 +02:00
|
|
|
|
2023-05-30 10:08:55 +02:00
|
|
|
# Create the local Git repository
|
|
|
|
GITFiles=$WORKDIR/GITFiles/$TARGETORG
|
|
|
|
mkdir -p $GITFiles
|
|
|
|
cd $GITFiles
|
|
|
|
|
|
|
|
# Delete the local first
|
|
|
|
if [ -d "$TARGETPKG" ] ; then
|
2023-05-31 09:01:31 +02:00
|
|
|
if [ $DEBUG ] ; then echo "Deleting local GIT files" ; fi
|
2023-05-30 10:08:55 +02:00
|
|
|
rm -Rf $GITFiles/$TARGETPKG
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Clone the package
|
2023-06-05 00:52:52 +02:00
|
|
|
if [ $DEBUG ] ; then echo "git clone $GITEAHOST/$TARGETORG/$TARGETPKG.git" ; fi
|
2023-05-30 10:08:55 +02:00
|
|
|
cd $GITFiles
|
2023-06-05 00:52:52 +02:00
|
|
|
git clone "$GITEAHOST/$TARGETORG/$TARGETPKG.git" $QUIET
|
2023-05-30 10:08:55 +02:00
|
|
|
cd $GITFiles/$TARGETPKG
|
|
|
|
|
2023-05-30 08:34:06 +02:00
|
|
|
#Update README.md
|
|
|
|
# - new name
|
2023-05-31 09:01:31 +02:00
|
|
|
sed -i 's/e-smith/smeserver/g' README.md
|
2023-05-31 10:13:20 +02:00
|
|
|
|
|
|
|
# - Bugzilla link to new name whilst keeping old link for Legacy
|
|
|
|
sed -i '/Show list/p' README.md
|
2023-05-31 10:25:19 +02:00
|
|
|
sed -i "/Show list/{ n; s/Show list of outstanding bugs\:/And a list of outstanding Legacy bugs\: ($SOURCEPKG)/}" README.md
|
2023-05-31 10:13:20 +02:00
|
|
|
sed -i '/Show list/{ n; s/smeserver-/e-smith-/g}' README.md
|
2023-05-31 10:25:19 +02:00
|
|
|
sed -i '/Show list/ s/)/)\\/' README.md
|
2023-05-31 10:13:20 +02:00
|
|
|
|
2023-06-01 01:56:37 +02:00
|
|
|
git add README.md
|
2023-05-30 08:34:06 +02:00
|
|
|
|
|
|
|
#Update Makefile
|
|
|
|
# - NAME := smeserver-<pkg>
|
|
|
|
|
2023-05-31 09:01:31 +02:00
|
|
|
sed -i 's/e-smith/smeserver/g' Makefile
|
2023-06-01 01:56:37 +02:00
|
|
|
git add Makefile
|
2023-05-30 10:08:55 +02:00
|
|
|
|
2023-05-31 09:01:31 +02:00
|
|
|
# spec file
|
2023-05-30 08:34:06 +02:00
|
|
|
#Rename e-smith-<pkg>.spec as smeserver-<pkg>.spec
|
2023-06-01 02:05:15 +02:00
|
|
|
git mv "$SOURCEPKG.spec" "$TARGETPKG.spec"
|
2023-05-30 08:34:06 +02:00
|
|
|
|
|
|
|
#Update smeserver-<pkg>.spec
|
2023-06-01 02:21:54 +02:00
|
|
|
# - change name to smeserver-<pkg>
|
|
|
|
sed -i "/^Summary:/ s/e-smith/smeserver/" "$TARGETPKG.spec"
|
2023-06-14 09:02:03 +02:00
|
|
|
sed -i "/^Name:/ s/e-smith/smeserver/" "$TARGETPKG.spec"
|
2023-05-31 09:14:29 +02:00
|
|
|
sed -i "s/^%define name.*$SOURCEPKG/%define name $TARGETPKG/" "$TARGETPKG.spec"
|
2023-06-01 02:21:54 +02:00
|
|
|
sed -i "/^%description/{ n; s/e-smith/smeserver/}" "$TARGETPKG.spec"
|
2023-05-31 09:01:31 +02:00
|
|
|
|
2023-06-07 02:38:12 +02:00
|
|
|
# Hold off on these for now
|
2023-05-31 09:01:31 +02:00
|
|
|
# - change all Requires: and BuildRequires: e-smith* to smeserver*
|
2023-06-07 02:38:12 +02:00
|
|
|
#sed -i 's/^Requires:.*e-smith/Requires: smeserver/g' "$TARGETPKG.spec"
|
|
|
|
#sed -i 's/^BuildRequires:.*e-smith/BuildRequires: smeserver/g' "$TARGETPKG.spec"
|
2023-05-31 09:01:31 +02:00
|
|
|
|
2023-05-30 08:34:06 +02:00
|
|
|
# - add changelog entry (Bugzilla #12359)
|
2023-05-31 09:01:31 +02:00
|
|
|
# Bump the release and add changelog
|
2023-06-01 02:49:18 +02:00
|
|
|
change-log "$TARGETPKG.spec" >/dev/null 2>&1
|
2023-05-31 09:01:31 +02:00
|
|
|
# and edit in the reason and add by whom
|
2023-05-31 09:14:29 +02:00
|
|
|
sed -i "s/fix \[SME: \]/Rename to $TARGETPKG \[SME: 12359\]/" "$TARGETPKG.spec"
|
2023-05-31 13:29:18 +02:00
|
|
|
sed -i 's/ME MYSELF <myemail@koozali.org>/rename-e-smith-pkg.sh by Trevor Batley <trevor@batley.id.au>/' "$TARGETPKG.spec"
|
2023-05-30 08:34:06 +02:00
|
|
|
|
2023-05-31 09:01:31 +02:00
|
|
|
# - add PROVIDES: smeserver-<pkg>
|
|
|
|
sed -i "/%description/i Provides: $SOURCEPKG" "$TARGETPKG.spec"
|
|
|
|
|
|
|
|
# - change Source: to new standard of tar.gz
|
2023-06-14 09:02:03 +02:00
|
|
|
#sed -i "/^Source:/ s/tar.xz/tar.gz/" "$TARGETPKG.spec"
|
2023-05-31 09:01:31 +02:00
|
|
|
|
|
|
|
# tell git about the changes
|
2023-06-01 01:56:37 +02:00
|
|
|
git add "$TARGETPKG.spec"
|
2023-05-30 10:08:55 +02:00
|
|
|
|
2023-05-31 09:01:31 +02:00
|
|
|
#Delete archivefilename file if it follows the new standard
|
2023-06-14 08:48:14 +02:00
|
|
|
if [[ -e archivefilename ]] ; then
|
|
|
|
if [ $DEBUG ] ; then echo "archivefilename exists" ; fi
|
|
|
|
if [[ $(cat archivefilename) == "$TARGETPKG-*.tar.gz" ]] ; then
|
|
|
|
if [ $DEBUG ] ; then echo "deleteing archivefilename - meets new standard" ; fi
|
2023-06-13 08:53:39 +02:00
|
|
|
git rm archivefilename $QUIET
|
|
|
|
else
|
2023-06-14 08:48:14 +02:00
|
|
|
if [ $DEBUG ] ; then echo "substituting smeserver for e-smith in archivefilename" ; fi
|
2023-06-13 08:58:04 +02:00
|
|
|
sed -i 's/e-smith/smeserver/g' archivefilename
|
2023-06-14 08:48:14 +02:00
|
|
|
git add archivefilename
|
2023-06-13 08:53:39 +02:00
|
|
|
fi
|
2023-06-13 08:39:10 +02:00
|
|
|
fi
|
2023-05-30 08:34:06 +02:00
|
|
|
#Update createlinks
|
2023-05-31 09:01:31 +02:00
|
|
|
# - if there is an e-smith-<pkg>-update event rename to smeserver-<pkg>-update and add symlink
|
2023-05-30 08:34:06 +02:00
|
|
|
|
2023-06-01 01:41:09 +02:00
|
|
|
git commit -m "rename-e-smith-pkg script (#12359)" $QUIET
|
2023-06-01 13:23:51 +02:00
|
|
|
git push origin &> /dev/null
|
2023-05-30 10:08:55 +02:00
|
|
|
|
2023-06-05 02:41:39 +02:00
|
|
|
# Do we want to transfer the new package into the source organisation
|
2023-06-05 01:21:54 +02:00
|
|
|
if [ $TRANSFER ] ; then
|
2023-06-05 06:04:19 +02:00
|
|
|
if [ $DEBUG ] ; then echo "Transferring $TARGETORG/$TARGETPKG to $SOURCEORG/$TARGETPKG" ; fi
|
2023-06-05 02:41:39 +02:00
|
|
|
#Check that target package does not exist
|
|
|
|
if [ $DEBUG ] ; then echo "Check if $SORCEORG/$TARGETPKG is there!" ; fi
|
|
|
|
RESPONSE=$(curl $SILENT -o /dev/null -w "%{http_code}" "$GITEAHOST/api/v1/repos/$SOURCEORG/$TARGETPKG")
|
|
|
|
EXISTS=
|
|
|
|
if [ "$RESPONSE" == "200" ]; then
|
|
|
|
EXISTS=true
|
|
|
|
if [ $DEBUG ] ; then echo "Repository for $SOURCEORG/$TARGETPKG exists!" ; fi
|
|
|
|
if [ -z ${DELETEIT} ] ; then
|
|
|
|
while true; do
|
|
|
|
read -p "$SOURCEORG/$TARGETPKG exists! Do you wish to delete it and continue?(y/n) " yn
|
|
|
|
case $yn in
|
|
|
|
[Yy]* )
|
|
|
|
DELETEIT=true
|
|
|
|
break ;;
|
|
|
|
[Nn]* )
|
|
|
|
DELETEIT=
|
|
|
|
break ;;
|
|
|
|
* ) echo "Please answer yes or no.";;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
if [ $DELETEIT ] ; then
|
2023-06-05 02:45:49 +02:00
|
|
|
if [ $DEBUG ] ; then echo "Deleting $SOURCEORG/$TARGETPKG" ; fi
|
2023-06-05 03:03:12 +02:00
|
|
|
RESPONSE=$(curl "$checkSSL" "$SILENT" -o /dev/null -w "%{http_code}" -X 'DELETE' \
|
2023-06-05 02:45:49 +02:00
|
|
|
"$GITEAHOST/api/v1/repos/$SOURCEORG/$TARGETPKG" \
|
2023-06-05 02:41:39 +02:00
|
|
|
-H 'accept: application/json' \
|
|
|
|
-H "Authorization: token $GITEAACCESSTOKEN" )
|
2023-06-05 02:58:40 +02:00
|
|
|
if [[ $RESPONSE != "204" ]] ; then
|
|
|
|
echo "Unable to delete $SOURCEORG/$TARGETPKG ($RESPONSE)"
|
|
|
|
else
|
|
|
|
EXISTS=
|
|
|
|
fi
|
2023-06-05 02:41:39 +02:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
if [ $DEBUG ] ; then echo "Repository for $SOURCEORG/$TARGETPKG does not exist on $GITEAHOST" ; fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Transfer the package back to source organisation
|
|
|
|
if [[ -z $EXISTS ]] ; then
|
2023-06-05 06:54:51 +02:00
|
|
|
if [ $DEBUG ] ; then echo "Actual Transfer" ; fi
|
2023-06-05 02:41:39 +02:00
|
|
|
RESPONSE=$(curl "$SILENT" "$checkSSL" -o /dev/null -w "%{http_code}" -X 'POST' \
|
|
|
|
"$GITEAHOST/api/v1/repos/$TARGETORG/$TARGETPKG/transfer" \
|
|
|
|
-H 'accept: application/json' \
|
|
|
|
-H "Authorization: token $GITEAACCESSTOKEN" \
|
|
|
|
-H 'Content-Type: application/json' \
|
|
|
|
-d '{
|
|
|
|
"new_owner": "'"$SOURCEORG"'"
|
|
|
|
}'
|
|
|
|
)
|
|
|
|
fi
|
|
|
|
if [[ $EXISTS || $RESPONSE != "202" ]] ; then
|
|
|
|
echo "Unable to transfer $TARGETORG/$TARGETPKG to $SOURCEORG/$TARGETPKG ($RESPONSE) - Aborting!"
|
2023-06-05 01:42:48 +02:00
|
|
|
echo "But everything else has been done and $TARGETORG/$TARGETPKG should be complete."
|
|
|
|
exit 1
|
2023-06-05 02:41:39 +02:00
|
|
|
else
|
|
|
|
if [[ -z $NOOUTPUT ]] ; then echo "$SOURCEORG/$SOURCEPKG has been renamed as $SOURCEORG/$TARGETPKG" ; fi
|
2023-06-05 01:42:48 +02:00
|
|
|
fi
|
2023-06-05 02:41:39 +02:00
|
|
|
else
|
|
|
|
if [[ -z $NOOUTPUT ]] ; then echo "$SOURCEORG/$SOURCEPKG has been renamed as $TARGETORG/$TARGETPKG" ; fi
|
2023-06-05 01:21:54 +02:00
|
|
|
fi
|
|
|
|
|
2023-06-01 02:36:25 +02:00
|
|
|
exit 0
|