-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
create-monitor-user
executable file
·29 lines (23 loc) · 1.13 KB
/
create-monitor-user
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/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 -c 'from weblate.auth.models import User; user = User.objects.create(username="monitor"); print(user.auth_token.key)')"
else
KEY="$(sudo -u weblate /home/weblate/weblate-env/bin/weblate shell -c 'from weblate.auth.models import User; user = User.objects.create(username="monitor"); print(user.auth_token.key)')"
fi
sed -i "s/^env.KEY .*/env.KEY $KEY/" /etc/munin/plugin-conf.d/weblate_servers
fi