syncia 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 04e08d9bb8ea6c595e519d78a79a18b14430a6c3
4
+ data.tar.gz: bfc2e145a62b283bcb457b5f7c8b4001cad44124
5
+ SHA512:
6
+ metadata.gz: e51122e3bc7fd30f3d8c93556b44c1df778e2a42d96d95effbc64f533b89d616c329df209e1ab23200ca3dc82c38abfdd063c6a8652409f316daee994d57dfca
7
+ data.tar.gz: 7fb3cb46bb9fbfdbfb3850f435348074e110c2112b1177b08c7c0e961788cc33d0eb498411d66692f038939cbb888bc7b171b2044e978e0da5d77a56d63b66fa
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in syncia.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # Syncia
2
+
3
+ File sync service with Ruby. The procedure is:
4
+
5
+ ```
6
+ 1. Start as a daemon process
7
+ 2. Start to watch a designated folder
8
+ 3. If updated, execute rsync command
9
+ 4. Synchronize your files to remote host
10
+ 5. Endup if it received a signal.
11
+ ```
12
+
13
+ Before synchronizing your file, you must register public key to the remote host like below:
14
+
15
+ ```
16
+ $ cat ~/.ssh/id_rsa.pub | shh your_remote_host 'cat >> ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys'
17
+ ```
18
+
19
+ ## Installation
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ ```ruby
24
+ gem 'syncia'
25
+ ```
26
+
27
+ And then execute:
28
+
29
+ $ bundle
30
+
31
+ Or install it yourself as:
32
+
33
+ $ gem install syncia
34
+
35
+ ## Usage
36
+
37
+ ```syncia.rb
38
+ require 'syncia'
39
+
40
+ syncia = Syncia.new('./testdir')
41
+ syncia.set_remote_info('timakin', '153.121.70.114')
42
+ syncia.set_remote_dir('/home/timakin/sync')
43
+ syncia.run
44
+ ```
45
+
46
+ ```CLI
47
+ $ ruby syncia.rb
48
+ $ cat .syncia.pid | xargs kill
49
+ ```
50
+
51
+ ## Development
52
+
53
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
54
+
55
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
56
+
57
+ ## Contributing
58
+
59
+ 1. Fork it ( https://github.com/timakin/syncia/fork )
60
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
61
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
62
+ 4. Push to the branch (`git push origin my-new-feature`)
63
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "syncia"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/lib/syncia.rb ADDED
@@ -0,0 +1,94 @@
1
+ require 'filewatcher'
2
+ require 'logger'
3
+ require 'fileutils'
4
+
5
+ class Syncia
6
+ def initialize(local_dir_path)
7
+ @pid_file_path = './.syncia.pid'
8
+ @logger = Logger.new(STDOUT)
9
+
10
+ unless directory_exists?(local_dir_path)
11
+ @logger.error directory_not_found_error
12
+ return
13
+ end
14
+
15
+ @local_dir_path = local_dir_path
16
+ @logger.info syncia_start
17
+ end
18
+
19
+ def set_remote_info(remote_user, remote_host)
20
+ @remote_user = remote_user
21
+ @remote_host = remote_host
22
+ @remote_info = @remote_user + "@" + @remote_host
23
+ end
24
+
25
+ def set_remote_dir(remote_dir_path)
26
+ @remote_dir_path = remote_dir_path
27
+ end
28
+
29
+ def run
30
+ unless (@remote_info && @remote_dir_path)
31
+ @logger.error set_remote_before_running_error
32
+ return
33
+ end
34
+
35
+ daemonize
36
+ begin
37
+ Signal.trap(:TERM) { shutdown($$) }
38
+ Signal.trap(:INT) { shutdown($$) }
39
+ execute
40
+ rescue => ex
41
+ @logger.error ex
42
+ end
43
+ end
44
+
45
+ def shutdown(pid)
46
+ @logger.close
47
+ FileUtils.rm @pid_file_path
48
+ Process.kill('KILL', pid)
49
+ end
50
+
51
+ private
52
+ def directory_exists?(directory)
53
+ File.directory?(directory)
54
+ end
55
+
56
+ def execute
57
+ FileWatcher.new("#{@local_dir_path}/**/*").watch do |filename, event|
58
+ system(sync_command)
59
+ end
60
+ end
61
+
62
+ def daemonize
63
+ exit!(0) if Process.fork
64
+ Process.setsid
65
+ exit!(0) if Process.fork
66
+ open_pid_file
67
+ end
68
+
69
+ def open_pid_file
70
+ begin
71
+ open(@pid_file_path, 'w') {|f| f << Process.pid } if @pid_file_path
72
+ rescue => ex
73
+ @logger.error "Could not open pid file (#@pid_file_path)"
74
+ @logger.error "Error: #{ex}"
75
+ @logger.error ex.backtrace * "\n"
76
+ end
77
+ end
78
+
79
+ def sync_command
80
+ "rsync -azr -e ssh #{@local_dir_path}/* #{@remote_info}:#{@remote_dir_path} --delete"
81
+ end
82
+
83
+ def syncia_start
84
+ "[Syncia] start ..."
85
+ end
86
+
87
+ def set_remote_before_running_error
88
+ "Set a host infomation and a dir_path of your remote environment, before running."
89
+ end
90
+
91
+ def directory_not_found_error
92
+ "Directory not found."
93
+ end
94
+ end
data/syncia.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "syncia"
7
+ spec.version = "0.1.0"
8
+ spec.authors = ["timakin"]
9
+ spec.email = ["timaki.st@gmail.com"]
10
+
11
+ spec.summary = "File sync tool like Dropbox, scripted with Ruby."
12
+ spec.description = "File sync tool like Dropbox, scripted with Ruby."
13
+ spec.homepage = "https://github.com/timakin"
14
+
15
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
16
+ # delete this section to allow pushing this gem to any host.
17
+ if spec.respond_to?(:metadata)
18
+ spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
19
+ else
20
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
21
+ end
22
+
23
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.9"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "filewatcher", "~> 0.5.2"
31
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: syncia
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - timakin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: filewatcher
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 0.5.2
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.5.2
55
+ description: File sync tool like Dropbox, scripted with Ruby.
56
+ email:
57
+ - timaki.st@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .travis.yml
64
+ - Gemfile
65
+ - README.md
66
+ - Rakefile
67
+ - bin/console
68
+ - bin/setup
69
+ - lib/syncia.rb
70
+ - syncia.gemspec
71
+ homepage: https://github.com/timakin
72
+ licenses: []
73
+ metadata:
74
+ allowed_push_host: 'TODO: Set to ''http://mygemserver.com'''
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.0.14
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: File sync tool like Dropbox, scripted with Ruby.
95
+ test_files: []