Version 5.1 by Normann P. Nielsen on 2026/11/15 15:43

Show last authors
1 This script travles a directory structure and creates WIKI markup and uses the [[Atlassian CLI for Confluence>>https://studio.plugins.atlassian.com/wiki/display/CSOAP/Confluence+Command+Line+Interface]] for updating a page
2
3
4
5 {{warning}}Several Requirements are needed for the final page to be displayed correctly:
6
7 [[Atlassian CLI>>https://bobswift.atlassian.net/wiki/display/ACLI/Atlassian+CLI+license]] (Notice the 3.X versions are not free, last free download versions at [[Atlassian CLI>>Main.atlassian.atlassian-confluence.atlassian-cli]]
8
9 [[User Macro: me-filecontent>>Main.atlassian.atlassian-confluence.mos-eisley-filecontent.user-macro-me-filecontent]]{{/warning}}
10
11
12
13 Executing the script:
14
15
16 {{code}}
17 ./updateFileContent.sh RelativeDirectory SpaceName PageName OpenMethod(same|new|lightbox) MakeTOC(yes|no)
18
19 {{/code}}
20
21 Sample
22
23
24 {{code}}
25 ./updateFileContent.sh "FlashGames" DiverseSpace "Flash Games" lightbox yes
26
27 {{/code}}
28
29 Gives the Page - [[Christopher>>Main.familien.christopher]]
30
31
32
33 | **Parameter**| **Description**
34 |= **RelativeDirectory**| is the path to be traveled (this is /data/images/FamilieBilleder) for my installation, where /data/images is hardcoded in the script
35 |= SpaceName| is the Name of the Space where a page will be updated (or created)
36 | **PageName**| is the Name of the Confluence page to be updated (or created) in the SpaceName Space
37 | OpenMethod| How does the Content Opens - newwin=In a New Window, lightbox=In a lightbox, Default is the same browserwindow
38 |= yes|no| determines if a TOC markup is inserted at the top of the page
39
40
41
42 Source of the Script:
43
44
45 {{code language="true"}}
46 #!/bin/bash
47
48 source config.txt
49
50 IFS=$(echo -en "\n\b")
51
52 # Arguments
53 Dir=$1
54 Space=$2
55 PageTitle=$3
56 OpenMethod=$4
57 MakeToc=$5
58 # Check Arguments
59 if [ $# -lt 5 ]
60 then
61 echo "There are not 5 required arguments: Directoryname Spacekey PageTitle OpenMethod(same|new|lightbox) MakeTOC(yes|no)"
62 exit 0
63 fi
64 if [ ! -d $FileContentRoot ]
65 then
66 echo "FileContentRoot in config.txt: $FileContentRoot does not exist"
67 exit 0
68 fi
69 if [ $Dir == "" ]
70 then
71 echo "Argument 1 is empty"
72 exit 0
73 fi
74 if [ ! -d $FileContentRoot/$Dir ]
75 then
76 echo "Argument 1 Dir: $Dir does not exist under $FileContentRoot"
77 exit 0
78 fi
79 if [ ! -d $CLIHome ]
80 then
81 echo "CLIHome in config.txt: $CLIHome does not exist"
82 exit 0
83 fi
84 if [ $MakeToc == "no" ]
85 then
86 echo "{make-top}" > $WikiFile
87 else
88 echo "{make-top}" > $WikiFile
89 echo "{toc}" >> $WikiFile
90 fi
91 if [ $OpenMethod == "" ]
92 then
93 OpenMethod == "same"
94 fi
95 cd $FileContentRoot/"$Dir"
96 for file in `find . -type d | grep -v "thumbs" | grep -v "cache" | sort`
97 do
98 echo $file
99 NumOfFiles=`ls -lt "$file" | awk 'NR!=1 && !/^d/ {print $NF}' | wc -l`
100 if [ $NumOfFiles -gt 0 ]
101 then
102 file=$(echo "$file"|sed 's/\.\///g')
103 if [ $file != "." ]
104 then
105 echo "h1. ${file}" >> $WikiFile
106 echo "{go-top}" >> $WikiFile
107 fi
108 for content in `ls "$file"`
109 do
110 file2=$(echo "$file"|sed 's/ /%20/g')
111 if [ $file2 == "." ]
112 then
113 file2=""
114 fi
115
116 echo "{me-filecontent:path=$Dir/$file2|file=$content|openmethod=$OpenMethod}" >> $WikiFile
117 done
118 fi
119
120 done
121
122 $CLIHome/confluence.sh --action storePage --space "$Space" --title "$PageTitle" --file $WikiFile
123 {{/code}}
124
125 This is a sample output for the script - screenhot of a page:
126
127 [[image:Screen Shot 2013-08-23 at 20.10.07.jpg||width="700"||height="288"||alt="Screen Shot 2013-08-23 at 20.10.07.jpg"]]
128
129 Content opened up in a lightbox:
130
131 [[image:Screen Shot 2013-08-23 at 20.14.11.jpg||width="700"||alt="Screen Shot 2013-08-23 at 20.14.11.jpg"]]