diff options
| author | Lexi Winter <lexi@le-fay.org> | 2025-07-12 07:52:42 +0100 |
|---|---|---|
| committer | Lexi Winter <lexi@le-fay.org> | 2025-07-12 07:52:42 +0100 |
| commit | 799dc834e0fe94ed62c0d6bb65e6d15a639ab668 (patch) | |
| tree | bb3b7a89764f768b6b1c4a4918e9eb37a88645b8 /lfldap-update.sh | |
| download | lfldap-005d76af033af44cf5e9b18d5cbdc31823814683.tar.gz lfldap-005d76af033af44cf5e9b18d5cbdc31823814683.tar.bz2 | |
initial commitv1.0
Diffstat (limited to 'lfldap-update.sh')
| -rw-r--r-- | lfldap-update.sh | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/lfldap-update.sh b/lfldap-update.sh new file mode 100644 index 0000000..50c067f --- /dev/null +++ b/lfldap-update.sh @@ -0,0 +1,57 @@ +#! /bin/sh + +PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin + +FILTER="(&(objectClass=lfNetwork))" +DBDIR="/var/db/lfldap" +PREFIX="/usr/local" +HOOKDIR="${PREFIX}/share/lfldap/hooks" +NETWORKS_FILE="${DBDIR}/networks" +NETWORKS_TEMP="${DBDIR}/networks.tmp" + +trap cleanup 0 +cleanup() +{ + rm -f "$NETWORKS_TEMP" +} + +mkdir -p "$DBDIR" +rm -f "$NETWORKS_TEMP" + +if [ ! -f "$NETWORKS_FILE" ]; then + touch "$NETWORKS_FILE" +fi + +ldapsearch \ + -x -s sub \ + "$FILTER" \ + cidrPrefix \ + | awk '/^cidrPrefix: / { print $2 }' >${NETWORKS_TEMP} + +if ! [ -s "$NETWORKS_TEMP" ]; then + printf >&2 '%s: no networks returned; configuration error?\n' "$0" + exit 1 +fi + +if ! cmp -s "$NETWORKS_FILE" "$NETWORKS_TEMP"; then + printf '%s updated:\n\n' "$NETWORKS_FILE" + diff "$NETWORKS_FILE" "$NETWORKS_TEMP" + printf '\n' + + mv "$NETWORKS_TEMP" "$NETWORKS_FILE" +else + rm -f "$NETWORKS_TEMP" +fi + +# Run hooks even if the networks didn't change, since the user might want +# new hooks to run. + +exit=0 + +export NETWORKS_FILE + +for hook in ${HOOKDIR}/*.sh; do + sh $hook || exit=1 +done + +exit $exit |
