Class: Installer
- Inherits:
-
Object
- Object
- Installer
- Defined in:
- lib/installer.rb
Overview
owncloud-admin - the owncloud administration tool
Copyright © 2011 Cornelius Schumacher <[email protected]>
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Instance Attribute Summary collapse
-
#admin_password ⇒ Object
Returns the value of attribute admin_password.
-
#admin_user ⇒ Object
Returns the value of attribute admin_user.
-
#ftp_password ⇒ Object
Returns the value of attribute ftp_password.
-
#ftp_user ⇒ Object
Returns the value of attribute ftp_user.
-
#root_helper ⇒ Object
Returns the value of attribute root_helper.
-
#server ⇒ Object
Returns the value of attribute server.
-
#skip_download ⇒ Object
Returns the value of attribute skip_download.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(settings) ⇒ Installer
constructor
A new instance of Installer.
- #install(server_type) ⇒ Object
- #install_ftp ⇒ Object
- #install_local ⇒ Object
- #write_admin_config ⇒ Object
Constructor Details
#initialize(settings) ⇒ Installer
Returns a new instance of Installer.
25 26 27 |
# File 'lib/installer.rb', line 25 def initialize settings @settings = settings end |
Instance Attribute Details
#admin_password ⇒ Object
Returns the value of attribute admin_password.
22 23 24 |
# File 'lib/installer.rb', line 22 def admin_password @admin_password end |
#admin_user ⇒ Object
Returns the value of attribute admin_user.
22 23 24 |
# File 'lib/installer.rb', line 22 def admin_user @admin_user end |
#ftp_password ⇒ Object
Returns the value of attribute ftp_password.
22 23 24 |
# File 'lib/installer.rb', line 22 def ftp_password @ftp_password end |
#ftp_user ⇒ Object
Returns the value of attribute ftp_user.
22 23 24 |
# File 'lib/installer.rb', line 22 def ftp_user @ftp_user end |
#root_helper ⇒ Object
Returns the value of attribute root_helper.
22 23 24 |
# File 'lib/installer.rb', line 22 def root_helper @root_helper end |
#server ⇒ Object
Returns the value of attribute server.
22 23 24 |
# File 'lib/installer.rb', line 22 def server @server end |
#skip_download ⇒ Object
Returns the value of attribute skip_download.
22 23 24 |
# File 'lib/installer.rb', line 22 def skip_download @skip_download end |
Class Method Details
.server_types ⇒ Object
29 30 31 |
# File 'lib/installer.rb', line 29 def self.server_types [ "local", "ftp" ] end |
Instance Method Details
#install(server_type) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/installer.rb', line 33 def install server_type if !skip_download source = { :server => "owncloud.org", :path => "/releases/", :file => "owncloud-latest.tar.bz2" } local_source = @settings.tmp_dir + source[:file] puts "Downloading owncloud source archive..." Net::HTTP.start( source[:server] ) do |http| response = http.get( source[:path] + source[:file] ) open( local_source, "wb") do |file| file.write response.body end end puts "Extracting archive..." system "cd #{@settings.tmp_dir}; tar xjf #{source[:file]}" end @source_dir = @settings.tmp_dir + "owncloud" write_admin_config if server_type == "local" install_local elsif server_type == "ftp" install_ftp else STDERR.puts "Unsupported server type: #{server_type}" exit 1 end end |
#install_ftp ⇒ Object
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 |
# File 'lib/installer.rb', line 109 def install_ftp puts "Installing owncloud to remote web server via FTP..." [ :server, :ftp_user, :ftp_password ] ftp = Net::FTP.new( server ) ftp.passive = true puts " Logging in..." ftp.login ftp_user, ftp_password puts " Finding installation directory..." install_dir = "" [ "httpdocs" ].each do |d| dir = try_ftp_cd ftp, d if dir install_dir = dir break end end print " Installing to dir '#{install_dir}'..." upload_dir_ftp ftp, @source_dir, "owncloud" puts "" puts " Closing..." ftp.close end |
#install_local ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/installer.rb', line 96 def install_local # Requirements for ownCloud to run: # * packages installed: apache2, apache2-mod_php5, php5-json, php5-dom, # php5-sqlite, php5-mbstring php5-ctype # * apache2 running puts "Installing owncloud to local web server..." http_docs_dir = "/srv/www/htdocs/" system "#{@root_helper} \"cp -r #{@source_dir} #{http_docs_dir}\"" system "#{@root_helper} \"chown -R wwwrun:www #{http_docs_dir}owncloud\"" end |
#write_admin_config ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/installer.rb', line 69 def write_admin_config if !@admin_password STDERR.puts "Initial admin password is required" exit 1 end if !@admin_user @admin_user = ENV["USER"] end config = <<EOF <?php $AUTOCONFIG = array( "dbtype" => 'sqlite', "directory" => OC::$SERVERROOT."/data", "adminlogin" => "#{@admin_user}", "adminpass" => "#{@admin_password}" ); ?> EOF config_file = @source_dir + "/config/autoconfig.php" File.open config_file, "w" do |file| file.print config end end |