shtools/ldapserver/ldapserver.sh
2025-03-15 11:47:52 +08:00

39 lines
1.5 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 参数说明:
# organization: 组织名称(例如:"MyCompany"
# domain: LDAP 基域(例如:"example.com"
# split_domain: 分割后的 DC 格式(例如:"dc=example,dc=com"
# admin_password: 管理员密码
# backend: 后端数据库类型(建议使用默认值 HDB或替换为其他如 "MDB"
# instances: 实例名称(通常留空为默认,设置为 ""
set -e
echo "设置 Slapd 配置选项..."
echo "slapd shared/organization string {{organization}}" | sudo debconf-set-selections
echo "slapd slapd/domain string {{domain}}" | sudo debconf-set-selections
echo "slapd slapd/password1 password {{admin_password}}" | sudo debconf-set-selections
echo "slapd slapd/password2 password {{admin_password}}" | sudo debconf-set-selections
echo "slapd slapd/backend select {{backend}}" | sudo debconf-set-selections
echo "slapd slapd/instances string {{instances}}" | sudo debconf-set-selections
echo "slapd slapd/no_configuration boolean false" | sudo debconf-set-selections
echo "slapd slapd/allow_localhost boolean true" | sudo debconf-set-selections
echo "正在安装 LDAP 服务..."
sudo apt-get update && sudo apt-get install -y slapd ldap-utils
echo "启动并启用服务..."
sudo systemctl enable slapd && sudo systemctl restart slapd
echo "配置防火墙 (允许 LDAP 端口)..."
sudo ufw allow 389/tcp
echo "部署完成!"
echo "管理员 DN: cn=admin,{{split_domain}}"
echo ""
echo "测试命令:"
echo "ldapsearch -LL -x -H ldap://localhost -b {{split_domain}} -D 'cn=admin,{{split_domain}}' -W"
exit 0