confluence_get_article.sh
· 1.5 KiB · Bash
Raw
#!/bin/bash
# 1. Указать реквизиты доступа к confluence
USERNAME=""
PASSWORD=""
CONFLUENCE_URL=""
OUTPUT_PATH="./confluence/"
# 2. Вызвать: ./confluence_get_article.sh <page_id>
##################################################################
if [ $# -lt 1 ]; then
echo "Usage: $0 <article_id>"
exit 1
fi
command -v curl >/dev/null 2>&1 || { echo >&2 "Error: curl is required but not installed."; exit 1; }
command -v jq >/dev/null 2>&1 || { echo >&2 "Error: jq is required but not installed."; exit 1; }
DELAY=1
ARTICLE_ID="$1"
API_ENDPOINT="${CONFLUENCE_URL}/rest/api/content/${ARTICLE_ID}?expand=body.storage,children.page"
echo
echo "Downloading: $API_ENDPOINT"
response=$(curl -s -u "$USERNAME:$PASSWORD" -H "Accept: application/json" "${API_ENDPOINT}")
if [ $? -ne 0 ]; then
echo "Error: Failed to retrieve article"
fi
error_message=$(echo "$response" | jq -r '.message' 2>/dev/null)
if [ -n "$error_message" ] && [ "$error_message" != "null" ]; then
echo "API Error: $error_message"
else
title=$(echo "$response" | jq -r .title)
content=$(echo "$response" | jq -r .body.storage.value)
[ ! -d "$OUTPUT_PATH" ] && mkdir -p "$OUTPUT_PATH"
echo "<html><body>$content</body></html>" > "$OUTPUT_PATH/$title.html"
echo "Saved as: $OUTPUT_PATH/$title.html"
child_ids=$(echo "$response" | jq -r '.children.page.results[]?.id' 2>/dev/null)
for child_id in $child_ids; do
echo "Downloading child page ID: $child_id"
sleep $DELAY
./confluence_get_article.sh "$child_id"
done
fi
1 | #!/bin/bash |
2 | |
3 | # 1. Указать реквизиты доступа к confluence |
4 | USERNAME="" |
5 | PASSWORD="" |
6 | CONFLUENCE_URL="" |
7 | OUTPUT_PATH="./confluence/" |
8 | |
9 | # 2. Вызвать: ./confluence_get_article.sh <page_id> |
10 | |
11 | ################################################################## |
12 | |
13 | if [ $# -lt 1 ]; then |
14 | echo "Usage: $0 <article_id>" |
15 | exit 1 |
16 | fi |
17 | |
18 | command -v curl >/dev/null 2>&1 || { echo >&2 "Error: curl is required but not installed."; exit 1; } |
19 | command -v jq >/dev/null 2>&1 || { echo >&2 "Error: jq is required but not installed."; exit 1; } |
20 | |
21 | DELAY=1 |
22 | ARTICLE_ID="$1" |
23 | API_ENDPOINT="${CONFLUENCE_URL}/rest/api/content/${ARTICLE_ID}?expand=body.storage,children.page" |
24 | |
25 | echo |
26 | echo "Downloading: $API_ENDPOINT" |
27 | |
28 | response=$(curl -s -u "$USERNAME:$PASSWORD" -H "Accept: application/json" "${API_ENDPOINT}") |
29 | if [ $? -ne 0 ]; then |
30 | echo "Error: Failed to retrieve article" |
31 | fi |
32 | |
33 | error_message=$(echo "$response" | jq -r '.message' 2>/dev/null) |
34 | if [ -n "$error_message" ] && [ "$error_message" != "null" ]; then |
35 | echo "API Error: $error_message" |
36 | else |
37 | title=$(echo "$response" | jq -r .title) |
38 | content=$(echo "$response" | jq -r .body.storage.value) |
39 | [ ! -d "$OUTPUT_PATH" ] && mkdir -p "$OUTPUT_PATH" |
40 | echo "<html><body>$content</body></html>" > "$OUTPUT_PATH/$title.html" |
41 | echo "Saved as: $OUTPUT_PATH/$title.html" |
42 | |
43 | child_ids=$(echo "$response" | jq -r '.children.page.results[]?.id' 2>/dev/null) |
44 | for child_id in $child_ids; do |
45 | echo "Downloading child page ID: $child_id" |
46 | sleep $DELAY |
47 | ./confluence_get_article.sh "$child_id" |
48 | done |
49 | fi |
50 |