commit fed44789eb7d27d8973434c9db22d2f14587a52f Author: Trevor Batley Date: Tue Jul 18 18:22:05 2023 +1000 first commit diff --git a/e-smith-packages.lst b/e-smith-packages.lst new file mode 100644 index 0000000..8f92524 --- /dev/null +++ b/e-smith-packages.lst @@ -0,0 +1,48 @@ +e-smith-LPRng +e-smith-apache +e-smith-backup +e-smith-base +e-smith-cvm-unix-local +e-smith-devtools +e-smith-dnscache +e-smith-domains +e-smith-dynamicdns-dyndns +e-smith-dynamicdns-dyndns.org +e-smith-dynamicdns-tzo +e-smith-dynamicdns-yi +e-smith-email +e-smith-flexbackup +e-smith-formmagick +e-smith-grub +e-smith-horde +e-smith-hosts +e-smith-ibays +e-smith-imp +e-smith-ingo +e-smith-ldap +e-smith-lib +e-smith-lib-compspec +e-smith-manager +e-smith-mysql +e-smith-ntp +e-smith-nutUPS +e-smith-oidentd +e-smith-openssh +e-smith-packetfilter +e-smith-php +e-smith-pop3 +e-smith-portforwarding +e-smith-pptpd +e-smith-proftpd +e-smith-proxy +e-smith-qmail +e-smith-qmailanalog +e-smith-quota +e-smith-radiusd +e-smith-runit +e-smith-samba +e-smith-starterwebsite +e-smith-test +e-smith-tinydns +e-smith-turba +e-smith-viewlogfiles diff --git a/rename-e-smith-pkg.sh b/rename-e-smith-pkg.sh new file mode 100755 index 0000000..d53078a --- /dev/null +++ b/rename-e-smith-pkg.sh @@ -0,0 +1,370 @@ +#!/bin/bash +# +# Rename an e-smith package as smeserver and change relevant files +# Will migrate a repository from the source organisation into your work area and rename it as smeserver and do all changes there. +# If transfer is specified it will then transfer the new repository to the source organisation (you MUST be an owner to fo this) +# $1 = Module name e.g. e-smith-dnscache +# $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 +# = "transfer" will push completed package into source organisation (other wise leave in your area) +# = "debug" run in debug mode +# = "silent" suppress success message +# This works whether the repo and local files exist of not (it deletes them if necessary) +# + +if [[ -z $1 ]] ; then + echo "Rename an e-smith package as smeserver and change relevant files" + echo "rename-e-smith-pkg.sh [ ]" + echo " = Module/package name (e.g. e-smith-dnscache)" + echo " can appear in any order and are optional" + echo " - (any valid organisation - defaults to smeserver)" + echo " - will use parameters set for local repository, else it will use remote" + echo " - will automagically delete an existing repo, otherwise it will prompt" + echo " - will push completed package into source organisation (other wise leave in your area)" + echo " - run in debug mode" + echo " - suppress success message" + 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-cvs2git.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 +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 + +# Command line parameters +#Extract +SOURCEPKG=$1 +TARGETPKG=${SOURCEPKG/e-smith/smeserver} + +GITEAHOST=${remote_GITEAHOST} +GITEAACCESSTOKEN=${remote_GITEAACCESSTOKEN} +SOURCEORG="smeserver" +TARGETORG=${remote_USER} +DELETEIT= +NOOUTPUT= +TRANSFER= +for param in $2 $3 $4 $5 $6; do + if [ $param ] ; then + case $param in + local ) + GITEAHOST=${local_GITEAHOST} + GITEAACCESSTOKEN=${local_GITEAACCESSTOKEN} + TARGETORG=${local_USER} ;; + force ) + DELETEIT=true ;; + debug ) + DEBUG=true ;; + silent ) + NOOUTPUT=true ;; + transfer ) + TRANSFER=true ;; + * ) + SOURCEORGORG=$param ;; + esac + else + break + fi +done + +# 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" + +#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}" "$GITEAHOST/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 $GITEAHOST ($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}" "$GITEAHOST/api/v1/repos/$TARGETORG/$TARGETPKG") +if [ "$RESPONSE" == "200" ]; then + if [ $DEBUG ] ; then echo "Repository for $TARGETORG/$TARGETPKG exists!" ; fi + if [ -z ${DELETEIT} ] ; then + while true; do + read -p "Do you wish to delete it and continue?(y/n) " yn + case $yn in + [Yy]* ) + DELETEIT=true + break ;; + [Nn]* ) + echo "************Abandoning Fork of $SOURCEORG/$SOURCEPKG on $GITEAHOST ($RESPONSE)" + exit 1 ;; + * ) echo "Please answer yes or no.";; + esac + done + fi + if [ $DELETEIT ] ; then + if [ $DEBUG ] ; then echo "Deleting $TARGETORG/$TARGETPKG" ; fi + RESPONSE=$(curl "$checkSSL" "$SILENT" -X 'DELETE' \ + "$GITEAHOST/api/v1/repos/$TARGETORG/$TARGETPKG" \ + -H 'accept: application/json' \ + -H "Authorization: token $GITEAACCESSTOKEN" ) + fi +else + if [ $DEBUG ] ; then echo "Repository for $TARGETORG/$TARGETPKG does not exist on $GITEAHOST" ; fi +fi + +#Fork e-smith- into users repositories as smeserver- +# - add bugzilla and wiki references + +# create a Bugzilla URL +PRODUCTBUGZILLA="SME%20Server%2010.X" +BASEORCONTRIB="base" +if [[ "$SOURCEORG" == "smecontribs" ]]; then + PRODUCTBUGZILLA="SME%20Contribs" + BASEORCONTRIB="contrib" +fi + +# migrate the source package over to target with updated fields +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' \ + "$GITEAHOST/api/v1/repos/migrate" \ + -H 'accept: application/json' \ + -H "Authorization: token $GITEAACCESSTOKEN" \ + -H 'Content-Type: application/json' \ + -d '{ + "auth_token": "'"$GITEAACCESSTOKEN"'", + "clone_addr": "'"$GITEAHOST/$SOURCEORG/$SOURCEPKG.git"'", + "description": "'"SMEServer Koozali developed git repo for $TARGETPKG $BASEORCONTRIB"'", + "repo_name": "'"$TARGETPKG"'", + "repo_owner": "'"$TARGETORG"'" + }' + ) +if [[ $RESPONSE != 201 ]] ; then + echo "Unable to migrate $SOURCEORG/$SOURCEPKG to $TARGETORG/$TARGETPKG ($RESPOMNSE) - Aborting" + exit 1 +fi + +# Migrate does NOT copy accross the issues and wiki external links +# grab WIKILINK from source package +if [ $DEBUG ] ; then echo "Retrieving WIKIKLINK from $SOURCEORG/$SOURCEPKG" ; fi +WIKILINK=$(curl "$SILENT" "$checkSSL" -X 'GET' \ + "$GITEAHOST/api/v1/repos/$SOURCEORG/$SOURCEPKG" \ + -H 'accept: application/json' \ + -H 'Content-Type: application/json' \ + -H "Authorization: token $GITEAACCESSTOKEN" | \ + 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 +if [ $DEBUG ] ; then echo "Updating Bug and Wiki links" ; fi +RESPONSE=$(curl "$SILENT" "$checkSSL" -X 'PATCH' \ + "$GITEAHOST/api/v1/repos/$TARGETORG/$TARGETPKG" \ + -H 'accept: application/json' \ + -H "Authorization: token $GITEAACCESSTOKEN" \ + -H 'Content-Type: application/json' \ + -d '{ + "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"'" + } + }' + ) + +# Create the local Git repository +GITFiles=$WORKDIR/GITFiles/$TARGETORG +mkdir -p $GITFiles +cd $GITFiles + +# Delete the local first +if [ -d "$TARGETPKG" ] ; then + if [ $DEBUG ] ; then echo "Deleting local GIT files" ; fi + rm -Rf $GITFiles/$TARGETPKG +fi + +# Clone the package +if [ $DEBUG ] ; then echo "git clone $GITEAHOST/$TARGETORG/$TARGETPKG.git" ; fi +cd $GITFiles +git clone "$GITEAHOST/$TARGETORG/$TARGETPKG.git" $QUIET +cd $GITFiles/$TARGETPKG + +#Update README.md +# - new name +sed -i 's/e-smith/smeserver/g' README.md + +# - Bugzilla link to new name whilst keeping old link for Legacy +sed -i '/Show list/p' README.md +sed -i "/Show list/{ n; s/Show list of outstanding bugs\:/And a list of outstanding Legacy bugs\: ($SOURCEPKG)/}" README.md +sed -i '/Show list/{ n; s/smeserver/e-smith/g}' README.md +sed -i '/Show list/ s/)/)\\/' README.md + +git add README.md + +#Update Makefile +# - NAME := smeserver- + +sed -i 's/e-smith/smeserver/g' Makefile +git add Makefile + +# spec file +#Rename e-smith-.spec as smeserver-.spec +git mv "$SOURCEPKG.spec" "$TARGETPKG.spec" + +#Update smeserver-.spec +# - change name to smeserver- +sed -i "/^Summary:/ s/e-smith/smeserver/" "$TARGETPKG.spec" +sed -i "/^Name:/ s/e-smith/smeserver/" "$TARGETPKG.spec" +sed -i "s/^%define name.*$SOURCEPKG/%define name $TARGETPKG/" "$TARGETPKG.spec" +sed -i "/^%description/{ n; s/e-smith/smeserver/}" "$TARGETPKG.spec" + +# Hold off on these for now +# - change all Requires: and BuildRequires: e-smith* to smeserver* +#sed -i 's/^Requires:.*e-smith/Requires: smeserver/g' "$TARGETPKG.spec" +#sed -i 's/^BuildRequires:.*e-smith/BuildRequires: smeserver/g' "$TARGETPKG.spec" + +# - add changelog entry (Bugzilla #12359) +# Bump the release and add changelog +change-log "$TARGETPKG.spec" >/dev/null 2>&1 +# and edit in the reason and add by whom +sed -i "s/fix \[SME: \]/Rename to $TARGETPKG \[SME: 12359\]/" "$TARGETPKG.spec" +sed -i 's/ME MYSELF /rename-e-smith-pkg.sh by Trevor Batley /' "$TARGETPKG.spec" + +# - add PROVIDES: smeserver- +sed -i "/%description/i Provides: $SOURCEPKG" "$TARGETPKG.spec" + +# - change Source: to new standard of tar.gz +#sed -i "/^Source:/ s/tar.xz/tar.gz/" "$TARGETPKG.spec" + +# tell git about the changes +git add "$TARGETPKG.spec" + +#Delete archivefilename file if it follows the new standard +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 + git rm archivefilename $QUIET + else + if [ $DEBUG ] ; then echo "substituting smeserver for e-smith in archivefilename" ; fi + sed -i 's/e-smith/smeserver/g' archivefilename + git add archivefilename + fi +fi +#Update createlinks +# - if there is an e-smith--update event rename to smeserver--update and add symlink + +git commit -m "rename-e-smith-pkg script (#12359)" $QUIET +git push origin &> /dev/null + +# Do we want to transfer the new package into the source organisation +if [ $TRANSFER ] ; then + if [ $DEBUG ] ; then echo "Transferring $TARGETORG/$TARGETPKG to $SOURCEORG/$TARGETPKG" ; fi + #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 + if [ $DEBUG ] ; then echo "Deleting $SOURCEORG/$TARGETPKG" ; fi + RESPONSE=$(curl "$checkSSL" "$SILENT" -o /dev/null -w "%{http_code}" -X 'DELETE' \ + "$GITEAHOST/api/v1/repos/$SOURCEORG/$TARGETPKG" \ + -H 'accept: application/json' \ + -H "Authorization: token $GITEAACCESSTOKEN" ) + if [[ $RESPONSE != "204" ]] ; then + echo "Unable to delete $SOURCEORG/$TARGETPKG ($RESPONSE)" + else + EXISTS= + fi + 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 + if [ $DEBUG ] ; then echo "Actual Transfer" ; fi + 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!" + echo "But everything else has been done and $TARGETORG/$TARGETPKG should be complete." + exit 1 + else + if [[ -z $NOOUTPUT ]] ; then echo "$SOURCEORG/$SOURCEPKG has been renamed as $SOURCEORG/$TARGETPKG" ; fi + fi +else + if [[ -z $NOOUTPUT ]] ; then echo "$SOURCEORG/$SOURCEPKG has been renamed as $TARGETORG/$TARGETPKG" ; fi +fi + +exit 0