scripts/install-weblate

221 lines
7.6 KiB
Text
Raw Normal View History

#!/bin/sh
2020-04-22 12:21:03 +02:00
set -e
2021-02-09 10:20:23 +01:00
# shellcheck disable=SC1091
. /etc/weblate-bootstrap
cd /tmp
# Install deps
2021-08-06 14:34:46 +02:00
apt-get update
2025-04-08 11:35:17 +02:00
apt-get install --no-install-recommends -y build-essential \
2025-07-16 15:11:55 +02:00
certbot \
curl \
cython3 \
fail2ban python3-pyinotify python3-systemd \
g++ \
gcc \
gettext \
gir1.2-pango-1.0 \
gir1.2-rsvg-2.0 \
git \
git-svn \
git-lfs \
gnupg \
libcairo2-dev \
libenchant-2-2 \
libfreetype6-dev \
libgirepository1.0-dev \
libjpeg-dev \
libldap2-dev \
libleptonica-dev \
libsasl2-dev \
libssl-dev \
libtesseract-dev \
libxml2-dev \
libxmlsec1-dev \
libxslt1-dev \
libyaml-dev \
libacl1-dev \
zlib1g-dev \
liblz4-dev \
libzstd-dev \
libxxhash-dev \
nginx \
openssh-client \
pkg-config \
postgresql-client \
python3-certbot-nginx \
python3-dev \
python3-gdbm \
python3-pip \
python3-virtualenv \
redis-server \
rsync \
subversion \
tesseract-ocr \
virtualenv \
uwsgi \
uwsgi-plugin-python3
2020-10-04 10:38:18 +02:00
# Install ruby deps for licesee
apt-get install -y \
2025-07-16 15:11:55 +02:00
ruby bundler cmake pkg-config git libssl-dev ruby-dev
# Add user
adduser weblate --disabled-password --gecos Weblate
usermod --append --groups adm weblate
2020-04-04 13:25:36 +02:00
WEBLATE_HOME=~weblate
# Install Weblate and deps
2021-02-09 10:20:23 +01:00
sudo -u weblate virtualenv --python=python3 "$WEBLATE_HOME/weblate-env"
2025-09-17 13:55:43 +02:00
sudo -u weblate "$WEBLATE_HOME/weblate-env/bin/pip" install "Weblate[all,zxcvbn,wsgi]$WEBLATE_VERSION" wllegal 'pygobject<3.52'
PYVER=$(python3 -c 'import sys; print("{}.{}".format(*sys.version_info[:2]))')
2021-02-09 10:20:23 +01:00
SETTINGS_PY="$WEBLATE_HOME/weblate-env/lib/python$PYVER/site-packages/weblate/settings.py"
# Configure Weblate
2021-02-09 10:20:23 +01:00
sudo -u weblate cp "$WEBLATE_HOME/weblate-env/lib/python$PYVER/site-packages/weblate/settings_example.py" "$SETTINGS_PY"
2021-02-09 10:20:23 +01:00
# shellcheck disable=SC1004
sed -i \
2025-07-16 15:11:55 +02:00
-e "s#^DATA_DIR.*#DATA_DIR = \"$WEBLATE_HOME/data\"#" \
-e 's#^ENABLE_HTTPS.*#ENABLE_HTTPS = True#' \
-e 's#^SERVER_EMAIL.*#SERVER_EMAIL = "noreply@weblate.org"#' \
-e 's#^DEFAULT_FROM_EMAIL.*#DEFAULT_FROM_EMAIL = "noreply@weblate.org"#' \
-e "s#^SECRET_KEY.*#SECRET_KEY = '$WEBLATE_SECRET'#" \
-e "s#^SITE_TITLE.*#SITE_TITLE = '$WEBLATE_TITLE'#" \
-e "s#^SITE_DOMAIN.*#SITE_DOMAIN = '$WEBLATE_DOMAIN'#" \
-e "s#^SENTRY_DSN.*#SENTRY_DSN = '$WEBLATE_SENTRY'#" \
-e "s#^SENTRY_ENVIRONMENT.*#SENTRY_ENVIRONMENT = SITE_DOMAIN#" \
-e "/HiredisParser/ D" \
-e "/SENTRY_DSN/ a \
2020-04-14 15:23:07 +02:00
SENTRY_TOKEN = '$WEBLATE_SENTRY_TOKEN'" \
2025-07-16 15:11:55 +02:00
-e "s#^ \"PASSWORD\":.*# \"PASSWORD\": '$POSTGRES_PASS',#" \
-e "s#.*your_email@example.com.*# ('Michal Čihař', 'michal@cihar.com'),#" \
-e '/social_core.pipeline.social_auth.load_extra_data/ a \
"weblate.legal.pipeline.tos_confirm",' \
2025-07-16 15:11:55 +02:00
-e '/weblate.middleware.SecurityMiddleware/ a \
"weblate.legal.middleware.RequireTOSMiddleware",' \
2025-07-16 15:11:55 +02:00
-e '/weblate.gitexport/ a \
2020-03-14 05:45:16 +01:00
"wllegal",' \
2025-07-16 15:11:55 +02:00
-e '/weblate.gitexport/ a \
"weblate.legal",' \
2025-07-16 15:11:55 +02:00
-e 's#^MT_APERTIUM_APY.*#MT_APERTIUM_APY = "http://172.16.0.9:2737/"#' \
-e 's/^# MT_SERVICES/MT_SERVICES/' \
-e 's/^# "weblate.machinery.apertium./ "weblate.machinery.apertium./' \
-e 's/^# "weblate.machinery.weblatetm./ "weblate.machinery.weblatetm./' \
-e 's/^# "weblate.memory.machine/ "weblate.memory.machine/' \
-e 's/^DEBUG =.*/DEBUG = False/' \
-e 's/"admin.E408"/"admin.E408", "weblate.E012", "weblate.E013"/' \
-e 's/^REGISTRATION_OPEN =.*/REGISTRATION_OPEN = False/' \
-e 's/^REQUIRE_LOGIN =.*/REQUIRE_LOGIN = True/' \
-e 's/^COMPRESS_OFFLINE =.*/COMPRESS_OFFLINE = True/' \
-e 's/# "weblate.machinery.apertium.ApertiumAPYTranslation",/"weblate.machinery.apertium.ApertiumAPYTranslation",/' \
"$SETTINGS_PY"
cat << EOT >> "$SETTINGS_PY"
# Hosted customization
2023-04-29 10:53:30 +02:00
ADMINS_CONTACT = ['care@weblate.org']
DEFAULT_COMMITER_EMAIL = 'hosted@weblate.org'
DEFAULT_COMMITER_NAME = 'Hosted Weblate'
2020-03-20 14:11:21 +01:00
STATUS_URL = "https://status.weblate.org/"
2021-03-17 19:54:29 +01:00
GET_HELP_URL = "https://care.weblate.org/"
CONTACT_FORM = "from"
EOT
# Fill the database
2020-04-04 13:25:36 +02:00
sudo -u weblate $WEBLATE_HOME/weblate-env/bin/weblate migrate
2025-04-08 11:35:17 +02:00
if [ -n "$WEBLATE_PASSWORD" ]; then
2025-07-16 15:11:55 +02:00
sudo -u weblate $WEBLATE_HOME/weblate-env/bin/weblate createadmin --username nijel --email michal@cihar.com --name 'Michal Čihař' --password "$WEBLATE_PASSWORD"
2020-04-14 16:34:28 +02:00
else
2025-07-16 15:11:55 +02:00
sudo -u weblate $WEBLATE_HOME/weblate-env/bin/weblate createadmin --username nijel --email michal@cihar.com --name 'Michal Čihař'
2020-04-14 16:34:28 +02:00
fi
2020-04-04 13:25:36 +02:00
sudo -u weblate $WEBLATE_HOME/weblate-env/bin/weblate collectstatic --noinput
sudo -u weblate $WEBLATE_HOME/weblate-env/bin/weblate compress --force
# Track deploy at Sentry
2025-04-08 11:35:17 +02:00
if ! grep -q "SENTRY_TOKEN = ''" "$SETTINGS_PY"; then
2025-07-16 15:11:55 +02:00
sudo -u weblate "$WEBLATE_HOME/weblate-env/bin/weblate" sentry_deploy
fi
# Celery and uwsgi
2021-02-09 10:20:23 +01:00
cd "$WEBLATE_HOME/weblate-env/lib/python$PYVER/site-packages/weblate/examples/"
cp celery-weblate.logrotate /etc/logrotate.d/
cp celery-weblate.service /etc/systemd/system/
cp celery-weblate.conf /etc/default/celery-weblate
cp weblate.uwsgi.ini /etc/uwsgi/apps-available/weblate.ini
systemctl daemon-reload
2020-04-22 12:21:03 +02:00
systemctl enable celery-weblate.service
systemctl start celery-weblate.service
ln -s ../apps-available/weblate.ini /etc/uwsgi/apps-enabled/
systemctl restart uwsgi.service
# SSL cert
2025-04-08 11:35:17 +02:00
if [ "$1" != "--nocert" ]; then
2025-07-16 15:11:55 +02:00
certbot --agree-tos --email care@weblate.org --redirect --no-eff-email -d "$WEBLATE_DOMAIN"
fi
# Enable http/2
2020-06-19 06:53:49 +02:00
sed -i -e 's/ssl;/ssl http2;/' -e 's/ssl ipv6only=on/ssl ipv6only=on http2/' /etc/nginx/sites-available/default
# Enable status locally
2025-04-08 11:35:17 +02:00
sed -i '/server_name _/a location = /nginx_status {\n stub_status;\n}' /etc/nginx/sites-available/default
# Enable compression for js/css
sed -i 's/^\t# gzip/\tgzip/' /etc/nginx/nginx.conf
# Hide server version
sed -i 's/# server_tokens off/server_tokens off/' /etc/nginx/nginx.conf
# Weblate nginx snippet
2025-07-16 15:11:55 +02:00
cat > /etc/nginx/snippets/weblate.conf << EOT
location /static/ {
# DATA_DIR/static/
2020-04-04 13:25:36 +02:00
alias $WEBLATE_HOME/data/static/;
expires 30d;
}
location /media/ {
# DATA_DIR/media/
2020-04-04 13:25:36 +02:00
alias $WEBLATE_HOME/data/media/;
expires 30d;
}
location / {
include uwsgi_params;
# Needed for long running operations in admin interface
uwsgi_read_timeout 3600;
# Adjust based to uwsgi configuration:
uwsgi_pass unix:///run/uwsgi/app/weblate/socket;
# uwsgi_pass 127.0.0.1:8080;
}
client_max_body_size 20m;
error_page 500 502 504 /weblate_50x.html;
error_page 503 /weblate_503.html;
location = /weblate_503.html {
2020-04-04 13:25:36 +02:00
root $WEBLATE_HOME/weblate-env/lib/python$PYVER/site-packages/wllegal/templates;
internal;
}
location = /weblate_50x.html {
2020-04-04 13:25:36 +02:00
root $WEBLATE_HOME/weblate-env/lib/python$PYVER/site-packages/wllegal/templates;
internal;
}
2020-12-21 15:58:54 +01:00
access_log /var/log/nginx/access.log;
EOT
# Insert include after first server_name stanza
sed -i "0,/server_name $WEBLATE_DOMAIN.*/s//&\\ninclude snippets\/weblate.conf;/" /etc/nginx/sites-available/default
# Delete default location, replaced by snippet
sed -i ':a;N;$!ba;s/\(snippets\/weblate.conf;\)[^}]*}/\1/g' /etc/nginx/sites-available/default
2021-02-06 13:30:07 +01:00
systemctl enable nginx.service
systemctl restart nginx.service
# Licensee
2024-05-10 13:12:12 +02:00
apt install -y ruby-licensee
2020-02-20 12:52:13 +01:00
# Fail2ban
2020-04-04 13:25:36 +02:00
sudo -u weblate git clone https://github.com/WeblateOrg/fail2ban.git $WEBLATE_HOME/fail2ban
ln -s $WEBLATE_HOME/fail2ban/filter.d/* /etc/fail2ban/filter.d/
ln -s $WEBLATE_HOME/fail2ban/jail.d/* /etc/fail2ban/jail.d/
2023-08-22 11:01:11 +02:00
ln -s $WEBLATE_HOME/fail2ban/action.d/* /etc/fail2ban/action.d/
2020-02-20 12:52:13 +01:00
systemctl restart fail2ban.service