forked from dmathieu/glynn
/
glynn
executable file
·59 lines (53 loc) · 1.61 KB
/
glynn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
#!/usr/bin/env ruby
require 'rubygems'
require 'jekyll'
require 'glynn'
$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
options = {}
case ARGV.size
when 0
when 1
options['destination'] = ARGV[0]
when 2
options['source'] = ARGV[0]
options['destination'] = ARGV[1]
when 4
options['source'] = ARGV[0]
options['destination'] = ARGV[1]
options['ftp_username'] = ARGV[2]
options['ftp_password'] = ARGV[3]
end
options = Jekyll.configuration(options)
ftp_port = (options['ftp_port'] || 21).to_i
ftp_disable_passive = options['ftp_disable_passive'] || false
puts "Building site: #{options['source']} -> #{options['destination']}"
jekyll = Glynn::Jekyll.new
jekyll.build
puts "Successfully generated site"
puts "Sending site over FTP (host: #{options['ftp_host']}, port: #{ftp_port})"
begin
if options['ftp_username'].nil?
print "FTP Username: "
username = $stdin.gets.chomp
else
username = options['ftp_username']
end
if options['ftp_password'].nil?
print "FTP Password: "
# We hide the entered characters before to ask for the password
system "stty -echo"
password = $stdin.gets.chomp
system "stty echo"
else
password = options['ftp_password']
end
rescue NoMethodError, Interrupt
# When the process is exited, we display the characters again
# And we exit
system "stty echo"
exit
end
ftp = Glynn::Ftp.new(options['ftp_host'], ftp_port, {:username => username, :password => password, :disable_passive => ftp_disable_passive})
puts "\r\nConnected to server. Sending site"
ftp.sync(options['destination'], options['ftp_dir'])
puts "Successfully sent site"