-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathaddme
executable file
·105 lines (78 loc) · 1.69 KB
/
addme
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#/bin/bash
#set -x
OS=`uname -s`
mygid=7903
myuid="556"
myuname="jeffcof"
mygrpname=scxdev
while [ $# -ne 0 ]; do
case "$1" in
-uid )
myuid=$2
shift
;;
-uname )
myuname=$2
shift
;;
* )
echo "addme -uid <uid> -uname <username>"
exit 2
;;
esac
shift
done
myhome=/home/$myuname
if [ "$myuid" = "<UID GOES HERE>" -o "$myuname" = "<USERNAME GOES HERE>" ]; then
echo "You need to modify the script with your information"
echo "or supply the information on the command line..."
exit 1
fi
# Override default for Solaris
if [ "$OS" = "SunOS" ]; then
myhome=/export/home/$myuname
fi
# Is my group already here?
grep :${mygid}: /etc/group > /dev/null
if [ $? -eq 0 ]; then
echo "group already exists..."
else
if [ "$OS" = "AIX" ]; then
mkgroup -A id=$mygid $mygrpname
else
groupadd -g $mygid $mygrpname
fi
fi
# Check for my username
pwdentrybyname=`grep $myuname /etc/passwd`
if [ -n "$pwdentry" ]; then
echo "Username already exists, checking uid."
// Get the entry by UID...
pwdentrybyuid=`grep $myuid /etc/passwd`
if [ -z "$pwentrybyuid" ] && ["$pwdentrybyname" != "pwdentrybyuid" ]; then
echo "uid already in use and it's not you..."
exit 2
fi
fi
case "$OS" in
"SunOS"|"AIX" )
useradd -g $mygid -u $myuid -d $myhome -s /bin/bash $myuname
usermod -G staff $myuname
;;
* )
useradd -g $mygrpname -u $myuid -d $myhome -s /bin/bash $myuname
usermod -G users $myuname
;;
esac
# SLES9 seems to ignore the create directory step, for some reason..
if [ ! -d $myhome ]; then
mkdir $myhome
if [ $? -ne 0 ]; then
echo "Unable to create home directory..."
exit 99
fi
fi
chown $myuname $myhome
chgrp $mygrpname $myhome
chmod 755 $myhome
passwd $myuname