Add librephoto install script

This commit is contained in:
Thomas Legay 2021-02-28 11:27:33 +01:00
commit b5df652761
1 changed files with 186 additions and 0 deletions

186
librephotos.sh Normal file
View File

@ -0,0 +1,186 @@
#!/bin/bash
#Requirement
# -DEBIAN 11
set -ex
apt install -y wget
wget -qO - deb.lgy.fr | bash 2>&1 >/dev/null
apt -y install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget libbz2-dev liblzma-dev
wget https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tar.xz -O - | tar -Jx -C /usr/src/
cd /usr/src/Python-3.8.2/
./configure --enable-optimizations
make -j 8
make altinstall
apt install --no-install-recommends -y \
swig libpq-dev postgresql-common curl libopenblas-dev libmagic1 libboost-all-dev libxrender-dev liblapack-dev git bzip2 cmake build-essential libsm6 libglib2.0-0 libgl1-mesa-glx gfortran gunicorn libheif-dev libssl-dev rustc liblzma-dev
mkdir -p /data_models/places365/
mkdir -p /data_models/im2txt/
mkdir -p /root/.cache/torch/hub/checkpoints/
curl -SL https://s3.eu-central-1.amazonaws.com/ownphotos-deploy/places365_model.tar.gz | tar -zxC /data_models/places365/
curl -SL https://s3.eu-central-1.amazonaws.com/ownphotos-deploy/im2txt_model.tar.gz | tar -zxC /data_models/im2txt/
curl -SL https://s3.eu-central-1.amazonaws.com/ownphotos-deploy/im2txt_data.tar.gz | tar -zxC /data_models/im2txt/
curl -SL https://download.pytorch.org/models/resnet152-b121ed2d.pth -o /root/.cache/torch/hub/checkpoints/resnet152-b121ed2d.pth
/usr/local/bin/pip3.8 install pip --upgrade
/usr/local/bin/pip3.8 install psycopg2
/usr/local/bin/pip3.8 install wheel
/usr/local/bin/pip3.8 install torch==1.7.1+cpu torchvision==0.8.2+cpu -f https://download.pytorch.org/whl/torch_stable.html
/usr/local/bin/pip3.8 install -v --install-option="--no" --install-option="DLIB_USE_CUDA" --install-option="--no" --install-option="USE_AVX_INSTRUCTIONS" --install-option="--no" --install-option="USE_SSE4_INSTRUCTIONS" dlib
cd /usr/src
git clone https://github.com/LibrePhotos/librephotos
cd librephotos
/usr/local/bin/pip3.8 install -r requirements.txt
/usr/local/bin/python3.8 -m spacy download en_core_web_sm
cat << 'EOF' > /etc/systemd/system/librephotos-backend.service
[Unit]
Description=librephotos-backend
[Service]
ExecStart=/usr/local/bin/librephotos-backend
[Install]
WantedBy=multi-user.target
EOF
systemctl enable librephotos-backend
cat << 'EOF' > /usr/local/bin/librephotos-backend
#! /bin/bash
cd /usr/src/librephotos/
export PYTHONUNBUFFERED=TRUE
mkdir -p /logs
export PYTHONUNBUFFERED=TRUE
export BACKEND_HOST=localhost
export DB_BACKEND=postgresql
export DB_NAME=librephoto
export DB_USER=librephoto
export DB_PASS=bovCevIrwomNeOgceshteudhekCubyosogvoanFaSokyodvonIgEnOyRabZypVam
export DB_HOST=postgres.net.lgy.fr
export DB_PORT=5432
#redis local ou redis distant
export REDIS_PATH=
export REDIS_DB=
# redis distant
export REDIS_HOST=redis.net.lgy.fr
export REDIS_PASS=
export REDIS_PORT=6379
export TIME_ZONE=Europe/Paris
export SECRET_KEY=gimagsebwawsIajsegItByevDehivatdijTubAmtyecDanBiongIsOphtEekhyd
export ADMIN_USERNAME=thomas
export ADMIN_EMAIL=thomas@lgy.fr
export ADMIN_PASSWORD=toto
export MAPBOX_API_KEY=
/usr/local/bin/python3.8 image_similarity/main.py 2>&1 | tee /logs/gunicorn_image_similarity.log &
/usr/local/bin/python3.8 manage.py showmigrations | tee /logs/show_migrate.log
/usr/local/bin/python3.8 manage.py migrate | tee /logs/command_migrate.log
/usr/local/bin/python3.8 manage.py showmigrations | tee /logs/show_migrate.log
/usr/local/bin/python3.8 manage.py build_similarity_index 2>&1 | tee /logs/command_build_similarity_index.log
/usr/local/bin/python3.8 manage.py clear_cache
/usr/local/bin/python3.8 manage.py createadmin -u $ADMIN_USERNAME $ADMIN_EMAIL 2>&1 | tee /logs/command_createadmin.log
echo "Running backend server..."
/usr/local/bin/python3.8 manage.py rqworker default 2>&1 | tee /logs/rqworker.log &
if [ "$DEBUG" = 1 ]
then
echo "develompent backend starting"
/usr/local/bin/gunicorn --worker-class=gevent --timeout 36000 --reload --bind localhost:8001 --log-level=info ownphotos.wsgi 2>&1 | tee /logs/gunicorn_django.log
else
echo "production backend starting"
/usr/local/bin/gunicorn --worker-class=gevent --timeout 3600 --bind localhost:8001 --log-level=info ownphotos.wsgi 2>&1 | tee /logs/gunicorn_django.log
fi
EOF
chmod +x /usr/local/bin/librephotos-backend
apt-get install -y curl git xsel nodejs git npm --no-install-recommends
mkdir -p /usr/src/librephotos-frontend
git clone https://github.com/LibrePhotos/librephotos-frontend /usr/src/librephotos-frontend
cd /usr/src/librephotos-frontend
npm install
npm run build
npm install serve
cat << EOF > /etc/systemd/system/librephotos-frontend.service
[Unit]
Description=librephotos-frontend
[Service]
ExecStart=/usr/local/bin/librephotos-frontend
[Install]
WantedBy=multi-user.target
EOF
systemctl enable librephotos-frontend
cat << 'EOF' > /usr/local/bin/librephotos-frontend
#!/usr/bin/env bash
cd /usr/src/librephotos-frontend
npm install
npm run start
#/root/node_modules/.bin/serve build -d -l 3000
EOF
chmod +x /usr/local/bin/librephotos-frontend
apt install -y nginx
cat << 'EOF' > /etc/nginx/nginx.conf
user www-data;
worker_processes 1;
error_log /var/log/nginx/error.log debug;
events {
worker_connections 1024;
}
http {
server {
listen 80;
location / {
# React routes are entirely on the App side in the web broswer
# Always proxy to root with the same page request when nginx 404s
error_page 404 /;
proxy_intercept_errors on;
proxy_set_header Host $host;
proxy_pass http://localhost:3000/;
}
location ~ ^/(api|media)/ {
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host backend;
include uwsgi_params;
proxy_pass http://localhost:8001;
}
# Django media
location /protected_media {
internal;
alias /protected_media/;
}
# Original Photos
location /original {
internal;
alias /data/;
}
# Nextcloud Original Photos
location /nextcloud_original {
internal;
alias /data/nextcloud_media/;
}
}
}
EOF
systemctl restart nginx