ko 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #!/bin/bash
  2. ######################################
  3. #### Default Vars ####################
  4. ######################################
  5. user_groups=""
  6. default_groups=(users disk network netdev 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. # kullanıcıya Milis Xfce4 öntanımlı masaüstü ayarlarının kopyalanması
  44. xfce4_ayarla(){
  45. if [ $1 ];then
  46. _isim=$1
  47. mkdir -p /home/${_isim}/.config
  48. if [ -d /etc/skel/xfce4 ];then
  49. cp -rf /etc/skel/xfce4 /home/${_isim}/.config/
  50. else
  51. cp -rf /root/.config/xfce4 /home/${_isim}/.config/
  52. fi
  53. else
  54. echo "kullanıcı parametresi eksik"
  55. fi
  56. }
  57. if [ $# -eq 1 -o $# -gt 2 ]; then
  58. usage
  59. fi
  60. if [ $UID -ne 0 ]; then
  61. echo 1>&2 "Bu betik root yetkileriyle çalışmaktadır."
  62. exit 1;
  63. fi
  64. if [ $# -lt 2 ]; then
  65. echo -n "Kullanıcı: "
  66. read name
  67. echo -n "Uzun ismi: "
  68. read description
  69. else
  70. description="$1"
  71. name="$2"
  72. fi
  73. check_args "$description" "$name"
  74. ret=$?
  75. while [ $ret -ne 0 ]; do
  76. if [ $ret -lt 3 ]; then
  77. echo -n "Kullancı: "
  78. read name
  79. fi
  80. if [ $ret -eq 3 ]; then
  81. echo -n "Uzun ismi: "
  82. read description
  83. fi
  84. if [ "$name" == "!stop!" -o "$description" == "!stop!" ]; then
  85. exit 1
  86. fi
  87. check_args "$description" "$name"
  88. ret=$?
  89. done
  90. i=0
  91. while [ -n "${default_groups[i]}" ]; do
  92. if grep "${default_groups[i]}" /etc/group > /dev/null ; then
  93. if [ -z "$user_groups" ]; then
  94. user_groups="${default_groups[i]}"
  95. else
  96. user_groups="$user_groups,${default_groups[i]}"
  97. fi
  98. fi
  99. i=$((i+1))
  100. done
  101. echo 1>&2 "
  102. $name kullanıcısının oluşturulması.
  103. "
  104. if [ -z "$user_groups" ]; then
  105. /sbin/useradd -c "${description}" -m "${name}" || exit 1
  106. else
  107. /sbin/useradd -c "${description}" -G "$user_groups" -m "${name}" || exit 1
  108. fi
  109. if [ -f /root/.xinitrc ]; then
  110. cp /root/.xinitrc /home/${name}
  111. fi
  112. passwd "$name"
  113. while true; do
  114. if [ `pgrep xfce4-session` ];then
  115. echo "${name} için Milis Xfce4 öntanımlı masaüstü ayarlarsın mı?";read -p "e veya h-> " eh
  116. case $eh in
  117. [Ee]* ) xfce4_ayarla ${name}; break;;
  118. [Hh]* ) break;;
  119. * ) echo "e veya h";;
  120. esac
  121. fi
  122. exit 0
  123. done
  124. # kullanıcı izinlerin ayarlanması
  125. if [ -d /home/${name} ]; then
  126. #evdizini
  127. chown -R ${name}:${name} /home/${name}
  128. #ses aygıtları
  129. setfacl -m u:${name}:rw /dev/snd/*
  130. fi
  131. exit 0