ko 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #!/bin/bash
  2. ######################################
  3. #### Default Vars ####################
  4. ######################################
  5. user_groups=""
  6. default_groups=(users disk network floppy fuse video lp tty audio cdrom scanner adm vboxusers wheel)
  7. # Avoid spaces troubles :)
  8. OLD_IFS=$IFS
  9. IFS="|
  10. "
  11. KDM_CONFFILE="/etc/kde/kdmrc"
  12. GDM_CONFFILE="/etc/gdm/custom.conf"
  13. LXDM_CONFFILE="/etc/lxdm/lxdm.conf"
  14. ######################################
  15. #### Functions #######################
  16. ######################################
  17. check_args()
  18. {
  19. description="$1"
  20. name="$2"
  21. name_test=`echo -n "$name" | sed 's@^[a-z][a-z0-9]*$@@g'`
  22. if [ "$name_test" != "" ]; then
  23. echo 1>&2 "HATA=kullanıcı sorunlu kareketerler içerrmektedir."
  24. return 1
  25. fi
  26. if grep "$name" /etc/passwd > /dev/null; then
  27. echo 1>&2 "$name kullanıcısı zaten var!"
  28. return 2
  29. fi
  30. desc_test=`echo "$description" | sed 's@^[[:alnum:]! -.,~_@;%<>?]*$@@ig'`
  31. if [ "$desc_test" != "" ]; then
  32. echo 1>&2 "HATA=Uzun ismi ! -.,~_\\\@;%<>? karekerleri içeremez.Harf-sayı olmalıdır! "
  33. return 3
  34. fi
  35. return 0
  36. }
  37. usage()
  38. {
  39. echo 1>&2 'KULLANIM:
  40. ko kullanıcı kullanıcı_ismi'
  41. exit 1
  42. }
  43. ######################################
  44. #### Scripting time ##################
  45. ######################################
  46. if [ $# -eq 1 -o $# -gt 2 ]; then
  47. usage
  48. fi
  49. if [ $UID -ne 0 ]; then
  50. echo 1>&2 "Bu betik root yetkileriyle çalışmaktadır."
  51. exit 1;
  52. fi
  53. if [ $# -lt 2 ]; then
  54. echo -n "Kullancı: "
  55. read name
  56. echo -n "Uzun ismi: "
  57. read description
  58. else
  59. description="$1"
  60. name="$2"
  61. fi
  62. check_args "$description" "$name"
  63. ret=$?
  64. while [ $ret -ne 0 ]; do
  65. if [ $ret -lt 3 ]; then
  66. echo -n "Kullancı: "
  67. read name
  68. fi
  69. if [ $ret -eq 3 ]; then
  70. echo -n "Uzun ismi: "
  71. read description
  72. fi
  73. if [ "$name" == "!stop!" -o "$description" == "!stop!" ]; then
  74. exit 1
  75. fi
  76. check_args "$description" "$name"
  77. ret=$?
  78. done
  79. i=0
  80. while [ -n "${default_groups[i]}" ]; do
  81. if grep "${default_groups[i]}" /etc/group > /dev/null ; then
  82. if [ -z "$user_groups" ]; then
  83. user_groups="${default_groups[i]}"
  84. else
  85. user_groups="$user_groups,${default_groups[i]}"
  86. fi
  87. # echo "groupes : $user_groups"
  88. # else
  89. # echo 1>&2 ' Veuillez installez un gestionnaire de fenetre,
  90. # redemarrer la machine dans ce gestionnaire,
  91. # et relancer cette commande.
  92. #'
  93. # exit 1
  94. fi
  95. i=$((i+1))
  96. done
  97. echo 1>&2 "
  98. $name kullanıcısının oluşturulması.
  99. "
  100. if [ -d /home/${name} ]; then
  101. chown -R ${name}:${name} /home/${name}
  102. fi
  103. if [ -z "$user_groups" ]; then
  104. /sbin/useradd -c "${description}" -m "${name}" || exit 1
  105. else
  106. /sbin/useradd -c "${description}" -G "$user_groups" -m "${name}" || exit 1
  107. fi
  108. if [ -f /root/.xinitrc ]; then
  109. cp /root/.xinitrc /home/${name}/
  110. fi
  111. passwd "$name"
  112. exit 0