#!/bin/sh
#
# Create computer object(s) in LDAP.  The computer should be seen by
# DNS, DHCP, Samba and LTSP.

set -e

hostname=tjener
dnsdomain=intern
fqdn=$hostname.$dnsdomain
ipaddr=10.0.2.2
hwaddr=00:00:00:00:00:00
LDAPBASE=dc=skole,dc=skolelinux,dc=no

# Set to true if the computer should be visible for samba (like a
# windows machine)
samba=true

set $(echo $ipaddr |tr '.' ' ')
ip1=$1; ip2=$2; ip3=$3; ip4=$4

ldif=""

# Forward and reverse DNS entries
ldif="$ldif
dn: dc=$hostname,dc=$dnsdomain,ou=hosts,$LDAPBASE
objectclass: top
objectclass: dnsdomain
objectclass: domainrelatedobject
dc: $hostname
arecord: $ipaddr
associateddomain: $fqdn

dn: dc=$ip4,dc=$ip3,dc=$ip2,dc=$ip1,dc=in-addr,dc=arpa,ou=hosts,$LDAPBASE
objectclass: top
objectclass: dnsdomain2
objectclass: domainrelatedobject
dc: $ip4
ptrrecord: $hostname
associateddomain: $ip4.$ip3.$ip2.$ip1.in-addr.arpa
"

# DHCP entry
ldif="$ldif
dn: cn=$hostname,cn=group1,cn=INTERNAL,cn=config,ou=dhcp,$LDAPBASE
objectClass: top
objectClass: dhcpHost
cn: $hostname
dhcpHWAddress: ethernet $hwaddr
dhcpStatements: fixed-address $fqdn
"

# Samba computer entry
if $samba ; then
    ldif="$ldif
dn: uid=$hostname\$,ou=machines,ou=people,$LDAPBASE
objectClass: account
objectClass: sambaSamAccount
uid: $hostname\$
sambaSID: $SAMBASID-$SAMBARIN
sambaAcctFlags: [S          ]
sambaPwdLastSet: 1279055792
sambaNTPassword: $SAMBANTPWDHASH
"
fi
