osx-useradd 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/COPYING +20 -0
  2. data/README.md +37 -0
  3. data/Rakefile +3 -0
  4. data/bin/useradd +134 -0
  5. metadata +60 -0
data/COPYING ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 James Pearson <pearson@changedmy.name>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to do
8
+ so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
20
+
@@ -0,0 +1,37 @@
1
+ `useradd` is a pretty cool tool. Unfortunately, Apple [didn't think
2
+ so](http://serverfault.com/questions/20702/).
3
+
4
+ This is an attempt to create a wrapper around `dscl` that behaves like
5
+ `useradd`.
6
+
7
+ ## Installation
8
+
9
+ [$]> gem install osx-useradd
10
+
11
+ ## Usage
12
+
13
+ [$]> useradd --help
14
+ Usage: useradd [options] LOGIN
15
+ -b, --base-dir BASE_DIR
16
+ -c, --comment COMMENT
17
+ -d, --home HOME_DIR
18
+ -D, --default
19
+ -e, --expiredate EXPIRE_DATE
20
+ -f, --inactive INACTIVE
21
+ -g, --gid GROUP
22
+ -G GROUP1[,GROUP2,...[,GROUPN]],
23
+ --groups
24
+ -k, --skel SKEL_DIR
25
+ -K, --key KEY=VAUE
26
+ -l, --no-log-init
27
+ -m, --create-home
28
+ -M
29
+ -N, --no-user-group
30
+ -o, --non-unique
31
+ -p, --password PASSWORD
32
+ -r, --system
33
+ -s, --shell SHELL
34
+ -u, --uid UID
35
+ -U, --user-group
36
+ -Z, --selinux-user SEUSER
37
+
@@ -0,0 +1,3 @@
1
+ require 'mg'
2
+ MG.new('osx-useradd.gemspec')
3
+
@@ -0,0 +1,134 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+
5
+ homeDirectory = '/Users/$username'
6
+ commands = ['-create $homeDirectory']
7
+ OptionParser.new do |opts|
8
+ opts.banner = "Usage: #{$0} [options] LOGIN"
9
+
10
+ opts.on('-b', '--base-dir BASE_DIR') do |baseDir|
11
+ puts '-b not yet implemented.'
12
+ exit 1
13
+ end
14
+
15
+ opts.on('-c', '--comment COMMENT') do |comment|
16
+ puts '-c not yet implemented.'
17
+ exit 1
18
+ end
19
+
20
+ opts.on('-d', '--home HOME_DIR') do |homeDir|
21
+ homeDirectory = homeDir
22
+ end
23
+
24
+ opts.on('-D', '--default') do
25
+ puts '-D not yet implemented.'
26
+ exit 1
27
+ end
28
+
29
+ opts.on('-e', '--expiredate EXPIRE_DATE') do |expireDate|
30
+ puts '-e not yet implemented.'
31
+ exit 1
32
+ end
33
+
34
+ opts.on('-f', '--inactive INACTIVE') do |inactive|
35
+ puts '-f not yet implemented.'
36
+ exit 1
37
+ end
38
+
39
+ opts.on('-g', '--gid GROUP') do |group|
40
+ commands << "-create $homeDirectory PrimaryGroupID #{group}"
41
+ end
42
+
43
+ opts.on('-G', '--groups GROUP1[,GROUP2,...[,GROUPN]]', Array) do |groups|
44
+ groups.each do |group|
45
+ commands << "-append /Groups/#{group} GroupMembership $username"
46
+ end
47
+ end
48
+
49
+ opts.on('-k', '--skel SKEL_DIR') do |skelDir|
50
+ puts '-k not yet implemented.'
51
+ exit 1
52
+ end
53
+
54
+ opts.on('-K', '--key KEY=VAUE') do |key|
55
+ puts '-K not yet implemented.'
56
+ exit 1
57
+ end
58
+
59
+ opts.on('-l', '--no-log-init') do
60
+ puts '-l not yet implemented.'
61
+ exit 1
62
+ end
63
+
64
+ opts.on('-m', '--create-home') do
65
+ puts '-m not yet implemented.'
66
+ exit 1
67
+ end
68
+
69
+ opts.on('-M') do
70
+ puts '-M not yet implemented.'
71
+ exit 1
72
+ end
73
+
74
+ opts.on('-N', '--no-user-group') do
75
+ puts '-N not yet implemented.'
76
+ exit 1
77
+ end
78
+
79
+ opts.on('-o', '--non-unique') do
80
+ puts '-o not yet implemented.'
81
+ exit 1
82
+ end
83
+
84
+ opts.on('-p', '--password PASSWORD') do |password|
85
+ puts '-p not yet implemented.'
86
+ exit 1
87
+ end
88
+
89
+ opts.on('-r', '--system') do
90
+ puts '-r not yet implemented.'
91
+ exit 1
92
+ end
93
+
94
+ opts.on('-s', '--shell SHELL') do |shell|
95
+ commands << "-create $homeDirectory UserShell #{shell}"
96
+ end
97
+
98
+ opts.on('-u', '--uid UID') do |uid|
99
+ `id #{uid} 2> /dev/null`
100
+ if $?.exitstatus == 0
101
+ puts 'Non-unique UID.'
102
+ exit 2
103
+ end
104
+ commands << "-create $homeDirectory UniqueID #{uid}"
105
+ end
106
+
107
+ opts.on('-U', '--user-group') do
108
+ puts '-U not yet implemented.'
109
+ exit 1
110
+ end
111
+
112
+ opts.on('-Z', '--selinux-user SEUSER') do |seUser|
113
+ puts '-Z not yet implemented.'
114
+ exit 1
115
+ end
116
+ end.parse!
117
+
118
+ # Since we use the destructive parse! above, we won't pick up a param here on
119
+ # accident.
120
+ username = ARGV[-1]
121
+ if username.nil?
122
+ puts 'Fool, you gotta give me a username!'
123
+ exit 2
124
+ end
125
+
126
+ commands.each do |command|
127
+ command.sub! '$homeDirectory', homeDirectory
128
+ # We didn't know the username while we were creating these.
129
+ command.sub! '$username', username
130
+
131
+ puts 'dscl . ' + command
132
+ `dscl . #{command}`
133
+ end
134
+
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: osx-useradd
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - xiongchiamiov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2014-04-26 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: useradd is a pretty cool tool. Unfortunately, Apple didn't think so. This is an attempt to create a wrapper around dscl that behaves like useradd.
18
+ email:
19
+ - xiong.chiamiov@gmail.com
20
+ executables:
21
+ - useradd
22
+ extensions: []
23
+
24
+ extra_rdoc_files:
25
+ - README.md
26
+ files:
27
+ - COPYING
28
+ - Rakefile
29
+ - README.md
30
+ - bin/useradd
31
+ has_rdoc: true
32
+ homepage: https://github.com/xiongchiamiov/osx-useradd/
33
+ licenses: []
34
+
35
+ post_install_message:
36
+ rdoc_options: []
37
+
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ requirements: []
53
+
54
+ rubyforge_project:
55
+ rubygems_version: 1.5.3
56
+ signing_key:
57
+ specification_version: 3
58
+ summary: A wrapper around dscl that behaves like useradd.
59
+ test_files: []
60
+