72 lines
2.3 KiB
Plaintext
72 lines
2.3 KiB
Plaintext
|
#!/usr/bin/with-contenv bash
|
||
|
|
||
|
mkdir -p /config/scripts
|
||
|
|
||
|
declare -A NETBOX_CONF
|
||
|
NETBOX_CONF[ALLOWED_HOST]=${ALLOWED_HOST:-netbox.example.com}
|
||
|
NETBOX_CONF[BASE_PATH]=${BASE_PATH:-}
|
||
|
NETBOX_CONF[DB_NAME]=${DB_NAME:-netbox}
|
||
|
NETBOX_CONF[DB_USER]=${DB_USER:-root}
|
||
|
NETBOX_CONF[DB_PASSWORD]=${DB_PASSWORD:-}
|
||
|
NETBOX_CONF[DB_HOST]=${DB_HOST:-postgres}
|
||
|
NETBOX_CONF[DB_PORT]=${DB_PORT:-}
|
||
|
NETBOX_CONF[REDIS_HOST]=${REDIS_HOST:-redis}
|
||
|
NETBOX_CONF[REDIS_PORT]=${REDIS_PORT:-6379}
|
||
|
NETBOX_CONF[REDIS_PASSWORD]=${REDIS_PASSWORD:-}
|
||
|
NETBOX_CONF[REDIS_DB_TASK]=${REDIS_DB_TASK:-0}
|
||
|
NETBOX_CONF[REDIS_DB_CACHE]=${REDIS_DB_CACHE:-1}
|
||
|
NETBOX_CONF[REMOTE_AUTH_ENABLED]=${REMOTE_AUTH_ENABLED:-False}
|
||
|
NETBOX_CONF[REMOTE_AUTH_BACKEND]=${REMOTE_AUTH_BACKEND:-netbox.authentication.RemoteUserBackend}
|
||
|
NETBOX_CONF[REMOTE_AUTH_HEADER]=${REMOTE_AUTH_HEADER:-HTTP_REMOTE_USER}
|
||
|
NETBOX_CONF[REMOTE_AUTH_AUTO_CREATE_USER]=${REMOTE_AUTH_AUTO_CREATE_USER:-False}
|
||
|
NETBOX_CONF[REMOTE_AUTH_DEFAULT_GROUPS]=${REMOTE_AUTH_DEFAULT_GROUPS:-[]}
|
||
|
NETBOX_CONF[REMOTE_AUTH_DEFAULT_PERMISSIONS]=${REMOTE_AUTH_DEFAULT_PERMISSIONS:-{}}
|
||
|
|
||
|
cd /app/netbox/netbox/netbox
|
||
|
NETBOX_CONF[SECRET_KEY]=${SECRET_KEY:-$(python3 ../generate_secret_key.py)}
|
||
|
|
||
|
if [ ! -f "/config/configuration.py" ]; then
|
||
|
cp /defaults/configuration.py /config/configuration.py
|
||
|
|
||
|
# sed in values or skip if value not set
|
||
|
for KEY in "${!NETBOX_CONF[@]}"; do \
|
||
|
sed -i 's|{{'$KEY'}}|'${NETBOX_CONF[$KEY]}'|g' /config/configuration.py
|
||
|
done
|
||
|
fi
|
||
|
|
||
|
[[ ! -e "/config/media" ]] && \
|
||
|
mv /app/netbox/netbox/media /config/media
|
||
|
|
||
|
rm -rf /app/netbox/netbox/media
|
||
|
ln -sf /config/media /app/netbox/netbox/media
|
||
|
|
||
|
ln -sf /config/configuration.py /app/netbox/netbox/netbox/configuration.py
|
||
|
|
||
|
mv /defaults/uwsgi.ini /app/netbox/netbox/uwsgi.ini > /dev/null 2>&1
|
||
|
|
||
|
# permissions
|
||
|
chown -R abc:abc \
|
||
|
/app/netbox \
|
||
|
/config
|
||
|
|
||
|
cd /app/netbox || exit
|
||
|
|
||
|
s6-setuidgid abc /usr/bin/python3 netbox/manage.py migrate
|
||
|
|
||
|
if [ -n "$SUPERUSER_EMAIL" ] && [ -n "$SUPERUSER_PASSWORD" ];
|
||
|
then
|
||
|
cat << EOF | s6-setuidgid abc python3 /app/netbox/netbox/manage.py shell
|
||
|
from django.contrib.auth.models import User;
|
||
|
|
||
|
username = 'admin';
|
||
|
password = '$SUPERUSER_PASSWORD';
|
||
|
email = '$SUPERUSER_EMAIL';
|
||
|
|
||
|
if User.objects.filter(username=username).count()==0:
|
||
|
User.objects.create_superuser(username, email, password);
|
||
|
print('Superuser created.');
|
||
|
else:
|
||
|
print('Superuser creation skipped. Already exists.');
|
||
|
EOF
|
||
|
fi
|