Last active
January 29, 2019 17:05
-
-
Save lucashalbert/fa27feb0be54ce709f5b41097655efd5 to your computer and use it in GitHub Desktop.
Post upgrade script to run after recompiling OpenLDAP server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#################################################################################### | |
# | |
# Author: Lucas Halbert <https://www.lhalbert.xyz> | |
# Date: 06/12/2018 | |
# Last Edited: 01/29/2019 | |
# Version: 2019.01.29 | |
# Description: Moves necessary schema and LDIF files from old slapd instance to | |
# newly compiled instance. Fixes permissions as necessary for slapd | |
# to run. | |
# License: BSD 3-Clause License | |
# | |
# Copyright (c) 2018, Lucas Halbert | |
# All rights reserved. | |
# | |
# Redistribution and use in source and binary forms, with or without | |
# modification, are permitted provided that the following conditions are met: | |
# | |
# * Redistributions of source code must retain the above copyright notice, this | |
# list of conditions and the following disclaimer. | |
# | |
# * Redistributions in binary form must reproduce the above copyright notice, | |
# this list of conditions and the following disclaimer in the documentation | |
# and#or other materials provided with the distribution. | |
# | |
# * Neither the name of the copyright holder nor the names of its | |
# contributors may be used to endorse or promote products derived from | |
# this software without specific prior written permission. | |
# | |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
# | |
#################################################################################### | |
# | |
# Revisions: 01/29/2019 Replace absolute paths with relative paths. Add | |
# license and commenting. | |
# | |
# 06/12/2018 Initial Draft | |
# | |
#################################################################################### | |
BASE_PATH="/opt/work" | |
SCHEMA_FILES=(owncloud.schema owncloud.ldif openssh-ldap.schema rfc2307bis.schema yubikey.schema sudo.schema) | |
CONFIG_FILES=(slapd.conf slapd.ldif) | |
# Check if the correct number of arguments have been provided | |
if [ "$#" -lt 2 ]; then | |
echo "ERROR: please provide both the current and upgrade versions as argument 1 and 2 respectively" | |
echo "INFO: argument expect versions in the form of '#.#.##'" | |
exit 1 | |
elif [ "$#" -eq 2 ]; then | |
CURRENT_VERSION=$1 | |
UPGRADE_VERSION=$2 | |
else | |
echo "ERROR: An incorrect number of arguments was provided." | |
echo "ERROR: please provide both the current and upgrade versions as argument 1 and 2 respectively" | |
echo "INFO: argument expect versions in the form of '#.#.##'" | |
exit 1 | |
fi | |
# Check if slapd is running | |
SLAPD_PID=$(pidof slapd) | |
if [ ! -z ${SLAPD_PID} ]; then | |
echo "ERROR: slapd process PID# ${SLAPD_PID} detected. Please terminate before running." | |
exit 2 | |
else | |
echo "INFO: no slapd process detected. proceeding..." | |
fi | |
# Check if Current version path exists | |
if [ ! -d "${BASE_PATH}/openldap-${CURRENT_VERSION}/" ]; then | |
echo "ERROR: The current version path does not exist" | |
exit 3 | |
else | |
echo "INFO: The current version path exists. Proceeding..." | |
fi | |
# Check if Upgrade version path exists | |
if [ ! -d "${BASE_PATH}/openldap-${UPGRADE_VERSION}/" ]; then | |
echo "ERROR: The upgrade version path does not exist" | |
exit 4 | |
else | |
echo "INFO: The upgrade version path exists. Proceeding..." | |
fi | |
# Copy third-party schema files to upgrade version location | |
for i in ${SCHEMA_FILES[*]}; do | |
cp -f ${BASE_PATH}/openldap-${CURRENT_VERSION}/etc/openldap/schema/${i} ${BASE_PATH}/openldap-${UPGRADE_VERSION}/etc/openldap/schema/${i} | |
done | |
# Copy current version configuration files to upgrade version location | |
for i in ${CONFIG_FILES[*]}; do | |
cp -f ${BASE_PATH}/openldap-${CURRENT_VERSION}/etc/openldap/${i} ${BASE_PATH}/openldap-${UPGRADE_VERSION}/etc/openldap/${i} | |
# fix ownership | |
chown ldap:root ${BASE_PATH}/openldap-${UPGRADE_VERSION}/etc/openldap/${i} | |
done | |
# Copy current version var data to upgrade version location | |
cp -f ${BASE_PATH}/openldap-${CURRENT_VERSION}/var/openldap-data/* ${BASE_PATH}/openldap-${UPGRADE_VERSION}/var/openldap-data/ | |
# Fix ownership of openldap-data | |
chown -R ldap ${BASE_PATH}/openldap-${UPGRADE_VERSION}/var/openldap-data/ | |
# Fix ownership of run data | |
chown -R ldap ${BASE_PATH}/openldap-${UPGRADE_VERSION}/var/run/ | |
# Reminder | |
echo "Don't forget to change the symbolic link for the new version of slapd" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment