aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohannes Löthberg <johannes@kyriasis.com>2014-08-04 18:52:08 +0200
committerJohannes Löthberg <johannes@kyriasis.com>2014-08-04 18:52:08 +0200
commit05de91989ca98cd8149012e24f3fa2cd8754be6c (patch)
tree6508ce2fc08d45c5f3d90aa3610611035a5e4325
parent17355e52af63c0081f2d7e875b5d2db9e6ba9f59 (diff)
downloadbin-05de91989ca98cd8149012e24f3fa2cd8754be6c.tar.xz
kchsh: Import kyriasis chsh util
LDAP users have their loginShell stored in LDAP and the Arch Linux chsh isn't built with LDAP support.
-rwxr-xr-xkchsh64
1 files changed, 64 insertions, 0 deletions
diff --git a/kchsh b/kchsh
new file mode 100755
index 0000000..6ed7ea9
--- /dev/null
+++ b/kchsh
@@ -0,0 +1,64 @@
+#!/usr/bin/env bash
+
+##
+# Prompt for a shell then uses change_shell() to set the loginShell of LDAP users
+#
+# arguments:
+# None
+kchsh() {
+ shells=('/usr/bin/bash'
+ '/usr/bin/zsh')
+
+ dn=$(ldapwhoami -Q)
+ if [[ $? -eq 0 ]]; then
+ dn="${dn:3}"
+ else
+ dn="uid=$USER,ou=users,dc=kyriasis,dc=com"
+ fi
+
+ printf "Current shell for %s is %s\n" $dn $(get_current_shell $dn)
+
+ select shell in "${shells[@]}" quit;
+ do
+ if [[ $shell == "quit" ]]; then
+ printf "Shell not changed.\n"
+ break
+ else
+ change_shell "$dn" "$shell"
+ if [[ $? -eq 0 ]]; then
+ printf "Shell changed successfully.\n"
+ else
+ printf "Uh-oh...\n"
+ fi
+
+ break
+ fi
+ done
+}
+
+##
+# Changes the current loginShell for an LDAP user
+#
+# arguments:
+# $1: The distinguished name of the entry to change
+# $2: The shell to change to
+change_shell() {
+ ldapmodify -Q >>/dev/null <<-EOF
+ dn: $1
+ changetype: modify
+ replace: loginShell
+ loginShell: $2
+ EOF
+}
+
+##
+# Get the current loginShell for an LDAP user
+#
+# arguments:
+# $1: The distinguished name of the entry to get the shell for
+get_current_shell() {
+ local shell="$(ldapsearch -Q -b "$1" loginShell | grep '^loginShell')"
+ printf "%s\n" "${shell:12}"
+}
+
+kchsh