forked from sandervanvugt/bash-scripting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makeuser
executable file
·67 lines (57 loc) · 1.14 KB
/
makeuser
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
#makeusr [-u uid] [-g gid] [-i info] [-h homedir] [-s shell] username
function usage
{
echo ‘usage: makeusr [-u uid] [-g gid] [-i info] [-h homedir] ‘
echo ‘[-s shell] username
exit 1
}
function helpmessage
{
echo "makeusr is a script ... "
echo "blablabla"
}
while getopts "u:g:i:h:s:" opt; do
case $opt in
u ) uid=$OPTARG ;;
g ) gid=$OPTARG ;;
i ) info=$OPTARG ;;
h ) home=$OPTARG ;;
s ) shell=$OPTARG ;;
? ) helpmessage ;;
* ) usage ;;
esac
shift $(($OPTIND -1))
done
if [ -z "$1" ]; then
usage
fi
if [ -n "$2" ]; then
usage
fi
if [ -z "$uid" ]; then
uid=500
while cut -d : -f3 /etc/passwd | grep -x $uid
do
uid=$((uid+1)) > /dev/null
done
fi
if [ -z "$gid" ]; then
gid=$(grep users /etc/group | cut -d: -f3)
fi
if [ -z "$info" ]; then
echo Provide information about the user.
read info
fi
if [ -z "$home" ]; then
home=/home/$1
fi
if [ -z "$shell" ]; then
shell=/bin/bash
fi
echo $1:x:$uid:$gid:$info:$home:$shell >> /etc/passwd
echo $1:::::::: >> /etc/shadow
mkdir -p $home
chmod 660 $home
chown $1:users $home
passwd $1