Class: Installer
- Inherits:
-
Object
- Object
- Installer
- Defined in:
- lib/yodel/command/installer.rb
Instance Attribute Summary collapse
-
#convert_path ⇒ Object
readonly
—————————————- Template variables —————————————-.
-
#database_hostname ⇒ Object
readonly
—————————————- Template variables —————————————-.
-
#database_name ⇒ Object
readonly
—————————————- Template variables —————————————-.
-
#database_port ⇒ Object
readonly
—————————————- Template variables —————————————-.
-
#dns_port ⇒ Object
readonly
—————————————- Template variables —————————————-.
-
#git_path ⇒ Object
readonly
—————————————- Template variables —————————————-.
-
#group ⇒ Object
readonly
—————————————- Template variables —————————————-.
-
#identify_path ⇒ Object
readonly
—————————————- Template variables —————————————-.
-
#public_directory ⇒ Object
readonly
—————————————- Template variables —————————————-.
-
#ruby_path ⇒ Object
readonly
—————————————- Template variables —————————————-.
-
#sites_root ⇒ Object
readonly
—————————————- Template variables —————————————-.
-
#user ⇒ Object
readonly
—————————————- Template variables —————————————-.
-
#web_port ⇒ Object
readonly
—————————————- Template variables —————————————-.
Instance Method Summary collapse
- #assign_default_user_and_group ⇒ Object
- #default_ruby_path ⇒ Object
- #default_sites_root ⇒ Object
- #escape_quotes(str) ⇒ Object
-
#initialize ⇒ Installer
constructor
A new instance of Installer.
- #install(file, permissions = '0644', file_name = nil) ⇒ Object
-
#install_linux_files ⇒ Object
—————————————- Linux —————————————-.
-
#install_mac_files ⇒ Object
—————————————- OS X —————————————-.
-
#install_system_files ⇒ Object
—————————————- Q & A —————————————-.
-
#system_path ⇒ Object
—————————————- Helpers —————————————-.
Constructor Details
#initialize ⇒ Installer
Returns a new instance of Installer.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/yodel/command/installer.rb', line 39 def initialize # assign default values; not all values have associated questions # presented to the user depen @database_hostname = 'localhost' @database_port = 27017 @database_name = 'yodel' @web_port = 80 @dns_port = 2828 @public_directory = '/var/www' @sites_root = default_sites_root @ruby_path = default_ruby_path @git_path = `which git`.strip @identify_path = `which identify`.strip @convert_path = `which convert`.strip assign_default_user_and_group end |
Instance Attribute Details
#convert_path ⇒ Object (readonly)
Template variables
11 12 13 |
# File 'lib/yodel/command/installer.rb', line 11 def convert_path @convert_path end |
#database_hostname ⇒ Object (readonly)
Template variables
11 12 13 |
# File 'lib/yodel/command/installer.rb', line 11 def database_hostname @database_hostname end |
#database_name ⇒ Object (readonly)
Template variables
11 12 13 |
# File 'lib/yodel/command/installer.rb', line 11 def database_name @database_name end |
#database_port ⇒ Object (readonly)
Template variables
11 12 13 |
# File 'lib/yodel/command/installer.rb', line 11 def database_port @database_port end |
#dns_port ⇒ Object (readonly)
Template variables
11 12 13 |
# File 'lib/yodel/command/installer.rb', line 11 def dns_port @dns_port end |
#git_path ⇒ Object (readonly)
Template variables
11 12 13 |
# File 'lib/yodel/command/installer.rb', line 11 def git_path @git_path end |
#group ⇒ Object (readonly)
Template variables
11 12 13 |
# File 'lib/yodel/command/installer.rb', line 11 def group @group end |
#identify_path ⇒ Object (readonly)
Template variables
11 12 13 |
# File 'lib/yodel/command/installer.rb', line 11 def identify_path @identify_path end |
#public_directory ⇒ Object (readonly)
Template variables
11 12 13 |
# File 'lib/yodel/command/installer.rb', line 11 def public_directory @public_directory end |
#ruby_path ⇒ Object (readonly)
Template variables
11 12 13 |
# File 'lib/yodel/command/installer.rb', line 11 def ruby_path @ruby_path end |
#sites_root ⇒ Object (readonly)
Template variables
11 12 13 |
# File 'lib/yodel/command/installer.rb', line 11 def sites_root @sites_root end |
#user ⇒ Object (readonly)
Template variables
11 12 13 |
# File 'lib/yodel/command/installer.rb', line 11 def user @user end |
#web_port ⇒ Object (readonly)
Template variables
11 12 13 |
# File 'lib/yodel/command/installer.rb', line 11 def web_port @web_port end |
Instance Method Details
#assign_default_user_and_group ⇒ Object
33 34 35 36 37 |
# File 'lib/yodel/command/installer.rb', line 33 def assign_default_user_and_group pwnam = Etc.getpwnam(Etc.getlogin) @user = pwnam.uid @group = pwnam.gid end |
#default_ruby_path ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/yodel/command/installer.rb', line 24 def default_ruby_path if RbConfig.ruby =~ /rubies\/(.*)\/bin/ `rvm wrapper #{$1} yodel` `which yodel_ruby`.strip else Config.ruby end end |
#default_sites_root ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/yodel/command/installer.rb', line 16 def default_sites_root if `uname -a` =~ /Darwin/ File.('~/Sites') else '/var/www' end end |
#escape_quotes(str) ⇒ Object
64 65 66 |
# File 'lib/yodel/command/installer.rb', line 64 def escape_quotes(str) str.gsub("'", "\\\\'") end |
#install(file, permissions = '0644', file_name = nil) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/yodel/command/installer.rb', line 68 def install(file, ='0644', file_name=nil) if file_name dest_path = File.join('/', File.dirname(file), file_name) else dest_path = File.join('/', file) end source_path = File.join(system_path, file) temp_file = Tempfile.new('yodel') Feedback.report('installing', dest_path) # render the file template temp_file.write Ember::Template.new(IO.read(source_path), {source_file: source_path}).render(binding) temp_file.close # create parent directories, copy the rendered file and set permissions `sudo mkdir -p #{File.dirname(dest_path)}` `sudo cp #{temp_file.path} #{dest_path}` `sudo chmod #{} #{dest_path}` # delete the temp file used for rendering temp_file.unlink end |
#install_linux_files ⇒ Object
Linux
214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/yodel/command/installer.rb', line 214 def install_linux_files install 'usr/local/bin/yodel_command_runner', '0777' install 'var/log/yodel.log', '0666' case @environment when 'development' install 'usr/local/etc/yodel/development_settings.rb', '0644', 'settings.rb' when 'production' install 'usr/local/etc/yodel/production_settings.rb', '0644', 'settings.rb' end end |
#install_mac_files ⇒ Object
OS X
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/yodel/command/installer.rb', line 193 def install_mac_files install 'etc/resolver/yodel' install 'Library/LaunchDaemons/com.yodelcms.dns.plist' install 'Library/LaunchDaemons/com.yodelcms.server.plist' install 'usr/local/bin/yodel_command_runner', '0777' install 'var/log/yodel.log', '0666' case @environment when 'development' install 'usr/local/etc/yodel/development_settings.rb', '0644', 'settings.rb' when 'production' install 'usr/local/etc/yodel/production_settings.rb', '0644', 'settings.rb' end Restart.restart! end |
#install_system_files ⇒ Object
Q & A
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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/yodel/command/installer.rb', line 95 def install_system_files @h = h = HighLine.new h.say "\n<%= color('Welcome to Yodel', BOLD) %>\n\n" # environment h.say "<%= color('Environment', BOLD) %>" h.say "Yodel can run in development (local) mode or as a production server. Press" h.say "enter to setup Yodel in development mode, or enter 'production' to setup" h.say "a production server." @environment = h.ask("Environment: ") do |q| q.default = 'development' q.in = %w{development production} q.responses[:ask_on_error] = :question end # local sites directory h.say "\n<%= color('1/3', RED) %> <%= color('Sites Directory', BOLD) %>" h.say "Yodel stores each of your sites in a single directory. You may place this directory" h.say "anywhere, but all sites created by Yodel must be accessible from it. Press enter to" h.say "accept the default directory, or enter a new path." @sites_root = h.ask("Sites directory: ") do |q| q.default = @sites_root q.responses[:ask_on_error] = :question end @sites_root = escape_quotes(@sites_root) # web server port if @environment == 'development' h.say "\n<%= color('2/3', RED) %> <%= color('Local Server', BOLD) %>" h.say "By default the yodel server will run on port 80, meaning you can access yodel" h.say "sites by visiting <http://sitename.yodel/>. If you already have Apache or" h.say "another web server running on this port, enter a different port (such as 8080)" @web_port = h.ask("Use port: ", Integer) do |q| q.default = @web_port q.responses[:ask_on_error] = :question end else h.say "\n<%= color('2/3', RED) %> <%= color('Public Directory', BOLD) %>" h.say "Yodel symlinks the public directory of sites served by the production server" h.say "to a directory visible to the fronting web server. The domain of a site is" h.say "used as the link name, meaning /var/www/domain.com could e.g link to" h.say "/var/git/ID/public. This makes serving public assets from a fronting server" h.say "possible by rewriting the request path to include the domain of the request." @public_directory = h.ask("Public directory: ") do |q| q.default = @public_directory q.responses[:ask_on_error] = :question end @public_directory = escape_quotes(@public_directory) end h.say "\n<%= color('3/3', RED) %> <%= color('Installing files', BOLD) %>" h.say "Yodel will now install the necessary system files. You may be asked to enter" h.say "your local user password.\n\n" h.say "-----------------------------------------------------------------------------\n\n" # default program paths Feedback.report('locating', "git: #{@git_path}") Feedback.report('warning', "git not found, path must be set manually in /usr/local/etc/yodel/settings.rb") if @git_path.empty? Feedback.report('locating', "identify: #{@identify_path}") Feedback.report('warning', "identify not found, path must be set manually in /usr/local/etc/yodel/settings.rb") if @identify_path.empty? Feedback.report('locating', "convert: #{@convert_path}") Feedback.report('warning', "convert not found, path must be set manually in /usr/local/etc/yodel/settings.rb") if @convert_path.empty? # install system files if `uname -a` =~ /Darwin/ install_mac_files else install_linux_files end # start yodel for environment installation Feedback.report('starting', 'yodel') require '../../yodel' Yodel.config.extensions_folder = $extensions_folder if $extensions_folder Yodel.load_extensions # install an environment support site Feedback.report('installing', "#{@environment} environment support site") site = Site.new site.name = "yodel" site.domains = ['yodel', 'localhost', '127.0.0.1'] extension = Yodel.extensions["yodel_#{@environment}_environment"] puts "Installation environment (#{@environment}) not found" and exit(1) if extension.nil? site.root_directory = extension.lib_dir site.save Migration.run_migrations(site) h.say "\n-----------------------------------------------------------------------------" h.say "\n<%= color('Installation complete', BOLD) %>" h.say "Visit http://yodel#{":#{@web_port}" if @web_port != 80}/ to setup accounts you have on a remote Yodel server." h.say "You can create a new site by visiting <http://sitename.yodel#{":#{@web_port}" if @web_port != 80}/> and" h.say "following the instructions\n\n" end |
#system_path ⇒ Object
Helpers
60 61 62 |
# File 'lib/yodel/command/installer.rb', line 60 def system_path @system_path ||= File.join(File.dirname(__FILE__), '..', '..', '..', 'system') end |