Page History
This script travles a directory structure and creates WIKI markup and uses the Atlassian CLI for Confluence for updating a page
Bemærk |
---|
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 Script for making thumbnail images (makeThumbs.sh) User Macro: me-image - Image lightbox with Flare User Macro: me-video - Linking to a Video file (User Macro) |
...
Executing the script:
./updateGallery.sh directory="FamilieBilleder/2014" space="familiebilleder" pagetitle="Familiebilleder 2014" maketoc="yes"
...
Gives the Page - Christopher
Parameter | Description | Required | In script |
RelativeDirectory | is the path to be traveled (this is /data/images/FamilieBilleder) for my installation, where /data/images is hardcoded in the script | Yes | $Dir |
---|---|---|---|
SpaceName | is the Name of the Space where a page will be updated (or created) | Yes | $Space |
PageName | is the Name of the Confluence page to be updated (or created) in the SpaceName Space | Yes | $PageTitle |
yes|no | determines if a TOC markup is inserted at the top of the page | Yes | $MakeToc |
ThumbSize | different thumbsize than the one included from config.txt | No | $Width |
eGrep | is an optional RegEx string for fine-picking from the RelativeDirectory structure (blank selects all images/movies) | No - If used, ThumbSize must be used also | $GrepFor |
Source of the Script:
Kodeblok | ||
---|---|---|
| ||
#!/bin/bash
source config.txt
IFS=$(echo -en "\n\b")
# Arguments from command line
for arg in "$@"; do
if [[ $arg =~ ^([a-z_]+)=(.*)$ ]]; then
key=${BASH_REMATCH[1]}
value=${BASH_REMATCH[2]}
case $key in
directory) Dir="$value" ;;
space) Space="$value" ;;
pagetitle) PageTitle="$value" ;;
maketoc) MakeToc="$value" ;;
width) Width="$value" ;;
grepfor) GrepFor="$value" ;;
esac
fi
done
# Check Arguments
if [ $# -lt 4 ]
then
echo "There are not at least 4 Arguments: Dir Space PageTitle yes/no"
exit 0
fi
if [ ! -d $MediaRoot ]
then
echo "MediaRoot in config.txt: $MediaRoot does not exist"
exit 0
fi
if [ $Dir == "" ]
then
echo "Argument 1 is empty"
exit 0
fi
if [ ! -d $MediaRoot/$Dir ]
then
echo "Argument 1 Dir: $Dir does not exist under $MediaRoot"
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
# Create Thumbnails for images and video
if [ ! -e makeThumbs.sh ]
then
echo "makeThumbs.sh script not found here"
exit 0
fi
if [ ! $Width == "" ]
then
# Replace with from config.txt with command line argument width
echo "Replacing config.txt ThumbSize $ThumbSize with argument $Width"
ThumbSize=$Width
fi
./makeThumbs.sh $ThumbSize $MediaRoot/"$Dir"
./makeThumbs.sh $DisplaySize $MediaRoot/"$Dir"
cd $MediaRoot/"$Dir"
# Create / update Parent - so we are sure it exists
$CLIHome/confluence.sh --action storePage --space "$Space" --title "$PageTitle" --content ""
for file in `find . -type d | grep -v "thumbs" | grep -v "cache" | egrep -i "$GrepFor" | sort`
do
if [ $file != "." ]
then
echo "" > $WikiPageFile
echo $file
NumOfPics=`ls -t "$file" | egrep -i "\.(jpg|jpeg|gif|png|avi|flv|mov)$" | wc -l`
if [ $NumOfPics -gt 0 ]
then
# The Directory is not emtpy, so update and create it
file=$(echo "$file"|sed 's/\.\///g')
group=$file
for image in `ls "$file" | egrep -i "\.(jpg|jpeg|gif|png)$"`
do
# Loop all images
file2=$(echo "$file"|sed 's/ /%20/g')
echo "{me-image:path=$Dir/$file2|image=$image|group=$group|thumbsize=$ThumbSize|displaysize=$DisplaySize}" >> $WikiPageFile
done
for movie in `ls "$file" | egrep -i "\.(flv|avi|mov)$"`
do
# Loop all video
file2=$(echo "$file"|sed 's/ /%20/g')
echo "{me-video:path=$Dir/$file2|image=$movie|thumbsize=$ThumbSize|displaysize=$DisplaySize}" >> $WikiPageFile
done
title=$(echo "$file"|sed 's/\//-/g')
echo "h1. ${file}" >> $WikiFile
echo "{go-top}" >> $WikiFile
echo "{include:${title}}" >> $WikiFile
echo "----" >> $WikiFile
$CLIHome/confluence.sh --action storePage --space "$Space" --title "${title}" --parent "$PageTitle" --file $WikiPageFile --labels "noshow"
fi
fi
done
$CLIHome/confluence.sh --action storePage --space "$Space" --title "$PageTitle" --file $WikiFile
rm $WikiPageFile
rm $WikiFile
|