In Files

Parent

Class/Module Index [+]

Quicksearch

Installer

owncloud-admin - the owncloud administration tool

Copyright (C) 2011 Cornelius Schumacher <schumacher@kde.org>

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.

Attributes

admin_password[RW]
admin_user[RW]
ftp_password[RW]
ftp_user[RW]
root_helper[RW]
server[RW]
skip_download[RW]

Public Class Methods

new(settings) click to toggle source
# File lib/installer.rb, line 25
def initialize settings
  @settings = settings
end
server_types() click to toggle source
# File lib/installer.rb, line 29
def self.server_types
  [ "local", "ftp" ]
end

Public Instance Methods

install(server_type) click to toggle source
# 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() click to toggle source
# File lib/installer.rb, line 109
def install_ftp
  puts "Installing owncloud to remote web server via FTP..."

  assert_options [ :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() click to toggle source
# 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() click to toggle source
# 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 = <?php$AUTOCONFIG = array(  "dbtype" => 'sqlite',  "directory" => OC::$SERVERROOT."/data",  "adminlogin" => "#{@admin_user}",  "adminpass" => "#{@admin_password}");?>

  config_file = @source_dir + "/config/autoconfig.php"

  File.open config_file, "w" do |file|
    file.print config
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.