-
Notifications
You must be signed in to change notification settings - Fork 10
/
setup-documentation.sh
executable file
·227 lines (194 loc) · 7.24 KB
/
setup-documentation.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/bin/bash
#
# Build a documentation package for Sailfish SDK installer
#
# Copyright (C) 2014 Jolla Oy
# Contact: Juha Kallioinen <[email protected]>
# All rights reserved.
#
# You may use this file under the terms of BSD license as follows:
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the Jolla Ltd nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
. $(dirname $0)/defaults.sh
SELF=$(basename "$0")
OPT_UPLOAD_HOST=$DEF_UPLOAD_HOST
OPT_UPLOAD_USER=$DEF_UPLOAD_USER
OPT_UPLOAD_PATH=$DEF_UPLOAD_PATH
OPT_DOCVERSION=$(date +%y%m%d)
OPT_DOCDIR=$PWD
OPT_COMPRESSION=9
QTDOC_NAME=qtdocumentation.7z
SAILDOC_NAME=sailfishdocumentation.7z
failure() {
echo "Error: $1"
exit 1
}
usage() {
cat <<EOF
Create SDK documentation packages and optionally them to a server.
Usage:
$SELF [OPTION]
Options:
-v | --version <STRING> set documentation version [$OPT_DOCVERSION]
-d | --docdir <DIR> search for .qch files from <DIR> [$OPT_DOCDIR]
-u | --upload <DIR> upload local build result to [$OPT_UPLOAD_HOST] as user [$OPT_UPLOAD_USER]
the uploaded build will be copied to [$OPT_UPLOAD_PATH/<DIR>]
the upload directory will be created if it is not there
-uh | --uhost <HOST> override default upload host
-up | --upath <PATH> override default upload path
-uu | --uuser <USER> override default upload user
-y | --non-interactive answer yes to all questions presented by the script
-c | --compression <0-9> compression level of 7z [$OPT_COMPRESSION]
-h | --help this help
EOF
# exit if any argument is given
[[ -n "$1" ]] && exit 1
}
add_filter() (
set -o nounset
QCH=$1
FILTER_ATTRIBUTE=$2
FILTER_NAME=$3
sql() {
local query=$1
sqlite3 "$QCH" "$query"
}
existing_filter_id=$(sql "SELECT Id FROM FilterNameTable WHERE Name = '$FILTER_NAME';") || exit
if [[ $existing_filter_id ]]; then
echo "$SELF: '$QCH' already contains required filter. Nothing to do." >&2
exit 0
else
echo "$SELF: Adding filter to '$QCH'" >&2
fi
sql "INSERT INTO FilterAttributeTable VALUES(NULL, '$FILTER_ATTRIBUTE');" || exit
attribute_id=$(sql "SELECT MAX(Id) FROM FilterAttributeTable;") || exit
sql "INSERT INTO FilterNameTable VALUES(NULL, '$FILTER_NAME');" || exit
filter_id=$(sql "SELECT MAX(Id) FROM FilterNameTable;") || exit
sql "INSERT INTO FilterTable VALUES($filter_id, $attribute_id);" || exit
sql "INSERT INTO IndexFilterTable (FilterAttributeId, IndexId) \
SELECT $attribute_id, Id FROM IndexTable;" || exit
sql "INSERT INTO ContentsFilterTable (FilterAttributeId, ContentsId) \
SELECT $attribute_id, Id FROM ContentsTable;" || exit
sql "INSERT INTO FileAttributeSetTable \
SELECT MAX(Id), $attribute_id FROM FileAttributeSetTable;" || exit
sql "INSERT INTO FileFilterTable \
SELECT $attribute_id, Id FROM FileDataTable;" || exit
)
# handle commandline options
while [[ ${1:-} ]]; do
case "$1" in
-v | --version ) shift
OPT_DOCVERSION=$1; shift
;;
-d | --docdir ) shift
OPT_DOCDIR=$1; shift
OPT_DOCDIR=$(readlink -f $OPT_DOCDIR)
;;
-u | --upload ) shift
OPT_UPLOAD=1
OPT_UL_DIR=$1; shift
if [[ -z $OPT_UL_DIR ]]; then
failure "upload option requires a directory name"
fi
;;
-uh | --uhost ) shift;
OPT_UPLOAD_HOST=$1; shift
;;
-up | --upath ) shift;
OPT_UPLOAD_PATH=$1; shift
;;
-uu | --uuser ) shift;
OPT_UPLOAD_USER=$1; shift
;;
-c | --compression ) shift
OPT_COMPRESSION=$1; shift
if [[ $OPT_COMPRESSION != [0123456789] ]]; then
usage quit
fi
;;
-y | --non-interactive ) shift
OPT_YES=1
;;
-h | --help ) shift
usage quit
;;
* )
shift
;;
esac
done
INSTALL_PATH=$PWD/documentation
# summary
echo "Summary of chosen actions:"
echo "Using .qch files in [$OPT_DOCDIR]"
echo "Workdir [$INSTALL_PATH]"
echo " 1) Create documentation packages with version [$OPT_DOCVERSION]"
if [[ -n $OPT_UPLOAD ]]; then
echo " 2) Upload packages as user [$OPT_UPLOAD_USER] to [$OPT_UPLOAD_HOST:$OPT_UPLOAD_PATH/$OPT_UL_DIR]"
else
echo " 2) Do NOT upload packages"
fi
# confirm
if [[ -z $OPT_YES ]]; then
while true; do
read -p "Do you want to continue? (y/n) " answer
case $answer in
[Yy]*)
break ;;
[Nn]*)
echo "Ok, exiting"
exit 0
;;
*)
echo "Please answer yes or no."
;;
esac
done
fi
mkdir -p $INSTALL_PATH
rm -rf $INSTALL_PATH/*
rm -f $QTDOC_NAME $SAILDOC_NAME
# create Qt documentation package
for NAME in $(ls $OPT_DOCDIR/q*.qch); do
newname=$(basename $NAME)
ln $NAME $INSTALL_PATH/${newname%.qch}$OPT_DOCVERSION.qch
done
7z a -mx=$OPT_COMPRESSION $QTDOC_NAME $INSTALL_PATH/
rm -f $INSTALL_PATH/*
# create Sailfish documentation package
for NAME in $(ls $OPT_DOCDIR/{amber,sdk-,*sailfish,KF5*,lipstick,nemo,libkeepalive}*.qch); do
if ! add_filter "$NAME" "$DEF_DOCS_FILTER_ATTRIBUTE" "$DEF_DOCS_FILTER_NAME"; then
failure "Failed to add filter to '$NAME'"
fi
newname=$(basename $NAME)
ln $NAME $INSTALL_PATH/${newname%.qch}$OPT_DOCVERSION.qch
done
7z a -mx=$OPT_COMPRESSION $SAILDOC_NAME $INSTALL_PATH/
rm -f $INSTALL_PATH/*
if [ "$OPT_UPLOAD" ]; then
echo "Uploading documentation"
# create upload dir
ssh $OPT_UPLOAD_USER@$OPT_UPLOAD_HOST mkdir -p $OPT_UPLOAD_PATH/$OPT_UL_DIR/
scp $QTDOC_NAME $SAILDOC_NAME $OPT_UPLOAD_USER@$OPT_UPLOAD_HOST:$OPT_UPLOAD_PATH/$OPT_UL_DIR/
fi