]> git.cameronkatri.com Git - pw-darwin.git/blob - adduser/adduser.sh
Yet one cleanup
[pw-darwin.git] / adduser / adduser.sh
1 #!/usr/bin/perl
2
3
4
5 # Copyright (c) 1994 GB Data Systems
6 # All rights reserved.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
15 # 3. The name of the Author may not be used to endorse or promote products
16 # derived from this software without specific prior written permission.
17 # THIS SOFTWARE IS PROVIDED BY GB DATA AND CONTRIBUTORS ``AS IS'' AND
18 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 # ARE DISCLAIMED. IN NO EVENT SHALL GB DATA OR CONTRIBUTORS BE LIABLE
21 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 # SUCH DAMAGE.
28
29 #
30 # $Id: adduser,v 1.4 1994/12/28 17:27:21 gclarkii Exp $
31 #
32
33 $configfile = "\/etc\/adduser.conf";
34
35 if (-f $configfile) {
36 open (CONFIG, "$configfile");
37 while (<CONFIG>) {
38 eval "$_";
39 }
40 }
41
42 open (WHOAMI, "whoami|");
43
44 while (<WHOAMI>) {
45 $whoami = $_;
46 }
47 chop $whoami;
48
49 if ($whoami ne "root") {
50 system "clear";
51 print "\n\nYou must be root to add an user\n\n";
52 close WHOAMI;
53 exit;
54 }
55 close WHOAMI;
56
57 # Start getting information and print a banner
58
59 print " Adduser\n";
60 print " A system utility for adding users with defaults\n";
61 print "\n\n";
62
63 #
64 # User ID
65 #
66
67
68 print "Please enter the login name of the user: ";
69 chop ($userlogin = <STDIN>);
70
71
72 sub subuid {
73 $userid = "";
74 print "Please enter the user id or hit enter for the next id: ";
75 chop ($userid = <STDIN>);
76 }
77
78 while (!$userid) {
79 &subuid;
80 if (!$userid) {
81 if ($useautoids) {
82 open (USERID, "+<$userids");
83 chop ($xxuserid = <USERID>);
84 $userid = $xxuserid + 1;
85 close USERID;
86 open (USERID, "+>$userids");
87 print (USERID "$userid\n");
88 close USERID;
89 } else { &subuid; }
90 }
91 }
92
93 #
94 # Group ID
95 #
96
97 sub groupids {
98 print "Please enter the group id or hit enter for the default id: ";
99 chop ($groupid = <STDIN>);
100 }
101
102 &groupids;
103
104 while (!$groupid) {
105 if ($defgroupid) {
106 if (!$groupid) {
107 $groupid = "$defgroupid";
108 } else { &groupids; }
109 } else { &groupids; }
110 }
111
112 #
113 # User name
114 #
115
116 print "Please enter the user's name: ";
117 chop ($username = <STDIN>);
118
119 #
120 # Home directory
121 #
122
123 print "Please enter the users home directory or hit enter for default: ";
124 chop ($userdir = <STDIN>);
125
126 if (!$userdir) {
127 $userdir = "$defusrdir\/$userlogin";
128 print "$userdir\n";
129 }
130
131 #
132 # Login Shell
133 #
134
135 print "Please enter the users login shell or hit enter for default: ";
136 chop ($usershell = <STDIN>);
137
138 if (!$usershell) {
139 $usershell = "$userdefshell";
140 print "$usershell\n";
141 }
142
143 #
144 # Create password file entry
145 #
146
147 print "Opening and locking passwd file in blocking mode.\n";
148 open (PASS, '>>/etc/master.passwd');
149 flock (PASS, 2) || die "Can't lock passwd file, must be in use!!\n";
150 print (PASS "$userlogin::$userid:$groupid::0:0:$username,,,:$userdir:$usershell\n");
151 print "Unlocking and closing password file\n";
152 flock (PASS,8);
153 close PASS;
154 print "Re-indexing password databases\n";
155 system 'pwd_mkdb -p /etc/master.passwd';
156 system "passwd $userlogin";
157
158 #
159 # Create user directory
160 #
161 print "Creating user directory\n";
162 if (! -e $defusrdir) {
163 system "mkdir -p $defusrdir\/$userdir";
164 } else {
165 system "mkdir $userdir";
166 }
167
168
169 print "Copying user shell files\n";
170 system "cp $skel_location\/dot.login $userdir\/\.login";
171 system "cp $skel_location\/dot.profile $userdir\/\.profile";
172
173 if ($usershell eq "\/bin\/csh" || $usershell eq "\/usr\/local\/bin\/tcsh")
174 {
175 system "cp $skel_location\/dot.cshrc $userdir\/.cshrc";
176 }
177 system "chmod -R 664 $userdir";
178 system "chown -R $userid.$groupid $userdir";
179
180
181
182 #
183 # Print out information used in creation of this account
184 #
185 print "\n\n";
186 print "Information used to create this account follows.\n";
187 print "\n";
188 print "Login Name: $userlogin\n";
189 print "UserId: $userid\n";
190 print "GroupId: $groupid\n";
191 print "UserName: $username\n";
192 print "HomeDir: $userdir\n";
193 print "Shell: $usershell\n";
194 print "\nDONE\n\n";
195