1+ #! /bin/bash
2+
3+ # Requirements:
4+ # - Windows Commandline
5+ # - Cygwin + curl (Intune-Client)
6+ # - Alternative: https://curl.se/windows/
7+ #
8+ # (c) 2024 Oliver Glowa (glo03) / Arvato Systems GmbH
9+ #
10+
11+ source ./common/env-restapi.sh
12+
13+ # set the maximum level of recursion
14+ MAX_LEVEL=2
15+
16+ PAGE_ID=532951146
17+ # 532951146 #98 Playground
18+ # 125380876 #Health%20and%Public
19+
20+ if [ " $1 " != " " ]; then
21+ PAGE_ID=$1
22+ fi
23+
24+ LEVEL=0
25+ if [ " $2 " != " " ]; then
26+ LEVEL=$2
27+ (( LEVEL= LEVEL+ 1 ))
28+ fi
29+
30+ STOP_BRANCH=0
31+ if [ ${LEVEL} -ge ${MAX_LEVEL} ]; then
32+ STOP_BRANCH=1
33+ fi
34+
35+ # set the indentation by level
36+ INDENT=$( printf " %-${LEVEL} s" ) $( printf " %-${LEVEL} s" )
37+
38+ # read the page
39+ PARENT_URL=" ${CONF_RESTAPI_URL} /${PAGE_ID} ?expand=space"
40+ CURL_RESULT=$( curl -s -H " ${CONF_AUTH} " " ${PARENT_URL} " )
41+ PARENT_INFO=$( jq -r ' .id + " [" + .space.key + "] \"" + .title +"\""' <<< " ${CURL_RESULT}" )
42+
43+ # get the children URL
44+ CHILD_URL=$( jq -r ' ._expandable.children' <<< " ${CURL_RESULT}" )
45+ CHILD_URL=${CONF_BASE_URL}${CHILD_URL} " /page?expand=space"
46+
47+ # Some output
48+ echo -e " \n${INDENT} LEV.${LEVEL} "
49+ echo -e " ${INDENT} │\t\t\t\t${PARENT_URL} "
50+ echo -e " ${INDENT} │\t\t\t\t${CHILD_URL} "
51+
52+ # read the child pages
53+ CURL_RESULT=$( curl -s -H " ${CONF_AUTH} " " ${CHILD_URL} " )
54+
55+ CHILD_IDX=-1
56+ jq -r ' .results[] | .id + " " + .space.key + " " + .title +""' <<< " ${CURL_RESULT}" |
57+ {
58+ while read -r CHILD_PAGE_ID CHILD_SPACE CHILD_TITLE ; do
59+ # looop through the child pages
60+ (( CHILD_IDX= CHILD_IDX+ 1 ))
61+
62+ # some output
63+ echo " ${INDENT} │"
64+ echo " ${INDENT} ├- PAGE : ${PARENT_INFO} "
65+ echo " ${INDENT} └- ${CHILD_IDX} .CHILD: ${CHILD_PAGE_ID} [${CHILD_SPACE} ] \" ${CHILD_TITLE} \" "
66+
67+ if [ ${STOP_BRANCH} -eq 0 ]; then
68+ # call the script recursively for the next level
69+ ./" $0 " " ${CHILD_PAGE_ID} " ${LEVEL}
70+ else
71+ # stop the recursion for this branch
72+ echo -e " ${INDENT} ## STOP_BRANCH ON LEV.${LEVEL} ##\n"
73+ fi
74+ done
75+
76+ if [ ${CHILD_IDX} -lt 0 ]; then
77+ # branch has no children
78+ echo " ${INDENT} ├- PAGE : ${PARENT_INFO} "
79+ echo -e " ${INDENT} └- x.CHILD: No children found\n"
80+ fi
81+ }
0 commit comments