owncloud-admin 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/TODO +1 -0
- data/bin/owncloud-admin +8 -0
- data/lib/cli.rb +70 -0
- data/lib/installer.rb +141 -0
- data/lib/owncloud-admin.rb +10 -0
- data/lib/settings.rb +25 -0
- data/lib/version.rb +5 -0
- metadata +91 -0
data/bin/owncloud-admin
ADDED
data/lib/cli.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
class Cli < Thor
|
2
|
+
|
3
|
+
default_task :global
|
4
|
+
|
5
|
+
class_option :version, :type => :boolean, :desc => "Show version"
|
6
|
+
|
7
|
+
def self.settings= s
|
8
|
+
@@settings = s
|
9
|
+
end
|
10
|
+
|
11
|
+
desc "global", "Global options", :hide => true
|
12
|
+
def global
|
13
|
+
if options[:version]
|
14
|
+
puts "owncloud-admin: #{@@settings.version}"
|
15
|
+
else
|
16
|
+
Cli.help shell
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "config", "Show and modify configuration"
|
21
|
+
method_option :set_server, :type => :string, :aliases => "-s",
|
22
|
+
:desc => "Set server"
|
23
|
+
def config
|
24
|
+
if options[:set_server]
|
25
|
+
puts "SET SERVER TO #{options[:set_server]}"
|
26
|
+
else
|
27
|
+
puts "SHOW CONFIG"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
desc "ping", "Ping server"
|
32
|
+
def ping
|
33
|
+
puts "PING SERVER"
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "install", "Install ownCloud server"
|
37
|
+
method_option :server_type, :type => :string,
|
38
|
+
:desc => "Server type", :required => true
|
39
|
+
method_option :server, :type => :string,
|
40
|
+
:desc => "Server name", :required => false
|
41
|
+
method_option :user, :type => :string,
|
42
|
+
:desc => "User name", :required => false
|
43
|
+
method_option :password, :type => :string,
|
44
|
+
:desc => "Password", :required => false
|
45
|
+
method_option :skip_download, :type => :boolean,
|
46
|
+
:desc => "Skip download of owncloud sources", :required => false
|
47
|
+
def install
|
48
|
+
installer = Installer.new @@settings
|
49
|
+
|
50
|
+
installer.skip_download = options["skip_download"]
|
51
|
+
|
52
|
+
installer.server = options["server"]
|
53
|
+
installer.user = options["user"]
|
54
|
+
installer.password = options["password"]
|
55
|
+
|
56
|
+
server_type = options["server_type"]
|
57
|
+
|
58
|
+
server_types = [ "local", "ftp" ]
|
59
|
+
if server_types.include? server_type
|
60
|
+
installer.install server_type
|
61
|
+
else
|
62
|
+
STDERR.puts "Unsupported server type '#{server_type}."
|
63
|
+
STDERR.puts "Supported types are: #{server_types.join}."
|
64
|
+
exit 1
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
end
|
data/lib/installer.rb
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
class Installer
|
2
|
+
|
3
|
+
attr_accessor :server, :user, :password, :skip_download
|
4
|
+
|
5
|
+
def initialize settings
|
6
|
+
@settings = settings
|
7
|
+
end
|
8
|
+
|
9
|
+
def install server_type
|
10
|
+
if !skip_download
|
11
|
+
source = {
|
12
|
+
:server => "owncloud.org",
|
13
|
+
:path => "/releases/",
|
14
|
+
:file => "owncloud-latest.tar.bz2"
|
15
|
+
}
|
16
|
+
|
17
|
+
local_source = @settings.tmp_dir + source[:file]
|
18
|
+
|
19
|
+
puts "Downloading owncloud source archive..."
|
20
|
+
Net::HTTP.start( source[:server] ) do |http|
|
21
|
+
response = http.get( source[:path] + source[:file] )
|
22
|
+
open( local_source, "wb") do |file|
|
23
|
+
file.write response.body
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
puts "Extracting archive..."
|
28
|
+
system "cd #{@settings.tmp_dir}; tar xjf #{source[:file]}"
|
29
|
+
end
|
30
|
+
|
31
|
+
@source_dir = @settings.tmp_dir + "owncloud"
|
32
|
+
|
33
|
+
if server_type == "local"
|
34
|
+
install_local
|
35
|
+
elsif server_type == "ftp"
|
36
|
+
install_ftp
|
37
|
+
else
|
38
|
+
STDERR.puts "Unsupported server type: #{server_type}"
|
39
|
+
exit 1
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def install_local
|
44
|
+
# Requirements for ownCloud to run:
|
45
|
+
# * packages installed: apache2, apache2-mod_php5, php5-json, php5-dom,
|
46
|
+
# php5-sqlite, php5-mbstring php5-ctype
|
47
|
+
# * apache2 running
|
48
|
+
|
49
|
+
puts "Installing owncloud to local web server..."
|
50
|
+
http_docs_dir = "/srv/www/htdocs/"
|
51
|
+
|
52
|
+
system "sudo cp -r #{@source_dir} #{http_docs_dir}"
|
53
|
+
system "sudo chown -R wwwrun:www #{http_docs_dir}owncloud"
|
54
|
+
end
|
55
|
+
|
56
|
+
def install_ftp
|
57
|
+
puts "Installing owncloud to remote web server via FTP..."
|
58
|
+
|
59
|
+
assert_options [ :server, :user, :password ]
|
60
|
+
|
61
|
+
ftp = Net::FTP.new( server )
|
62
|
+
ftp.passive = true
|
63
|
+
puts " Logging in..."
|
64
|
+
ftp.login user, password
|
65
|
+
|
66
|
+
puts " Finding installation directory..."
|
67
|
+
install_dir = ""
|
68
|
+
[ "httpdocs" ].each do |d|
|
69
|
+
dir = try_ftp_cd ftp, d
|
70
|
+
if dir
|
71
|
+
install_dir = dir
|
72
|
+
break
|
73
|
+
end
|
74
|
+
end
|
75
|
+
print " Installing to dir '#{install_dir}'..."
|
76
|
+
|
77
|
+
upload_dir_ftp ftp, @source_dir, "owncloud"
|
78
|
+
puts ""
|
79
|
+
|
80
|
+
puts " Closing..."
|
81
|
+
ftp.close
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def upload_dir_ftp ftp, source_path, target_path
|
87
|
+
puts ""
|
88
|
+
print " Uploading dir #{target_path}"
|
89
|
+
assert_ftp_directory ftp, target_path
|
90
|
+
if target_path == "owncloud/data"
|
91
|
+
# FIXME: When ownCloud allows it set permissions so that it works
|
92
|
+
# ftp.sendcmd("SITE CHMOD 0772 #{target_path}")
|
93
|
+
end
|
94
|
+
Dir.entries( source_path ).each do |entry|
|
95
|
+
next if entry =~ /^\.\.?$/
|
96
|
+
|
97
|
+
source_file = source_path + "/" + entry
|
98
|
+
target_file = target_path + "/" + entry
|
99
|
+
if File.directory? source_file
|
100
|
+
upload_dir_ftp ftp, source_file, target_path + "/" + entry
|
101
|
+
else
|
102
|
+
print "."
|
103
|
+
ftp.putbinaryfile source_file, target_file
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def assert_ftp_directory ftp, dir
|
109
|
+
begin
|
110
|
+
ftp.mkdir dir
|
111
|
+
rescue Net::FTPPermError => e
|
112
|
+
if e.message !~ /File exists/
|
113
|
+
raise e
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def try_ftp_cd ftp, dir
|
119
|
+
begin
|
120
|
+
ftp.chdir dir
|
121
|
+
return dir
|
122
|
+
rescue Net::FTPPermError => e
|
123
|
+
return nil
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def assert_options options
|
128
|
+
@errors = Array.new
|
129
|
+
options.each do |option|
|
130
|
+
value = send option
|
131
|
+
if value.nil?
|
132
|
+
@errors.push "Missing option: #{option}"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
if !@errors.empty?
|
136
|
+
STDERR.puts @errors.join( "\n" )
|
137
|
+
exit 1
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
|
3
|
+
require "thor"
|
4
|
+
require "net/http"
|
5
|
+
require "net/ftp"
|
6
|
+
|
7
|
+
require File.expand_path('../version', __FILE__)
|
8
|
+
require File.expand_path('../cli', __FILE__)
|
9
|
+
require File.expand_path('../settings', __FILE__)
|
10
|
+
require File.expand_path('../installer', __FILE__)
|
data/lib/settings.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
class Settings
|
2
|
+
|
3
|
+
def version
|
4
|
+
OwncloudAdmin::VERSION
|
5
|
+
end
|
6
|
+
|
7
|
+
def tmp_dir
|
8
|
+
local_dir "tmp/"
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def local_path dirname
|
14
|
+
home = ENV["HOME"] + "/.owncloud-admin/"
|
15
|
+
Dir::mkdir home unless File.exists? home
|
16
|
+
home + dirname
|
17
|
+
end
|
18
|
+
|
19
|
+
def local_dir dirname
|
20
|
+
path = local_path dirname
|
21
|
+
Dir::mkdir path unless File.exists? path
|
22
|
+
path
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/lib/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: owncloud-admin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Cornelius Schumacher
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-09-28 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: thor
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 39
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 14
|
33
|
+
- 0
|
34
|
+
version: 0.14.0
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
description: Command line tool for installing and administering ownCloud
|
38
|
+
email:
|
39
|
+
- cschum@suse.de
|
40
|
+
executables:
|
41
|
+
- owncloud-admin
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files: []
|
45
|
+
|
46
|
+
files:
|
47
|
+
- TODO
|
48
|
+
- bin/owncloud-admin
|
49
|
+
- lib/cli.rb
|
50
|
+
- lib/installer.rb
|
51
|
+
- lib/owncloud-admin.rb
|
52
|
+
- lib/settings.rb
|
53
|
+
- lib/version.rb
|
54
|
+
has_rdoc: true
|
55
|
+
homepage: https://github.com/opensuse/owncloud-admin
|
56
|
+
licenses: []
|
57
|
+
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
hash: 3
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 23
|
78
|
+
segments:
|
79
|
+
- 1
|
80
|
+
- 3
|
81
|
+
- 6
|
82
|
+
version: 1.3.6
|
83
|
+
requirements: []
|
84
|
+
|
85
|
+
rubyforge_project: inqlude
|
86
|
+
rubygems_version: 1.5.0
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: ownCloud administration
|
90
|
+
test_files: []
|
91
|
+
|