blob: ca9b074f39def243f7b78ee11c4d7ff5a22ccc48 (
plain) (
blame)
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
|
#!/usr/bin/env ruby
# frozen_string_literal: true
ADB = ENV['ADB'] || 'adb'
TARGETS = {
'.epub' => '/sdcard/',
'.mobi' => '/sdcard/Android/data/com.amazon.kindle/files/'
}.freeze
unless File.executable? ADB
warn %(adb-push-ebook: `adb` not found.\nPlease set the ADB environment variable or add `adb` to your PATH.)
exit 1
end
require 'open3'
require 'shellwords'
payload_file = ARGV[0] || '_output/sample-book'
transfers = if (payload_file_ext = File.extname payload_file).empty?
TARGETS.map do |(ext, target_dir)|
{
src: %(#{payload_file}#{ext}),
dest: target_dir
}
end
else
[{ src: payload_file, dest: TARGETS[payload_file_ext] }]
end
transfers.each do |transfer|
next unless File.file? transfer[:src]
Open3.popen2e Shellwords.join([ADB, 'push', transfer[:src], transfer[:dest]]) do |_input, output, _wait_thr|
output.each { |line| puts line }
end
end
|