-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepare
executable file
·294 lines (258 loc) · 7.79 KB
/
prepare
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
#!/usr/bin/env bash
# author : Altertech Group, http://www.altertech.com/
# copyright : Copyright (C) 2019 Altertech Group
# license : Apache License 2.0
# version: : 1.0.0
if [ ! -f app/src/main/java/com/altertech/evahi/AppConfig.java ]; then
echo "Please start this script in evaHI directory"
exit 3
fi
shopt -s extglob
_CONFIG=()
_SECTIONS=
_PROP=
classname=
name=
version=
versioncode=
copyright=
icon=
icon_round=
configurable=yes
authentication=yes
https=
address=
port=
PAUSE=1
CONFIG_FILE=./prepare.ini
DIRECTORY=
function parseIniFile() {
local LINE=""
local SECTION=""
local KEY=""
local VALUE=""
local IFS=""
while read LINE
do
LINE=${LINE%%[;#]*}
LINE=${LINE%%*( )}
if [[ -n $KEY && $LINE =~ ^[[:space:]]+(.+) ]]
then
VALUE+=" ${BASH_REMATCH[1]}"
else
if [[ -n $KEY ]]
then
_CONFIG=(${_CONFIG[@]} "${SECTION}.${KEY}" "${VALUE}")
KEY=""
VALUE=""
fi
if [[ $LINE =~ ^\[([[:alnum:]]+)\] ]]
then
SECTION=${BASH_REMATCH[1]}
_SECTIONS="${_SECTIONS} ${SECTION}"
KEY=""
elif [[ $LINE =~ ^([^[:space:]]+)[[:space:]]*=[[:space:]]*(.+) ]]
then
KEY=${BASH_REMATCH[1]}
VALUE="${BASH_REMATCH[2]}"
fi
fi
done
if [[ -n $KEY ]]
then
_CONFIG=(${_CONFIG[@]} "${SECTION}.${KEY}" "${VALUE}")
fi
}
function getProperty() {
_PROP=""
local -i i
local KEY=$1
for ((i=0; i<${#_CONFIG[@]}; i+=2))
do
if [[ ${_CONFIG[$i]} =~ ^\.?${KEY} ]]
then
_PROP=${_CONFIG[((i+1))]}
return 0
fi
done
return 1
}
function showHelp() {
cat <<EOF
Usage: prepare <-D DIR> [-f CONFIG] [-q] [--icon FILE] [--icon-round FILE]
-D DIR directory to store prepared app in
-f CONFIG configuration file (default: ./prepare.ini)
-q don't ask any questions, just do it
--icon FILE launcher icon (requires ImageMagick)
--icon-round FILE launcher round icon (both must be specified)
EOF
}
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-f)
CONFIG_FILE="$2"
shift
shift
;;
-D) DIRECTORY="$2"
shift
shift
;;
-q) PAUSE=
shift
;;
--icon) icon="$2"
shift
shift
;;
--icon-round) icon_round="$2"
shift
shift
;;
-h|--help) showHelp
exit 0
;;
*)
echo "Unknown option: ${key}"
showHelp
exit -1
;;
esac
done
if [ ! -f ${CONFIG_FILE} ]; then
echo "config not found: ${CONFIG_FILE}. Use -f to specify custom config file, -h for help"
exit 3
fi
if [ ! ${DIRECTORY} ]; then
echo "Directory not specified"
showHelp
exit 3
fi
if [ -d ${DIRECTORY} ]; then
echo "Directory ${DIRECTORY} already exists"
echo "Aborting"
exit 4
fi
if [ ${icon} ] || [ ${icon_round} ]; then
if [ ! ${icon} ]; then
echo "Icon not specified"
echo "Aborting"
exit 4
fi
if [ ! ${icon_round} ]; then
echo "Round icon not specified"
echo "Aborting"
exit 4
fi
which convert > /dev/null
if [ $? -ne 0 ]; then
echo "Icons specified but ImageMagick not found"
echo "Aborting"
exit 4
fi
if [ ! -f ${icon} ]; then
echo "File not found: ${icon}"
exit 4
fi
if [ ! -f ${icon_round} ]; then
echo "File not found: ${icon_round}"
exit 4
fi
fi
parseIniFile < $CONFIG_FILE
getProperty app.classname
classname=${_PROP}
getProperty app.name
name=${_PROP}
getProperty app.version
version=${_PROP}
getProperty app.versioncode
versioncode=${_PROP}
getProperty app.copyright
copyright=${_PROP}
getProperty server.configurable
configurable=${_PROP}
getProperty server.authentication
authentication=${_PROP}
getProperty server.https
https=${_PROP}
getProperty server.address
address=${_PROP}
getProperty server.port
port=${_PROP}
if [ ! $classname ]; then
echo "Class name not specified"
echo "Aborting"
exit 5
fi
echo "New evaHI-based app is ready to be created"
echo
echo "App directory: ${DIRECTORY}"
echo "Class name: ${classname}"
echo "App name: ${name}"
echo "App version: ${version}"
echo "App version code: ${versioncode}"
echo "App copyright: ${copyright}"
echo
echo "Server configurable: ${configurable}"
echo "Use basic authentication: ${authentication}"
echo "Use HTTPS: ${https}"
echo "Default server address: ${address}"
echo "Default server port: ${port}"
if [ ! ${icon} ]; then
echo "Launcher icon not set"
else
echo "Launcher icon: ${icon}"
echo "Launcher round icon: ${icon_round}"
fi
echo
if [ $PAUSE ]; then
echo "Check if everything is correct, press ENTER to continue, Ctrl+C to abort"
read
fi
echo "Creating app directory"
mkdir -p ${DIRECTORY} || exit 1
echo "Copying app files..."
cp -prf * ${DIRECTORY} || exit 1
cd ${DIRECTORY} || exit 1
echo "Configuring..."
sed -i "s/<string name=\"app_name\">EvaHI</<string name=\"app_name\">${name}</g" app/src/main/res/values/strings.xml || exit 1
sed -i "s/String NAME = \"\", VERSION = \"\", COPYRIGHT = \"\";/String NAME = \"${name}\", VERSION = \"${version}\", COPYRIGHT = \"${copyright}\";/g" app/src/main/java/com/altertech/evahi/AppConfig.java || exit 1
[ "x${configurable}" = "xyes" ] && C=false || C=true
[ "x${https}" = "xyes" ] && H=true || H=false
sed -i "s/ServerConfig(false, false, \"\", 443);/ServerConfig(${C}, ${H}, \"${address}\", ${port});/g" app/src/main/java/com/altertech/evahi/AppConfig.java || exit 1
[ "x${authentication}" = "xyes" ] && A=true || A=false
sed -i "s/boolean AUTHENTICATION = true;/boolean AUTHENTICATION = ${A};/g" app/src/main/java/com/altertech/evahi/AppConfig.java || exit 1
sed -i "s/versionCode .*/versionCode ${versioncode}/g" app/build.gradle || exit 1
sed -i "s/versionName .*/versionName \"${version}\"/g" app/build.gradle || exit 1
echo "Renaming classes..."
find . -type f -exec sed -i "s/com.altertech.evahi/${classname}/g" {} \; || exit 1
mkdir -p app/src/main/java/`echo ${classname} | tr "." "/"` || exit 1
mv -f app/src/main/java/com/altertech/evahi/* app/src/main/java/`echo ${classname} | tr "." "/"`/ || exit 1
rmdir app/src/main/java/com/altertech/evahi || exit 1
rmdir app/src/main/java/com/altertech > /dev/null 2>&1
rmdir app/src/main/java/com > /dev/null 2>&1
rm -f prepare prepare.ini evaHI.iml
rm -rf examples
rm -rf app/build
if [ ${icon} ]; then
echo "Generating icons..."
convert -resize 48x48 -unsharp 1x4 ${icon} app/src/main/res/mipmap-mdpi/ic_launcher.png || exit 1
convert -resize 72x72 -unsharp 1x4 ${icon} app/src/main/res/mipmap-hdpi/ic_launcher.png || exit 1
convert -resize 96x96 -unsharp 1x4 ${icon} app/src/main/res/mipmap-xhdpi/ic_launcher.png || exit 1
convert -resize 144x144 -unsharp 1x4 ${icon} app/src/main/res/mipmap-xxhdpi/ic_launcher.png || exit 1
convert -resize 192x192 -unsharp 1x4 ${icon} app/src/main/res/mipmap-xxxhdpi/ic_launcher.png || exit 1
convert -resize 48x48 -unsharp 1x4 ${icon_round} app/src/main/res/mipmap-mdpi/ic_launcher_round.png || exit 1
convert -resize 72x72 -unsharp 1x4 ${icon_round} app/src/main/res/mipmap-hdpi/ic_launcher_round.png || exit 1
convert -resize 96x96 -unsharp 1x4 ${icon_round} app/src/main/res/mipmap-xhdpi/ic_launcher_round.png || exit 1
convert -resize 144x144 -unsharp 1x4 ${icon_round} app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png || exit 1
convert -resize 192x192 -unsharp 1x4 ${icon_round} app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png || exit 1
fi
echo "-----------------------------------------------"
echo "Completed"
if [ ! ${icon} ]; then
echo "Don't forget to customize app icons (app/src/main/res)"
fi
exit 0