diff options
author | Johannes Löthberg <johannes@kyriasis.com> | 2014-08-04 18:52:08 +0200 |
---|---|---|
committer | Johannes Löthberg <johannes@kyriasis.com> | 2014-08-04 18:52:08 +0200 |
commit | 05de91989ca98cd8149012e24f3fa2cd8754be6c (patch) | |
tree | 6508ce2fc08d45c5f3d90aa3610611035a5e4325 /kchsh | |
parent | 17355e52af63c0081f2d7e875b5d2db9e6ba9f59 (diff) | |
download | bin-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.
Diffstat (limited to 'kchsh')
-rwxr-xr-x | kchsh | 64 |
1 files changed, 64 insertions, 0 deletions
@@ -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 |