-
Notifications
You must be signed in to change notification settings - Fork 8
/
deploy
executable file
·113 lines (96 loc) · 3.73 KB
/
deploy
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
#!/bin/bash
# SPDX-License-Identifier: AGPL-3.0-or-later
# SPDX-FileCopyrightText: 2022 grommunio GmbH
#set -x # debug
set -e # fail deployment if something goes wrong
export SHELLOPTS
DOCU_ROOT="/srv/www/vhosts/docs.grommunio.com/htdocs"
DOC_RELEASE="`date +%y.%m`"
DOC_RELEASEFULL="`date +%Y.%m.%d`"
declare -a AVAIL_MANUAL=("main" "admin" "user" "web" "man" "dev" "migration" "kb")
if [ -z "$1" ]; then
declare -a BUILD_MANUAL=("main" "admin" "user" "web" "man" "dev" "migration" "kb")
elif [[ ! " ${AVAIL_MANUAL[@]} " =~ " ${1} " ]]; then
echo "Manual \"$1\" is unknown. Valid manuals:"
printf '%s\n' "${AVAIL_MANUAL[@]}" | sed 's#^#-> #'
exit 1
else
declare -a BUILD_MANUAL=("$1")
fi
for MANUAL in ${BUILD_MANUAL[@]}; do
sed -i "s#^version =.*#version = \'${DOC_RELEASE}\'##g" ${MANUAL}/conf.py
sed -i "s#^release =.*#release = \'${DOC_RELEASEFULL}\'##g" ${MANUAL}/conf.py
if [ "${MANUAL}" == "man" ]; then
pushd man
./generate-man-pages.sh
popd
elif [ "${MANUAL}" == "dev" ]; then
pushd dev
./fetch-current-openapi.sh
popd
elif [ "${MANUAL}" == "admin" ]; then
pushd admin
./do-admin-cli.sh
popd
fi
for RSTFILE in ${MANUAL}/*.rst; do
if [[ ! " ${RSTFILE} " =~ " ${MANUAL}/legal_notice.rst " ]]; then
echo '' >> ${RSTFILE}
cat ${MANUAL}/meta.txt >> ${RSTFILE}
fi
done
cp -av resources/_templates/legal_notice.rst "${MANUAL}/legal_notice.rst"
make html DOCDIR=${MANUAL} BUILDDIR=${MANUAL}-build
# ref: https://web.dev/font-display/
sed -i 's#@font-face{#@font-face{font-display:swap;#' ${MANUAL}-build/html/_static/css/badge_only.css ${MANUAL}-build/html/_static/css/theme.css
# ref: https://web.dev/render-blocking-resources
sed -i -e 's#rel="stylesheet" href="_static/pygments.css" type="text/css"#rel="preload" href="_static/pygments.css" as="style" crossOrigin="anonymous" onload='this.rel=\'stylesheet\''#' ${MANUAL}-build/html/*.html
if [ "${MANUAL}" == "dev" ]; then
sed -i -e 's#<body>#<body><style>.operation-samples[_ngcontent-c9]{width:0%;background:none!important;}.operation-content[_ngcontent-c9]{width:90%;!important;}.background-actual[_ngcontent-c0]{background:none!important;}[sticky-sidebar][_ngcontent-c0]{max-width:90%;}.selected-tag[_ngcontent-c4]{margin-left:20px;}</style>#' ${MANUAL}-build/html/adminapispec.html
fi
if [ "${MANUAL}" != "main" ] && [ -n "$MAKE_PDF" ]; then
mkdir -p ${MANUAL}-build/latex
rsync -av resources/_static/img/back_a4.png ${MANUAL}-build/latex/background.png
rsync -av resources/_static/pdf/finalpage.pdf ${MANUAL}-build/latex/finalpage.pdf
if ! make latexpdf O="-D smartquotes_action=" DOCDIR=${MANUAL} BUILDDIR=${MANUAL}-build; then
if test -z "$IGNORE_PDF"; then
exit 1
fi
fi
fi
if [ "${MANUAL}" != "main" ] && [ -n "$MAKE_EPUB" ]; then
if ! make epub DOCDIR=${MANUAL} BUILDDIR=${MANUAL}-build; then
if test -z "$IGNORE_EPUB"; then
exit 1
fi
fi
fi
done
if [ -z "$PUBLISH" ]; then
exit 0
fi
for MANUAL in ${BUILD_MANUAL[@]}; do
if [ "${MANUAL}" != "main" ]; then
rm -rf $DOCU_ROOT/${MANUAL}
mkdir -p $DOCU_ROOT/${MANUAL}
rsync -av ${MANUAL}-build/html/ $DOCU_ROOT/${MANUAL}/
if [[ -f ${MANUAL}-build/latex/grommunio.pdf ]]; then
rsync -av ${MANUAL}-build/latex/grommunio.pdf $DOCU_ROOT/grommunio${MANUAL^}Doc.pdf
fi
if [[ -f ${MANUAL}-build/epub/grommunio.epub ]]; then
rsync -av ${MANUAL}-build/epub/grommunio.epub $DOCU_ROOT/grommunio${MANUAL^}Doc.epub
fi
else
mkdir -p $DOCU_ROOT
rsync -av ${MANUAL}-build/html/ $DOCU_ROOT/
fi
METALINECOUNT=0
for RSTFILE in ${MANUAL}/*.rst; do
if [[ ! "${RSTFILE}" = "${MANUAL}/legal_notice.rst" ]]; then
METALINECOUNT=`<${MANUAL}/meta.txt wc -l`
sed -i "$(( $(wc -l <${RSTFILE})-${METALINECOUNT} )),$ d" ${RSTFILE}
fi
done
#rm -rf "${MANUAL}-build"
done
service nginx restart