ahalogy-automation 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2ba9385a1723584f9cedfd001dc0f6bdeb608c96
4
- data.tar.gz: d0f8641b84854d7b45522b0df9519c129d6d7d43
3
+ metadata.gz: 42859894867e6063b4c1b93fa38d420c7e1727f7
4
+ data.tar.gz: 8934e5f981a1d1d610b53115ccbbc92d4df1dcff
5
5
  SHA512:
6
- metadata.gz: 16e3afbed2d39426d22c0125d21f9b940aba6e83a0d9272784e075e9b8070b1af3043cd118ec2dced26ee09d9c7e0862b8f0c511c6decf743a4a04eaa6805042
7
- data.tar.gz: 376de91809e352a2778db8a8a0ce73c484172661e8cff3f76dc276b53bc7b53e4ea0e20a213e3b47e257f86e0e60be696f0cada9c90f1315a21d718d0f179e4d
6
+ metadata.gz: 8809830e64244b56f95d584a7ae66e6f6e60f911c7045d70909ed61b00dfd154a3d028b2706485e9f59c26da5906e4ce81102829ceadceb3cf21f3398f279ed8
7
+ data.tar.gz: 8d8855b4c1294ffdeff2475c210e4481a90c7ffc4590ae98979a3dbb85351dc40679e1f70e1fa35eec0d6250f390d19a6f67f0fddcb6d3626d2bf55b8b6e775a
@@ -1,10 +1,10 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'ahalogy-automation'
3
- gem.version = '0.0.4'
3
+ gem.version = '0.0.5'
4
4
  gem.licenses = ['MIT']
5
- gem.date = '2015-05-05'
5
+ gem.date = '2015-05-15'
6
6
  gem.summary = 'Scripts to handle IT automation.'
7
- gem.description = 'Script that installs many applications on Ahalogy Mac computers.'
7
+ gem.description = 'Scripts that install applications on Ahalogy Mac computers.'
8
8
  gem.authors = ['Zan Loy']
9
9
  gem.email = 'zan.loy@gmail.com'
10
10
  gem.homepage = 'https://www.ahalogy.com'
@@ -12,6 +12,7 @@ Gem::Specification.new do |gem|
12
12
  gem.executables = ['a5y-configure']
13
13
 
14
14
  gem.add_runtime_dependency 'colorize', '~> 0'
15
+ gem.add_runtime_dependency 'command', '~> 1.0.0', '>= 1.0.0'
15
16
  gem.add_runtime_dependency 'daybreak', '~> 0.3', '>= 0.3.0'
16
17
  gem.add_runtime_dependency 'github_api', '~> 0.12', '>= 0.12.3'
17
18
  gem.add_runtime_dependency 'highline', '~> 1.7'
@@ -2,15 +2,19 @@
2
2
 
3
3
  require 'ahalogy/install-helper'
4
4
  require 'colorize'
5
+ require 'command'
5
6
  require 'daybreak'
6
7
  require 'github_api'
7
8
  require 'highline/import'
8
9
  require 'optparse'
9
10
 
10
- user = ENV['USER']
11
- fail 'This script should not be run as root.' if user == 'root'
11
+ fail 'This script should run as root using sudo.' unless ENV['USER'] == 'root'
12
+ user_name = ENV['SUDO_USER']
13
+ user_uid = ENV['SUDO_UID']
14
+ user_gid = ENV['SUDO_GID']
15
+ fail 'Environment variables for SUDO_UID and SUDO_GID are invalid' if user_uid.nil? or user_gid.nil?
12
16
 
