Update entrypoint.sh

This commit is contained in:
Marisa 2025-10-30 09:00:50 -04:00
parent 978692b28a
commit 4b9dc6947e

View File

@ -1,15 +1,15 @@
#!/bin/bash #!/bin/bash
# already INSIDE the container # already INSIDE the container
# 1. Start slapd in the background # start slapd in the background
echo "Starting slapd service..." echo "Starting slapd service..."
# slapd start command, running in the background (&) # slapd start command, running in the background (&)
/usr/sbin/slapd -h "ldap:/// ldapi:///" -g openldap -u openldap -F /etc/ldap/slapd.d & /usr/sbin/slapd -h "ldap:/// ldapi:///" -g openldap -u openldap -F /etc/ldap/slapd.d &
# Wait briefly for the service to start # wait briefly for the service to start
sleep 3 sleep 3
# Check if slapd started successfully # check if slapd started successfully
SLAPD_PID=$! SLAPD_PID=$!
if kill -0 $SLAPD_PID 2>/dev/null; then if kill -0 $SLAPD_PID 2>/dev/null; then
echo "OpenLDAP slapd service started successfully with PID: $SLAPD_PID" echo "OpenLDAP slapd service started successfully with PID: $SLAPD_PID"
@ -17,7 +17,24 @@ else
echo "OpenLDAP slapd already running with PID: $SLAPD_PID" echo "OpenLDAP slapd already running with PID: $SLAPD_PID"
fi fi
# 2. Execute the command passed to the container # get a hashed password
HASH_PWD="$(sh -c 'slappasswd -s 0p3nLd4p!')"
# create the .ldif file to create the admin user with the hashed password
cat > create_admin.ldif << EOF
dn: cn=admin,dc=example,dc=com
changetype: add
objectClass: organizationalRole
objectClass: simpleSecurityObject
cn: admin
description: LDAP administrator
userPassword: ${HASH_PWD}
EOF
# call the LDAP server to add it
ldapadd -x -H ldap:/// -D "cn=admin,dc=example,dc=com" -w admin -f create_admin.ldif
# execute the command passed to the container
# 'exec' replaces the script process with the command (e.g., /bin/bash), # 'exec' replaces the script process with the command (e.g., /bin/bash),
# ensuring the container stays alive as long as that command runs interactively. # ensuring the container stays alive as long as that command runs interactively.
echo "Executing: $@" echo "Executing: $@"