Sample Header Ad - 728x90

Automating Slapd Install

5 votes
1 answer
7968 views
I'm writing a script that automates the installation of slapd and phpldapadmin. The script: #!/bin/bash # make sure to run script as sudo # LDAP # update first apt-get -q -y update # install maven apt-get install -y maven # Install php dependencies apt-get -y install php php-cgi libapache2-mod-php php-common php-pear php-mbstring a2enconf php7.0-cgi service apache2 restart # Pre-seed the slapd passwords export DEBIAN_FRONTEND='non-interactive' echo -e "slapd slapd/root_password password KappaRoss" |debconf-set-selections echo -e "slapd slapd/root_password_again password KappaRoss" |debconf-set-selections echo -e "slapd slapd/internal/adminpw password test" |debconf-set-selections echo -e "slapd slapd/internal/generated_adminpw password test" |debconf-set-selections echo -e "slapd slapd/password2 password test" |debconf-set-selections echo -e "slapd slapd/password1 password test" |debconf-set-selections echo -e "slapd slapd/domain string acu.local" |debconf-set-selections echo -e "slapd shared/organization string IT410" |debconf-set-selections echo -e "slapd slapd/backend string HDB" |debconf-set-selections echo -e "slapd slapd/purge_database boolean true" |debconf-set-selections echo -e "slapd slapd/move_old_database boolean true" |debconf-set-selections echo -e "slapd slapd/allow_ldap_v2 boolean false" |debconf-set-selections echo -e "slapd slapd/no_configuration boolean false" |debconf-set-selections # Grab slapd and ldap-utils (pre-seeded) apt-get install -y slapd ldap-utils phpldapadmin # Must reconfigure slapd for it to work properly sudo dpkg-reconfigure slapd # Gotta replace the ldap.conf file, it comments out stuff we need set by default - first open it for writing chmod 777 /etc/ldap/ldap.conf cat /etc/ldap/ldap.conf # # LDAP Defaults # # See ldap.conf(5) for details # This file should be world readable but not world writable. BASE dc=acu,dc=local URI ldap://104.219.54.109 ldap://104.219.54.109:666 #SIZELIMIT 12 #TIMELIMIT 15 #DEREF never # TLS certificates (needed for GnuTLS) TLS_CACERT /etc/ssl/certs/ca-certificates.crt EOF # Be safe again chmod 744 /etc/ldap/ldap.conf # Now change all values in /etc/phpldapadmin/config.php to their actual values from example, or .com or localhost (I use sed) # Line 286 sed -i "s@$servers->setValue('server','name','My LDAP Server');.*@$servers->setValue('server','name','Nathans_LDAP');@" /etc/phpldapadmin/config.php # Line 293 sed -i "s@$servers->setValue('server','host','127.0.0.1');.*@$servers->setValue('server','host','104.219.54.109');@" /etc/phpldapadmin/config.php # Line 300 sed -i "s@$servers->setValue('server','base',array('dc=example,dc=com'));.*@$servers->setValue('server','base',array('dc=acu,dc=local'));@" /etc/phpldapadmin/config.php # Line 326 sed -i "s@$servers->setValue('login','bind_id','cn=admin,dc=example,dc=com');.*@$servers->setValue('login','bind_id','cn=admin,dc=acu,dc=local');@" /etc/phpldapadmin/config.php # Prevent error when creating users sed -i "s@$default = $this->getServer()->getValue('appearance','password_hash');.*@$default = $this->getServer()->getValue('appearance','password_hash_custom');@g" /usr/share/phpldapadmin/lib/TemplateRender.php service apache2 restart echo ------------------------# echo 'PHPldapadmin installed.' echo ------------------------# echo "" echo ------------------------------------------------------------# echo 'Can now access phpldapadmin at http://your-ip/phpldapadmin .' echo ------------------------------------------------------------# echo "" echo ------------------------------------------------------------------------# echo 'Username should be acu.local, password is the adminpw set during setup.' echo ------------------------------------------------------------------------# S # Logging echo -e 'Maven installed -done by' $USER 'at time\n' $DATE '\n' >> /var/log/installs/log.txt echo -e 'slapd and ldap-utils configured and installed -done by' $USER 'at time\n' $DATE '\n' >> /var/log/installs/log.txt echo -e 'phpldapadmin install configured -done by' $USER 'at time\n' $DATE '\n' >> /var/log/installs/log.txt echo -e 'LDAP installed completed by' $USER 'at time\n' $DATE '\n' >> /var/log/installs/log.txt Everything runs great, except I think that the debconf set selections for pre-seeding the "dpkg-reconfigure slapd" portion aren't being fully applied. Specifically, when I try to log into phpldapadmin with the admin password I pre-seed, it fails. I have to run "dpkg-reconfigure slapd" again (manually this time) in the terminal and set another admin password, then I can log into phpldapadmin properly and everything works. Any help is appreciated, I need this application fully automated for my final and I'm really close as is.
Asked by nwd12a (51 rep)
May 2, 2017, 04:51 AM
Last activity: Apr 30, 2021, 05:37 PM