Method: TheFox::MBrew::MBrew#init

Defined in:
lib/mbrew/mbrew.rb

#init(dir = '.') ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/mbrew/mbrew.rb', line 92

def init(dir = '.')
	Dir.chdir(dir) do
		if !Dir.exist?('.mbrew')
			Dir.mkdir('.mbrew', 0700)
			Dir.chdir('.mbrew') do
				Dir.mkdir('data')
				Dir.mkdir('bin')
				Dir.mkdir('index')
				
				Dir.chdir('bin') do
					File.open('push', 'w') do |file|
						file.chmod(0755)
						
						file.puts('#!/usr/bin/env bash')
						file.puts
						file.puts('SCRIPT_BASEDIR=$(dirname $0)')
						file.puts('RSYNC_BIN="rsync"')
						file.puts('RSYNC_OPTIONS="-vucr --delete --delete-excluded -h --progress --exclude=.DS_Store"')
						file.puts('RSYNC_REMOTE="user@remote:/path/to/public"')
						file.puts
						file.puts
						file.puts('cd $SCRIPT_BASEDIR/..')
						file.puts
						file.puts('# $RSYNC_BIN $RSYNC_OPTIONS index data $RSYNC_REMOTE')
					end
				end
				
				Dir.chdir('index') do
					grepo = Git.init('.')
					grepo.config('user.name', 'Mr. Robot')
					grepo.config('user.email', '[email protected]')
					
					File.write('.gitkeep', 'keep')
					grepo.add('.gitkeep')
					
					grepo.commit('Initial commit.')
				end
				
				config_yml = YAML::Store.new('config.yml')
				config_yml.transaction do
					config_yml['mbrew'] = {
						'release_id' => TheFox::MBrew::RELEASE_ID,
						'version' => TheFox::MBrew::VERSION,
					}
					config_yml['origin'] = {
						'downstream' => nil,
						'upstream' => nil,
					}
				end
			end
		else
			raise "Directory '#{dir}' is already a mbrew library."
		end
	end
end