This script travles a directory structure and creates WIKI markup (suitable for Confluence versions lower that 4.0).

Several Macros are neede for the final page to be displayed correctly. See User Macros

As this injects data directly into the MySQL database, either a Cache flushing or a Tomcat restart is needed afterwards

Executing the script:

./updateGallery.sh RelativeDirectory PageId yes|no eGrep

Sample

./updateGallery.sh "FamilieBilleder" 28000 yes "Christopher|Stoffer"

Gives the Page - Christopher

Parameters:

RelativeDirectory

is the path to be traveled (this is /data/images/FamilieBilleder) for my installation, where /data/images is hardcoded in the script

PageId

is Id for the Confluence page needed to be updated

yes|no

is if a TOC markup is inserted

eGrep

is an optional RegEx string for fine-picking from the Directory structure

Source of the Script:

#!/bin/bash

html=""
IFS=$(echo -en "\n\b")

# Arguments

Dir=$1
Id=$2
MakeToc=$3
GrepFor=$4

# Check Arguments

if [ $# -lt 3 ]
then

	echo "There are not at least 3 Arguments: Dir ArticleId yes/no"
	exit 0
fi

if [ Dir == "" ]
then

	echo "Argument 1 is empty"
	exit 0
fi

if [ ! -d /data/images/$Dir ]
then

	echo "Argument 1 Dir: $Dir does not exist"
	exit 0
fi


cd /data/images/"$Dir"

for file in `find . -type d | grep -v "thumbs" | grep -v "cache" | egrep -i "$GrepFor" | sort`
do
	NumOfPics=`ls -t "$file" | egrep -i "\.(jpg|gif|png|bmp)$" | wc -l`

	if [ $NumOfPics -gt 0 ]
	then

		file=$(echo "$file"|sed 's/\.\///g')
		html="$html\\nh1. $file\\n{go-top}\\n"
		group=$file

		for image in `ls "$file" | egrep -i "\.(jpg|gif|png|bmp)$"`
		do
			file2=$(echo "$file"|sed 's/ /%20/g')
			html="$html\\n{me-image:path=$Dir/$file2/|image=$image|group=$group}"

		done

		html="$html\\n"

	fi

#	for movie in `find "$file"/ -maxdepth 1 -type f | grep -v thumbs | egrep -i "\.(bobsos|flv)$" | sort`
#	do

#		html="$html {me-video:/images/$Dir/$movie}"

#	done

done

if [ $MakeToc == "no" ]
then

	sql="UPDATE BODYCONTENT set body='{make-top}\\n$html' where contentid=$Id"
else

	sql="UPDATE BODYCONTENT set body='{make-top}\\n{toc}\\n$html' where contentid=$Id"

fi

echo "SET NAMES 'utf8';$sql" > /tmp/insert.sql
#echo "SET NAMES 'utf8';$sql"

mysql --user=cadmin --password=******** confluence < /tmp/insert.sql
rm /tmp/insert.sql

Line 73 and 76 can be expandede with a {include-fancybox}\\\\n or {include-lightbox}\\\\n is You want a lighbox popup of the image

This is a sample output for the script:

{include-lightbox}
{make-top}
{toc}

h1. 2 x Fødselsdag 03-09-2011
{go-top}

{me-image:path=FamilieBilleder/2011/2%20x%20Fødselsdag%2003-09-2011/|image=CIMG2034.JPG|group=2 x Fødselsdag 03-09-2011}
{me-image:path=FamilieBilleder/2011/2%20x%20Fødselsdag%2003-09-2011/|image=CIMG2035.JPG|group=2 x Fødselsdag 03-09-2011}
{me-image:path=FamilieBilleder/2011/2%20x%20Fødselsdag%2003-09-2011/|image=CIMG2036.JPG|group=2 x Fødselsdag 03-09-2011}
{me-image:path=FamilieBilleder/2011/2%20x%20Fødselsdag%2003-09-2011/|image=CIMG2037.JPG|group=2 x Fødselsdag 03-09-2011}
{me-image:path=FamilieBilleder/2011/2%20x%20Fødselsdag%2003-09-2011/|image=CIMG2038.JPG|group=2 x Fødselsdag 03-09-2011}
{me-image:path=FamilieBilleder/2011/2%20x%20Fødselsdag%2003-09-2011/|image=CIMG2039.JPG|group=2 x Fødselsdag 03-09-2011}

h1. Afslapning 24-07-2011
{go-top}