-
Notifications
You must be signed in to change notification settings - Fork 588
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make gnirehtet run whenever I plug in my device #49
Comments
I found this type of feature in an app called Reverse Tethering NoRoot. But that app includes ads and paid version. It's server exe app in PC constantly running background with
Hope this info may help. |
Yes, that's what I would like to avoid (cf #47 (comment)). At least, it won't be the default behavior. But maybe as an alternative to |
Thanks @Biswa96 for sketching it out for lazy me. There sure are more elegant ways to go about this, but in the meantime, the following script does the job for me (here on linux). On startup, it fires up #!/usr/bin/env clojure
(import 'java.lang.Runtime)
(def home-dir (java.io.File. (System/getProperty "user.home")))
(def gnirehtet-dir (java.io.File. home-dir "gnirehtet-java"))
(defn- bash-exec
([cmd-line] (bash-exec cmd-line nil))
([cmd-line home-dir]
(let [proc (. (Runtime/getRuntime) exec (into-array [ "bash" "-c" cmd-line]) nil gnirehtet-dir)
proc-in (java.io.BufferedReader. (java.io.InputStreamReader. (.getInputStream proc)))
proc-err (java.io.BufferedReader. (java.io.InputStreamReader. (.getErrorStream proc)))]
(concat (line-seq proc-in) (line-seq proc-err)))))
(defn- bash-exec-and-out
[cmd-line home-dir]
(doseq [line (bash-exec cmd-line home-dir)]
(println line)))
(future (bash-exec-and-out "./gnirehtet relay" gnirehtet-dir))
(loop [last-device-set nil]
(let [device-set (set (bash-exec "adb devices -l|sed -nre 's/^([0-9A-Za-z]+) +device .*$/\\1/p'"))
new-devices (apply disj device-set last-device-set)]
(doseq [device new-devices]
(println "Newly connected device " device)
(bash-exec-and-out (str "./gnirehtet start " device) gnirehtet-dir))
(Thread/sleep 1000)
(recur device-set))) |
Great, it made me discover some clojure code :) It works for me (I just changed the |
You can do this a lot more easily with udev rules than a daemon that polls adb. Check out the |
@CameronNemo Yes, but:
|
I rewrote above script, chiefly in order to remove the dependence on (the UNIX specific) external #!/usr/bin/env clojure
(def home-dir (java.io.File. (System/getProperty "user.home")))
(def gnirehtet-dir (java.io.File. home-dir "gnirehtet-java"))
(defn- exec
([cmd-line-args] (exec cmd-line-args nil))
([cmd-line-args home-dir]
(let [proc (. (java.lang.Runtime/getRuntime) exec (into-array cmd-line-args) nil home-dir)
proc-in (java.io.BufferedReader. (java.io.InputStreamReader. (.getInputStream proc)))
proc-err (java.io.BufferedReader. (java.io.InputStreamReader. (.getErrorStream proc)))]
(concat (line-seq proc-in) (line-seq proc-err)))))
(defn- gnirehtet
[& cmd-line-args]
(doseq [line (exec (concat ["java" "-jar" "gnirehtet.jar"] cmd-line-args) gnirehtet-dir)]
(println line)))
(defn- replaced-only
[s match replacement]
(let [result (clojure.string/replace s match replacement)]
(if (not= result s)
result)))
(future (gnirehtet "relay"))
(loop [last-device-set nil]
(let [adb-devices-out (exec ["adb" "devices"])
device-set (set (filter identity (map #(replaced-only % #"^(\w+)\s+device$" "$1") adb-devices-out)))
new-devices (apply disj device-set last-device-set)]
(doseq [device new-devices]
(println "Newly connected device" device)
(gnirehtet "start" device))
(Thread/sleep 1000)
(recur device-set))) |
Hello I am using gnirehtet on a Linux server. If you use it frequently udev rules does the trick pretty easy on linux. |
Could you provide the udev rules for people which are interested in the same behavior, please? |
https://wiki.archlinux.org/index.php/Android#Adding_udev_Rules Then add another line with a command using
|
I did this with my Raspi - runs perfect with the ARM library (thx again :-) ) In /etc/udev/rules.d I put the files
Both REBOOT to get udev reload the
the
Further when my raspi starts I have the relay server just started automatically. With that, Hope this explains everything rom1v thank you very very much for the great work and especially for the ARM Binary :-) |
I implemented the feature, see #47 (comment). |
Currently, I have to run the command gnirehtet each time I connect my phone to my computer. Is there a way to start the gnirehtet server so it waits in the background and activates reverse tethering every time I plug my phone in?
The text was updated successfully, but these errors were encountered: