-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·266 lines (224 loc) · 6.97 KB
/
install.sh
File metadata and controls
executable file
·266 lines (224 loc) · 6.97 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
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
#!/bin/bash
set -xeuo pipefail
REV=v2.5.6
IMMICH_PATH=/var/lib/immich
APP=$IMMICH_PATH/app
if ! command -v pnpm >/dev/null 2>&1; then
echo "pnpm is not activated, please follow README's Node.js setup"
exit 1
fi
# Prevent Javascript OOM
export NODE_OPTIONS="--max-old-space-size=4096"
if [[ "$USER" != "immich" ]]; then
# Disable systemd services, if installed
(
systemctl list-unit-files --type=service | grep "^immich" | while read i unused; do
systemctl stop $i && \
systemctl disable $i && \
rm /*/systemd/system/$i &&
systemctl daemon-reload
done
) || true
mkdir -p $IMMICH_PATH
chown immich:immich $IMMICH_PATH
mkdir -p /var/log/immich
chown immich:immich /var/log/immich
echo "Forking the script as user immich"
sudo -u immich $0 $*
echo "Starting systemd services"
cp immich*.service /lib/systemd/system/
systemctl daemon-reload
for i in immich*.service; do
systemctl enable $i
systemctl start $i
done
exit 0
fi
# Sanity check, users should have VectorChord enabled
if psql -U immich -c "SELECT 1;" > /dev/null 2>&1; then
# Immich is installed, check VectorChord
if ! psql -U immich -c "SELECT * FROM pg_extension;" | grep "vchord" > /dev/null 2>&1; then
echo "VectorChord is not enabled for Immich."
echo "Please read https://github.com/immich-app/immich/blob/main/docs/docs/administration/postgres-standalone.md"
exit 1
fi
fi
if [ -e "$IMMICH_PATH/env" ]; then
if grep -q DB_VECTOR_EXTENSION "$IMMICH_PATH/env"; then
echo "Please remove DB_VECTOR_EXTENSION from your env file"
exit 1
fi
fi
BASEDIR=$(dirname "$0")
umask 077
rm -rf $APP $APP/../i18n
mkdir -p $APP
# Wipe pnpm, uv, etc
# This expects immich user's home directory to be on $IMMICH_PATH/home
rm -rf $IMMICH_PATH/home
mkdir -p $IMMICH_PATH/home
mkdir -p $IMMICH_PATH/home/.local/bin
echo 'umask 077' > $IMMICH_PATH/home/.bashrc
export PATH="$HOME/.local/bin:$PATH"
TMP=/tmp/immich-$(uuidgen)
if [[ $REV =~ ^[0-9A-Fa-f]+$ ]]; then
# REV is a full commit hash, full clone is required
git clone https://github.com/immich-app/immich $TMP
else
git clone https://github.com/immich-app/immich $TMP --depth=1 -b $REV
fi
cd $TMP
git reset --hard $REV
rm -rf .git
# Replace /usr/src
grep -Rl /usr/src | xargs -n1 sed -i -e "s@/usr/src@$IMMICH_PATH@g"
mkdir -p $IMMICH_PATH/cache
grep -RlE "\"/build\"|'/build'" | xargs -n1 sed -i -e "s@\"/build\"@\"$APP\"@g" -e "s@'/build'@'$APP'@g"
# Setup pnpm
corepack use pnpm@latest
# Install extism/js-pdk for extism-js
curl -O https://raw.githubusercontent.com/extism/js-pdk/main/install.sh
sed -i \
-e 's@sudo@@g' \
-e "s@/usr/local/binaryen@$HOME/binaryen@g" \
-e "s@/usr/local/bin@$HOME/.local/bin@g" \
install.sh
./install.sh
rm install.sh
# immich-server
cd server
pnpm install --frozen-lockfile --force
pnpm run build
pnpm prune --prod --no-optional --config.ci=true
cd -
cd open-api/typescript-sdk
pnpm install --frozen-lockfile --force
pnpm run build
cd -
cd web
pnpm install --frozen-lockfile --force
pnpm run build
cd -
cd plugins
pnpm install --frozen-lockfile --force
pnpm run build
cd -
cp -aL server/node_modules server/dist server/bin $APP/
cp -a web/build $APP/www
cp -a server/resources server/package.json pnpm-lock.yaml $APP/
mkdir -p $APP/corePlugin
cp -a plugins/dist $APP/corePlugin/
cp -a plugins/manifest.json $APP/corePlugin/
cp -a LICENSE $APP/
cp -a i18n $APP/../
cd $APP
pnpm store prune
cd -
# immich-machine-learning
mkdir -p $APP/machine-learning
python3 -m venv $APP/machine-learning/venv
(
# Initiate subshell to setup venv
. $APP/machine-learning/venv/bin/activate
pip3 install uv
if [ "$(python3 -c 'import sys; print(sys.version_info[:2] > (3, 12))')" = "True" ]; then
echo "Python > 3.12, pinning to 3.12"
uv venv --python 3.12 --allow-existing $APP/machine-learning/venv
# Reload
deactivate
. $APP/machine-learning/venv/bin/activate
fi
cd machine-learning
uv sync --no-install-project --no-install-workspace --extra cpu --no-cache --active --link-mode=copy
cd ..
)
cp -a \
machine-learning/immich_ml \
$APP/machine-learning/
# Install GeoNames
mkdir -p $APP/geodata
cd $APP/geodata
wget -o - https://download.geonames.org/export/dump/admin1CodesASCII.txt &
wget -o - https://download.geonames.org/export/dump/admin2Codes.txt &
wget -o - https://download.geonames.org/export/dump/cities500.zip &
wget -o - https://raw.githubusercontent.com/nvkelso/natural-earth-vector/v5.1.2/geojson/ne_10m_admin_0_countries.geojson &
wait
unzip cities500.zip
date --iso-8601=seconds | tr -d "\n" > geodata-date.txt
rm cities500.zip
# Install sharp
cd $APP
# https://github.com/lovell/sharp/blob/main/src/common.h#L20
VIPS_LOCAL_VERSION="$(pkg-config --modversion vips || true)"
VIPS_TARGET_VERSION="8.17.3"
if [[ "$(printf '%s\n' $VIPS_TARGET_VERSION $VIPS_LOCAL_VERSION | sort -V | tail -n1)" == "$VIPS_LOCAL_VERSION" ]]; then
echo "Local libvips-dev is installed, manually building sharp"
pnpm remove sharp
SHARP_FORCE_GLOBAL_LIBVIPS=1 npm_config_build_from_source=true pnpm add sharp --ignore-scripts=false --allow-build=sharp
else
if [ ! -z "$VIPS_LOCAL_VERSION" ]; then
echo "Local libvips-dev is installed, but it's too out-of-date"
echo "Detected $VIPS_LOCAL_VERSION, but $VIPS_TARGET_VERSION or higher is required"
sleep 5
fi
pnpm install sharp
fi
# Setup upload directory
mkdir -p $IMMICH_PATH/upload
ln -s $IMMICH_PATH/upload $APP/
ln -s $IMMICH_PATH/upload $APP/machine-learning/
# Custom start.sh script
cat <<EOF > $APP/start.sh
#!/bin/bash
export PATH=/usr/lib/jellyfin-ffmpeg:$HOME/.local/bin:$PATH
set -a
. $IMMICH_PATH/env
set +a
cd $APP
exec node $APP/dist/main "\$@"
EOF
chmod 700 $APP/start.sh
cat <<EOF > $APP/machine-learning/start.sh
#!/bin/bash
export PATH=/usr/lib/jellyfin-ffmpeg:$HOME/.local/bin:$PATH
set -a
. $IMMICH_PATH/env
set +a
cd $APP/machine-learning
. venv/bin/activate
set -a
: "\${MACHINE_LEARNING_HOST:=127.0.0.1}"
: "\${MACHINE_LEARNING_PORT:=3003}"
: "\${MACHINE_LEARNING_WORKERS:=1}"
: "\${MACHINE_LEARNING_HTTP_KEEPALIVE_TIMEOUT_S:=2}"
: "\${MACHINE_LEARNING_WORKER_TIMEOUT:=300}"
: "\${MACHINE_LEARNING_CACHE_FOLDER:=$IMMICH_PATH/cache}"
: "\${TRANSFORMERS_CACHE:=$IMMICH_PATH/cache}"
exec gunicorn immich_ml.main:app \\
-k immich_ml.config.CustomUvicornWorker \\
-c immich_ml/gunicorn_conf.py \\
-b "\$MACHINE_LEARNING_HOST":"\$MACHINE_LEARNING_PORT" \\
-w "\$MACHINE_LEARNING_WORKERS" \\
-t "\$MACHINE_LEARNING_WORKER_TIMEOUT" \\
--log-config-json log_conf.json \\
--keep-alive "\$MACHINE_LEARNING_HTTP_KEEPALIVE_TIMEOUT_S" \\
--graceful-timeout 10
EOF
chmod 700 $APP/machine-learning/start.sh
# Migrate env file
if [ -e "$IMMICH_PATH/env" ]; then
if grep -q "^MACHINE_LEARNING_HOST=" "$IMMICH_PATH/env"; then
# Simply change MACHINE_LEARNING_HOST to IMMICH_HOST
sed -i -e 's/MACHINE_LEARNING_HOST/IMMICH_HOST/g' "$IMMICH_PATH/env"
fi
fi
# Cleanup
rm -rf \
$TMP \
$IMMICH_PATH/home/.wget-hsts \
$IMMICH_PATH/home/.pnpm \
$IMMICH_PATH/home/.local/share/pnpm \
$IMMICH_PATH/home/.cache
echo
echo "Done."
echo