Skip to content

Instantly share code, notes, and snippets.

@ozzi-
Last active December 13, 2018 07:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ozzi-/d59644878bdefd5a96ba076674d9ed6d to your computer and use it in GitHub Desktop.
Save ozzi-/d59644878bdefd5a96ba076674d9ed6d to your computer and use it in GitHub Desktop.
rewrites URLs in confluence xml export zip files and creates sensible named zips
#!/bin/bash
if ! [ -x "$(command -v zip)" ]; then
echo 'Error: zip is not installed.' >&2
exit 1
fi
if ! [ -x "$(command -v unzip)" ]; then
echo 'Error: unzip is not installed.' >&2
exit 1
fi
dir=.
cur=0
for zip in $dir/Confluence-space-export*.zip; do
cur=$((cur + 1))
folder=$dir"/export_"$cur
unzip -o -q $zip -d $folder
if [[ $? == 0 ]] ; then
pathXML=$folder"/entities.xml"
pathPROP=$folder"/exportDescriptor.properties"
if [ -e $pathXML ]; then
sed -i 's/https:\/\/confluence.domain.ch/http:\/\/confluence-c.domainlocal.ch/g' $pathXML
key=$(grep -i -e "spaceKey" $pathPROP | cut -f2 -d "=")
cd $folder
rm -rf "../"$key".zip"
zip -r -q "../"$key".zip" *
cd ..
rm -rf $folder
echo "Finished rewriting and repacking space '$key'"
else
echo $pathXML
echo "Confluence Space export does not contain entitites.xml. Skipping "$zip
fi;
else
echo "Error unzipping "$dir
fi;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment