Revert "Revert "oran-shell-release: release image for F""
[pti/rtp.git] / meta-starlingx / meta-stx-integ / recipes-support / openldap / files / sources / libexec-convert-config.sh
1 #!/bin/sh
2 # Author: Jan Vcelak <jvcelak@redhat.com>
3
4 . /usr/libexec/openldap/functions
5
6 function help()
7 {
8         error "usage: %s [-f config-file] [-F config-dir]\n" "`basename $0`"
9         exit 2
10 }
11
12 load_sysconfig
13
14 while getopts :f:F: opt; do
15         case "$opt" in
16         f)
17                 SLAPD_CONFIG_FILE="$OPTARG"
18                 ;;
19         F)
20                 SLAPD_CONFIG_DIR="$OPTARG"
21                 ;;
22         *)
23                 help
24                 ;;
25         esac
26 done
27 shift $((OPTIND-1))
28 [ -n "$1" ] && help
29
30 # check source, target
31
32 if [ ! -f "$SLAPD_CONFIG_FILE" ]; then
33         error "Source configuration file '%s' not found." "$SLAPD_CONFIG_FILE"
34         exit 1
35 fi
36
37 if grep -iq '^dn: cn=config$' "$SLAPD_CONFIG_FILE"; then
38         SLAPD_CONFIG_FILE_FORMAT=ldif
39 else
40         SLAPD_CONFIG_FILE_FORMAT=conf
41 fi
42
43 if [ -d "$SLAPD_CONFIG_DIR" ]; then
44         if [ `find "$SLAPD_CONFIG_DIR" -maxdepth 0 -empty | wc -l` -eq 0 ]; then
45                 error "Target configuration directory '%s' is not empty." "$SLAPD_CONFIG_DIR"
46                 exit 1
47         fi
48 fi
49
50 # perform the conversion
51
52 tmp_convert=`mktemp --tmpdir=/var/run/openldap`
53
54 if [ `id -u` -eq 0 ]; then
55         install -d --owner $SLAPD_USER --group `id -g $SLAPD_USER` --mode 0750 "$SLAPD_CONFIG_DIR" &>>$tmp_convert
56         if [ $SLAPD_CONFIG_FILE_FORMAT = ldif ]; then
57                 run_as_ldap "/usr/sbin/slapadd -F \"$SLAPD_CONFIG_DIR\" -n 0 -l \"$SLAPD_CONFIG_FILE\"" &>>$tmp_convert
58         else
59                 run_as_ldap "/usr/sbin/slaptest -f \"$SLAPD_CONFIG_FILE\" -F \"$SLAPD_CONFIG_DIR\"" &>>$tmp_convert
60         fi
61         retcode=$?
62 else
63         error "You are not root! Permission will not be set."
64         install -d --mode 0750 "$SLAPD_CONFIG_DIR" &>>$tmp_convert
65         if [ $SLAPD_CONFIG_FILE_FORMAT = ldif ]; then
66                 /usr/sbin/slapadd -F "$SLAPD_CONFIG_DIR" -n 0 -l "$SLAPD_CONFIG_FILE" &>>$tmp_convert
67         else
68                 /usr/sbin/slaptest -f "$SLAPD_CONFIG_FILE" -F "$SLAPD_CONFIG_DIR" &>>$tmp_convert
69         fi
70         retcode=$?
71 fi
72
73 if [ $retcode -ne 0 ]; then
74         error "Configuration conversion failed:"
75         cat $tmp_convert >&2
76 fi
77
78 rm $tmp_convert
79 exit $retcode