crazylion / drupal_install_template

auto download durpal and modules by your setting

This URL has Read+Write access

drupal_install_template / build_drupal.rb
100755 46 lines (41 sloc) 1.557 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/ruby
require 'yaml'
require 'rexml/document'
include REXML
require 'open-uri'
settings = YAML::load(open(ARGV[0]))
version = settings["base_setting"]["version"]
update_base_url = settings["base_setting"]["update_url"]
 
def fetch_download_url update_base_url,projectname,version
  f = open("#{update_base_url}/#{projectname}/#{version}")
  doc = REXML::Document.new(f)
  # p doc.elements['project'].elements["releases"]
  url = XPath.first(doc,"/project/releases/release/download_link").text
  f.close
  return url
end
 
#fetch drupal
url = fetch_download_url( update_base_url,"drupal",version)
#parser to drupal filename
 
filename = url[(url.rindex("/")+1)..-1]
durpal_dirname = filename[0...filename.index(".tar.gz")]
p "downloading drupal-#{version}"
`wget #{url} && tar vzxf #{filename} && rm #{filename}`
p "Down. Start downloading modules"
for mod in settings["modules"]
  p "downloading #{mod['name']}"
  url = fetch_download_url update_base_url,mod["name"],version
  filename = url[(url.rindex("/")+1)..-1]
  dirname = filename[0...filename.rindex("-#{version}")]
  `wget #{url} && tar vzxf #{filename} && rm #{filename} && mv #{dirname} #{durpal_dirname}/modules`
  p "done"
end
#download themes
 
for mod in settings["themes"]
  p "downloading #{mod['name']}"
  url = fetch_download_url update_base_url,mod["name"],version
  filename = url[(url.rindex("/")+1)..-1]
  dirname = filename[0...filename.rindex("-#{version}")]
  `wget #{url} && tar vzxf #{filename} && rm #{filename} && mv #{dirname} #{durpal_dirname}/themes`
  p "done"
end