summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2014-07-29 02:15:41 -0600
committerDan Allen <dan.j.allen@gmail.com>2014-07-29 02:15:41 -0600
commit5aef9cb5b05c2814fe4fb2a8afb05421ef1cef3e (patch)
tree9e43605da060be0c2fbbcf91015f49ce004a4c9f /bin
parent903aae72812edbc5011493a10b9fe118c990954b (diff)
rewrite adb-push-ebook as Ruby script
Diffstat (limited to 'bin')
-rwxr-xr-xbin/adb-push-ebook37
1 files changed, 22 insertions, 15 deletions
diff --git a/bin/adb-push-ebook b/bin/adb-push-ebook
index d45442d..da5edb1 100755
--- a/bin/adb-push-ebook
+++ b/bin/adb-push-ebook
@@ -1,18 +1,25 @@
-#!/bin/sh
+#!/usr/bin/env ruby
-if [ -z $ADB ]; then
- ADB=~/opt/android-sdk/platform-tools/adb
-fi
+ADB = ENV['ADB'] || 'adb'
-if [ -z $1 ]; then
- DOCNAME=_output/sample-book
-else
- DOCNAME=$1
-fi
+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
-if [ -f $DOCNAME.epub ]; then
- $ADB push $DOCNAME.epub /sdcard/
-fi
-if [ -f $DOCNAME.mobi ]; then
- $ADB push $DOCNAME.mobi /sdcard/Android/data/com.amazon.kindle/files/
-fi
+require 'open3'
+require 'shellwords'
+
+docname = ARGV[0] || '_output/sample-book'
+
+targets = {
+ 'epub' => '/sdcard/',
+ 'mobi' => '/sdcard/Android/data/com.amazon.kindle/files/'
+}
+
+targets.each {|(ext, target)|
+ file = %(#{docname}.#{ext})
+ Open3.popen2e(Shellwords.join [ADB, 'push', file, target]) {|input, output, wait_thr|
+ output.each {|line| puts line }
+ } if File.file? file
+}