-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuber.sh
executable file
·64 lines (51 loc) · 939 Bytes
/
uber.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
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
# check root
if [[ "${UID}" -ne 0 ]]
then
echo "ure not root" >&2
exit 1
fi
# check for args
if [[ "${#}" -lt 1 ]]
then
echo "give args ${0} USER_NAME [COMMENT]..." >&2
exit 1
fi
# add to parm
USER_NAME="${1}"
#rest parm for acc comments
shift
COMMENT="${@}"
# generate a password
PASSWORD=$(date +%s%N | sha256sum | head -c20)
#make acc
useradd -c "${COMMENT}" -m ${USER_NAME} &> /dev/null
#check for return
if [[ "${?}" -eq 1 ]]
then
echo "someting went wrong with account creation" >&2
exit 1
fi
#set pass
echo ${PASSWORD} | passwd --stdin ${USER_NAME} &>/dev/null
#check if pass works
if [[ "${?}" -eq 1 ]]
then
echo "someting went wrong with password" >&2
exit 1
fi
#force change
passwd -e ${USER_NAME} &> /dev/null
# display info
echo 'username'
echo "${USER_NAME}"
echo
echo 'password'
echo "${PASSWORD}"
echo
echo 'hostname'
echo "${HOSTNAME}"
echo
echo 'name of user'
echo "${COMMENT}"
exit 0