add fix_collation_mismatch function for db container

This commit is contained in:
2025-09-23 15:57:48 +02:00
parent 9d1d89ff81
commit fde3efb0d0

76
abra.sh
View File

@ -21,8 +21,7 @@ export PG_BACKUP_VERSION=v2
export ENTRYPOINT_CSS_VERSION=v1 export ENTRYPOINT_CSS_VERSION=v1
customize() { customize() {
if [ -z "$1" ] if [ -z "$1" ]; then
then
echo "Usage: ... customize <assets_path>" echo "Usage: ... customize <assets_path>"
exit 1 exit 1
fi fi
@ -35,9 +34,8 @@ customize() {
done done
} }
shell(){ shell() {
if [ -z "$1" ] if [ -z "$1" ]; then
then
echo "Usage: ... shell <python code>" echo "Usage: ... shell <python code>"
exit 1 exit 1
fi fi
@ -45,8 +43,7 @@ shell(){
} }
import_user() { import_user() {
if [ -z "$1" ] if [ -z "$1" ]; then
then
echo "Usage: ... import_user <users.csv>" echo "Usage: ... import_user <users.csv>"
exit 1 exit 1
fi fi
@ -57,7 +54,7 @@ import_user() {
} }
_import_user() { _import_user() {
/manage.py shell -c """ /manage.py shell -c """
import csv import csv
new_user = User() new_user = User()
with open('/tmp/$1', newline='') as file: with open('/tmp/$1', newline='') as file:
@ -85,9 +82,9 @@ with open('/tmp/$1', newline='') as file:
} }
set_admin_pass() { set_admin_pass() {
password=$(cat /run/secrets/admin_pass) password=$(cat /run/secrets/admin_pass)
token=$(cat /run/secrets/admin_token) token=$(cat /run/secrets/admin_token)
/manage.py shell -c """ /manage.py shell -c """
import time import time
i = 0 i = 0
while (not User.objects.filter(username='akadmin')): while (not User.objects.filter(username='akadmin')):
@ -160,7 +157,7 @@ apply_blueprint() {
} }
blueprint_state() { blueprint_state() {
/manage.py shell -c """ /manage.py shell -c """
import time import time
blueprint_state=$1 blueprint_state=$1
blueprint_path='$2' blueprint_path='$2'
@ -178,9 +175,9 @@ print(f'{blueprint.name} enabled: {blueprint.enabled}')
} }
# This function adds each application with its name, slug and group if passed # This function adds each application with its name, slug and group if passed
add_applications(){ add_applications() {
export APPLICATIONS export APPLICATIONS
/manage.py shell -c """ /manage.py shell -c """
import json import json
import os import os
if os.environ['APPLICATIONS'] == '': if os.environ['APPLICATIONS'] == '':
@ -207,7 +204,7 @@ for name, details in applications.items():
## This function is for renaming apps - usage: rename "old name" "new name" ## This function is for renaming apps - usage: rename "old name" "new name"
rename() { rename() {
/manage.py shell -c """ /manage.py shell -c """
old_name = '$1' old_name = '$1'
new_name = '$2' if '$2' else old_name new_name = '$2' if '$2' else old_name
@ -221,39 +218,35 @@ else:
""" 2>&1 | quieten """ 2>&1 | quieten
} }
quieten() {
quieten(){
# 'SyntaxWarning|version_regex|"http\[' # 'SyntaxWarning|version_regex|"http\['
# is a workaround to get rid of some verbose syntax warnings, this might be fixed with another version # is a workaround to get rid of some verbose syntax warnings, this might be fixed with another version
grep -Pv '"level": "(info|debug)"|SyntaxWarning|version_regex|"http\[|RuntimeWarning:' grep -Pv '"level": "(info|debug)"|SyntaxWarning|version_regex|"http\[|RuntimeWarning:'
} }
add_email_templates(){ add_email_templates() {
for file_path in "$@"; do for file_path in "$@"; do
echo copy template $file_path echo copy template $file_path
abra app cp $APP_NAME $file_path app:/templates/ abra app cp $APP_NAME $file_path app:/templates/
done done
} }
set_icons(){ set_icons() {
if [ -n "$1" ] if [ -n "$1" ]; then
then APP_ICONS="$1"
APP_ICONS="$1" fi
fi for icon in $APP_ICONS; do
for icon in $APP_ICONS; do
app=$(echo $icon | cut -d ":" -f1) app=$(echo $icon | cut -d ":" -f1)
file_path=$(eval echo $(echo $icon | cut -d ":" -f2)) file_path=$(eval echo $(echo $icon | cut -d ":" -f2))
file=$(basename $file_path) file=$(basename $file_path)
echo copy icon $file_path for $app echo copy icon $file_path for $app
abra app cp $APP_NAME $file_path app:/media/ abra app cp $APP_NAME $file_path app:/media/
abra app cmd -T $APP_NAME app set_app_icon $app /media/$file abra app cmd -T $APP_NAME app set_app_icon $app /media/$file
done done
} }
set_extra_icons(){ set_extra_icons() {
if [ -z "$EXTRA_ICONS" ] if [ -z "$EXTRA_ICONS" ]; then
then
echo "Variable EXTRA_ICONS is not set" echo "Variable EXTRA_ICONS is not set"
exit 1 exit 1
fi fi
@ -268,8 +261,8 @@ for key, value in json.loads(os.environ['EXTRA_ICONS']).items():
} }
set_app_icon() { set_app_icon() {
TOKEN=$(cat /run/secrets/admin_token) TOKEN=$(cat /run/secrets/admin_token)
python -c """ python -c """
import requests import requests
import os import os
my_token = '$TOKEN' my_token = '$TOKEN'
@ -288,18 +281,18 @@ with open(icon_path, 'rb') as img:
} }
blueprint_cleanup() { blueprint_cleanup() {
/manage.py shell -c """ /manage.py shell -c """
delete_flows = ['default-recovery-flow' , 'custom-authentication-flow' , 'invitation-enrollment-flow' , 'initial-setup'] delete_flows = ['default-recovery-flow' , 'custom-authentication-flow' , 'invitation-enrollment-flow' , 'initial-setup']
Flow.objects.filter(slug__in=delete_flows).delete() Flow.objects.filter(slug__in=delete_flows).delete()
Stage.objects.filter(flow=None).delete() Stage.objects.filter(flow=None).delete()
Prompt.objects.filter(promptstage=None).delete() Prompt.objects.filter(promptstage=None).delete()
Brand.objects.filter(default=True).delete() Brand.objects.filter(default=True).delete()
""" 2>&1 | quieten """ 2>&1 | quieten
apply_blueprints apply_blueprints
} }
get_certificate() { get_certificate() {
/manage.py shell -c """ /manage.py shell -c """
provider_name='$1' provider_name='$1'
if not provider_name: if not provider_name:
print('no Provider Name given') print('no Provider Name given')
@ -312,7 +305,14 @@ print(''.join(cert.certificate_data.splitlines()[1:-1]))
} }
get_user_uid() { get_user_uid() {
/manage.py shell -c """ /manage.py shell -c """
print(User.objects.filter(username='$1').first().uid) print(User.objects.filter(username='$1').first().uid)
""" 2>&1 | quieten """ 2>&1 | quieten
} }
fix_collation_mismatch() {
psql -U ${POSTGRES_USER} -d authentik -c "ALTER DATABASE authentik REFRESH COLLATION VERSION;"
psql -U ${POSTGRES_USER} -d authentik -c "REINDEX DATABASE authentik;"
psql -U ${POSTGRES_USER} -d postgres -c "ALTER DATABASE postgres REFRESH COLLATION VERSION;"
psql -U ${POSTGRES_USER} -d postgres -c "REINDEX DATABASE postgres;"
}