]> git.openstreetmap.org Git - chef.git/blob - cookbooks/taginfo/recipes/default.rb
b4f487a051720b9d17821b8587a22495f542e132
[chef.git] / cookbooks / taginfo / recipes / default.rb
1 #
2 # Cookbook Name:: taginfo
3 # Recipe:: default
4 #
5 # Copyright 2014, OpenStreetMap Foundation
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #     http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19
20 include_recipe "apache::ssl"
21 include_recipe "passenger"
22 include_recipe "git"
23
24 package "libsqlite3-dev"
25 package "zlib1g-dev"
26 package "libosmpbf-dev"
27 package "libprotobuf-dev"
28 package "libboost-dev"
29 package "libexpat1-dev"
30 package "libsparsehash-dev"
31 package "libgd2-xpm-dev"
32 package "make"
33 package "g++"
34
35 package "sqlite3"
36
37 package "ruby"
38 package "rubygems"
39 gem_package "json"
40 gem_package "sqlite3"
41 gem_package "sinatra"
42 gem_package "sinatra-r18n"
43 gem_package "rack-contrib"
44
45 node[:taginfo][:sites].each do |site|
46   name = site[:name]
47   directory = site[:directory] || "/srv/#{name}"
48   description = site[:description]
49   icon = site[:icon]
50   contact = site[:contact]
51
52   directory directory do
53     owner "taginfo"
54     group "taginfo"
55     mode 0755
56   end
57
58   git "#{directory}/osmium" do
59     action :sync
60     repository "git://github.com/joto/osmium.git"
61     revision "master"
62     user "taginfo"
63     group "taginfo"
64   end
65
66   git "#{directory}/taginfo" do
67     action :sync
68     repository "git://github.com/joto/taginfo.git"
69     revision "master"
70     user "taginfo"
71     group "taginfo"
72   end
73
74   settings = edit_file "#{directory}/taginfo/taginfo-config-example.json" do |line|
75     line.gsub!(/^( *)"url": ".*",/, "\\1\"url\": \"http://#{name}/\",")
76     line.gsub!(/^( *)"description": ".*Change this text.*,/, "\\1\"description\": \"#{description}\",")
77     line.gsub!(/^( *)"icon": ".*",/, "\\1\"icon\": \"/img/logo/#{icon}.png\",")
78     line.gsub!(/^( *)"contact": "Anonymous",/, "\\1\"contact\": \"#{contact}\",")
79     line.gsub!(/^( *)"shortname": ".*",/, "\\1\"shortname\": \"Taginfo\",")
80     line.gsub!(/^( *)"contact": "somebody@example.com",/, "\\1\"contact\": \"webmaster@openstreetmap.org\",")
81     line.gsub!(/^( *)"cxxflags": ".*",/, "\\1\"cxxflags\": \"-I../../osmium/include\",")
82
83     line
84   end
85
86   file "#{directory}/taginfo-config.json" do
87     owner "taginfo"
88     group "taginfo"
89     mode 0644
90     content settings
91   end
92
93   execute "#{directory}/taginfo/tagstats/Makefile" do
94     action :nothing
95     command "make"
96     cwd "#{directory}/taginfo/tagstats"
97     user "taginfo"
98     group "taginfo"
99     subscribes :run, "git[#{directory}/osmium]"
100     subscribes :run, "git[#{directory}/taginfo]"
101     notifies :restart, "service[apache2]"
102   end
103
104   directory "#{directory}/data" do
105     owner "taginfo"
106     group "taginfo"
107     mode 0755
108   end
109
110   apache_site name do
111     template "apache.erb"
112     directory "#{directory}/taginfo/web/public"
113   end
114 end