You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ublinux-init/ublinux/rc.preinit.d/23-realmd

107 lines
4.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/usr/bin/env bash
#
# Author: Dmitry Razumov <asmeron@ublinux.com>
# Copyright (c) 2021-2025 UBLinux <support@ublinux.com>
#
# Initial script for Linux UBLinux
# This script are launching before starting init from initrd script
# Current dir allways must be set to root (/)
# All system path must be relative, except initrd dirs
ENABLED=yes
[[ ${ENABLED} == "yes" ]] || exit 0
DEBUGMODE=no
PATH=.:/:/usr/bin:/usr/local/bin:/usr/local/sbin
[[ -d /usr/lib/ublinux ]] && { ROOTFS= ; CMD_CHROOT= ; } || { [[ -d /sysroot ]] && ROOTFS="/sysroot" || ROOTFS="."; CMD_CHROOT="chroot ${ROOTFS}"; }
SOURCE=${ROOTFS}/usr/lib/ublinux/functions; [[ -f ${SOURCE} ]] && . ${SOURCE} 2>/dev/null || exit 0
SOURCE=${ROOTFS}/usr/lib/ublinux/default; [[ -f ${SOURCE} ]] && . ${SOURCE} 2>/dev/null || exit 0
debug_mode "$0" "$@"
SYSCONF="${ROOTFS}${SYSCONF}"
SOURCE=${SYSCONF}/config; [[ -f ${SOURCE} ]] && . ${SOURCE} 2>/dev/null
SOURCE=${SYSCONF}/network; [[ -f ${SOURCE} ]] && . ${SOURCE} 2>/dev/null
# [[ -z ${KERBEROS_REALM} ]] && KERBEROS_REALM=${DOMAIN^^}
# [[ -z ${SAMBADOMAIN} ]] && SAMBADOMAIN=$(echo ${KERBEROS_REALM} | awk -F . '{print $1}')
# sed -i s/kerberos.ublinux.ru/$ADSERVER/ etc/krb5.conf
# sed -i s/LOCAL.UBLINUX.RU/$KERBEROS_REALM/ etc/krb5.conf
# sed -i s/local.ublinux.ru/$DOMAIN/ etc/krb5.conf
#
# sed -i '/realm =/d' etc/samba/smb.conf
# sed -i '/security =/d' etc/samba/smb.conf
# sed -i '/password server =/d' etc/samba/smb.conf
# sed -i '/\[global\]/ s/$/'"\n realm = ${KERBEROS_REALM}\n security = ADS\n password server = ${ADSERVER}"/ etc/samba/smb.conf
#
#
#if [[ -n "${SAMBADOMAIN}" ]]; then
# sed -i s/"workgroup = .*"/"workgroup = ${SAMBADOMAIN}"/ etc/samba/smb.conf
# sed -i s/"^NT_DOMAIN=.*"/"NT_DOMAIN=${SAMBADOMAIN}"/ etc/ntlmaps.cfg
#fi
exec_domain(){
[[ $1 == @("set="|"set+="|"set++="|"set-="|"set--="|"remove") ]] && COMMAND=$1 && shift
[[ -n ${COMMAND} ]] || COMMAND="set="
local PARAM="$@"
[[ $(declare -p DOMAIN 2>/dev/null) =~ "declare -A" ]] || declare -A DOMAIN
if [[ -n ${PARAM} ]]; then
unset DOMAIN
declare -A DOMAIN
[[ ${PARAM%%=*} =~ [!\$%\&()*+,./:\;\<\=\>?\@\^\{|\}~-] ]] || eval "${PARAM%%=*}=\${PARAM#*=}"
fi
if [[ ${COMMAND} == @("set="|"set+="|"set++=") ]]; then
if [[ -n ${DOMAIN} && ${DOMAIN[client]} == "realmd_sssd" ]]; then
if [[ -f ${ROOTFS}/etc/krb5.keytab ]]; then
${CMD_CHROOT} /usr/bin/ubdomain-client --quiet configure
#[[ -f ${ROOTFS}/etc/krb5.conf && -f ${ROOTFS}/etc/sssd/sssd.conf ]] || ${CMD_CHROOT} /usr/bin/ubdomain-client --quite configure #2>/dev/null
[[ -f ${ROOTFS}/usr/lib/systemd/system/sssd.service ]] && ln -sf /usr/lib/systemd/system/sssd.service ${ROOTFS}/etc/systemd/system/multi-user.target.wants/sssd.service
fi
elif [[ -n ${DOMAIN} && ${DOMAIN[client]} == "realmd_winbind" ]]; then
true
elif [[ -n ${DOMAIN} && ${DOMAIN[client]} == "samba" ]]; then
true
fi
elif [[ ${COMMAND} == @("set-="|"set--="|"remove") ]]; then
${CMD_CHROOT} /usr/bin/ubdomain-client unconfigure
fi
}
domain_configure_live(){
# Если выполнение в initrd, то выход
[[ -z ${ROOTFS} ]] || return 0
[[ $1 == @("set="|"set+="|"set++="|"set-="|"set--="|"remove") ]] && COMMAND=$1 && shift
[[ -n ${COMMAND} ]] || COMMAND="set="
local PARAM="$@"
if [[ ${COMMAND} == @("set="|"set+="|"set++=") ]]; then
[[ -z ${DOMAIN} ]] && return 0
${ROOTFS}/usr/bin/ubdomain-client configure
systemctl restart sssd.service
elif [[ ${COMMAND} == @("set-="|"set--="|"remove") ]]; then
[[ -z ${DOMAIN} ]] && return 0
${ROOTFS}/usr/bin/ubdomain-client configure
systemctl restart sssd.service
fi
}
################
##### MAIN #####
################
# Если файл подключен как ресурс с функциями, то выйти
return 0 2>/dev/null && return 0
if [[ -z $@ ]]; then
while read -r FUNCTION; do
$"${FUNCTION##* }"
done < <(declare -F | grep "declare -f exec_")
else
FUNCTION=
while [[ $# -gt 0 ]]; do
[[ -z ${1} ]] || { declare -f ${1} &>/dev/null && FUNCTION+="; ${1}" || FUNCTION+=" '${1}'"; }
shift
done
eval ${FUNCTION#*; }
fi