главная|main page

состояние|status

блог|blog

файлы|files

программы|software

summaryrefslogtreecommitdiff
path: root/setup.sh
blob: b8771469f4c85a8078ec412602bb6427337cc11f (plain)
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
#!/bin/sh

if [ -f .env ]; then
  set -a
  . ./.env
  set +a
else
  . ./.env.example
fi

# ---

echo 'Updating package index...'
apt-get update

echo 'Installing dependencies...'
# Install Python, PyICU dependencies (https://community.libretranslate.com/t/pyicu-fails-to-install-on-ubuntu-20-04/23), Nginx and optionally Certbot with Nginx plugin
apt-get install -y python3 python3-virtualenv python-is-python3 python3-pip python3-dev build-essential libssl-dev libffi-dev python3-setuptools \
libicu-dev python3-icu pkg-config \
nginx

# ---

echo 'Creating LibreTranslate user...'
useradd --system -m --home-dir $LT_DIR $LT_USER
cp $PWD/.env $LT_DIR/.env && chown -R $LT_USER $LT_DIR

echo 'Downloading and installing LibreTranslate...'
su -ls /bin/sh $LT_USER <<EOF
  # Download LibreTranslate source code
  git clone https://github.com/LibreTranslate/LibreTranslate.git $LT_DIR/lt
  mv $LT_DIR/lt/* $LT_DIR/
  mv $LT_DIR/lt/.* $LT_DIR/
  rmdir $LT_DIR/lt

  # Setup virtualenv
  python -m venv $LT_DIR/venv

  # Install gunicorn
  $LT_DIR/venv/bin/pip install gunicorn

  # Install and run LibreTranslate on port 5000
  $LT_DIR/venv/bin/pip install $LT_DIR --no-cache-dir
  $LT_DIR/scripts/install_models.py
EOF

# ---

echo 'Configuring system services...'
echo 'Setting up systemd service...'
sed -e "{s|\$LT_DIR|$LT_DIR|;s|\$LT_USER|$LT_USER|}" libretranslate.service.example > libretranslate.service
cp -v libretranslate.service /etc/systemd/system/
systemctl enable --now libretranslate

echo 'Configuring Nginx site...'
sed -e "{s|\$LT_DIR|$LT_DIR|;s|\$LT_DOMAIN|$LT_DOMAIN|}" nginx.example > nginx
cp -v nginx /etc/nginx/sites-available/libretranslate
ln -sv /etc/nginx/sites-available/libretranslate /etc/nginx/sites-enabled/libretranslate
nginx -t && systemctl restart nginx

# ---

echo "Done! Now you can visit the http://$LT_DOMAIN website. You can use the ./get-cert.sh script to get an SSL certificate."