admin scripts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.9 KiB

  1. #!/bin/bash
  2. #Get Gids from LDAP
  3. names=$(ldapsearch -xLLL "(objectClass=posixGroup)" gidNumber | grep dn | awk -F = '{print $2}' | awk -F , '{print $1}')
  4. ids=$(ldapsearch -xLLL "(objectClass=posixGroup)" gidNumber | grep gidNumber | awk '{print $2}')
  5. count=$(ldapsearch -xLLL "(objectClass=posixGroup)" gidNumber | grep -c dn)
  6. #Convet strings to Arrays
  7. acount=$(("$count" - 1))
  8. for i in $(seq 1 "$count"); do
  9. # echo loop debug $i
  10. ai=$(("$i" - 1))
  11. a_names[$ai]=$(echo "$names" | awk '{print $'"$i"'}')
  12. # echo ${a_names[$ai]}
  13. a_ids[$ai]=$(echo "$ids" | awk '{print $'"$i"'}')
  14. # echo ${a_ids[$ai]}
  15. done
  16. #Compare LDAP GIDS to System GIDS
  17. for a in $(seq 0 $acount); do
  18. # echo ${a_names[$a]}
  19. # Check for group name in /etc/groups
  20. if [ "$(grep -c "${a_names[$a]}" /etc/group)" -gt 0 ]; then
  21. # Check its been assigned the right gid
  22. [ "$(grep "${a_names[$a]}" /etc/group | awk -F : '{print $3}')" = "${a_ids[$a]}" ] || echo FUCK UP IN "${a_names[$a]}" Group is not assigned the correct GID
  23. else
  24. #IF Group is not there WARN AND ASK TO FIX
  25. echo "${a_names[$a]}:x:${a_ids[$a]} not in /etc/group"
  26. # Check for GID in use
  27. if [ "$(grep -c :"${a_ids[$a]}": /etc/group)" -gt 0 ]; then
  28. #GID is in use
  29. echo GID "${a_ids[$a]}" in use by "$(grep :"${a_ids[$a]}": /etc/group | awk -F : '{print $1}')"
  30. #This is complicated bit that requires finding and chgrping files in use by GID
  31. #genetate new gid
  32. RANDOM=$a
  33. newgid=$RANDOM
  34. while [ "$(grep -c :"$newgid": /etc/group)" -gt 0 ]; do
  35. newgid=$RANDOM
  36. done
  37. echo New GID is "$newgid"
  38. else
  39. echo GID "${a_ids[$a]}" not in use
  40. # Append GID and name to /etc/group possible ask first
  41. echo "${a_names[$a]}:x:${a_ids[$a]}:" >> /etc/group
  42. #may use a fix variable for this instead and do writing at the end
  43. fi
  44. fi
  45. done
  46. #ASSIGN NEW GIDS
  47. #CHECH AND FIX GIDS of FILES NOT IN /STORAGE OR /FAST-STORAGE or TMP Dirs