13
- groups = [:developer, :pinner, :cs, :designer]
17
+ groups = [:developer, :pinner, :cs, :designer, :'systems-manager']
14
18
  options = {
15
19
  groups: [:default],
16
20
  verbose: false,
@@ -28,7 +32,8 @@ OptionParser.new do |opts|
28
32
  end
29
33
  opts.on('--skip-filevault', 'Skip configuration of FileVault.') { options[:skip_filevault] = true }
30
34
  opts.on('--skip-github', 'Skip configuration of GitHub sshkey') { options[:skip_github] = true }
31
- opts.on('-a', '--ask', '"Ask to confirm settings stored in settings database.') { options[:ask] = true }
35
+ opts.on('-a', '--ask', 'Ask to confirm settings stored in settings database.') { options[:ask] = true }
36
+ opts.on('--xcode FILE', 'Use local xcode dmg file for install.') { |file| options[:xcode] = file }
32
37
  opts.on('-d', '--debug', 'Enable debug messaging.') { options[:verbose] = true }
33
38
  end.parse!
34
39
 
@@ -50,36 +55,89 @@ notes = []
50
55
 
51
56
  begin
52
57
  if options[:groups].include? :default
53
- ## Install xcode command line tools
58
+ # Install xcode command line tools
54
59
  system('xcode-select -v')
55
60
  if $? != 0
56
61
  run_cmd 'xcode-select --install', 'Installing Xcode CLI tools.'
57
62
  else
58
63
  puts 'Xcode CLI tools is already installed...skipped.'.colorize(:green)
59
64
  end
60
- ## Install full xcode
61
- system 'xcodebuild &> /dev/null'
62
- case $?.exitstatus
63
- when 1
64
- fail 'The full xcode developer application needs to be installed before running this script.'.colorize(:red)
65
- when 69
66
- puts 'You need to agree to the Xcode license before continuing...'.colorize(:red)
67
- system('sudo xcodebuild -license')
68
- if $? != 0
69
- fail 'Xcode is not configured correctly.'
70
- end
71
- end
72
65
 
73
66
  # Enable FileVault
74
67
  unless options[:skip_filevault]
75
68
  begin
76
- run_cmd "sudo fdesetup enable -user admin -usertoadd #{user}", 'Enabling FileVault... (skip by re-running script with --skip-filevault)'
69
+ run_cmd "fdesetup enable -user admin -usertoadd #{user_name}", 'Enabling FileVault... (skip by re-running script with --skip-filevault)'
77
70
  notes << 'FileVault was enabled. You will need to reboot to start the encryption process.'
78
71
  rescue
79
72
  puts 'FileVault already enabled...skipped'.colorize(:green)
80
73
  end
81
74
  end
82
75
 
76
+ # Install full xcode
77
+ system 'xcodebuild &> /dev/null'
78
+ case $?.exitstatus
79
+ when 1
80
+ if options[:xcode]
81
+ xcode_dmg = options[:xcode]
82
+ else
83
+ puts 'Downloading Xcode to install...'.colorize(:blue)
84
+ system('curl --output /tmp/xcode.dmg https://s3-us-west-1.amazonaws.com/a5y-is-and-t/Xcode_6.3.1.dmg')
85
+ xcode_dmg = '/tmp/xcode.dmg'
86
+ end
87
+ command = Command.run("hdiutil attach -nobrowse '#{xcode_dmg}'")
88
+ fail "Can't mount Xcode dmg at #{xcode_dmg}." unless command.status == 0
89
+ line = command.stdout.lines.last
90
+ device = line.split(' ').first.strip
91
+ dir = line.split(' ').last.strip
92
+ puts 'Copying Xcode.app to /Applications...'.colorize(:blue)
93
+ command = Command.run("cp -R '#{dir}/Xcode.app' /Applications")
94
+ fail 'Error trying to install Xcode.app in /Applications' unless command.status == 0
95
+ Command.run "hdiutil unmount #{device}"
96
+ FileUtils.rm xcode_dmg if xcode_dmg == '/tmp/xcode.dmg'
97
+ install_file 'com.apple.dt.Xcode.plist', '/Library/Preferences/com.apple.dt.Xcode.plist'
98
+ when 69
99
+ install_file 'com.apple.dt.Xcode.plist', '/Library/Preferences/com.apple.dt.Xcode.plist'
100
+ end
101
+
102
+ # Enable system firewall
103
+ run_cmd 'defaults write /Library/Preferences/com.apple.alf globalstate -int 1', 'Enabling firewall.'
104
+
105
+ # A few more random things to do while we are still root
106
+ # TODO: Clean this up
107
+
108
+ # Make some directories so HomeBrew installer doesn't need sudo
109
+ mkdir '/usr/local', mode: 0775
110
+ mkdir '/Library/Caches/Homebrew', mode: 0775
111
+
112
+ # Make Caskroom for brew cask so it doesn't need sudo to do it.
113
+ mkdir '/opt', mode: 0755
114
+ mkdir '/opt/homebrew-cask', owner: user_name, group: user_gid
115
+ mkdir '/opt/homebrew-cask/Caskroom', owner: user_name, group: user_gid
116
+
117
+ if options[:groups].include? :developer
118
+ # Set the user shell here before we drop privs so oh-my-zsh installer doesn't ask for password
119
+ Command.run "chsh -s /bin/zsh #{user_name}"
120
+ # Setup rbenv
121
+ run_cmd "grep -q -F 'export RBENV_ROOT=/usr/local/var/rbenv' /etc/profile || echo 'export RBENV_ROOT=/usr/local/var/rbenv' >> /etc/profile", 'Adding RBENV_ROOT to /etc/profile...'
122
+ run_cmd "grep -q -F 'rbenv init -' /etc/profile || echo 'eval \"$(rbenv init -)\"' >> /etc/profile", 'Adding rbenv init to /etc/profile...'
123
+ mkdir '/usr/local/var/rbenv/plugins'
124
+ if File.exists? '/usr/local/var/rbenv/plugins/rbenv-gem-rehash'
125
+ puts 'rbenv-gem-rehash already installed...skipped.'.colorize(:green)
126
+ else
127
+ run_cmd 'git clone https://github.com/sstephenson/rbenv-gem-rehash.git /usr/local/var/rbenv/plugins/rbenv-gem-rehash', 'Installing rbenv-gem-rehash...'
128
+ end
129
+ end
130
+
131
+ if options[:groups].include? :'systems-manager'
132
+ puts 'Installing Ahalogy-Systems-Manager.pkg...'.colorize(:blue)
133
+ system('curl --output /tmp/ahalogy-systems-manager.pkg https://s3-us-west-1.amazonaws.com/a5y-is-and-t/Ahalogy-Systems-Manager.pkg')
134
+ system('installer -pkg /tmp/ahalogy-systems-manager.pkg -target /')
135
+ FileUtils.rm '/tmp/ahalogy-systems-manager.pkg'
136
+ end
137
+
138
+ # Dropping privileges to the sudo_user
139
+ Process::Sys.setuid(user_name)
140
+
83
141
  unless options[:skip_github]
84
142
  # Let's setup our sshkey and github
85
143
  if File.exists? File.expand_path('~/.ssh/id_rsa')
@@ -107,14 +165,11 @@ begin
107
165
  end
108
166
  end
109
167
 
110
- # Enable system firewall
111
- run_cmd 'sudo defaults write /Library/Preferences/com.apple.alf globalstate -int 1', 'Enabling firewall.'
112
-
113
168
  # Install homebrew
114
169
  if File.exists? '/usr/local/bin/brew'
115
170
  puts 'Homebrew already installed...skipped.'.colorize(:green)
116
171
  else
117
- run_cmd 'ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"', "Installing homebrew."
172
+ run_cmd 'echo | ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"', "Installing homebrew."
118
173
  run_cmd 'brew doctor', 'Verifying Homebrew Install...'
119
174
  end
120
175
 
@@ -129,8 +184,12 @@ begin
129
184
  run_cmd 'brew tap homebrew/versions', 'Tapping homebrew/versions...'
130
185
 
131
186
  ### Install Applications
187
+ # Apps via Brew
188
+ install_brew [:git, :python, :python3, :cassandra, :macvim]
189
+ #install_brew 'macvim', '--override-system-vim --with-python3'
190
+ # Apps via Cask
191
+ install_cask [:backblaze, :slack, :github, 'google-chrome', 'google-drive', :screenhero, :textmate, :zoomus]
132
192
  # BackBlaze
133
- install_cask 'backblaze'
134
193
  notes << "If this is the first run of the Ahalogy installer script, you will need to install BackBlaze by running:\n open '/opt/homebrew-cask/Caskroom/backblaze/latest/Backblaze Installer.app'"
135
194
  # Hidden.app
136
195
  target_dir = File.expand_path('~/Downloads')
@@ -138,14 +197,10 @@ begin
138
197
  unless File.exists? filename
139
198
  cmd = "curl -o #{filename} https://hiddenapp.com/static/downloads/hidden2.1.zip"
140
199
  run_cmd(cmd, 'Downloading Hiddenapp...')
141
- run_cmd "cd ~/Downloads && unzip -o #{filename}", 'Unzipping hiddenapp payload...'
142
- notes << 'You will need to manually install Hidden.app. It has been unzipped in ~/Downloads.'
200
+ run_cmd "cd #{target_dir} && unzip -o #{filename}", 'Unzipping hiddenapp payload...'
201
+ notes << "You will need to manually install Hidden.app. It has been unzipped in #{target_dir}."
143
202
  end
144
- # Apps via Brew
145
- install_brew [:git, :python, :python3, :cassandra]
146
- install_brew 'macvim', '--override-system-vim --with-python3'
147
- # Apps via Cask
148
- install_cask [:github, 'google-chrome', 'google-drive', :screenhero, :textmate, :zoomus]
203
+ # MacVim
149
204
  install_file 'vimrc', '~/.vimrc'
150
205
  if File.directory? File.expand_path('~/.vim/bundle/Vundle.vim')
151
206
  run_cmd 'cd ~/.vim/bundle/Vundle.vim && git pull', 'Updating Vundle via GitHub...'
@@ -158,7 +213,7 @@ begin
158
213
  if options[:groups].include? :developer
159
214
  puts "### Starting installation of developer apps... ###"
160
215
  install_brew [:node, :phantomjs, 'homebrew/versions/postgresql92', :redis, 'ruby-build', :nvm, :pow, :rbenv]
161
- install_cask ['1password', :alfred, :anvil, :dash, :slack, :tower]
216
+ install_cask ['1password', :alfred, :anvil, :dash, :tower]
162
217
  # Setup cql
163
218
  run_cmd 'pip install cql &> /dev/null', 'Installing cql python module via pip...'
164
219
  run_cmd 'pip3 install cql &> /dev/null', 'Installing cql python3 module via pip3...'
@@ -167,35 +222,17 @@ begin
167
222
  add_line_to_file '~/.zshrc', 'export NVM_DIR=~/.nvm'
168
223
  add_line_to_file '~/.zshrc', 'source $(brew --prefix nvm)/nvm.sh'
169
224
  # Setup pow
170
- if not File.directory? File.expand_path('~/Library/Application Support/Pow/Hosts')
225
+ unless File.directory? File.expand_path('~/Library/Application Support/Pow/Hosts')
171
226
  run_cmd 'mkdir -p ~/Library/Application\ Support/Pow/Hosts', 'Creating support directory for pow hosts...'
172
227
  end
173
- if not File.symlink? File.expand_path('~/.pow')
228
+ unless File.symlink? File.expand_path('~/.pow')
174
229
  run_cmd 'ln -s ~/Library/Application\ Support/Pow/Hosts ~/.pow', 'Symlinking pow hosts directory to ~/.pow ...'
175
230
  end
176
- run_cmd 'sudo pow --install-system', 'Configuring port 80 forwarding for pow...'
177
- run_cmd 'pow --install-local', 'Configuring launchd agent for pow...'
178
- run_cmd 'sudo launchctl load -w /Library/LaunchDaemons/cx.pow.firewall.plist', 'Configuring pow launchd agent to start on boot...'
179
- run_cmd 'launchctl load -w ~/Library/LaunchAgents/cx.pow.powd.plist', 'Starting pow...'
180
- # Setup rbenv
181
- system("grep -q -F 'export RBENV_ROOT=/usr/local/var/rbenv' /etc/profile")
182
- if $? != 0
183
- run_cmd "echo 'export RBENV_ROOT=/usr/local/var/rbenv' | sudo tee -a /etc/profile > /dev/null", "Adding RBENV_ROOT to /etc/profile..."
184
- end
185
- system("grep -q -F 'rbenv init -' /etc/profile")
186
- if $? != 0
187
- run_cmd %q[echo 'eval "$(rbenv init -)"' | sudo tee -a /etc/profile > /dev/null], "Adding rbenv init to /etc/profile..."
188
- end
189
- mkdir '/usr/local/var/rbenv'
190
- mkdir '/usr/local/var/rbenv/plugins'
191
- if File.exists? '/usr/local/var/rbenv/plugins/rbenv-gem-rehash'
192
- puts 'rbenv-gem-rehash already installed...skipped.'.colorize(:green)
193
- else
194
- run_cmd 'sudo git clone https://github.com/sstephenson/rbenv-gem-rehash.git /usr/local/var/rbenv/plugins/rbenv-gem-rehash', "Installing rbenv-gem-rehash..."
195
- end
231
+ notes << "You will need to run the following commands to setup port 80 forwarding for pow:\n sudo pow --install-system\n pow --install-local"
232
+ notes << "You will need to run the following commands if you want pow to start on boot:\n sudo launchctl load -w /Library/LaunchDaemons/cx.pow.firewall.plist\n launchctl load -w ~/Library/LaunchAgents/cx.pow.powd.plist"
196
233
  # OH MY ZSH!
197
- if not File.directory? File.expand_path('~/.oh-my-zsh')
198
- run_cmd "curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh", "Installing oh-my-zsh..."
234
+ unless File.directory? File.expand_path('~/.oh-my-zsh')
235
+ run_cmd 'curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh', 'Installing oh-my-zsh...'
199
236
  end
200
237
  # Set the default terminal theme to something more bareable.
201
238
  #run_cmd 'defaults write com.apple.Terminal "Default Window Settings" "Pro"'
@@ -211,16 +248,17 @@ begin
211
248
  end
212
249
 
213
250
  if options[:groups].include? :designer
214
- install_cask [:slack, 'adobe-creative-cloud', 'sketch-tool', :invisionsync, :tower, :anvil]
251
+ install_cask ['adobe-creative-cloud', 'sketch-tool', :invisionsync, :tower, :anvil]
215
252
  notes << "If this is the first time running a5y-configure, you will need to manually install Adobe Creative Cloud by running:\n open '/opt/homebrew-cask/Caskroom/adobe-creative-cloud/latest/Creative Cloud Installer.app'"
216
253
  end
254
+
217
255
  rescue
218
256
  raise
219
257
  ensure
220
258
  db.close
221
259
  end
222
260
 
223
- if not notes.empty?
261
+ unless notes.empty?
224
262
  puts '### Installer Notes ###'.colorize(:red)
225
263
  notes.each_with_index do |note, index|
226
264
  puts "#{index + 1}. #{note}"
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>IDELastGMLicenseAgreedTo</key>
6
+ <string>EA1187</string>
7
+ <key>IDEXcodeVersionForAgreedToGMLicense</key>
8
+ <string>6.3.1</string>
9
+ </dict>
10
+ </plist>
@@ -86,7 +86,7 @@ def add_line_to_file(file, line, regex = nil)
86
86
  run_cmd "grep '#{regex}' #{file} --quiet || echo '#{line}' >> #{file}", "Updating #{file}..."
87
87
  end
88
88
 
89
- def mkdir(dir)
89
+ def mkdir(dir, mode: nil, owner: nil, group: nil)
90
90
  dir = File.expand_path dir
91
91
  if File.exists? dir
92
92
  if File.directory? dir
@@ -96,6 +96,8 @@ def mkdir(dir)
96
96
  end
97
97
  else
98
98
  puts "(mkdir) Creating directory #{dir}...".colorize(:blue)
99
- FileUtils.mkdir dir
99
+ FileUtils.mkdir_p dir
100
100
  end
101
+ FileUtils.chmod mode, dir unless mode.nil?
102
+ FileUtils.chown owner, group, dir
101
103
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ahalogy-automation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zan Loy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-05 00:00:00.000000000 Z
11
+ date: 2015-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -24,6 +24,26 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: command
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.0
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 1.0.0
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: 1.0.0
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 1.0.0
27
47
  - !ruby/object:Gem::Dependency
28
48
  name: daybreak
29
49
  requirement: !ruby/object:Gem::Requirement
@@ -78,7 +98,7 @@ dependencies:
78
98
  - - "~>"
79
99
  - !ruby/object:Gem::Version
80
100
  version: '1.7'
81
- description: Script that installs many applications on Ahalogy Mac computers.
101
+ description: Scripts that install applications on Ahalogy Mac computers.
82
102
  email: zan.loy@gmail.com
83
103
  executables:
84
104
  - a5y-configure
@@ -89,6 +109,7 @@ files:
89
109
  - TODO
90
110
  - ahalogy-automation.gemspec
91
111
  - bin/a5y-configure
112
+ - data/ahalogy-automation/com.apple.dt.Xcode.plist
92
113
  - data/ahalogy-automation/vimrc
93
114
  - lib/ahalogy/install-helper.rb
94
115
  homepage: https://www.ahalogy.com