2016-06-14 15:08:00 +02:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
######################################
|
|
|
|
|
#### Default Vars ####################
|
|
|
|
|
######################################
|
|
|
|
|
|
|
|
|
|
user_groups=""
|
2017-08-15 13:37:46 +02:00
|
|
|
|
default_groups=(users disk network netdev floppy fuse video lp tty audio cdrom scanner adm vboxusers wheel)
|
2016-06-14 15:08:00 +02:00
|
|
|
|
|
|
|
|
|
# Avoid spaces troubles :)
|
|
|
|
|
OLD_IFS=$IFS
|
|
|
|
|
IFS="|
|
|
|
|
|
"
|
|
|
|
|
KDM_CONFFILE="/etc/kde/kdmrc"
|
|
|
|
|
GDM_CONFFILE="/etc/gdm/custom.conf"
|
|
|
|
|
LXDM_CONFFILE="/etc/lxdm/lxdm.conf"
|
|
|
|
|
|
|
|
|
|
######################################
|
|
|
|
|
#### Functions #######################
|
|
|
|
|
######################################
|
|
|
|
|
|
|
|
|
|
check_args()
|
|
|
|
|
{
|
|
|
|
|
description="$1"
|
|
|
|
|
name="$2"
|
|
|
|
|
|
|
|
|
|
name_test=`echo -n "$name" | sed 's@^[a-z][a-z0-9]*$@@g'`
|
|
|
|
|
if [ "$name_test" != "" ]; then
|
2016-06-14 19:10:02 +02:00
|
|
|
|
echo 1>&2 "HATA=kullanıcı sorunlu kareketerler içerrmektedir."
|
2016-06-14 15:08:00 +02:00
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
if grep "$name" /etc/passwd > /dev/null; then
|
2016-06-14 19:10:02 +02:00
|
|
|
|
echo 1>&2 "$name kullanıcısı zaten var!"
|
2016-06-14 15:08:00 +02:00
|
|
|
|
return 2
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
desc_test=`echo "$description" | sed 's@^[[:alnum:]! -.,~_@;%<>?]*$@@ig'`
|
|
|
|
|
if [ "$desc_test" != "" ]; then
|
2016-06-14 19:10:02 +02:00
|
|
|
|
echo 1>&2 "HATA=Uzun ismi ! -.,~_\\\@;%<>? karekerleri içeremez.Harf-sayı olmalıdır! "
|
2016-06-14 15:08:00 +02:00
|
|
|
|
return 3
|
|
|
|
|
fi
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
usage()
|
|
|
|
|
{
|
2016-06-14 19:10:02 +02:00
|
|
|
|
echo 1>&2 'KULLANIM:
|
|
|
|
|
ko kullanıcı kullanıcı_ismi'
|
2016-06-14 15:08:00 +02:00
|
|
|
|
exit 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
######################################
|
|
|
|
|
#### Scripting time ##################
|
|
|
|
|
######################################
|
|
|
|
|
|
|
|
|
|
if [ $# -eq 1 -o $# -gt 2 ]; then
|
|
|
|
|
usage
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ $UID -ne 0 ]; then
|
2016-06-14 19:10:02 +02:00
|
|
|
|
echo 1>&2 "Bu betik root yetkileriyle çalışmaktadır."
|
2016-06-14 15:08:00 +02:00
|
|
|
|
exit 1;
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ $# -lt 2 ]; then
|
2016-06-14 19:10:02 +02:00
|
|
|
|
echo -n "Kullancı: "
|
2016-06-14 15:08:00 +02:00
|
|
|
|
read name
|
2016-06-14 19:10:02 +02:00
|
|
|
|
echo -n "Uzun ismi: "
|
2016-06-14 15:08:00 +02:00
|
|
|
|
read description
|
|
|
|
|
else
|
|
|
|
|
description="$1"
|
|
|
|
|
name="$2"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
check_args "$description" "$name"
|
|
|
|
|
ret=$?
|
|
|
|
|
while [ $ret -ne 0 ]; do
|
|
|
|
|
if [ $ret -lt 3 ]; then
|
2016-06-14 19:10:02 +02:00
|
|
|
|
echo -n "Kullancı: "
|
2016-06-14 15:08:00 +02:00
|
|
|
|
read name
|
|
|
|
|
fi
|
|
|
|
|
if [ $ret -eq 3 ]; then
|
2016-06-14 19:10:02 +02:00
|
|
|
|
echo -n "Uzun ismi: "
|
2016-06-14 15:08:00 +02:00
|
|
|
|
read description
|
|
|
|
|
fi
|
|
|
|
|
if [ "$name" == "!stop!" -o "$description" == "!stop!" ]; then
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
check_args "$description" "$name"
|
|
|
|
|
ret=$?
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
i=0
|
|
|
|
|
while [ -n "${default_groups[i]}" ]; do
|
|
|
|
|
if grep "${default_groups[i]}" /etc/group > /dev/null ; then
|
|
|
|
|
if [ -z "$user_groups" ]; then
|
|
|
|
|
user_groups="${default_groups[i]}"
|
|
|
|
|
else
|
|
|
|
|
user_groups="$user_groups,${default_groups[i]}"
|
|
|
|
|
fi
|
|
|
|
|
# echo "groupes : $user_groups"
|
|
|
|
|
# else
|
|
|
|
|
# echo 1>&2 ' Veuillez installez un gestionnaire de fenetre,
|
|
|
|
|
# redemarrer la machine dans ce gestionnaire,
|
|
|
|
|
# et relancer cette commande.
|
|
|
|
|
#'
|
|
|
|
|
# exit 1
|
|
|
|
|
fi
|
|
|
|
|
i=$((i+1))
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
echo 1>&2 "
|
2016-06-14 19:10:02 +02:00
|
|
|
|
$name kullanıcısının oluşturulması.
|
2016-06-14 15:08:00 +02:00
|
|
|
|
"
|
2017-09-26 08:02:04 +02:00
|
|
|
|
if [ -f /root/.xinitrc ]; then
|
|
|
|
|
cp /root/.xinitrc /home/${name}/
|
|
|
|
|
fi
|
|
|
|
|
# kullanıcı izinlerin ayarlanması
|
2016-06-14 15:08:00 +02:00
|
|
|
|
if [ -d /home/${name} ]; then
|
2017-09-26 08:02:04 +02:00
|
|
|
|
#evdizini
|
2016-06-14 15:08:00 +02:00
|
|
|
|
chown -R ${name}:${name} /home/${name}
|
2017-09-26 08:02:04 +02:00
|
|
|
|
#ses aygıtları
|
|
|
|
|
setfacl -m u:${name}:rw /dev/snd/*
|
2016-06-14 15:08:00 +02:00
|
|
|
|
fi
|
2017-09-26 08:02:04 +02:00
|
|
|
|
|
2016-06-14 15:08:00 +02:00
|
|
|
|
if [ -z "$user_groups" ]; then
|
|
|
|
|
/sbin/useradd -c "${description}" -m "${name}" || exit 1
|
|
|
|
|
else
|
|
|
|
|
/sbin/useradd -c "${description}" -G "$user_groups" -m "${name}" || exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2017-09-26 08:02:04 +02:00
|
|
|
|
|
2017-04-22 19:43:49 +02:00
|
|
|
|
|
2016-06-14 15:08:00 +02:00
|
|
|
|
passwd "$name"
|
|
|
|
|
|
|
|
|
|
exit 0
|