ko 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #!/bin/bash
  2. # Milis Linux Kullanıcı Ekleme Betiği
  3. # Milis Linux 2.0 2019
  4. # Nutyx Linux kullanıcı ekleme betiğinden çatallanmıştır.
  5. # https://github.com/NuTyX/packages-x86_64/blob/rolling/scripts/setup-nutyx.in#L203
  6. # Değişkenler
  7. user_groups=""
  8. default_groups="users,disk,network,netdev,floppy,fuse,video,lp,tty,audio,cdrom,scanner,adm,vboxusers,wheel,pulse-access"
  9. # İşlevler
  10. check_args()
  11. {
  12. description="$1"
  13. name="$2"
  14. name_test=`echo -n "$name" | sed 's@^[a-z][a-z0-9]*$@@g'`
  15. if [ "$name_test" != "" ]; then
  16. echo 1>&2 "HATA=kullanıcı sorunlu kareketerler içerrmektedir."
  17. return 1
  18. fi
  19. if grep "$name" /etc/passwd > /dev/null; then
  20. echo 1>&2 "$name kullanıcısı zaten var!"
  21. return 2
  22. fi
  23. desc_test=`echo "$description" | sed 's@^[[:alnum:]! -.,~_@;%<>?]*$@@ig'`
  24. if [ "$desc_test" != "" ]; then
  25. echo 1>&2 "HATA=Kullanıcı tam ismi ! -.,~_\\\@;%<>? karekerleri içeremez.Harf-sayı olmalıdır! "
  26. return 3
  27. fi
  28. return 0
  29. }
  30. usage()
  31. {
  32. echo 1>&2 'KULLANIM:
  33. ko kullanıcı kullanıcı_ismi'
  34. exit 1
  35. }
  36. # kullanıcıya Milis Xfce4 öntanımlı masaüstü ayarlarının kopyalanması
  37. xfce4_ayarla(){
  38. if [ $1 ];then
  39. _isim=$1
  40. mkdir -p /home/${_isim}/.config
  41. if [ -d /etc/skel/xfce4 ];then
  42. cp -rf /etc/skel/xfce4 /home/${_isim}/.config/
  43. else
  44. cp -rf /root/.config/xfce4 /home/${_isim}/.config/
  45. fi
  46. else
  47. echo "kullanıcı parametresi eksik"
  48. fi
  49. }
  50. if [ $# -eq 1 -o $# -gt 2 ]; then
  51. usage
  52. fi
  53. if [ $UID -ne 0 ]; then
  54. echo 1>&2 "Bu betik root yetkileriyle çalışmaktadır."
  55. exit 1;
  56. fi
  57. if [ $# -lt 2 ]; then
  58. echo -n "Kullanıcı: "
  59. read name
  60. echo -n "Kullanıcı tam ismi: "
  61. read description
  62. else
  63. description="$1"
  64. name="$2"
  65. fi
  66. check_args "$description" "$name"
  67. ret=$?
  68. while [ $ret -ne 0 ]; do
  69. if [ $ret -lt 3 ]; then
  70. echo -n "Kullanıcı: "
  71. read name
  72. fi
  73. if [ $ret -eq 3 ]; then
  74. echo -n "Kullanıcı tam ismi: "
  75. read description
  76. fi
  77. if [ "$name" == "!stop!" -o "$description" == "!stop!" ]; then
  78. exit 1
  79. fi
  80. check_args "$description" "$name"
  81. ret=$?
  82. done
  83. export IFS=","
  84. for entry in $default_groups; do
  85. if grep $entry /etc/group > /dev/null ; then
  86. if [ -z "$user_groups" ]; then
  87. user_groups=$entry
  88. else
  89. user_groups="$user_groups,$entry"
  90. fi
  91. fi
  92. done
  93. echo 1>&2 "
  94. $name kullanıcısının oluşturulması.
  95. "
  96. if [ -z "$user_groups" ]; then
  97. /usr/bin/useradd -c "${description}" -m "${name}" || exit 1
  98. else
  99. /usr/bin/useradd -c "${description}" -G "$user_groups" -m "${name}" || exit 1
  100. fi
  101. if [ -f /root/.xinitrc ]; then
  102. cp /root/.xinitrc /home/${name}
  103. fi
  104. passwd "$name"
  105. while true; do
  106. if [ `pgrep xfce4-session` ];then
  107. echo "${name} için Milis-Xfce4 öntanımlı masaüstü ayarları kopyalansın mı?";read -p "e veya h-> " eh
  108. case $eh in
  109. [Ee]* ) xfce4_ayarla ${name}; break;;
  110. [Hh]* ) break;;
  111. * ) echo "e veya h";;
  112. esac
  113. fi
  114. exit 0
  115. done
  116. # kullanıcı izinlerinin ayarlanması
  117. if [ -d /home/${name} ]; then
  118. #evdizini
  119. chown -R ${name}:${name} /home/${name}
  120. #ses aygıtları
  121. # todo!!! Milis2 için gerek var mı? kontro edilecek
  122. setfacl -m u:${name}:rw /dev/snd/*
  123. fi
  124. exit 0