This script travles a directory structure and creates WIKI markup and uses the Atlassian CLI for Confluence for updating a page 

 

Several Requirements are needed for the final page to be displayed correctly:

Atlassian CLI (Notice the 3.X versions are not free, last free download versions at Atlassian CLI

User Macro: me-filecontent

 

Executing the script:

./updateFileContent.sh RelativeDirectory SpaceName PageName OpenMethod(same|new|lightbox) MakeTOC(yes|no)

Sample

./updateFileContent.sh "FlashGames" DiverseSpace "Flash Games" lightbox yes

Gives the Page - Christopher

 

ParameterDescription
RelativeDirectory

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

SpaceName

is the Name of the Space where a page will be updated (or created)

PageNameis the Name of the Confluence page to be updated (or created) in the SpaceName Space
OpenMethodHow does the Content Opens - newwin=In a New Window, lightbox=In a lightbox, Default is the same browserwindow

yes|no

determines if a TOC markup is inserted at the top of the page

 

Source of the Script:

#!/bin/bash

source config.txt

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

# Arguments
Dir=$1
Space=$2
PageTitle=$3
OpenMethod=$4
MakeToc=$5
# Check Arguments
if [ $# -lt 5 ] 
then
	echo "There are not 5 required arguments: Directoryname Spacekey PageTitle OpenMethod(same|new|lightbox) MakeTOC(yes|no)"
	exit 0
fi
if [ ! -d $FileContentRoot ]
then
        echo "FileContentRoot in config.txt: $FileContentRoot does not exist"
        exit 0
fi
if [ $Dir == "" ]
then
	echo "Argument 1 is empty"
	exit 0
fi
if [ ! -d $FileContentRoot/$Dir ]
then
	echo "Argument 1 Dir: $Dir does not exist under $FileContentRoot"
	exit 0
fi
if [ ! -d $CLIHome ]
then
        echo "CLIHome  in config.txt: $CLIHome does not exist"
        exit 0
fi
if [ $MakeToc == "no" ]
then
        echo "{make-top}" > $WikiFile
else
	echo "{make-top}" > $WikiFile
        echo "{toc}" >> $WikiFile
fi
if [ $OpenMethod == "" ]
then
       OpenMethod == "same"
fi
cd $FileContentRoot/"$Dir"
for file in `find . -type d | grep -v "thumbs" | grep -v "cache" | sort`
do
	echo $file
	NumOfFiles=`ls -lt "$file" | awk 'NR!=1 && !/^d/ {print $NF}' | wc -l`
	if [ $NumOfFiles -gt 0 ]
	then
		file=$(echo "$file"|sed 's/\.\///g')
		if [ $file != "." ]
		then
			echo "h1. ${file}" >> $WikiFile
			echo "{go-top}" >> $WikiFile
		fi
		for content in `ls "$file"`
		do
			file2=$(echo "$file"|sed 's/ /%20/g')
			if [ $file2 == "." ]
			then
				file2=""
			fi

			echo "{me-filecontent:path=$Dir/$file2|file=$content|openmethod=$OpenMethod}" >> $WikiFile
		done
	fi
	
done

$CLIHome/confluence.sh --action storePage --space "$Space" --title "$PageTitle" --file $WikiFile

This is a sample output for the script - screenhot of a page:

Content opened up in a lightbox: