scripts/create-monitor-user
renovate[bot] 64d215f99d
chore(deps): update pre-commit hook scop/pre-commit-shfmt to v3.12.0-1 (#307)
* chore(deps): update pre-commit hook scop/pre-commit-shfmt to v3.12.0-1

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-07-07 23:34:04 +00:00

29 lines
1.1 KiB
Bash
Executable file

#!/bin/sh
KEY="$(sed -n '/^env.KEY/ s/^env.KEY \(.*\)/\1/p' /etc/munin/plugin-conf.d/weblate_servers)"
SERVER="$(sed -n '/^env.SERVER/ s/^env.SERVER \(.*\)/\1/p' /etc/munin/plugin-conf.d/weblate_servers)"
if [ -z "$SERVER" ]; then
echo "Missing server configuration!"
exit 1
fi
if [ -n "$KEY" ]; then
if ! curl -f -s -H "Authorization: Token $KEY" "${SERVER}api/metrics/" -o /dev/null; then
echo "Key not working, recreating"
KEY=""
fi
fi
if [ -z "$KEY" ]; then
echo "Generating new key"
if [ -f "/home/weblate/weblate/docker-compose.override.yml" ]; then
cd /home/weblate/weblate || exit 1
KEY="$(sudo -u weblate docker compose exec --user weblate weblate weblate shell --no-imports -c 'from weblate.auth.models import User; user = User.objects.get_or_create(username="monitor")[0]; print(user.auth_token.key)')"
else
KEY="$(sudo -u weblate /home/weblate/weblate-env/bin/weblate shell --no-imports -c 'from weblate.auth.models import User; user = User.objects.get_or_create(username="monitor")[0]; print(user.auth_token.key)')"
fi
sed -i "s/^env.KEY .*/env.KEY $KEY/" /etc/munin/plugin-conf.d/weblate_servers
fi