-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathaccount.sh
executable file
·54 lines (47 loc) · 1016 Bytes
/
account.sh
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
#!/usr/bin/env bash
USER="${1}"
COMMENT="${1} user on Vagrant for demo"
GROUP="${1}"
HOME="/srv/${1}"
YUM=$(which yum 2>/dev/null)
APT_GET=$(which apt-get 2>/dev/null)
user_rhel() {
sudo /usr/sbin/groupadd --force --system ${GROUP}
if ! getent passwd ${USER} >/dev/null ; then
sudo /usr/sbin/adduser \
--system \
--gid ${GROUP} \
--home ${HOME} \
--no-create-home \
--comment "${COMMENT}" \
--shell /bin/false \
${USER} >/dev/null
fi
}
user_deb() {
## Debian user
if ! getent group ${GROUP} >/dev/null
then
sudo addgroup --system ${GROUP} >/dev/null
fi
if ! getent passwd ${USER} >/dev/null
then
sudo adduser \
--system \
--disabled-login \
--ingroup ${GROUP} \
--home ${HOME} \
--no-create-home \
--gecos "${COMMENT}" \
--shell /bin/false \
${USER} >/dev/null
fi
}
if [[ ! -z ${YUM} ]]; then
user_rhel
elif [[ ! -z ${APT_GET} ]]; then
user_deb
else
echo "ERROR"
exit 1;
fi