-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathpre-install.sh
executable file
·317 lines (240 loc) · 7.03 KB
/
pre-install.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
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#!/bin/bash
# Build dependencies
## This is mostly a copy-and-paste work from immich's base image
set -xeuo pipefail # Make people's life easier
# -------------------
# Common variables
# -------------------
SCRIPT_DIR=$PWD
REPO_URL="https://github.com/immich-app/base-images"
BASE_IMG_REPO_DIR=$SCRIPT_DIR/base-images
SOURCE_DIR=$SCRIPT_DIR/image-source
LD_LIBRARY_PATH=/usr/local/lib # :$LD_LIBRARY_PATH
LD_RUN_PATH=/usr/local/lib # :$LD_RUN_PATH
# -------------------
# Git clone function
# -------------------
function git_clone () {
# $1 is repo URL
# $2 is clone target folder
# $3 is branch name
if [ ! -d "$2" ]; then
git clone "$1" "$2"
fi
cd $2
# Get updates
git fetch
# REMOVE all the change one made to source repo, which is sth not supposed to happen
git reset FETCH_HEAD --hard
# In case one is not on the branch
git reset --hard "$3"
}
# -------------------
# Remove build folder function
# -------------------
function remove_build_folder () {
cd $1
if [ -d "build" ]; then
rm -r build
fi
}
# -------------------
# Clone the base images repo
# -------------------
git_clone $REPO_URL $BASE_IMG_REPO_DIR main
# -------------------
# Change build-lock permission
# -------------------
change_permission () {
# Change file permission so that install script could copy the content
chmod 666 $BASE_IMG_REPO_DIR/server/bin/build-lock.json
}
change_permission
# -------------------
# Setup folders
# -------------------
setup_folders () {
cd $SCRIPT_DIR
if [ ! -d "$SOURCE_DIR" ]; then
mkdir $SOURCE_DIR
fi
}
setup_folders
# -------------------
# Build libjxl
# -------------------
change_locale () {
sed -i 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen
locale-gen
}
change_locale
# -------------------
# Build libjxl
# -------------------
build_libjxl () {
cd $SCRIPT_DIR
SOURCE=$SOURCE_DIR/libjxl
set -e
# Monitor these often
JPEGLI_LIBJPEG_LIBRARY_SOVERSION="62"
JPEGLI_LIBJPEG_LIBRARY_VERSION="62.3.0"
: "${LIBJXL_REVISION:=$(jq -cr '.sources[] | select(.name == "libjxl").revision' $BASE_IMG_REPO_DIR/server/bin/build-lock.json)}"
set +e
git_clone https://github.com/libjxl/libjxl.git $SOURCE $LIBJXL_REVISION
cd $SOURCE
git submodule update --init --recursive --depth 1 --recommend-shallow
git apply $BASE_IMG_REPO_DIR/server/bin/jpegli-empty-dht-marker.patch
git apply $BASE_IMG_REPO_DIR/server/bin/jpegli-icc-warning.patch
remove_build_folder $SOURCE
mkdir build
cd build
cmake \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_TESTING=OFF \
-DJPEGXL_ENABLE_DOXYGEN=OFF \
-DJPEGXL_ENABLE_MANPAGES=OFF \
-DJPEGXL_ENABLE_PLUGIN_GIMP210=OFF \
-DJPEGXL_ENABLE_BENCHMARK=OFF \
-DJPEGXL_ENABLE_EXAMPLES=OFF \
-DJPEGXL_FORCE_SYSTEM_BROTLI=ON \
-DJPEGXL_FORCE_SYSTEM_HWY=ON \
-DJPEGXL_ENABLE_JPEGLI=ON \
-DJPEGXL_ENABLE_JPEGLI_LIBJPEG=ON \
-DJPEGXL_INSTALL_JPEGLI_LIBJPEG=ON \
-DJPEGXL_ENABLE_PLUGINS=ON \
-DJPEGLI_LIBJPEG_LIBRARY_SOVERSION="${JPEGLI_LIBJPEG_LIBRARY_SOVERSION}" \
-DJPEGLI_LIBJPEG_LIBRARY_VERSION="${JPEGLI_LIBJPEG_LIBRARY_VERSION}" \
-DLIBJPEG_TURBO_VERSION_NUMBER=2001005 \
..
# Move the following flag to above if one's system support AVX512
# -DJPEGXL_ENABLE_AVX512=ON \
# -DJPEGXL_ENABLE_AVX512_ZEN4=ON \
echo "Building libjxl using $(nproc) threads"
cmake --build . -- -j"$(nproc)"
cmake --install .
ldconfig /usr/local/lib
# Clean up builds
make clean
remove_build_folder $SOURCE
rm -rf $SOURCE/third_party/
}
# Experimental build, currently broken
while getopts "e" opt; do
case $opt in
e)
build_libjxl
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
# -------------------
# Build libheif
# -------------------
build_libheif () {
cd $SCRIPT_DIR
SOURCE=$SOURCE_DIR/libheif
set -e
: "${LIBHEIF_REVISION:=$(jq -cr '.sources[] | select(.name == "libheif").revision' $BASE_IMG_REPO_DIR/server/bin/build-lock.json)}"
set +e
git_clone https://github.com/strukturag/libheif.git $SOURCE $LIBHEIF_REVISION
cd $SOURCE
remove_build_folder $SOURCE
mkdir build
cd build
cmake --preset=release-noplugins \
-DWITH_DAV1D=ON \
-DENABLE_PARALLEL_TILE_DECODING=ON \
-DWITH_LIBSHARPYUV=ON \
-DWITH_LIBDE265=ON \
-DWITH_AOM_DECODER=OFF \
-DWITH_AOM_ENCODER=OFF \
-DWITH_X265=OFF \
-DWITH_EXAMPLES=OFF \
..
make install
ldconfig /usr/local/lib
# Clean up builds
make clean
remove_build_folder $SOURCE
}
build_libheif
# -------------------
# Build libraw
# -------------------
build_libraw () {
cd $SCRIPT_DIR
SOURCE=$SOURCE_DIR/libraw
set -e
: "${LIBRAW_REVISION:=$(jq -cr '.sources[] | select(.name == "libraw").revision' $BASE_IMG_REPO_DIR/server/bin/build-lock.json)}"
set +e
git_clone https://github.com/libraw/libraw.git $SOURCE $LIBRAW_REVISION
cd $SOURCE
autoreconf --install
./configure
echo "Building libraw using $(nproc) threads"
make -j"$(nproc)"
make install
ldconfig /usr/local/lib
# Clean up builds
make clean
}
build_libraw
# DO NOT ASK WHY, RUNNING ONE TIME NEVER WORK FOR ME
build_libraw
# -------------------
# Build image magick
# -------------------
build_image_magick () {
cd $SCRIPT_DIR
SOURCE=$SOURCE_DIR/image-magick
set -e
: "${IMAGEMAGICK_REVISION:=$(jq -cr '.sources[] | select(.name == "imagemagick").revision' $BASE_IMG_REPO_DIR/server/bin/build-lock.json)}"
set +e
git_clone https://github.com/ImageMagick/ImageMagick.git $SOURCE $IMAGEMAGICK_REVISION
cd $SOURCE
./configure --with-modules
echo "Building ImageMagick using $(nproc) threads"
make -j"$(nproc)"
make install
ldconfig /usr/local/lib
# Clean up builds
make clean
}
build_image_magick
# -------------------
# Build libvips
# -------------------
build_libvips () {
cd $SCRIPT_DIR
SOURCE=$SOURCE_DIR/libvips
set -e
: "${LIBVIPS_REVISION:=$(jq -cr '.sources[] | select(.name == "libvips").revision' $BASE_IMG_REPO_DIR/server/bin/build-lock.json)}"
set +e
git_clone https://github.com/libvips/libvips.git $SOURCE $LIBVIPS_REVISION
cd $SOURCE
remove_build_folder $SOURCE
# -Djpeg-xl=disabled is added because previous broken install will break libvips
meson setup build --buildtype=release --libdir=lib -Dintrospection=disabled -Dtiff=disabled -Djpeg-xl=disabled
cd build
ninja install
ldconfig /usr/local/lib
# Clean up builds
remove_build_folder $SOURCE
}
build_libvips
# -------------------
# Remove unused packages
# -------------------
remove_unused_packages () {
# Dockerfile 109
## Debian
dpkg -r --force-depends libjpeg62-turbo
## Ubuntu
dpkg -r --force-depends libjpeg-turbo8
}
# Skip this because this causes much headache down the road
# To fix it, apt --fix-broken install
# remove_unused_packages