forked from einsiedler90/Whonix-Installer
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·184 lines (149 loc) · 5.58 KB
/
build.sh
File metadata and controls
executable file
·184 lines (149 loc) · 5.58 KB
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
#!/bin/bash
## Copyright (C) 2023 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
## See the file COPYING for copying conditions.
## This script will be called by:
## dm-prepare-release
## https://github.com/Kicksecure/developer-meta-files/blob/master/usr/bin/dm-prepare-release
set -x
set -e
set -o pipefail
set -o nounset
true "$0: START"
## 1) Requires various environment variables:
## See build-einsiedler.sh
if ! printf '%s\n' "WINDOWS LINUX" | grep -w -- "$TARGET_SYSTEM" &>/dev/null; then
printf '%s\n' "$0: ERROR: TARGET_SYSTEM must be either WINDOWS or LINUX." >&2
exit 1
fi
## 2) sanity tests
command -v xmllint >/dev/null
command -v lazbuild >/dev/null
command -v ldd >/dev/null
## from package libfile-mimeinfo-perl
command -v mimetype >/dev/null
[[ -v skip_fpc_windows_dependencies_check ]] || skip_fpc_windows_dependencies_check=""
[[ -v use_ppcross_x64_maybe ]] || use_ppcross_x64_maybe=""
## If using
## export use_ppcross_x64_maybe="--compiler=/usr/bin/ppcrossx64"
## then this is not needed.
## This can maybe be removed from developer machines start using Debian trixie or higher?
if [ ! "$skip_fpc_windows_dependencies_check" = "true" ]; then
## lazbuild requires build dependency packages from Debian trixie.
dpkg -l | grep fp-units-win-base >/dev/null
dpkg -l | grep fp-units-win-rtl >/dev/null
dpkg -l | grep fp-units-win-fcl >/dev/null
dpkg -l | grep fp-units-win-misc >/dev/null
fi
## Debugging.
pwd
if [ "$TARGET_SYSTEM" = "WINDOWS" ]; then
for fso in "$FILE_LICENSE" "$FILE_WHONIX_OVA" "$FILE_WHONIX_STARTER_MSI" "$FILE_VCREDIST_INST_EXE" "$FILE_VBOX_INST_EXE" ; do
test -r "$fso"
done
fi
if [ "$TARGET_SYSTEM" = "LINUX" ]; then
for fso in "$FILE_LICENSE" "$FILE_CLI_INSTALLER_SCRIPT" ; do
test -r "$fso"
done
fi
## 3) set current whonix OVA size in INI file for main installer executable
if [ "$TARGET_SYSTEM" = "WINDOWS" ]; then
FILE_WHONIX_OVA_SIZE=$(stat -c%s "$FILE_WHONIX_OVA")
else
FILE_WHONIX_OVA_SIZE="0"
fi
## TODO: Do this inside tmp_src or other temporary folder.
printf '%s\n' "\
[general]
size=$FILE_WHONIX_OVA_SIZE" \
| tee "WhonixOvaInfo.ini" >/dev/null
## Debugging.
cat "WhonixOvaInfo.ini"
## 4.0) copy src folder
rm -rf "tmp_src"
cp -r "src" "tmp_src"
## 4.1) update version info in lpi file
echo -e "\
cd //VersionInfo/StringTable/@ProductVersion
set $VERSION_FULL
cd //VersionInfo/StringTable/@OriginalFilename
set $FILE_INSTALLER_BINARY_FINAL
save" | xmllint --shell "tmp_src/WhonixInstaller.lpi"
## 4.2) update resources in lpi file
## Unfortunately lazbuild as of Debian Trixie does not seem to be able to
## resolve relative paths in resource definitions. Thus we have to fill in the
## absolute paths for all resources.
echo -e "\
cd //Resources/Resource_0[@ResourceName='BANNERLINUX']/@FileName
set $(realpath WhonixInstallerBannerLinux.jpg)
cd //Resources/Resource_1[@ResourceName='BANNERWINDOWS']/@FileName
set $(realpath WhonixInstallerBannerWindows.jpg)
cd //Resources/Resource_2[@ResourceName='LICENSE']/@FileName
set $(realpath "$FILE_LICENSE")
save" | xmllint --shell "tmp_src/WhonixInstaller.lpi"
if [ "$TARGET_SYSTEM" = "WINDOWS" ]; then
echo -e "\
cd //Resources/Resource_4[@ResourceName='OVAINFO']/@FileName
set $(realpath WhonixOvaInfo.ini)
cd //Resources/Resource_5[@ResourceName='VCREDIST']/@FileName
set $(realpath "$FILE_VCREDIST_INST_EXE")
cd //Resources/Resource_6[@ResourceName='VBOX']/@FileName
set $(realpath "$FILE_VBOX_INST_EXE")
cd //Resources/Resource_7[@ResourceName='STARTER']/@FileName
set $(realpath "$FILE_WHONIX_STARTER_MSI")
cd //Resources/Resource_8[@ResourceName='DISABLEHYPERV']/@FileName
set $(realpath DisableHyperV.bat)
cd //Resources/Resource_9[@ResourceName='UNDODISABLEHYPERV']/@FileName
set $(realpath UndoDisableHyperV.bat)
save" | xmllint --shell "tmp_src/WhonixInstaller.lpi"
fi
if [ "$TARGET_SYSTEM" = "LINUX" ]; then
echo -e "\
cd //Resources/Resource_3[@ResourceName='SCRIPT']/@FileName
set $(realpath "$FILE_CLI_INSTALLER_SCRIPT")
save" | xmllint --shell "tmp_src/WhonixInstaller.lpi"
fi
## 5.0) build static library libQt5Pas.a
if [ "$TARGET_SYSTEM" = "LINUX" ]; then
mkdir -p build
cd build
apt-get source libqt5pas-dev
matching_dirs=$(find . -maxdepth 1 -type d -name 'libqtpas*')
first_dir=$(printf '%s\n' "$matching_dirs" | head -n1)
cd "$first_dir"
test -r Qt5Pas.pro
sed -i '/^TEMPLATE = lib/a CONFIG += staticlib' Qt5Pas.pro
qmake
make
cp libQt5Pas.a ..
cd ..
test libQt5Pas.a
cd ..
fi
## 5.1) build executable WhonixInstaller.exe
true "use_ppcross_x64_maybe: $use_ppcross_x64_maybe"
if [ "$TARGET_SYSTEM" = "WINDOWS" ]; then
# shellcheck disable=SC2086
lazbuild --lazarusdir=/usr/lib/lazarus/4.0 -B "tmp_src/WhonixInstaller.lpr" --cpu=x86_64 --os=win64 $use_ppcross_x64_maybe
elif [ "$TARGET_SYSTEM" = "LINUX" ]; then
# shellcheck disable=SC2086
lazbuild --lazarusdir=/usr/lib/lazarus/4.0 -B "tmp_src/WhonixInstaller.lpr" --ws=qt5 --cpu=x86_64 --os=linux $use_ppcross_x64_maybe
fi
## 6) append Whonix OVA to WhonixInstaller.exe
if [ "$TARGET_SYSTEM" = "WINDOWS" ]; then
cat "build/WhonixInstaller.exe" "$FILE_WHONIX_OVA" | tee "$FILE_INSTALLER_BINARY_FINAL" >/dev/null
fi
if [ "$TARGET_SYSTEM" = "LINUX" ]; then
cp "build/WhonixInstaller" "$FILE_INSTALLER_BINARY_FINAL"
fi
## Debugging.
du -sh "$FILE_INSTALLER_BINARY_FINAL"
mimetype "$FILE_INSTALLER_BINARY_FINAL"
if [ "$TARGET_SYSTEM" = "LINUX" ]; then
if ldd "$FILE_INSTALLER_BINARY_FINAL" | grep -q "Qt5Pas"; then
# this can happen if linker finds a libQt5Pas.so before libQt5Pas.a
false "$0: ERROR: $FILE_INSTALLER_BINARY_FINAL depends on QT5Pas"
fi
fi
true "$0: SUCCESS"
exit 0