andyh-valhalla 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ A collection of Thor tasks for automating TYPO3
@@ -0,0 +1,4 @@
1
+ ---
2
+ :minor: 1
3
+ :patch: 1
4
+ :major: 0
@@ -0,0 +1,275 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "digest/md5"
4
+ require "fileutils"
5
+ require "rubygems"
6
+ require "rake"
7
+ require "mysql"
8
+ require "thor"
9
+ require "open-uri"
10
+ require "yaml"
11
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
12
+ require "valhalla"
13
+
14
+
15
+ CONFIG = {
16
+ :webuser_group => "_www",
17
+ }
18
+
19
+
20
+ class TYPO3Installer < Thor
21
+
22
+ desc "install [VERSION]", "install latest version of TYPO3, optionally select a specific version to install"
23
+ method_options :version => :optional, :nosource => true, :nodummy => true, :dryrun => true, :repo => true
24
+ def install(version = 'latest')
25
+ new_site = Typo3Site.new
26
+
27
+ unless options.dryrun?
28
+ # TODO enable specifying versions other than automatically getting latest
29
+ scrape_typo3_source
30
+
31
+ unless options.nosource?
32
+ install_latest_source
33
+ end
34
+
35
+ unless options.nodummy?
36
+ if options.repo?
37
+ # set up repository structure
38
+ dir_structure = %w{src assets db doc util vendor vendorsrc}
39
+
40
+ dir_structure.each do |f|
41
+ FileUtils.mkdir_p "#{FileUtils.pwd}/#{new_site.project}/#{f}"
42
+ end
43
+ FileUtils.chdir "#{new_site.project}"
44
+ FileUtils.touch %w{README GLOSSARY BUILDING}
45
+ end
46
+ install_latest_dummy
47
+ new_site.generate_localconf
48
+ new_site.setup_database
49
+ puts "Now run the Install Tool"
50
+ end
51
+
52
+ end
53
+
54
+ puts new_site.details
55
+ end
56
+
57
+ desc "generate", "Generate an extension based on -t [template] with extension key -k [key]"
58
+ method_options :template => :required, :key => :required
59
+ def generate
60
+ puts "Generating #{options[:key]} from template #{options[:template]}"
61
+ extension = Installer.new(options[:template], options[:key])
62
+ extension.build
63
+ end
64
+
65
+ desc "config", "show current site config"
66
+ def config
67
+ if current_directory_is_typo3_install?
68
+ t3site = Typo3.new
69
+ t3site.show_config
70
+ else
71
+ abort 'Not a TYPO3 Installation'
72
+ end
73
+ end
74
+
75
+ desc "clearcache [type]","clear the TYPO3 caches, specify either 'all', 'page' or 'temp'. If none are supplied it defaults to 'all'"
76
+ def clearcache(type = "all")
77
+ if current_directory_is_typo3_install? && ["all","page","temp"].include?(type)
78
+ t3site = Typo3.new
79
+ t3site.clear_cache(type)
80
+ end
81
+ end
82
+
83
+ private
84
+
85
+ def install_latest_dummy
86
+ latest_dummy = @dummy_list.last[0]
87
+ `curl #{typo3_locations[:heanet_mirror]}#{latest_dummy} > #{latest_dummy}`
88
+ `rm -rf src`
89
+ `tar -zxvf #{latest_dummy} && mv #{latest_dummy.sub(".tar.gz","")} src && rm #{latest_dummy}`
90
+ `rm src/typo3_src`
91
+ `ln -s /usr/local/typo3/latest src/typo3_src`
92
+ `sudo chgrp -R #{CONFIG[:webuser_group]} src/fileadmin src/uploads src/typo3conf src/typo3temp`
93
+ `sudo chmod -R 775 src/fileadmin src/uploads src/typo3conf src/typo3temp`
94
+ `rm src/INSTALL.txt src/README.txt src/RELEASE_NOTES.txt`
95
+ end
96
+
97
+ def install_latest_source
98
+ latest_source = @source_list.last[0]
99
+ usr_local = typo3_locations[:local]
100
+ unless File.exist?(usr_local+latest_source.sub(".tar.gz",""))
101
+ `curl #{typo3_locations[:heanet_mirror]}#{latest_source} > #{latest_source}`
102
+ `tar -zxvf #{latest_source}`
103
+ puts "Enter your (sudo) admin password when prompted"
104
+ `sudo mv #{latest_source.sub(".tar.gz","")} #{usr_local} && rm #{latest_source}`
105
+ `sudo ln -s /usr/local/typo3/#{latest_source.sub(".tar.gz","")} /usr/local/typo3/latest`
106
+ `sudo chgrp -R #{CONFIG[:webuser_group]} typo3/ext/`
107
+ `sudo chmod -R 775 typo3/ext/`
108
+ end
109
+ end
110
+
111
+ def scrape_typo3_source
112
+ scraped_content = open(typo3_locations[:heanet_mirror]).read
113
+ @dummy_list, @source_list = Hash.new, Hash.new
114
+
115
+ scraped_content.scan(/.*(dummy-\d\.\d\.\d\.tar\.gz).*(\d\d\-[A-Z][a-z][a-z]\-\d\d\d\d).*/) {|name,mod_date| @dummy_list[name] = mod_date }
116
+ scraped_content.scan(/.*(typo3_src-\d\.\d\.\d\.tar\.gz).*(\d\d\-[A-Z][a-z][a-z]\-\d\d\d\d).*/) {|name,mod_date| @source_list[name] = mod_date }
117
+ @dummy_list = @dummy_list.sort_by {|f| f }
118
+ @source_list = @source_list.sort_by {|f| f }
119
+ end
120
+
121
+ def current_directory_is_typo3_install?
122
+ local_typo3_structure = ["fileadmin","typo3conf","typo3temp","uploads"]
123
+ if (Dir.glob('*').find_all {|f| local_typo3_structure.include?(f) }).size == 4
124
+ true
125
+ else
126
+ false
127
+ end
128
+ end
129
+
130
+ def typo3_locations
131
+ { :official => 'http://sourceforge.net/project/showfiles.php?group_id=20391&package_id=14557',
132
+ :heanet_mirror => 'http://heanet.dl.sourceforge.net/sourceforge/typo3/',
133
+ :local => '/usr/local/typo3/',
134
+ }
135
+ end
136
+
137
+ end
138
+
139
+ class Typo3Site
140
+ attr_accessor :sitename, :project
141
+
142
+ def initialize
143
+ print "Project Codename:"
144
+ @project = STDIN.gets.chomp
145
+
146
+ print "Enter Site Name:"
147
+ @sitename = STDIN.gets.chomp
148
+
149
+ @extensions = %w{tsconfig_help context_help extra_page_cm_options impexp sys_note tstemplate tstemplate_ceditor tstemplate_info tstemplate_objbrowser tstemplate_analyzer func_wizards wizard_crpages wizard_sortpages lowlevel install belog beuser aboutmodules setup taskcenter info_pagetsconfig viewpage rtehtmlarea css_styled_content t3skin}
150
+ end
151
+
152
+ def username
153
+ "#{project}_typo3"
154
+ end
155
+
156
+ def database
157
+ username
158
+ end
159
+
160
+ def password
161
+ @password ||= generate_password(12)
162
+ end
163
+
164
+ def install_tool_password
165
+ @install_password ||= generate_password(12)
166
+ end
167
+
168
+ def details
169
+ %{
170
+ Project: #{project} - #{sitename}
171
+ -------------------------------
172
+ Database:
173
+ Username: #{username}
174
+ Password: #{password}
175
+ Database: #{database}
176
+
177
+ Install Tool Password: #{install_tool_password} (#{Digest::MD5.hexdigest(self.install_tool_password)})
178
+ }
179
+ end
180
+
181
+ def generate_localconf
182
+ File.open(Dir.getwd+"/src/typo3conf/localconf.php","w") do |f|
183
+ f.write localconf
184
+ end
185
+ end
186
+
187
+ def setup_database
188
+ # TODO
189
+ port = 3306
190
+ socket = `locate -l 1 mysql.sock`.to_s.strip
191
+
192
+ dbh = Mysql.real_connect("localhost","root","","",port,socket)
193
+ dbh.query("create database #{self.database} CHARACTER SET 'utf8'")
194
+ dbh.query("GRANT ALL ON #{self.database}.* TO '#{self.username}'@'localhost'")
195
+ dbh.query("SET PASSWORD FOR '#{self.username}'@'localhost' = PASSWORD('#{self.password}')")
196
+ dbh.query("flush privileges")
197
+ dbh.close
198
+
199
+ # Form from Install Tool which does import
200
+ # <form action="index.php?TYPO3_INSTALL[type]=database&mode=123&step=3#bottom" method="post">
201
+ # <input type="hidden" name="TYPO3_INSTALL[database_type]" value="import">
202
+ # <input type="hidden" name="TYPO3_INSTALL[database_import_all]" value=1>
203
+ # <input type="hidden" name="step" value="">
204
+ # <input type="hidden" name="goto_step" value="go">
205
+ # <select name="TYPO3_INSTALL[database_type]">
206
+ # <option value="import|CURRENT_TABLES+STATIC">Create default database tables</option>
207
+ # </select>
208
+ # <input type="submit" value="Import database">
209
+ # Returns HTML, look for "You're done!" for successful confirmation
210
+
211
+ end
212
+
213
+ def extension_list
214
+ @extensions.join(",")
215
+ end
216
+
217
+ private
218
+
219
+ def localconf
220
+ <<-LC
221
+ <?php
222
+ $TYPO3_CONF_VARS['SYS']['sitename'] = '#{self.sitename}';
223
+
224
+ // Default password is "joh316" :
225
+ $TYPO3_CONF_VARS['BE']['installToolPassword'] = 'bacb98acf97e0b6112b1d1b650b84971';
226
+ $TYPO3_CONF_VARS['BE']['installToolPassword'] = '#{Digest::MD5.hexdigest(self.install_tool_password)}';
227
+
228
+ $typo_db_extTableDef_script = 'extTables.php';
229
+
230
+ $typo_db_username = '#{self.username}';
231
+ $typo_db_password = '#{self.password}';
232
+ $typo_db = '#{self.database}';
233
+ $typo_db_host = 'localhost';
234
+
235
+ $TYPO3_CONF_VARS['SYS']['encryptionKey'] = '#{Digest::MD5.hexdigest(self.install_tool_password+self.username+self.password)}';
236
+
237
+ ## TODO make these more dynamic and templateable
238
+
239
+ $TYPO3_CONF_VARS['EXT']['extList'] = '#{self.extension_list}';
240
+
241
+ $TYPO3_CONF_VARS['SYS']['compat_version'] = '4.2';
242
+
243
+ ## ImageMagick/GraphicsMagick Configuration
244
+
245
+ $TYPO3_CONF_VARS['GFX']['im_combine_filename'] = 'composite';
246
+ $TYPO3_CONF_VARS['GFX']["im_path"] = '/usr/local/bin/';
247
+ $TYPO3_CONF_VARS['GFX']["im_path_lzw"] = '/usr/local/bin/';
248
+ $TYPO3_CONF_VARS['GFX']['im_version_5'] = 'gm';
249
+ $TYPO3_CONF_VARS['GFX']['TTFdpi'] = '96';
250
+ $TYPO3_CONF_VARS['SYS']['setMemoryLimit'] = '256';
251
+ $TYPO3_CONF_VARS['GFX']['gdlib_2'] = '1';
252
+ $TYPO3_CONF_VARS['GFX']['im_imvMaskState'] = '0';
253
+ $TYPO3_CONF_VARS['GFX']['im_v5effects'] = '0';
254
+ $TYPO3_CONF_VARS['GFX']['im_negate_mask'] = '1';
255
+ $TYPO3_CONF_VARS['GFX']['im_no_effects'] = '0';
256
+ $TYPO3_CONF_VARS['FE']['disableNoCacheParameter'] = '0';
257
+
258
+ // For backend charset
259
+ $TYPO3_CONF_VARS['BE']['forceCharset'] = 'utf-8';
260
+ $TYPO3_CONF_VARS['SYS']['setDBinit'] = 'SET NAMES utf8;';
261
+
262
+ ## INSTALL SCRIPT EDIT POINT TOKEN - all lines after this points may be changed by the install script!
263
+
264
+ ?>
265
+ LC
266
+
267
+ end
268
+ def generate_password(size)
269
+ chars = (('a'..'z').to_a + ('0'..'9').to_a) - %w(i o 0 1 l 0)
270
+ (1..size).collect{|a| chars[rand(chars.size)] }.join
271
+ end
272
+ end
273
+
274
+
275
+ TYPO3Installer.start
@@ -0,0 +1,69 @@
1
+ require "erubis"
2
+
3
+ class Installer
4
+ def initialize(template_name, extension_key)
5
+ @template_locations = ["/Volumes/Work/Projects/Foxsoft/t3templates"]
6
+ @template_name = template_name
7
+ @extension_key = extension_key
8
+ end
9
+
10
+ def build
11
+ if found_location = template_location_contains(@template_name)
12
+ puts "Building #{found_location}"
13
+ require "#{found_location}"
14
+ include_name = @template_name.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
15
+ instance_eval "extend #{include_name}"
16
+
17
+ filelist = FileList.new(found_location.gsub("#{@template_name}","**/*")) do |fl|
18
+ fl.exclude(found_location+'.rb')
19
+ end
20
+
21
+ destfilelist = filelist.clone
22
+
23
+ destination_base = FileUtils.pwd
24
+ source_base = found_location.sub("/#{@template_name}","")
25
+
26
+ mappings.each_pair do |k,v|
27
+ out = eval(v)
28
+ destfilelist.sub!(k,out)
29
+ end
30
+ destfilelist.sub!(source_base,destination_base)
31
+
32
+ filelist.each_index do |src|
33
+ if filelist[src][-4..-1]==".erb"
34
+
35
+ # TODO sort out where to put this lot for access in erb templates
36
+ ext_key = @extension_key
37
+ project = "test project"
38
+ generate_md5_values = "// md5 stuff"
39
+
40
+ eruby = Erubis::Eruby.new
41
+ input = File.read(filelist[src])
42
+ output = eruby.convert(input)
43
+ new_filepath = destfilelist[src].gsub(".erb","")
44
+ File.open(new_filepath,"w") do |fe|
45
+ fe.write(eval(output))
46
+ end
47
+ else
48
+ if File.directory?(filelist[src])
49
+ FileUtils.mkdir destfilelist[src]
50
+ else
51
+ FileUtils.copy filelist[src], destfilelist[src]
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ private
59
+
60
+ def template_location_contains(template_name)
61
+ @template_locations.each do |l|
62
+ if File.exist?(l+"/"+@template_name)
63
+ return l+"/"+@template_name+"/"+@template_name
64
+ end
65
+ end
66
+ abort %{Template not found in any of the following locations:
67
+ - #{@template_locations.join("\n- ")}}
68
+ end
69
+ end
@@ -0,0 +1,83 @@
1
+ require "typo3/installer"
2
+
3
+ class Typo3
4
+ attr_reader :sitename,:username, :password, :host, :dbname, :install_password
5
+
6
+ def initialize
7
+ get_TYPO3_details
8
+
9
+ # look at somehow making this more automatically specific to environment
10
+ @port = 3306
11
+
12
+ @socket = `locate -l 1 mysql.sock`.to_s.strip
13
+ end
14
+
15
+ def show_config
16
+ config = %{
17
+ TYPO3 Sitename: #{@sitename}
18
+ DB Username: #{@username}
19
+ DB Password: #{@password}
20
+ DB Host: #{@host}
21
+ DB Name: #{@dbname}
22
+ Install Tool: #{@install_password}
23
+ }
24
+
25
+ print config
26
+ end
27
+
28
+ def with_db
29
+ dbh = Mysql.real_connect(self.host,self.username,self.password,self.dbname,@port,@socket)
30
+
31
+ begin
32
+ yield dbh
33
+ ensure
34
+ dbh.close
35
+ end
36
+ end
37
+
38
+ def clear_cache(type)
39
+ case type.to_sym
40
+ when :all
41
+ clear_pages
42
+ clear_temp
43
+ puts "Cleared All"
44
+ when :page
45
+ clear_pages
46
+ puts "Cleared Pages"
47
+ when :temp
48
+ clear_temp
49
+ puts "Cleared Temp"
50
+ end
51
+
52
+ end
53
+
54
+ private
55
+
56
+ def clear_pages
57
+ self.with_db do |db|
58
+ db.query('delete from cache_pagesection')
59
+ db.query('delete from cache_hash')
60
+ end
61
+ end
62
+
63
+ def clear_temp
64
+ temp = FileList['**/temp_CACHED*.php']
65
+ puts "hi"
66
+ rm temp
67
+ end
68
+
69
+ def get_TYPO3_details
70
+ localconf = FileList['**/localconf.php']
71
+
72
+ localconf.each do |t|
73
+ conf = IO.read(t)
74
+ @sitename = conf.scan(/\$TYPO3_CONF_VARS\[\'SYS\'\]\[\'sitename\'\]\s+=\s+\'(.*)\'\;/).last.to_s ||= ''
75
+ @username = conf.scan(/\$typo_db_username\s+=\s+\'(.*)\'\;/).last.to_s ||= ''
76
+ @password = conf.scan(/\$typo_db_password\s+=\s+\'(.*)\'\;/).last.to_s ||= ''
77
+ @host = conf.scan(/\$typo_db_host\s+=\s+\'(.*)\'\;/).last.to_s ||= ''
78
+ @dbname = conf.scan(/\$typo_db\s+=\s+\'(.*)\'\;/).last.to_s ||= ''
79
+ @install_password = conf.scan(/\$TYPO3_CONF_VARS\[\'BE\'\]\[\'installToolPassword\'\]\s+=\s+\'(.*)\'\;/).last.to_s ||= ''
80
+ end
81
+
82
+ end
83
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: andyh-valhalla
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Andy Henson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-07 00:00:00 -08:00
13
+ default_executable: typo3
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: erubis
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.6.2
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: rake
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 0.8.3
32
+ version:
33
+ - !ruby/object:Gem::Dependency
34
+ name: mysql
35
+ version_requirement:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: "2.7"
41
+ version:
42
+ - !ruby/object:Gem::Dependency
43
+ name: wycats-thor
44
+ version_requirement:
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 0.9.8
50
+ version:
51
+ description: A collection of tasks for automating TYPO3
52
+ email: andy@foxsoft.co.uk
53
+ executables:
54
+ - typo3
55
+ extensions: []
56
+
57
+ extra_rdoc_files: []
58
+
59
+ files:
60
+ - README.textile
61
+ - VERSION.yml
62
+ - bin/typo3
63
+ - lib/typo3
64
+ - lib/typo3/installer.rb
65
+ - lib/valhalla.rb
66
+ has_rdoc: true
67
+ homepage: http://github.com/andyh/valhalla
68
+ post_install_message:
69
+ rdoc_options:
70
+ - --inline-source
71
+ - --charset=UTF-8
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ version:
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: "0"
85
+ version:
86
+ requirements: []
87
+
88
+ rubyforge_project:
89
+ rubygems_version: 1.2.0
90
+ signing_key:
91
+ specification_version: 2
92
+ summary: TODO
93
+ test_files: []
94
+