#!/bin/bash # # Authelia Service PATH=$HOME/.docker/cli-plugins:/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin get_appvars config_authelia() { echo -ne "\n* Configuring /federated/apps/authelia container.." if [ ! -d "/federated/apps/authelia" ]; then mkdir -p /federated/apps/authelia/data/config mkdir -p /federated/apps/authelia/data/secrets fi cat > /federated/apps/authelia/docker-compose.yml < /federated/apps/authelia/data/secrets/JWT_SECRET tr -cd '[:alnum:]' < /dev/urandom | fold -w "64" | head -n 1 > /federated/apps/authelia/data/secrets/SESSION_SECRET tr -cd '[:alnum:]' < /dev/urandom | fold -w "64" | head -n 1 > /federated/apps/authelia/data/secrets/STORAGE_ENCRYPTION_KEY echo "$LDAP_SECRET" > /federated/apps/authelia/data/secrets/AUTHENTICATION_BACKEND_LDAP_PASSWORD echo "$ADMINPASS" > /federated/apps/authelia/data/secrets/NOTIFIER_SMTP_PASSWORD openssl genrsa -out /federated/apps/authelia/data/secrets/private.pem 4096 openssl rsa -in /federated/apps/authelia/data/secrets/private.pem -outform PEM -pubout -out /federated/apps/authelia/data/secrets/public.pem POWERDNS_CLIENT_SECRET=$(create_password); POWERDNS_CLIENT_SECRET_HASH=$(docker run -it --rm authelia/authelia:latest authelia crypto hash generate pbkdf2 --password $POWERDNS_CLIENT_SECRET | awk '{ print $2 }') [[ -d "/federated/apps/pdnsmysql/data/var/lib/mysql/pdnsadmin" ]] && POWERDNS_DB="pdnsadmin" || POWERDNS_DB="pdns" NEXTCLOUD_CLIENT_SECRET=$(create_password); NEXTCLOUD_CLIENT_SECRET_HASH=$(docker run -it --rm authelia/authelia:latest authelia crypto hash generate pbkdf2 --password $NEXTCLOUD_CLIENT_SECRET | awk '{ print $2 }') cat > /federated/apps/authelia/.env < /federated/apps/authelia/data/config/configuration.yml < /federated/apps/authelia/data/config/idproviders.yml < /dev/null" "7" docker exec pdns pdnsutil add-record $DOMAIN authelia A 86400 $EXTERNALIP &> /dev/null [ $? -ne 0 ] && fail "Couldn't add dns record for authelia" # If extra_hosts doesn't exist then insert extra_host configuration in pdnsadmin [[ ! $(grep extra_hosts /federated/apps/pdnsadmin/docker-compose.yml 2>/dev/null) ]] && sed -i "/192.168.0.12/a \ extra_hosts:\n\ - \"authelia.$DOMAIN:$EXTERNALIP\"" /federated/apps/pdnsadmin/docker-compose.yml # Stop and start pdnsadmin for internal dns externalhosts to work /federated/bin/stop pdnsadmin /federated/bin/start pdnsadmin echo -ne "done." } uninstall_authelia() { echo -ne "* Uninstalling authelia container.." spin & SPINPID=$! # First stop the service cd /federated/apps/authelia && docker-compose -f docker-compose.yml -p authelia down &> /dev/null # Delete the entries in the settings table [[ -d "/federated/apps/pdnsmysql/data/var/lib/mysql/pdnsadmin" ]] && POWERDNS_DB="pdnsadmin" || POWERDNS_DB="pdns" docker exec pdnsmysql mysql -uroot -p$MYSQL_ROOTPASSWORD $POWERDNS_DB -e "delete from setting where name like '%oidc_oauth%';" # Delete the app directory rm -rf /federated/apps/authelia # Delete the image docker image rm authelia/authelia:$IMAGE_VERSION &> /dev/null # Delete the DNS record docker exec pdns pdnsutil delete-rrset $DOMAIN authelia A kill -9 $SPINPID &> /dev/null echo -ne "done.\n" }