главная|main page

состояние|status

блог|blog

файлы|files

программы|software

summaryrefslogtreecommitdiff
path: root/setup.sh
diff options
context:
space:
mode:
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."