-
Notifications
You must be signed in to change notification settings - Fork 4
/
pdf-build.sh
executable file
·183 lines (166 loc) · 5.54 KB
/
pdf-build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/bin/bash
# Check if Prince XML is installed
if ! command -v prince &> /dev/null; then
echo "To generate PDF files, you must install Prince XML: https://www.princexml.com/download/"
exit 1
fi
# Exit when you hit an error
set -e
# Display list of containers, count them, and kill them if they exist
echo 'Killing all running containers...'
if [ $(docker ps | grep -c 'docs-container$') -gt 0 ]; then
docker kill docs-container || true
docker wait docs-container || true
fi
echo
echo -e "📄 \033[1;33mBuild PDF documentation\033[0m"
# Declaring a future array of actions
# Actions are what the script will do
ACTIONS=()
# Options are what the user will choose
PS3='What would you like to build? '
# Prints the options on screen
options=("Qumulo-Certified Platinum-Tier Hardware Servicing Guide" "Gold-Tier Hardware Servicing Guide for Qumulo" "Azure Native Qumulo Administrator Guide" "Cloud Native Qumulo on AWS Administrator Guide" "Cloud Native Qumulo on Azure Administrator Guide" "Qumulo On-Premises Administrator Guide" "Qumulo Alerts Guide" "Qumulo qq CLI Command Guide" "Qumulo REST API Guide" "Qumulo Integration Guide" "All Administrator Guides" "All Guides" "Exit")
echo
select opt in "${options[@]}"
# Matches the option to the action
# Populates the ACTIONS array
do
case $opt in
"Qumulo-Certified Platinum-Tier Hardware Servicing Guide")
ACTIONS+=("Platinum_Tier_Hardware_Guide")
break
;;
"Gold-Tier Hardware Servicing Guide for Qumulo")
ACTIONS+=("Gold_Tier_Hardware_Guide")
break
;;
"Azure Native Qumulo Administrator Guide")
ACTIONS+=("ANQ_Guide")
break
;;
"Cloud Native Qumulo on AWS Administrator Guide")
ACTIONS+=("CNQ_AWS_Guide")
break
;;
"Cloud Native Qumulo on Azure Administrator Guide")
ACTIONS+=("CNQ_Azure_Guide")
break
;;
"Qumulo On-Premises Administrator Guide")
ACTIONS+=("Administrator_Guide")
break
;;
"Qumulo Alerts Guide")
ACTIONS+=("Qumulo_Alerts_Guide")
break
;;
"Qumulo qq CLI Command Guide")
ACTIONS+=("Qumulo_qq_CLI_Command_Guide")
break
;;
"Qumulo REST API Guide")
ACTIONS+=("Qumulo_REST_API_Guide")
break
;;
"Qumulo Integration Guide")
ACTIONS+=("Integration_Guide")
break
;;
"All Administrator Guides")
ACTIONS+=("ANQ_Guide" "CNQ_AWS_Guide" "CNQ_Azure_Guide" "Administrator_Guide")
break
;;
"All Guides")
ACTIONS+=("Platinum_Tier_Hardware_Guide" "Gold_Tier_Hardware_Guide" "ANQ_Guide" "CNQ_AWS_Guide" "CNQ_Azure_Guide" "Administrator_Guide" "Qumulo_Alerts_Guide" "Qumulo_qq_CLI_Command_Guide" "Integration_Guide")
break
;;
"Exit")
exit 0
;;
*) echo "You must enter a valid option."
;;
esac
done
# Define the build config and output filename for each guide
build_prince () {
# Match input against the first parameter
case "$1" in
"Platinum_Tier_Hardware_Guide")
JEKYLL_CONFIG=config_platinum_tier_hardware_guide_pdf.yml
PRINCE_OUTPUT=qumulo-certified-platinum-tier-hardware-guide.pdf
;;
"Gold_Tier_Hardware_Guide")
JEKYLL_CONFIG=config_gold_tier_hardware_guide_pdf.yml
PRINCE_OUTPUT=gold-tier-hardware-guide-for-qumulo.pdf
;;
"ANQ_Guide")
JEKYLL_CONFIG=config_azure_native_guide_pdf.yml
PRINCE_OUTPUT=azure-native-qumulo-administrator-guide.pdf
;;
"CNQ_AWS_Guide")
JEKYLL_CONFIG=config_cloud_native_aws_guide_pdf.yml
PRINCE_OUTPUT=cloud-native-qumulo-on-aws-administrator-guide.pdf
;;
"CNQ_Azure_Guide")
JEKYLL_CONFIG=config_cloud_native_azure_guide_pdf.yml
PRINCE_OUTPUT=cloud-native-qumulo-on-azure-administrator-guide.pdf
;;
"Administrator_Guide")
JEKYLL_CONFIG=config_administrator_guide_pdf.yml
PRINCE_OUTPUT=qumulo-administrator-guide.pdf
;;
"Qumulo_Alerts_Guide")
JEKYLL_CONFIG=config_qumulo_alerts_guide_pdf.yml
PRINCE_OUTPUT=qumulo-alerts-guide.pdf
;;
"Qumulo_qq_CLI_Command_Guide")
JEKYLL_CONFIG=config_qq_cli_command_guide_pdf.yml
PRINCE_OUTPUT=qumulo-qq-cli-command-guide.pdf
;;
"Qumulo_REST_API_Guide")
JEKYLL_CONFIG=config_rest_api_guide_pdf.yml
PRINCE_OUTPUT=qumulo-rest-api-guide.pdf
;;
"Integration_Guide")
JEKYLL_CONFIG=config_integration_guide_pdf.yml
PRINCE_OUTPUT=qumulo-integration-guide.pdf
;;
esac
echo ""
echo "Building PDF-friendly HTML site..."
echo -e "\033[1;33mNote: You can ignore any warnings about setting the locale.\033[0m"
docker run -ti \
--rm \
--user $(id -u):$(id -g) \
--name docs-container \
-v "$(pwd)":/src:rw \
-P \
--detach \
--env NOLIVERELOAD=1 \
--network host \
docs-builder \
serve \
--config "_config.yml,pdfconfigs/${JEKYLL_CONFIG}"
# -F: sets the field delimiter to colon
port=$(grep '^port:' "pdfconfigs/${JEKYLL_CONFIG}" | awk -F: '{print $2;}')
echo "Waiting for port$port to become available..."
while ! nc -z localhost $port; do
sleep 0.2
done
echo "Building the PDF..."
prince --javascript --input-list=_site/pdfconfigs/prince-list.txt -o "pdf/${PRINCE_OUTPUT}"
echo "Cleaning up the Docker container..."
if [ $(docker ps | grep -c 'docs-container$') -gt 0 ]; then
docker kill docs-container || true
docker wait docs-container || true
fi
}
# Build the PDF for each item in the array
for i in ${ACTIONS[@]}
do
build_prince "$i"
done
#echo "Deleting temporary build files..."
#cd _site && rm * -rf
echo "Done. The PDF output is in the /pdf directory."