-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_backend.sh
executable file
·71 lines (61 loc) · 1.33 KB
/
generate_backend.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
# Default values
domain=""
root_pw=""
# Function to display script usage
printUsage() {
echo "Usage: $0 -d <domain> -p <rootPW>"
echo ""
echo "Options:"
echo " -d, --domain Domain name (e.g., example.com)"
echo " -p, --root-pw Root password for LDAP directory"
echo " -h, --help Display this help message"
}
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
-d|--domain)
domain="$2"
shift 2
;;
-p|--root-pw)
root_pw="$2"
shift 2
;;
-h|--help)
printUsage
exit 0
;;
*)
echo "Invalid argument: $1"
printUsage
exit 1
;;
esac
done
# Validate required arguments
if [ -z "$domain" ] || [ -z "$root_pw" ]; then
echo "Error: Missing required arguments"
printUsage
exit 1
fi
# Generate suffix from the domain
suffix="dc=$(echo $domain | sed 's/\./,dc=/g')"
# Construct root DN
root_dn="cn=admin,$suffix"
# Generate hashed root password using slappasswd
hashed_root_pw=$(slappasswd -s "$root_pw")
cat << EOF
dn: olcDatabase={1}mdb,cn=config
changetype: modify
replace: olcSuffix
olcSuffix: $suffix
dn: olcDatabase={1}mdb,cn=config
changetype: modify
replace: olcRootDN
olcRootDN: $root_dn
dn: olcDatabase={1}mdb,cn=config
changetype: modify
replace: olcRootPW
olcRootPW: $hashed_root_pw
EOF