dropup 0.3 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/dropup +48 -35
  3. data/dropup.gemspec +2 -2
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 03c30c13c98abc02b9d87f010acc331123d3cf06
4
- data.tar.gz: d4152baf7b405a3ab1aecfaaf83b6f9e76ca9018
3
+ metadata.gz: a03754a4747eef5b1938fe47b553685ab63be063
4
+ data.tar.gz: 92bedd3c2711fe348e1a1c4911811bcbabb0c0b8
5
5
  SHA512:
6
- metadata.gz: 31c15038b0c35eb90d034a973b8e262dca67272f4a4d15c34778041cf5d4e5dea52416c55d2d49665b101d996a987962c35aa8f1ea01b2ade84939db47dd2bab
7
- data.tar.gz: ff421385f1c942aaf864a133cbeddf2b5d9247112384470120244f906dcee1cd4577c3a901540b5dfbc3df499103df81e27060ef7d935f3847146feb912d7b05
6
+ metadata.gz: 1480e362f5fc041135570edde3b870b0f8601edd732efdf2adc20883b940e8dd28b0ec9b4c935a8311aee1449dc7dec7b2c6a3f6214ee3af5d357052dba66200
7
+ data.tar.gz: 4043a53236c625b587d0004664e397127a548e4f80eff2030e0d8f85a253a6ccd9f906c62ecc5e6a547a5be050f35e999991647e3b51323cca1458d5b352338f
data/bin/dropup CHANGED
@@ -8,12 +8,14 @@ require 'time'
8
8
  require 'optparse'
9
9
  require 'open3'
10
10
  require 'terminal-notifier'
11
+ require 'fileutils'
11
12
 
12
13
  options = {
13
14
  :size => 400, # in MB
14
15
  :keep => 0, # number of backups to keep
15
16
  :verbose => false,
16
- :notification => false
17
+ :notification => false,
18
+ :temp => '/tmp/backup-%.dmg'
17
19
  }
18
20
 
19
21
  opt_parser = OptionParser.new do |opt|
@@ -42,6 +44,10 @@ opt_parser = OptionParser.new do |opt|
42
44
  opt.on("-s", "--size SIZE", "size") do |size|
43
45
  options[:size] = size.to_i
44
46
  end
47
+
48
+ opt.on("-t", "--temp TEMP", "temp") do |temp|
49
+ options[:temp] = temp.to_s
50
+ end
45
51
  end
46
52
 
47
53
  opt_parser.parse!
@@ -51,59 +57,66 @@ if ARGV.length < 2
51
57
  exit
52
58
  end
53
59
 
54
- destination = File.expand_path(ARGV.pop)
60
+ def backup(srcs, temp, password, size)
55
61
 
56
- backups = Dir[destination.gsub(/%/,'*')].sort.reverse
62
+ cmd = %W(
63
+ hdiutil create
64
+ -encryption AES-256
65
+ -stdinpass
66
+ -volname "Backup"
67
+ -format UDZO
68
+ -megabytes #{size}
69
+ #{srcs.map{|s| "-srcfolder \"#{File.expand_path(s)}\"" }.join(' ')}
70
+ "#{File.expand_path(temp)}"
71
+ ).join(' ')
72
+
73
+ Open3.popen3(cmd) do |stdin, stdout, stderr, wait|
74
+ stdin.printf(password)
75
+ stdin.close
57
76
 
58
- puts "Backups: #{backups}" if options[:verbose]
77
+ yield wait.value == 0
59
78
 
60
- while backups.length > options[:keep]
61
- backup = backups.pop
62
- puts "Deleting: #{backup}" if options[:verbose]
63
- File.delete(backup)
79
+ end
64
80
  end
65
81
 
66
- backup = destination.gsub(/%/, Time.now.strftime("%Y%m%d%M%H%S%L"))
67
-
68
- puts "Creating: #{backup}" if options[:verbose]
82
+ time = Time.now.strftime("%Y%m%d%M%H%S%L")
83
+ temp_pattern = File.expand_path(options[:temp])
84
+ dest_pattern = File.expand_path(ARGV.pop)
69
85
 
70
86
  password = %x[security find-internet-password -s dropup -a password -g 2>&1][/^password:\s"([^"]*)"/,1]
71
-
72
87
  if password.nil? || password.length == 0
73
88
  puts "Set a password: security add-internet-password -s dropup -U -T \"\" -a password -w <PASSWORD>"
74
89
  exit
75
90
  end
76
91
 
77
- cmd = %W(
78
- hdiutil create
79
- -encryption AES-256
80
- -stdinpass
81
- -volname "Backup"
82
- -format UDZO
83
- -megabytes #{options[:size]}
84
- #{ARGV.map{|s| "-srcfolder \"#{File.expand_path(s)}\"" }.join(' ')}
85
- "#{File.expand_path(backup)}"
86
- ).join(' ')
92
+ temp = temp_pattern.gsub(/%/, time)
93
+ dest = dest_pattern.gsub(/%/, time)
87
94
 
88
- puts "Command: #{cmd}" if options[:verbose]
95
+ puts "Creating: #{dest}" if options[:verbose]
89
96
 
90
- if not options[:dry]
91
- Open3.popen3(cmd) do |stdin, stdout, stderr, wait|
92
- stdin.printf(password)
93
- stdin.close
97
+ backup(ARGV, temp, password, options[:size]) do |success|
94
98
 
95
- TerminalNotifier.notify('Backup Starting') if options[:notification]
96
- puts "Building dmg" if options[:verbose]
99
+ TerminalNotifier.notify('Backup Starting') if options[:notification]
100
+ puts "Building dmg" if options[:verbose]
97
101
 
98
- if wait.value == 0 then
102
+ if success then
99
103
 
100
- TerminalNotifier.notify('Backup Successful', :title => 'Success') if options[:notification]
101
- puts "Success" if options[:verbose]
104
+ TerminalNotifier.notify('Backup Successful', :title => 'Success') if options[:notification]
105
+ puts "Success" if options[:verbose]
102
106
 
103
- else
107
+ backups = Dir[dest_pattern.gsub(/%/,'*')].sort.reverse
104
108
 
105
- TerminalNotifier.notify('Backup Failed', :title => 'Error', :sound => 'default') if options[:notification]
106
- puts "Error: #{stderr.read}" if options[:verbose]
109
+ while backups.length > options[:keep]
110
+ backup = backups.pop
111
+ puts "Deleting: #{backup}" if options[:verbose]
112
+ File.delete(backup)
107
113
  end
114
+
115
+ FileUtils.move(temp, dest)
116
+
117
+ else
118
+
119
+ TerminalNotifier.notify('Backup Failed', :title => 'Error', :sound => 'default') if options[:notification]
120
+ puts "Error: #{stderr.read}" if options[:verbose]
108
121
  end
109
122
  end
data/dropup.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = 'dropup'
3
- s.version = '0.3'
4
- s.date = '2014-10-01'
3
+ s.version = '0.4'
4
+ s.date = '2014-10-02'
5
5
 
6
6
  s.authors = [ 'Torsten Curdt' ]
7
7
  s.email = [ 'tcurdt@vafer.org' ]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dropup
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
4
+ version: '0.4'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Torsten Curdt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-01 00:00:00.000000000 Z
11
+ date: 2014-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: terminal-notifier