Newer
Older
nc-env / templates / template04-ldap / provision.sh
@pmarini pmarini on 13 Apr 2022 2 KB initial commit
#!/bin/bash

timedatectl set-timezone Europe/Madrid

start_time=`date`
  
echo "provisioning started: ${start_time}" 

#### The user must fill these variables - START

# Fully Qualified Name: ex. "ldap.localenv.com"
MACHINE_HOSTNAME=

#### The user must fill these variables - END

LDAP_USER=usrv

NETWORK_INTERFACE=eth0

hostnamectl set-hostname ${MACHINE_HOSTNAME}

# Print some information about the container OS
hostnamectl

# Print some information about the container timezone
timedatectl

#####################################################################
## Get the IP address into an environment variable. This command outputs 
## an empty variable if the network interface name is not ${NETWORK_INTERFACE}
#####################################################################
ip_address=`ip -4 addr show ${NETWORK_INTERFACE} | grep -oP '(?<=inet\s)\d+(\.\d+){3}'`

adduser --disabled-password --gecos GECOS ${LDAP_USER}
 
usermod -p "`openssl passwd -1  -salt 5RPVAd ${LDAP_USER}`" ${LDAP_USER}
 
adduser ${LDAP_USER} sudo

export DEBIAN_FRONTEND=noninteractive

apt update

# Quiet installation of OpenLDAP server
# https://apassionatechie.wordpress.com/2017/12/12/automating-slapd-install/

cat /vagrant/artifacts/debconf-slapd.conf | debconf-set-selections

apt install ldap-utils slapd -y

# Install phpldapadmin
# https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-openldap-and-phpldapadmin-on-ubuntu-16-04

apt install phpldapadmin -y

cp /vagrant/artifacts/config.php /etc/phpldapadmin

systemctl restart apache2

end_time=`date`

echo "This container has IP (interface: ${NETWORK_INTERFACE}): ${ip_address}"

echo "If you add this IP to the hostname (${MACHINE_HOSTNAME}) in your hosts file:"

echo "	You can connect with user ${LDAP_USER} via ssh (password ${LDAP_USER}): ssh ${LDAP_USER}@${MACHINE_HOSTNAME}"

echo "	Your Keycloak Server instance is  accessible via the following URL: http://${MACHINE_HOSTNAME}/phpldapadmin"

echo " 	The phpldapadmin panel is accessible with user 'admin' and password 'admin'"

echo "provisioning started: ${start_time}" 

echo "provisioning ended: ${end_time}"