2023-03-15 14:20:57 +01:00
|
|
|
#!/bin/bash
|
2023-03-10 13:24:11 +01:00
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# shellcheck disable=SC1091
|
|
|
|
. /etc/weblate-bootstrap
|
|
|
|
|
2023-03-13 10:51:23 +01:00
|
|
|
if [ "$1" = "--nocert" ] ; then
|
2023-04-23 10:04:53 +02:00
|
|
|
CERT=0
|
2023-03-13 10:51:23 +01:00
|
|
|
shift
|
2023-04-27 14:05:46 +02:00
|
|
|
else
|
|
|
|
CERT=1
|
2023-03-13 10:51:23 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$1" = "--nomail" ] ; then
|
|
|
|
IGNORE_CHECKS=,weblate.E003
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
IGNORE_CHECKS=""
|
|
|
|
fi
|
|
|
|
|
2023-04-23 10:04:53 +02:00
|
|
|
if [ "$1" = "--migrate" ] ; then
|
|
|
|
MIGRATE=1
|
|
|
|
CERT=0
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
MIGRATE=0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$MIGRATE" -eq 0 ] ; then
|
|
|
|
adduser weblate --disabled-password --gecos Weblate
|
|
|
|
fi
|
2023-04-23 13:00:39 +02:00
|
|
|
usermod --append --groups adm weblate
|
|
|
|
usermod --append --groups docker weblate
|
2023-03-10 13:24:11 +01:00
|
|
|
|
|
|
|
WEBLATE_HOME=~weblate
|
2023-03-10 13:38:42 +01:00
|
|
|
WEBLATE_DOCKER="$WEBLATE_HOME/weblate"
|
2023-03-10 13:24:11 +01:00
|
|
|
|
2023-03-15 14:20:57 +01:00
|
|
|
cd /tmp
|
|
|
|
apt-get update
|
|
|
|
apt-get install --no-install-recommends -y\
|
|
|
|
fail2ban python3-pyinotify python3-systemd \
|
2024-04-09 12:41:12 +02:00
|
|
|
systemd-timesyncd \
|
2023-06-16 13:16:56 +02:00
|
|
|
rsyslog \
|
2023-03-15 14:20:57 +01:00
|
|
|
nginx \
|
|
|
|
openssh-client \
|
2023-09-11 13:56:01 +02:00
|
|
|
python3-certbot-nginx \
|
|
|
|
git
|
|
|
|
|
|
|
|
# Legal stuff
|
|
|
|
sudo -u weblate git clone https://github.com/WeblateOrg/wllegal.git $WEBLATE_HOME/wllegal
|
2023-03-15 14:20:57 +01:00
|
|
|
|
|
|
|
# SSL cert
|
2023-04-23 10:04:53 +02:00
|
|
|
if [ "$CERT" -eq 1 ] ; then
|
2023-03-15 14:20:57 +01:00
|
|
|
certbot --agree-tos --email care@weblate.org --redirect --no-eff-email -d "$WEBLATE_DOMAIN"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Enable http/2
|
|
|
|
sed -i -e 's/ssl;/ssl http2;/' -e 's/ssl ipv6only=on/ssl ipv6only=on http2/' /etc/nginx/sites-available/default
|
2023-04-23 10:04:53 +02:00
|
|
|
if [ "$MIGRATE" -eq 0 ] ; then
|
|
|
|
# Enable status locally
|
|
|
|
sed -i '/server_name _/a location = /nginx_status {\n stub_status;\n}' /etc/nginx/sites-available/default
|
|
|
|
fi
|
2023-03-15 14:20:57 +01:00
|
|
|
# Hide server version
|
|
|
|
sed -i 's/# server_tokens off/server_tokens off/' /etc/nginx/nginx.conf
|
|
|
|
|
|
|
|
# Weblate nginx snippet
|
|
|
|
cat > /etc/nginx/snippets/weblate.conf <<EOT
|
|
|
|
location / {
|
|
|
|
proxy_pass http://127.0.0.1:8080;
|
2023-06-30 07:46:56 +02:00
|
|
|
proxy_read_timeout 3600s;
|
2023-03-15 14:20:57 +01:00
|
|
|
proxy_set_header Host \$host;
|
|
|
|
proxy_set_header X-Forwarded-Proto https;
|
|
|
|
proxy_set_header X-Real-IP \$remote_addr;
|
|
|
|
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
|
|
|
|
proxy_set_header X-Forwarded-Host \$server_name;
|
|
|
|
}
|
2025-02-17 14:56:51 +01:00
|
|
|
client_max_body_size 1000m;
|
2023-03-16 09:32:36 +01:00
|
|
|
error_page 500 502 504 /weblate_50x.html;
|
|
|
|
error_page 503 /weblate_503.html;
|
|
|
|
location = /weblate_503.html {
|
|
|
|
root $WEBLATE_HOME/wllegal/wllegal/templates;
|
|
|
|
internal;
|
|
|
|
}
|
|
|
|
location = /weblate_50x.html {
|
|
|
|
root $WEBLATE_HOME/wllegal/wllegal/templates;
|
|
|
|
internal;
|
|
|
|
}
|
2023-03-15 14:20:57 +01:00
|
|
|
access_log /var/log/nginx/access.log;
|
|
|
|
EOT
|
2023-04-23 10:04:53 +02:00
|
|
|
|
|
|
|
if [ "$MIGRATE" -eq 0 ] ; then
|
|
|
|
# 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
|
|
|
|
fi
|
2023-03-15 14:20:57 +01:00
|
|
|
systemctl enable nginx.service
|
|
|
|
systemctl restart nginx.service
|
|
|
|
|
|
|
|
# Fail2ban
|
2023-04-23 10:04:53 +02:00
|
|
|
if [ ! -d "$WEBLATE_HOME/fail2ban" ] ; then
|
|
|
|
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/
|
|
|
|
systemctl restart fail2ban.service
|
|
|
|
fi
|
2023-03-15 14:20:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
# Install Weblate dirs
|
2023-03-15 14:26:42 +01:00
|
|
|
mkdir -p "$WEBLATE_DOCKER" "$WEBLATE_HOME/cache" "$WEBLATE_HOME/data" "$WEBLATE_HOME/postgresql" "$WEBLATE_HOME/redis"
|
2023-03-10 14:11:11 +01:00
|
|
|
|
|
|
|
# Go to the docker dir
|
2023-04-23 10:04:53 +02:00
|
|
|
cd "$WEBLATE_DOCKER"
|
2023-03-10 14:11:11 +01:00
|
|
|
|
2023-03-15 14:20:57 +01:00
|
|
|
curl -fsSL https://raw.githubusercontent.com/WeblateOrg/docker-compose/main/docker-compose.yml > docker-compose.yml
|
2023-03-10 14:11:11 +01:00
|
|
|
curl -fsSL https://raw.githubusercontent.com/WeblateOrg/docker-compose/main/environment > environment
|
|
|
|
cat > docker-compose.override.yml <<EOT
|
2023-03-10 13:24:11 +01:00
|
|
|
services:
|
|
|
|
weblate:
|
2023-03-16 09:06:04 +01:00
|
|
|
image: weblate/weblate:edge
|
2023-03-15 14:26:12 +01:00
|
|
|
ports:
|
|
|
|
- 127.0.0.1:8080:8080
|
2023-03-16 09:56:08 +01:00
|
|
|
database:
|
|
|
|
ports:
|
|
|
|
- 127.0.0.1:5432:5432
|
|
|
|
cache:
|
|
|
|
ports:
|
|
|
|
- 127.0.0.1:6379:6379
|
2023-03-10 13:24:11 +01:00
|
|
|
volumes:
|
|
|
|
weblate-data:
|
|
|
|
driver: local
|
|
|
|
driver_opts:
|
|
|
|
type: 'none'
|
|
|
|
o: 'bind'
|
|
|
|
device: '$WEBLATE_HOME/data'
|
2023-03-15 14:20:57 +01:00
|
|
|
weblate-cache:
|
|
|
|
driver: local
|
|
|
|
driver_opts:
|
|
|
|
type: 'none'
|
|
|
|
o: 'bind'
|
|
|
|
device: '$WEBLATE_HOME/cache'
|
2023-03-10 13:24:11 +01:00
|
|
|
postgres-data:
|
|
|
|
driver: local
|
|
|
|
driver_opts:
|
|
|
|
type: 'none'
|
|
|
|
o: 'bind'
|
|
|
|
device: '$WEBLATE_HOME/postgresql'
|
|
|
|
redis-data:
|
|
|
|
driver: local
|
|
|
|
driver_opts:
|
|
|
|
type: 'none'
|
|
|
|
o: 'bind'
|
|
|
|
device: '$WEBLATE_HOME/redis'
|
|
|
|
EOT
|
|
|
|
|
2023-03-10 14:11:11 +01:00
|
|
|
cat >> environment <<EOT
|
2023-03-10 13:24:11 +01:00
|
|
|
|
|
|
|
# E-mail setup
|
2025-02-25 12:39:43 +01:00
|
|
|
WEBLATE_EMAIL_HOST=172.16.0.84
|
2023-03-10 13:24:11 +01:00
|
|
|
WEBLATE_EMAIL_PORT=587
|
2025-02-25 12:39:43 +01:00
|
|
|
WEBLATE_EMAIL_USE_TLS=0
|
2023-03-10 13:24:11 +01:00
|
|
|
|
|
|
|
# Hosted customization
|
|
|
|
WEBLATE_SERVER_EMAIL=noreply@weblate.org
|
|
|
|
WEBLATE_DEFAULT_FROM_EMAIL=noreply@weblate.org
|
|
|
|
WEBLATE_SITE_TITLE="$WEBLATE_TITLE"
|
|
|
|
WEBLATE_SITE_DOMAIN="$WEBLATE_DOMAIN"
|
|
|
|
WEBLATE_ADMIN_NAME='Michal Čihař'
|
|
|
|
WEBLATE_ADMIN_EMAIL='michal@cihar.com'
|
|
|
|
WEBLATE_DEFAULT_COMMITER_EMAIL='hosted@weblate.org'
|
|
|
|
WEBLATE_DEFAULT_COMMITER_NAME='Hosted Weblate'
|
|
|
|
WEBLATE_STATUS_URL="https://status.weblate.org/"
|
|
|
|
WEBLATE_GET_HELP_URL="https://care.weblate.org/"
|
|
|
|
WEBLATE_CONTACT_FORM="from"
|
2023-04-29 10:53:30 +02:00
|
|
|
WEBLATE_ADMINS_CONTACT='care@weblate.org'
|
2023-03-13 10:51:23 +01:00
|
|
|
WEBLATE_SILENCED_SYSTEM_CHECKS=weblate.E012,weblate.E013$IGNORE_CHECKS
|
2024-11-29 15:11:43 +01:00
|
|
|
WEBLATE_ZAMMAD_URL=https://care.weblate.org
|
2023-03-10 13:24:11 +01:00
|
|
|
|
|
|
|
# Sentry integration
|
|
|
|
SENTRY_DSN="$WEBLATE_SENTRY"
|
|
|
|
SENTRY_TOKEN="$WEBLATE_SENTRY_TOKEN"
|
|
|
|
SENTRY_TRACES_SAMPLE_RATE="0.1"
|
|
|
|
|
|
|
|
# Registration
|
|
|
|
WEBLATE_REGISTRATION_OPEN=0
|
|
|
|
WEBLATE_REQUIRE_LOGIN=1
|
|
|
|
WEBLATE_LEGAL_INTEGRATION=wllegal
|
|
|
|
|
2023-03-15 14:20:57 +01:00
|
|
|
# SSL
|
|
|
|
WEBLATE_ENABLE_HTTPS=1
|
|
|
|
WEBLATE_IP_PROXY_HEADER=HTTP_X_FORWARDED_FOR
|
2023-03-10 13:24:11 +01:00
|
|
|
EOT
|
2023-03-10 13:38:42 +01:00
|
|
|
|
|
|
|
# Fix permissions
|
|
|
|
chown -R weblate:weblate $WEBLATE_HOME
|
|
|
|
|
2023-04-23 10:04:53 +02:00
|
|
|
# Fetch Weblate containers
|
|
|
|
sudo -u weblate docker compose pull
|
|
|
|
|
|
|
|
if [ "$MIGRATE" -eq 1 ] ; then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2023-03-10 13:38:42 +01:00
|
|
|
# Start Weblate
|
2023-03-13 10:15:26 +01:00
|
|
|
sudo -u weblate docker compose up -d --wait
|
2023-03-10 13:52:34 +01:00
|
|
|
|
|
|
|
# Show logs
|
2023-03-11 15:55:42 +01:00
|
|
|
sudo -u weblate docker compose logs
|
2023-03-10 13:38:42 +01:00
|
|
|
|
2023-03-15 10:23:47 +01:00
|
|
|
# Track deploy to Sentry
|
2023-03-15 14:44:17 +01:00
|
|
|
if [ -n "$WEBLATE_SENTRY_TOKEN" ] ; then
|
2024-06-12 14:18:40 +02:00
|
|
|
sudo -u weblate docker compose exec --user weblate weblate weblate sentry_deploy || true
|
2023-03-15 14:44:17 +01:00
|
|
|
fi
|
2023-03-15 10:23:47 +01:00
|
|
|
|
2023-03-15 10:30:11 +01:00
|
|
|
# Create admin user
|
|
|
|
if [ -n "$WEBLATE_PASSWORD" ] ; then
|
|
|
|
sudo -u weblate docker compose exec --user weblate weblate weblate createadmin --username nijel --email michal@cihar.com --name 'Michal Čihař' --password "$WEBLATE_PASSWORD" --update
|
|
|
|
fi
|
|
|
|
|
2023-06-07 11:37:03 +02:00
|
|
|
# Machinery configuration
|
2023-06-16 13:54:08 +02:00
|
|
|
if [ "$CERT" -eq 1 ] ; then
|
|
|
|
sudo -u weblate docker compose exec --user weblate weblate weblate install_machinery --service libretranslate --configuration '{"key": "", "url": "http://172.16.0.9:5000/"}'
|
|
|
|
sudo -u weblate docker compose exec --user weblate weblate weblate install_machinery --service apertium-apy --configuration '{"url": "http://172.16.0.9:2737/"}'
|
|
|
|
fi
|
2023-06-07 11:37:03 +02:00
|
|
|
|
2023-03-10 13:38:42 +01:00
|
|
|
# Check
|
2023-03-11 15:55:42 +01:00
|
|
|
sudo -u weblate docker compose exec --user weblate weblate weblate check --deploy
|