forked from arter97/immich-native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·165 lines (134 loc) · 4.23 KB
/
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
#!/bin/bash
set -xeuo pipefail
TAG=v1.109.2
IMMICH_PATH=/var/lib/immich
APP=$IMMICH_PATH/app
if [[ "$USER" != "immich" ]]; then
# Disable systemd services, if installed
(
for i in immich*.service; do
systemctl stop $i && \
systemctl disable $i && \
rm /etc/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 "Restarting the script as user immich"
exec sudo -u immich $0 $*
fi
BASEDIR=$(dirname "$0")
umask 077
rm -rf $APP
mkdir -p $APP
# Wipe npm, pypoetry, etc
# This expects immich user's home directory to be on $IMMICH_PATH/home
rm -rf $IMMICH_PATH/home
mkdir -p $IMMICH_PATH/home
echo 'umask 077' > $IMMICH_PATH/home/.bashrc
TMP=/tmp/immich-$(uuidgen)
git clone https://github.com/immich-app/immich $TMP
cd $TMP
git reset --hard $TAG
rm -rf .git
# Use 127.0.0.1
find . -type f \( -name '*.ts' -o -name '*.js' \) -exec grep app.listen {} + | \
sed 's/.*app.listen//' | grep -v '()' | grep '^(' | \
tr -d "[:blank:]" | awk -F"[(),]" '{print $2}' | sort | uniq | while read port; do
find . -type f \( -name '*.ts' -o -name '*.js' \) -exec sed -i -e "[email protected](${port})@app.listen(${port}, '127.0.0.1')@g" {} +
done
find . -type f \( -name '*.ts' -o -name '*.js' \) -exec sed -i -e "s@PrometheusExporter({ port })@PrometheusExporter({ host: '127.0.0.1', port: port })@g" {} +
grep -RlE "\"0\.0\.0\.0\"|'0\.0\.0\.0'" | xargs -n1 sed -i -e "s@'0\.0\.0\.0'@'127.0.0.1'@g" -e 's@"0\.0\.0\.0"@"127.0.0.1"@g'
# 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 "\"/cache\"|'/cache'" | xargs -n1 sed -i -e "s@\"/cache\"@\"$IMMICH_PATH/cache\"@g" -e "s@'/cache'@'$IMMICH_PATH/cache'@g"
grep -RlE "\"/build\"|'/build'" | xargs -n1 sed -i -e "s@\"/build\"@\"$IMMICH_PATH/app\"@g" -e "s@'/build'@'$IMMICH_PATH/app'@g"
# immich-server
cd server
npm ci
npm run build
npm prune --omit=dev --omit=optional
cd -
cd open-api/typescript-sdk
npm ci
npm run build
cd -
cd web
npm ci
npm run build
cd -
cp -a server/node_modules server/dist server/bin $APP/
cp -a web/build $APP/www
cp -a server/resources server/package.json server/package-lock.json $APP/
cp -a server/start*.sh $APP/
cp -a LICENSE $APP/
cd $APP
npm cache clean --force
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 poetry
cd machine-learning
poetry install --no-root --with dev --with cpu
cd ..
)
cp -a machine-learning/ann machine-learning/start.sh machine-learning/app $APP/machine-learning/
# Install GeoNames
mkdir -p $IMMICH_PATH/app/geodata
cd $IMMICH_PATH/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
npm install sharp
# 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
set -a
. $IMMICH_PATH/env
set +a
cd $APP
exec node $APP/dist/main "\$@"
EOF
cat <<EOF > $APP/machine-learning/start.sh
#!/bin/bash
set -a
. $IMMICH_PATH/env
set +a
cd $APP/machine-learning
. venv/bin/activate
: "\${MACHINE_LEARNING_HOST:=127.0.0.1}"
: "\${MACHINE_LEARNING_PORT:=3003}"
: "\${MACHINE_LEARNING_WORKERS:=1}"
: "\${MACHINE_LEARNING_WORKER_TIMEOUT:=120}"
exec gunicorn app.main:app \
-k app.config.CustomUvicornWorker \
-w "\$MACHINE_LEARNING_WORKERS" \
-b "\$MACHINE_LEARNING_HOST":"\$MACHINE_LEARNING_PORT" \
-t "\$MACHINE_LEARNING_WORKER_TIMEOUT" \
--log-config-json log_conf.json \
--graceful-timeout 0
EOF
# Cleanup
rm -rf $TMP
echo
echo "Done. Please install the systemd services to start using Immich."
echo