forked from artem78/AutoScreenshot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakeInstallerAndZip.sh
executable file
·258 lines (219 loc) · 5.36 KB
/
MakeInstallerAndZip.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
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
#!/bin/bash
# ToDo: remake to apache ant build script
# Script for building project on Linux or Windows (using Cygwin or MinGW)
#
# Note for Winows only!
# Do not forget to define variables LazarusDir and InnoSetupDir first,
# for example in your ~/.bashrc:
# export LazarusDir="/path/to/lazarus"
# export InnoSetupDir="/path/to/inno setup"
#
# *** Functions ***
function StopBuild(){
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "!!! Fatal error! !!!"
echo ""
echo $1
echo ""
echo "!!! Build failed. Sorry :( !!!"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo ""
Pause
exit 1
}
function Pause(){
read -n 1 -s -r -p "Press any key to continue..."
}
function Compile(){
# Run compile project
echo "Starting compile project..."
if IsWindows; then
"$LazarusDir/lazbuild.exe" --build-mode="Release (32bit)" --verbose AutoScreenshot.lpi
elif IsLinux; then
"lazbuild" --build-mode="Release" --verbose AutoScreenshot.lpi
fi
echo "Compiling finished!"
echo ""
}
function MakeZip(){
Compile
RunTests
# Create and clear build directory
echo "Clear build directory..."
rm -f -r "$BuildDir"
mkdir -p "$BuildDir"
mkdir -p "$TargetZipDir"
echo "Done!"
echo ""
# Executable
echo "Copy EXE..."
if IsWindows; then
local ExecutableFileName="AutoScreenshot.exe"
elif IsLinux; then
local ExecutableFileName="AutoScreenshot"
fi
cp -v --preserve=timestamps "$ExecutableFileName" "$BuildDir"
echo "Done!"
echo ""
# DLLs
if IsWindows; then
echo "Copy DLLs..."
cp -v --preserve=timestamps "$LazarusDir/libeay32.dll" "$BuildDir"
cp -v --preserve=timestamps "$LazarusDir/ssleay32.dll" "$BuildDir"
echo "Done!"
echo ""
fi
# # Config
# echo "Copy config.ini..."
# cp -v --preserve=timestamps config.sample.ini "$BuildDir/config.ini"
# echo "Done!"
# echo ""
# Translations
echo "Copy translation files..."
mkdir -p "$BuildDir/lang"
cp -v --preserve=timestamps lang/*.ini "$BuildDir/lang/"
echo "Done!"
echo ""
# Sounds
echo "Copy sound files..."
mkdir -p "$BuildDir/sounds"
cp -v --preserve=timestamps sounds/*.wav "$BuildDir/sounds/"
echo "Done!"
echo ""
# Move files to subfolder
TmpDir=$(mktemp -d --suffix "-AutoScreenshotBuild")
echo "TmpDir=${TmpDir}"
#mkdir -p "$TmpDir/AutoScreenshot_${ProgramVersion}"
cp -R --preserve=timestamps "$BuildDir" "$TmpDir/AutoScreenshot_${ProgramVersion}"
# Pack to ZIP archive
### Note! For MinGW (Git Bash) see https://stackoverflow.com/a/55749636 ###
echo "Pack all files to ZIP archive..."
if IsWindows; then
local OsTypeName="Windows"
elif IsLinux; then
local OsTypeName="Linux"
fi
ZipPath="$TargetZipDir/AutoScreenshot_${ProgramVersion}_${OsTypeName}_portable.zip"
rm -f "$ZipPath"
cd "$TmpDir"
zip -r "$ZipPath" *
#tar -C "$BuildDir" -cvf "$ZipPath" "$BuildDir/*"
echo "Done!"
echo ""
rm -rf "$TmpDir"
}
function MakeInstaller(){
Compile
RunTests
# Make installation file
echo "Make installation file..."
"$InnoSetupDir/iscc.exe" //F"AutoScreenshot_${ProgramVersion}_Windows_setup" "setup.iss"
echo "Done!"
echo ""
}
function RunTests(){
cd Test
echo "Compile tests..."
if IsWindows; then
local LazBuildPath="$LazarusDir/lazbuild.exe"
elif IsLinux; then
local LazBuildPath="lazbuild"
fi
# "$LazBuildPath" --verbose AutoScreenshotTest.lpi
"$LazBuildPath" AutoScreenshotTest.lpi
echo "Tests compiled!"
echo ""
echo "Run tests..."
if IsWindows; then
local TestExecutableFileName="./AutoScreenshotTest.exe"
elif IsLinux; then
local TestExecutableFileName="./AutoScreenshotTest"
fi
"$TestExecutableFileName" --all --format=plain
echo "Tests finished!"
echo ""
cd ..
}
function IsWindows {
if [[ "$OSTYPE" == "cygwin" ]]; then
return 0
elif [[ "$OSTYPE" == "msys" ]]; then
return 0
elif [[ "$OSTYPE" == "win32" ]]; then
return 0
else
return 1
fi
}
function IsLinux {
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
return 0
else
return 1
fi
}
# ***********************
set -e
if IsWindows; then
# *** Set variables ***
LazarusDir=${LazarusDir:="/c/lazarus"}
#if [[ $(uname -s | tr '[:upper:]' '[:lower:]') == *"cygwin"* ]]; then
# LazarusDir="/cygdrive${LazarusDir}"
#fi
echo "LazarusDir=${LazarusDir}"
fi
# Output dirs
BuildDir=$(realpath -m "build/files")
TargetZipDir=$(realpath -m "build/zip")
if IsWindows; then
InnoSetupDir=${InnoSetupDir:="/c/Program Files/Inno Setup 5"}
#if [[ $(uname -s | tr '[:upper:]' '[:lower:]') == *"cygwin"* ]]; then
# InnoSetupDir="/cygdrive${InnoSetupDir}"
#fi
echo "InnoSetupDir=${InnoSetupDir}"
fi
# Program version
#ProgramVersion=$(grep -Po '\<StringTable.+ ProductVersion="\K[0-9\.]+' AutoScreenshot.lpi)
ProgramVersion=$(git describe --dirty)
echo "Current program version: $ProgramVersion"
echo ""
usage="$(basename "$0") [-z] [-i]
where:
-z make zip arhive
-l make installer (not available for Linux)"
# ***********************
if [ -z $* ]
then
#echo "No options found!"
echo "$usage" >&2
exit 1
fi
if IsWindows; then
while getopts "zih" opt
do
case $opt in
z) MakeZip;;
i) MakeInstaller;;
h) echo "$usage"
exit 0;;
*) echo "$usage">&2
exit 1;;
esac
done
elif IsLinux; then
while getopts "zh" opt
do
case $opt in
z) MakeZip;;
h) echo "$usage"
exit 0;;
*) echo "$usage">&2
exit 1;;
esac
done
else
echo "This OS not supported!">&2
exit 1
fi
Pause
exit 0