Wiki source code of Import images into a Confluence page (V3)
Version 1.1 by Normann P. Nielsen on 2026/11/15 15:43
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | This script travles a directory structure and creates WIKI markup (suitable for Confluence versions lower that 4.0). | ||
| 2 | |||
| 3 | Several Macros are neede for the final page to be displayed correctly. See [[User Macros>>Main.atlassian.atlassian-confluence.user-macros]] | ||
| 4 | |||
| 5 | {{warning}}As this injects data directly into the MySQL database, either a Cache flushing or a [[Tomcat restart>>Main.atlassian.atlassian-confluence.confluence-restart-script-restart-sh]] is needed afterwards{{/warning}} | ||
| 6 | |||
| 7 | {{error}}Is not Confluence 4 compatible - see [[Script for linking images into a Confluence page (updateGallery.sh)>>Main.atlassian.atlassian-confluence.mos-eisley-gallery.script-for-linking-images-into-a-confluence-page-updategallery-sh]]{{/error}} | ||
| 8 | |||
| 9 | Executing the script: | ||
| 10 | |||
| 11 | |||
| 12 | {{code}} | ||
| 13 | ./updateGallery.sh RelativeDirectory PageId yes|no eGrep | ||
| 14 | |||
| 15 | {{/code}} | ||
| 16 | |||
| 17 | Sample | ||
| 18 | |||
| 19 | |||
| 20 | {{code}} | ||
| 21 | ./updateGallery.sh "FamilieBilleder" 28000 yes "Christopher|Stoffer" | ||
| 22 | |||
| 23 | {{/code}} | ||
| 24 | |||
| 25 | Gives the Page - [[Christopher>>Main.familien.christopher]] | ||
| 26 | |||
| 27 | Parameters: | ||
| 28 | |||
| 29 | |= RelativeDirectory| is the path to be traveled (this is /data/images/FamilieBilleder) for my installation, where /data/images is hardcoded in the script | ||
| 30 | |= PageId| is Id for the Confluence page needed to be updated | ||
| 31 | |= yes|no| is if a TOC markup is inserted | ||
| 32 | |= eGrep| is an optional RegEx string for fine-picking from the Directory structure | ||
| 33 | |||
| 34 | Source of the Script: | ||
| 35 | |||
| 36 | |||
| 37 | {{code language="true"}} | ||
| 38 | #!/bin/bash | ||
| 39 | |||
| 40 | html="" | ||
| 41 | IFS=$(echo -en "\n\b") | ||
| 42 | |||
| 43 | # Arguments | ||
| 44 | |||
| 45 | Dir=$1 | ||
| 46 | Id=$2 | ||
| 47 | MakeToc=$3 | ||
| 48 | GrepFor=$4 | ||
| 49 | |||
| 50 | # Check Arguments | ||
| 51 | |||
| 52 | if [ $# -lt 3 ] | ||
| 53 | then | ||
| 54 | |||
| 55 | echo "There are not at least 3 Arguments: Dir ArticleId yes/no" | ||
| 56 | exit 0 | ||
| 57 | fi | ||
| 58 | |||
| 59 | if [ Dir == "" ] | ||
| 60 | then | ||
| 61 | |||
| 62 | echo "Argument 1 is empty" | ||
| 63 | exit 0 | ||
| 64 | fi | ||
| 65 | |||
| 66 | if [ ! -d /data/images/$Dir ] | ||
| 67 | then | ||
| 68 | |||
| 69 | echo "Argument 1 Dir: $Dir does not exist" | ||
| 70 | exit 0 | ||
| 71 | fi | ||
| 72 | |||
| 73 | |||
| 74 | cd /data/images/"$Dir" | ||
| 75 | |||
| 76 | for file in `find . -type d | grep -v "thumbs" | grep -v "cache" | egrep -i "$GrepFor" | sort` | ||
| 77 | do | ||
| 78 | NumOfPics=`ls -t "$file" | egrep -i "\.(jpg|gif|png|bmp)$" | wc -l` | ||
| 79 | |||
| 80 | if [ $NumOfPics -gt 0 ] | ||
| 81 | then | ||
| 82 | |||
| 83 | file=$(echo "$file"|sed 's/\.\///g') | ||
| 84 | html="$html\\nh1. $file\\n{go-top}\\n" | ||
| 85 | group=$file | ||
| 86 | |||
| 87 | for image in `ls "$file" | egrep -i "\.(jpg|gif|png|bmp)$"` | ||
| 88 | do | ||
| 89 | file2=$(echo "$file"|sed 's/ /%20/g') | ||
| 90 | html="$html\\n{me-image:path=$Dir/$file2/|image=$image|group=$group}" | ||
| 91 | |||
| 92 | done | ||
| 93 | |||
| 94 | html="$html\\n" | ||
| 95 | |||
| 96 | fi | ||
| 97 | |||
| 98 | # for movie in `find "$file"/ -maxdepth 1 -type f | grep -v thumbs | egrep -i "\.(bobsos|flv)$" | sort` | ||
| 99 | # do | ||
| 100 | |||
| 101 | # html="$html {me-video:/images/$Dir/$movie}" | ||
| 102 | |||
| 103 | # done | ||
| 104 | |||
| 105 | done | ||
| 106 | |||
| 107 | if [ $MakeToc == "no" ] | ||
| 108 | then | ||
| 109 | |||
| 110 | sql="UPDATE BODYCONTENT set body='{make-top}\\n$html' where contentid=$Id" | ||
| 111 | else | ||
| 112 | |||
| 113 | sql="UPDATE BODYCONTENT set body='{make-top}\\n{toc}\\n$html' where contentid=$Id" | ||
| 114 | |||
| 115 | fi | ||
| 116 | |||
| 117 | echo "SET NAMES 'utf8';$sql" > /tmp/insert.sql | ||
| 118 | #echo "SET NAMES 'utf8';$sql" | ||
| 119 | |||
| 120 | mysql --user=cadmin --password=******** confluence < /tmp/insert.sql | ||
| 121 | rm /tmp/insert.sql | ||
| 122 | |||
| 123 | {{/code}} | ||
| 124 | |||
| 125 | 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 | ||
| 126 | |||
| 127 | This is a sample output for the script: | ||
| 128 | |||
| 129 | |||
| 130 | {{code}} | ||
| 131 | {include-lightbox} | ||
| 132 | {make-top} | ||
| 133 | {toc} | ||
| 134 | |||
| 135 | h1. 2 x Fødselsdag 03-09-2011 | ||
| 136 | {go-top} | ||
| 137 | |||
| 138 | {me-image:path=FamilieBilleder/2011/2%20x%20Fødselsdag%2003-09-2011/|image=CIMG2034.JPG|group=2 x Fødselsdag 03-09-2011} | ||
| 139 | {me-image:path=FamilieBilleder/2011/2%20x%20Fødselsdag%2003-09-2011/|image=CIMG2035.JPG|group=2 x Fødselsdag 03-09-2011} | ||
| 140 | {me-image:path=FamilieBilleder/2011/2%20x%20Fødselsdag%2003-09-2011/|image=CIMG2036.JPG|group=2 x Fødselsdag 03-09-2011} | ||
| 141 | {me-image:path=FamilieBilleder/2011/2%20x%20Fødselsdag%2003-09-2011/|image=CIMG2037.JPG|group=2 x Fødselsdag 03-09-2011} | ||
| 142 | {me-image:path=FamilieBilleder/2011/2%20x%20Fødselsdag%2003-09-2011/|image=CIMG2038.JPG|group=2 x Fødselsdag 03-09-2011} | ||
| 143 | {me-image:path=FamilieBilleder/2011/2%20x%20Fødselsdag%2003-09-2011/|image=CIMG2039.JPG|group=2 x Fødselsdag 03-09-2011} | ||
| 144 | |||
| 145 | h1. Afslapning 24-07-2011 | ||
| 146 | {go-top} | ||
| 147 | |||
| 148 | {{/code}} |