add ldap-hostname script and service
Deploy Package / Explore-Gitea-Actions (push) Successful in 14s Details

This commit is contained in:
Carneiro 2024-11-18 10:32:21 -03:00
parent 60f506b2c7
commit 0a77bc0003
2 changed files with 21 additions and 0 deletions

11
usr/bin/ldap-hostname Executable file
View File

@ -0,0 +1,11 @@
#!/bin/sh
IP=$(hostname -I | awk '{print $1}')
HOSTNAME=$(getent hosts | grep $IP | awk '{print $2}')
if [ -n "$HOSTNAME" ]; then
hostnamectl set-hostname "$HOSTNAME"
echo "Hostname set to $HOSTNAME"
else
echo "Hostname not found for IP $IP"
fi

View File

@ -0,0 +1,10 @@
[Unit]
Description=Set hostname based on IP from LDAP
After=network.target
[Service]
Type=oneshot
ExecStart=/usr/bin/ldap-hostname
[Install]
WantedBy=multi-user.target