diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cf7711c..31700e1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -53,7 +53,7 @@ repos: hooks: - id: actionlint - repo: https://github.com/scop/pre-commit-shfmt - rev: v3.11.0-1 + rev: v3.12.0-1 hooks: - id: shfmt - repo: https://github.com/adamchainz/blacken-docs diff --git a/bootstrap b/bootstrap index 7251b57..833ff60 100755 --- a/bootstrap +++ b/bootstrap @@ -4,33 +4,33 @@ echo "Weblate domain:" read -r domain cloud_domain="${domain%.weblate.cloud}" if [ "$cloud_domain" = "$domain" ]; then - echo "Cloud domain (without .weblate.cloud):" - read -r cloud_domain + echo "Cloud domain (without .weblate.cloud):" + read -r cloud_domain fi echo "Weblate title:" read -r title if [ -f ~/.config/weblate-bootstrap/sentry_dsn ]; then - sentry=$(cat ~/.config/weblate-bootstrap/sentry_dsn) + sentry=$(cat ~/.config/weblate-bootstrap/sentry_dsn) else - echo "Sentry DSN:" - read -r sentry + echo "Sentry DSN:" + read -r sentry fi if [ -f ~/.config/weblate-bootstrap/sentry_token ]; then - sentry_token=$(cat ~/.config/weblate-bootstrap/sentry_token) + sentry_token=$(cat ~/.config/weblate-bootstrap/sentry_token) else - echo "Sentry Token:" - read -r sentry_token + echo "Sentry Token:" + read -r sentry_token fi if [ -f ~/.config/weblate-bootstrap/graylog_token ]; then - graylog_token=$(cat ~/.config/weblate-bootstrap/graylog_token) + graylog_token=$(cat ~/.config/weblate-bootstrap/graylog_token) else - echo "Graylog Token:" - read -r graylog_token + echo "Graylog Token:" + read -r graylog_token fi smtp_pass=$(openssl rand -hex 32) -cat > "${1:-/etc/weblate-bootstrap}" << EOT +cat >"${1:-/etc/weblate-bootstrap}" < /etc/fail2ban/jail.d/sshd.conf << EOT +cat >/etc/fail2ban/jail.d/sshd.conf < /etc/apt/sources.list.d/docker.list + "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/$(lsb_release -is | tr '[:upper:]' '[:lower:]') \ + $(lsb_release -cs) stable" >/etc/apt/sources.list.d/docker.list # Install Docker apt-get update apt-get install -y \ - docker-ce \ - docker-ce-cli \ - containerd.io \ - docker-buildx-plugin \ - docker-compose-plugin + docker-ce \ + docker-ce-cli \ + containerd.io \ + docker-buildx-plugin \ + docker-compose-plugin diff --git a/install-exim b/install-exim index 3b71f52..6873428 100755 --- a/install-exim +++ b/install-exim @@ -8,12 +8,12 @@ set -e apt install -y exim4 sed -i \ - -e "s#dc_eximconfig_configtype=.*#dc_eximconfig_configtype='satellite'#" \ - -e "s#dc_local_interfaces=.*#dc_local_interfaces='127.0.0.1'#" \ - -e "s#dc_readhost=.*#dc_readhost='$WEBLATE_DOMAIN'#" \ - -e "s#dc_smarthost=.*#dc_smarthost='172.16.0.84'#" \ - -e "s#dc_hide_mailname=.*#dc_hide_mailname='true'#" \ - /etc/exim4/update-exim4.conf.conf + -e "s#dc_eximconfig_configtype=.*#dc_eximconfig_configtype='satellite'#" \ + -e "s#dc_local_interfaces=.*#dc_local_interfaces='127.0.0.1'#" \ + -e "s#dc_readhost=.*#dc_readhost='$WEBLATE_DOMAIN'#" \ + -e "s#dc_smarthost=.*#dc_smarthost='172.16.0.84'#" \ + -e "s#dc_hide_mailname=.*#dc_hide_mailname='true'#" \ + /etc/exim4/update-exim4.conf.conf #cat >> /etc/exim4/passwd.client < /etc/munin/plugin-conf.d/postgres << EOT +cat >/etc/munin/plugin-conf.d/postgres < /etc/munin/plugin-conf.d/redis << EOT +cat >/etc/munin/plugin-conf.d/redis < /etc/munin/plugin-conf.d/weblate_servers << EOT +cat >/etc/munin/plugin-conf.d/weblate_servers <> "$BOOTSTRAP" << EOT +cat >>"$BOOTSTRAP" <> "$SETTINGS_PY" +cat <>"$SETTINGS_PY" # Hosted customization ADMINS_CONTACT = ['care@weblate.org'] @@ -131,15 +131,15 @@ EOT # Fill the database sudo -u weblate $WEBLATE_HOME/weblate-env/bin/weblate migrate if [ -n "$WEBLATE_PASSWORD" ]; then - sudo -u weblate $WEBLATE_HOME/weblate-env/bin/weblate createadmin --username nijel --email michal@cihar.com --name 'Michal Čihař' --password "$WEBLATE_PASSWORD" + sudo -u weblate $WEBLATE_HOME/weblate-env/bin/weblate createadmin --username nijel --email michal@cihar.com --name 'Michal Čihař' --password "$WEBLATE_PASSWORD" else - sudo -u weblate $WEBLATE_HOME/weblate-env/bin/weblate createadmin --username nijel --email michal@cihar.com --name 'Michal Čihař' + sudo -u weblate $WEBLATE_HOME/weblate-env/bin/weblate createadmin --username nijel --email michal@cihar.com --name 'Michal Čihař' fi 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 if ! grep -q "SENTRY_TOKEN = ''" "$SETTINGS_PY"; then - sudo -u weblate "$WEBLATE_HOME/weblate-env/bin/weblate" sentry_deploy + sudo -u weblate "$WEBLATE_HOME/weblate-env/bin/weblate" sentry_deploy fi # Celery and uwsgi @@ -156,7 +156,7 @@ systemctl restart uwsgi.service # SSL cert if [ "$1" != "--nocert" ]; then - certbot --agree-tos --email care@weblate.org --redirect --no-eff-email -d "$WEBLATE_DOMAIN" + certbot --agree-tos --email care@weblate.org --redirect --no-eff-email -d "$WEBLATE_DOMAIN" fi # Enable http/2 @@ -168,7 +168,7 @@ 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 -cat > /etc/nginx/snippets/weblate.conf << EOT +cat >/etc/nginx/snippets/weblate.conf < /etc/nginx/snippets/weblate.conf << EOT +cat >/etc/nginx/snippets/weblate.conf < /etc/nginx/snippets/weblate.conf << EOT EOT 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 + # 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 systemctl enable nginx.service systemctl restart nginx.service # Fail2ban 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 + 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 # Install Weblate dirs @@ -111,9 +111,9 @@ mkdir -p "$WEBLATE_DOCKER" "$WEBLATE_HOME/cache" "$WEBLATE_HOME/data" "$WEBLATE_ # Go to the docker dir cd "$WEBLATE_DOCKER" -curl -fsSL https://raw.githubusercontent.com/WeblateOrg/docker-compose/main/docker-compose.yml > docker-compose.yml -curl -fsSL https://raw.githubusercontent.com/WeblateOrg/docker-compose/main/environment > environment -cat > docker-compose.override.yml << EOT +curl -fsSL https://raw.githubusercontent.com/WeblateOrg/docker-compose/main/docker-compose.yml >docker-compose.yml +curl -fsSL https://raw.githubusercontent.com/WeblateOrg/docker-compose/main/environment >environment +cat >docker-compose.override.yml <> environment << EOT +cat >>environment < "$WEBLATE_HOME/weblate.sql" +sudo -u "postgres" pg_dump --no-privileges --no-owner --clean --if-exists weblate >"$WEBLATE_HOME/weblate.sql" systemctl stop postgresql cd "$WEBLATE_DOCKER" docker compose up -d database --wait sleep 60 -docker compose exec -T database psql --username weblate --dbname weblate < "$WEBLATE_HOME/weblate.sql" +docker compose exec -T database psql --username weblate --dbname weblate <"$WEBLATE_HOME/weblate.sql" # Move redis data cp /var/lib/redis/dump.rdb "$WEBLATE_HOME/redis" @@ -50,9 +50,9 @@ chown -R 1000:1000 "$WEBLATE_HOME/data" # Cleanup system packages apt-get purge -y \ - redis-server \ - uwsgi \ - postgresql + redis-server \ + uwsgi \ + postgresql # Start Weblate sudo -u weblate docker compose up -d --wait @@ -62,7 +62,7 @@ sudo -u weblate docker compose logs # Track deploy to Sentry if [ -n "$WEBLATE_SENTRY_TOKEN" ]; then - sudo -u weblate docker compose exec --user weblate weblate weblate sentry_deploy + sudo -u weblate docker compose exec --user weblate weblate weblate sentry_deploy fi # Check diff --git a/upgrade-nginx-ssl b/upgrade-nginx-ssl index 36f4013..3e1a882 100755 --- a/upgrade-nginx-ssl +++ b/upgrade-nginx-ssl @@ -9,7 +9,7 @@ sed -i '/\/etc\/letsencrypt\/options-ssl-nginx.conf/ D' /etc/nginx/sites-availab sed -i -e '/ssl_protocols/D' -e '/ssl_prefer_server_ciphers/D' /etc/nginx/nginx.conf # Update SSL config -cat > /etc/nginx/conf.d/ssl.conf << EOT +cat >/etc/nginx/conf.d/ssl.conf < /etc/nginx/ffdhe4096.pem + curl https://ssl-config.mozilla.org/ffdhe2048.txt >/etc/nginx/ffdhe4096.pem fi # Reload ngxin diff --git a/upgrade-weblate b/upgrade-weblate index 10a4e01..2827467 100755 --- a/upgrade-weblate +++ b/upgrade-weblate @@ -5,73 +5,73 @@ set -e cd /tmp if [ -f /etc/weblate-bootstrap ]; then - # shellcheck disable=SC1091 - . /etc/weblate-bootstrap + # shellcheck disable=SC1091 + . /etc/weblate-bootstrap fi DO_DIFF=1 LAZY_RESTART=0 usage() { - echo "Usage: upgrade-weblate [--no-diff] [--lazy-restart]" + echo "Usage: upgrade-weblate [--no-diff] [--lazy-restart]" } PARSED_ARGUMENTS=$(getopt -a -n upgrade-weblate -o drh --long help,nodiff,no-diff,lazy-restart -- "$@") VALID_ARGUMENTS=$? if [ "$VALID_ARGUMENTS" != "0" ]; then - echo "Invalid arguments" - usage - exit 1 + echo "Invalid arguments" + usage + exit 1 fi eval set -- "$PARSED_ARGUMENTS" while :; do - case "$1" in - -d | --nodiff | --no-diff) - DO_DIFF=0 - shift - ;; - -r | --lazy-restart) - LAZY_RESTART=1 - shift - ;; - -h | --help) - usage - exit - ;; - --) - shift - break - ;; - *) - echo "Unexpected option: $1 - this should not happen." - usage - exit 1 - ;; - esac + case "$1" in + -d | --nodiff | --no-diff) + DO_DIFF=0 + shift + ;; + -r | --lazy-restart) + LAZY_RESTART=1 + shift + ;; + -h | --help) + usage + exit + ;; + --) + shift + break + ;; + *) + echo "Unexpected option: $1 - this should not happen." + usage + exit 1 + ;; + esac done # Detect user if [ -n "$WEBLATE_USERNAME" ]; then - USERNAME=$WEBLATE_USERNAME + USERNAME=$WEBLATE_USERNAME else - for u in weblate ec2-user apache; do - if id $u > /dev/null 2>&1; then - USERNAME=$u - break - fi - done + for u in weblate ec2-user apache; do + if id $u >/dev/null 2>&1; then + USERNAME=$u + break + fi + done fi if [ -z "$USERNAME" ]; then - echo "Could not detect username!" - exit 1 + echo "Could not detect username!" + exit 1 fi if [ "$USERNAME" = root ] && [ -d /opt/weblate ]; then - WEBLATE_HOME=/opt/weblate - WEBLATE_USERNAME=apache + WEBLATE_HOME=/opt/weblate + WEBLATE_USERNAME=apache else - WEBLATE_HOME=$(getent passwd "$USERNAME" | cut -d: -f 6) - WEBLATE_USERNAME=$USERNAME + WEBLATE_HOME=$(getent passwd "$USERNAME" | cut -d: -f 6) + WEBLATE_USERNAME=$USERNAME fi # At this point: @@ -79,173 +79,173 @@ fi # USERNAME is user owning Weblate sources if [ -f "$WEBLATE_HOME/weblate/docker-compose.override.yml" ]; then - # Docker based upgrade - cd "$WEBLATE_HOME/weblate" - sudo -u weblate docker compose pull - sudo -u weblate docker compose up -d --wait - sudo -u weblate docker compose logs - sudo -u weblate docker image prune --all --force - sudo -u weblate docker compose exec --user weblate weblate weblate check --deploy || true - sudo -u weblate docker compose exec --user weblate weblate weblate sentry_deploy || true + # Docker based upgrade + cd "$WEBLATE_HOME/weblate" + sudo -u weblate docker compose pull + sudo -u weblate docker compose up -d --wait + sudo -u weblate docker compose logs + sudo -u weblate docker image prune --all --force + sudo -u weblate docker compose exec --user weblate weblate weblate check --deploy || true + sudo -u weblate docker compose exec --user weblate weblate weblate sentry_deploy || true else - # Detect web service - for service in gunicorn.service uwsgi.service httpd.service; do - if systemctl cat -- $service > /dev/null 2>&1; then - SERVICE=$service - break - fi - done - if [ -z "$SERVICE" ]; then - echo "Could not detect web service!" - exit 1 - fi + # Detect web service + for service in gunicorn.service uwsgi.service httpd.service; do + if systemctl cat -- $service >/dev/null 2>&1; then + SERVICE=$service + break + fi + done + if [ -z "$SERVICE" ]; then + echo "Could not detect web service!" + exit 1 + fi - if [ "$WEBLATE_HOME" = /opt/weblate ]; then - WEBLATE_ENV="/opt/weblate" - else - WEBLATE_ENV="$WEBLATE_HOME/weblate-env" - fi + if [ "$WEBLATE_HOME" = /opt/weblate ]; then + WEBLATE_ENV="/opt/weblate" + else + WEBLATE_ENV="$WEBLATE_HOME/weblate-env" + fi - PYVER="$("$WEBLATE_ENV/bin/python" -c 'import sys; print("{}.{}".format(*sys.version_info[:2]))')" + PYVER="$("$WEBLATE_ENV/bin/python" -c 'import sys; print("{}.{}".format(*sys.version_info[:2]))')" - if [ -d "$WEBLATE_HOME/weblate-src" ]; then - WEBLATE_DIR="$WEBLATE_HOME/weblate-src" - WEBLATE_PKG="$WEBLATE_DIR" - PIP_ARGS="--editable" - elif [ -d "$WEBLATE_HOME/weblate" ]; then - WEBLATE_DIR="$WEBLATE_HOME/weblate" - WEBLATE_PKG="$WEBLATE_DIR" - PIP_ARGS="--editable" - else - WEBLATE_DIR="$WEBLATE_ENV/lib/python$PYVER/site-packages" - WEBLATE_PKG="Weblate" - PIP_ARGS="" - fi - WEBLATE_FLAGS="all,zxcvbn,wllegal" - if [ -d "$WEBLATE_HOME/hosted" ]; then - PIP_ARGS="--editable $WEBLATE_HOME/hosted $PIP_ARGS" - WEBLATE_FLAGS="$WEBLATE_FLAGS,mysql,saml2idp" - fi + if [ -d "$WEBLATE_HOME/weblate-src" ]; then + WEBLATE_DIR="$WEBLATE_HOME/weblate-src" + WEBLATE_PKG="$WEBLATE_DIR" + PIP_ARGS="--editable" + elif [ -d "$WEBLATE_HOME/weblate" ]; then + WEBLATE_DIR="$WEBLATE_HOME/weblate" + WEBLATE_PKG="$WEBLATE_DIR" + PIP_ARGS="--editable" + else + WEBLATE_DIR="$WEBLATE_ENV/lib/python$PYVER/site-packages" + WEBLATE_PKG="Weblate" + PIP_ARGS="" + fi + WEBLATE_FLAGS="all,zxcvbn,wllegal" + if [ -d "$WEBLATE_HOME/hosted" ]; then + PIP_ARGS="--editable $WEBLATE_HOME/hosted $PIP_ARGS" + WEBLATE_FLAGS="$WEBLATE_FLAGS,mysql,saml2idp" + fi - # Backup settings - cp "$WEBLATE_DIR/weblate/settings.py" "/root/weblate-settings-$(date -I).py" + # Backup settings + cp "$WEBLATE_DIR/weblate/settings.py" "/root/weblate-settings-$(date -I).py" - # Upgrade pip - sudo -u "$USERNAME" "$WEBLATE_ENV/bin/pip" install -U pip wheel + # Upgrade pip + sudo -u "$USERNAME" "$WEBLATE_ENV/bin/pip" install -U pip wheel - # Prebuild wheels, they are stored in the cache - WHEELS=$(mktemp -d) - chown "$USERNAME" "$WHEELS" - sudo -u "$USERNAME" "$WEBLATE_ENV/bin/pip" wheel --wheel-dir "$WHEELS" "Weblate[${WEBLATE_FLAGS}]" 'pygobject<3.52' - rm -rf "$WHEELS" + # Prebuild wheels, they are stored in the cache + WHEELS=$(mktemp -d) + chown "$USERNAME" "$WHEELS" + sudo -u "$USERNAME" "$WEBLATE_ENV/bin/pip" wheel --wheel-dir "$WHEELS" "Weblate[${WEBLATE_FLAGS}]" 'pygobject<3.52' + rm -rf "$WHEELS" - if [ $LAZY_RESTART -eq 0 ]; then - # Stop web - if [ "$SERVICE" = gunicorn.service ]; then - systemctl disable gunicorn.socket - fi - systemctl stop "$SERVICE" - # Wait for celery to process all jobs - while sudo -u "$WEBLATE_USERNAME" "$WEBLATE_ENV/bin/weblate" celery_queues | grep ': [^0]'; do - sleep 1 - done + if [ $LAZY_RESTART -eq 0 ]; then + # Stop web + if [ "$SERVICE" = gunicorn.service ]; then + systemctl disable gunicorn.socket + fi + systemctl stop "$SERVICE" + # Wait for celery to process all jobs + while sudo -u "$WEBLATE_USERNAME" "$WEBLATE_ENV/bin/weblate" celery_queues | grep ': [^0]'; do + sleep 1 + done - # Stop celery - systemctl stop celery-weblate.service - for WORKER in $WEBLATE_WORKERS; do - ssh "root@$WORKER" systemctl stop celery-weblate.service - done - fi + # Stop celery + systemctl stop celery-weblate.service + for WORKER in $WEBLATE_WORKERS; do + ssh "root@$WORKER" systemctl stop celery-weblate.service + done + fi - # Upgrade modules - if [ "$WEBLATE_PKG" != "Weblate" ]; then - OLD_DIR=$PWD - cd "$WEBLATE_DIR" - git config --global safe.directory "$WEBLATE_DIR" - OLD_HEAD=$(git log -n1 --format=%H) - sudo -u "$USERNAME" sh -c "cd $WEBLATE_DIR; git pull" - if [ -d "$WEBLATE_HOME/hosted" ]; then - sudo -u "$WEBLATE_USERNAME" sh -c "cd $WEBLATE_HOME/hosted; git pull -q" - fi - if [ "$DO_DIFF" -eq 1 ] && git diff --exit-code "$OLD_HEAD".. -- weblate/settings_example.py > /dev/null; then - DO_DIFF="0" - fi - cd "$OLD_DIR" - fi - # shellcheck disable=SC2086 - sudo -u "$USERNAME" "$WEBLATE_ENV/bin/pip" install 'pygobject<3.52' --upgrade-strategy eager --upgrade $PIP_ARGS "${WEBLATE_PKG}[${WEBLATE_FLAGS}]" + # Upgrade modules + if [ "$WEBLATE_PKG" != "Weblate" ]; then + OLD_DIR=$PWD + cd "$WEBLATE_DIR" + git config --global safe.directory "$WEBLATE_DIR" + OLD_HEAD=$(git log -n1 --format=%H) + sudo -u "$USERNAME" sh -c "cd $WEBLATE_DIR; git pull" + if [ -d "$WEBLATE_HOME/hosted" ]; then + sudo -u "$WEBLATE_USERNAME" sh -c "cd $WEBLATE_HOME/hosted; git pull -q" + fi + if [ "$DO_DIFF" -eq 1 ] && git diff --exit-code "$OLD_HEAD".. -- weblate/settings_example.py >/dev/null; then + DO_DIFF="0" + fi + cd "$OLD_DIR" + fi + # shellcheck disable=SC2086 + sudo -u "$USERNAME" "$WEBLATE_ENV/bin/pip" install 'pygobject<3.52' --upgrade-strategy eager --upgrade $PIP_ARGS "${WEBLATE_PKG}[${WEBLATE_FLAGS}]" - # Adjust configuration - if [ "$DO_DIFF" -eq 1 ]; then - vimdiff "$WEBLATE_DIR/weblate/settings_example.py" "$WEBLATE_DIR/weblate/settings.py" - fi - if [ -z "$WEBLATE_WORKERS" ]; then - sed "s@/home/weblate/weblate-env@$WEBLATE_ENV@" "$WEBLATE_DIR/weblate/examples/celery-weblate.conf" > /etc/default/celery-weblate - fi + # Adjust configuration + if [ "$DO_DIFF" -eq 1 ]; then + vimdiff "$WEBLATE_DIR/weblate/settings_example.py" "$WEBLATE_DIR/weblate/settings.py" + fi + if [ -z "$WEBLATE_WORKERS" ]; then + sed "s@/home/weblate/weblate-env@$WEBLATE_ENV@" "$WEBLATE_DIR/weblate/examples/celery-weblate.conf" >/etc/default/celery-weblate + fi - # Migrate database, compile gettext and collect static files - sudo -u "$WEBLATE_USERNAME" "$WEBLATE_ENV/bin/weblate" migrate - sudo -u "$WEBLATE_USERNAME" "$WEBLATE_ENV/bin/weblate" ensure_stats - sudo -u "$WEBLATE_USERNAME" "$WEBLATE_ENV/bin/weblate" collectstatic --noinput - sudo -u "$WEBLATE_USERNAME" "$WEBLATE_ENV/bin/weblate" compress --force - if ! grep -q UPDATE_LANGUAGES "$WEBLATE_DIR/weblate/settings.py"; then - sudo -u "$WEBLATE_USERNAME" "$WEBLATE_ENV/bin/weblate" setuplang - fi - if [ "$WEBLATE_DIR" = "$WEBLATE_HOME/weblate" ]; then - sudo -u "$WEBLATE_USERNAME" sh -c "cd $WEBLATE_DIR; $WEBLATE_ENV/bin/weblate compilemessages" - if [ -d "$WEBLATE_HOME/hosted" ]; then - sudo -u "$WEBLATE_USERNAME" sh -c "cd $WEBLATE_HOME/hosted; $WEBLATE_ENV/bin/weblate compilemessages" - fi - fi - # Track deploy at Sentry - if ! grep -q "SENTRY_TOKEN = ''" "$WEBLATE_DIR/weblate/settings.py"; then - sudo -u "$WEBLATE_USERNAME" "$WEBLATE_ENV/bin/weblate" sentry_deploy - fi + # Migrate database, compile gettext and collect static files + sudo -u "$WEBLATE_USERNAME" "$WEBLATE_ENV/bin/weblate" migrate + sudo -u "$WEBLATE_USERNAME" "$WEBLATE_ENV/bin/weblate" ensure_stats + sudo -u "$WEBLATE_USERNAME" "$WEBLATE_ENV/bin/weblate" collectstatic --noinput + sudo -u "$WEBLATE_USERNAME" "$WEBLATE_ENV/bin/weblate" compress --force + if ! grep -q UPDATE_LANGUAGES "$WEBLATE_DIR/weblate/settings.py"; then + sudo -u "$WEBLATE_USERNAME" "$WEBLATE_ENV/bin/weblate" setuplang + fi + if [ "$WEBLATE_DIR" = "$WEBLATE_HOME/weblate" ]; then + sudo -u "$WEBLATE_USERNAME" sh -c "cd $WEBLATE_DIR; $WEBLATE_ENV/bin/weblate compilemessages" + if [ -d "$WEBLATE_HOME/hosted" ]; then + sudo -u "$WEBLATE_USERNAME" sh -c "cd $WEBLATE_HOME/hosted; $WEBLATE_ENV/bin/weblate compilemessages" + fi + fi + # Track deploy at Sentry + if ! grep -q "SENTRY_TOKEN = ''" "$WEBLATE_DIR/weblate/settings.py"; then + sudo -u "$WEBLATE_USERNAME" "$WEBLATE_ENV/bin/weblate" sentry_deploy + fi - # Start the services - if [ $LAZY_RESTART -eq 0 ]; then - systemctl start celery-weblate.service - for WORKER in $WEBLATE_WORKERS; do - ssh "root@$WORKER" systemctl start celery-weblate.service - done - systemctl start "$SERVICE" - if [ "$SERVICE" = gunicorn.service ]; then - systemctl enable gunicorn.socket - fi - else - systemctl restart celery-weblate.service & - for WORKER in $WEBLATE_WORKERS; do - ssh "root@$WORKER" systemctl restart celery-weblate.service & - done - systemctl restart "$SERVICE" - fi + # Start the services + if [ $LAZY_RESTART -eq 0 ]; then + systemctl start celery-weblate.service + for WORKER in $WEBLATE_WORKERS; do + ssh "root@$WORKER" systemctl start celery-weblate.service + done + systemctl start "$SERVICE" + if [ "$SERVICE" = gunicorn.service ]; then + systemctl enable gunicorn.socket + fi + else + systemctl restart celery-weblate.service & + for WORKER in $WEBLATE_WORKERS; do + ssh "root@$WORKER" systemctl restart celery-weblate.service & + done + systemctl restart "$SERVICE" + fi fi # Upgrade legal if [ -d "$WEBLATE_HOME/wllegal" ]; then - sudo -u "$USERNAME" sh -c "cd $WEBLATE_HOME/wllegal && git pull" + sudo -u "$USERNAME" sh -c "cd $WEBLATE_HOME/wllegal && git pull" fi # Upgrade munin plugin if [ -d /usr/share/munin/plugins ]; then - wget -O - https://raw.githubusercontent.com/WeblateOrg/munin/master/weblate > /usr/share/munin/plugins/weblate - wget -O - https://raw.githubusercontent.com/WeblateOrg/munin/master/ksm > /usr/share/munin/plugins/ksm + wget -O - https://raw.githubusercontent.com/WeblateOrg/munin/master/weblate >/usr/share/munin/plugins/weblate + wget -O - https://raw.githubusercontent.com/WeblateOrg/munin/master/ksm >/usr/share/munin/plugins/ksm fi # Upgrade fail2ban if [ -d "$WEBLATE_HOME/fail2ban" ]; then - sudo -u "$USERNAME" sh -c "cd $WEBLATE_HOME/fail2ban && git pull" - # shellcheck disable=SC2086 - ln -sf $WEBLATE_HOME/fail2ban/filter.d/* /etc/fail2ban/filter.d/ - # shellcheck disable=SC2086 - ln -sf $WEBLATE_HOME/fail2ban/jail.d/* /etc/fail2ban/jail.d/ - # shellcheck disable=SC2086 - ln -sf $WEBLATE_HOME/fail2ban/action.d/* /etc/fail2ban/action.d/ - systemctl reload fail2ban.service + sudo -u "$USERNAME" sh -c "cd $WEBLATE_HOME/fail2ban && git pull" + # shellcheck disable=SC2086 + ln -sf $WEBLATE_HOME/fail2ban/filter.d/* /etc/fail2ban/filter.d/ + # shellcheck disable=SC2086 + ln -sf $WEBLATE_HOME/fail2ban/jail.d/* /etc/fail2ban/jail.d/ + # shellcheck disable=SC2086 + ln -sf $WEBLATE_HOME/fail2ban/action.d/* /etc/fail2ban/action.d/ + systemctl reload fail2ban.service fi if [ -n "$WEBLATE_WORKERS" ]; then - echo "Celery configuration not updated, using remote workers!" + echo "Celery configuration not updated, using remote workers!" fi