From 85c561f9a32f8f2b9ddf34e7d60ef4b7bf0d3680 Mon Sep 17 00:00:00 2001
From: Sam Chudnick <sam@chudnick.com>
Date: Fri, 15 Apr 2022 21:08:34 -0400
Subject: inital commit - various scripts

---
 automap | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
 create mode 100755 automap

(limited to 'automap')

diff --git a/automap b/automap
new file mode 100755
index 0000000..b92b0b9
--- /dev/null
+++ b/automap
@@ -0,0 +1,37 @@
+#!/bin/sh
+#
+# Configures a FreeIPA client to use a provided location for automount
+
+help() {
+	echo "usage: automap [--append] --location location"
+	echo "-a, --append:\tappend location (default is to replace existing locations)"
+	echo "-l, --location:\tname of automount location"
+	exit 1
+}
+
+[ $(id -u) -ne 0 ] && echo "error: must be run as root" && exit 1
+
+opts=$(getopt -o "a,h,l:" -l "append,help,location:" -- "$@")
+eval set -- "$opts"
+location=
+append=0
+while true
+do
+		case "$1" in
+				'-a' | '--append') append=1 shift; continue ;;
+				'-l' | '--location') location="$2" shift 2; continue ;;
+				'-h' | '--help') help ;;
+				'--') shift; break ;;
+		esac
+done
+[ -z "$location" ] && help
+
+domain="$(grep "domain =" /etc/ipa/default.conf | cut -d '=' -f 2 | tr -d ' ')"
+dc1="$(echo $domain | cut -d '.' -f 1)"
+dc2="$(echo $domain | cut -d '.' -f 2)"
+mstr="+ldap:automountmapname=auto.master,cn=$location,cn=automount,dc=$dc1,dc=$dc2"
+drct="/-\tldap:automountmapname=auto.direct,cn=$location,cn=automount,dc=$dc1,dc=$dc2"
+str="$mstr\n$drct"
+[ $append -eq 0 ] && echo $str > /etc/auto.master || echo $str >> /etc/auto.master
+
+systemctl restart autofs
-- 
cgit v1.2.3