главная|main page

состояние|status

блог|blog

файлы|files

программы|software

summaryrefslogtreecommitdiff
path: root/setup.sh
diff options
context:
space:
mode:
authorIvan Davydov <lotigara@lotigara.ru>2025-03-23 16:07:46 +0300
committerIvan Davydov <lotigara@lotigara.ru>2025-03-28 10:41:24 +0300
commita0f5891f7ebaef61c8ea362b4540d027f633849d (patch)
tree97571e7e46bf06af8d2f005ffbc54ca7a4aeb79d /setup.sh
parent553e884a45de6f67fb842dd281c662db1000cce3 (diff)
Big refactorHEADmain
TL;DR: this commit makes README.md more simple and makes scripts more complex. This commit makes scripts look (and behave) like scripts. That is, they now contain shebangs, `echo` lines to allow user to watch the installation process. The latter is now more configurable: user can customize the directory, where LibreTranslate will be installed, username, which will be used to run LibreTranslate and the domain name configuration is now contained in the .env file, which used for all other settings.
Diffstat (limited to 'setup.sh')
-rwxr-xr-xsetup.sh73
1 files changed, 55 insertions, 18 deletions
diff --git a/setup.sh b/setup.sh
index e97c9df..b877146 100755
--- a/setup.sh
+++ b/setup.sh
@@ -1,26 +1,63 @@
-sudo apt-get update
-sudo apt-get upgrade -y
-sudo apt-get install -y vim git
+#!/bin/sh
-# Install Python
-sudo apt-get install -y python3 python3-virtualenv python-is-python3 python3-pip python3-dev build-essential libssl-dev libffi-dev python3-setuptools
+if [ -f .env ]; then
+ set -a
+ . ./.env
+ set +a
+else
+ . ./.env.example
+fi
-# Install PyICU dependencies
-# https://community.libretranslate.com/t/pyicu-fails-to-install-on-ubuntu-20-04/23
-sudo apt-get install -y libicu-dev python3-icu pkg-config
+# ---
-# Install Nginx
-sudo apt-get install -y nginx
+echo 'Updating package index...'
+apt-get update
-# Download LibreTranslate source
-git clone https://github.com/LibreTranslate/LibreTranslate.git ~/LibreTranslate
+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
-# Setup virtualenv
-virtualenv ~/LibreTranslate/env
+# ---
-# Install gunicorn
-~/LibreTranslate/env/bin/pip install gunicorn
+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
-# Install and run LibreTranslate on port 5000
-~/LibreTranslate/env/bin/pip install ~/LibreTranslate/ --no-cache-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."