]> hydra-www.ietfng.org Git - smallutils/commitdiff
Some small utilities for Lil' Debi on Android
authorNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Sun, 5 Oct 2014 20:52:54 +0000 (16:52 -0400)
committerNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Sun, 5 Oct 2014 20:55:51 +0000 (16:55 -0400)
android/lildebi-hooks [new file with mode: 0644]
android/watchprops-netevents.gawk [new file with mode: 0644]

diff --git a/android/lildebi-hooks b/android/lildebi-hooks
new file mode 100644 (file)
index 0000000..171cf40
--- /dev/null
@@ -0,0 +1,25 @@
+#!/bin/bash
+#
+# Utility script for Lil' Debi startup and shutdown; invoke as
+# "ld start" or "ld stop" from the provided hooks.
+
+export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin:/usr/local/bin
+
+case $1 in
+  start) echo ld startup
+    /etc/init.d/busybox-syslogd start
+
+    watchprops-netevents.gawk <(exec /system/bin/watchprops 2>&1) \
+      | exec logger -t watchprops-netevents &
+
+    /etc/init.d/openvpn start
+    /etc/init.d/ssh start
+    ;;
+  stop) echo ld shut 
+    /etc/init.d/openvpn stop
+    /etc/init.d/ssh stop
+    /etc/init.d/busybox-syslogd stop
+
+    # We let everything else get killed by the usual Lil' Debi process
+    ;;
+esac
diff --git a/android/watchprops-netevents.gawk b/android/watchprops-netevents.gawk
new file mode 100644 (file)
index 0000000..f1a9651
--- /dev/null
@@ -0,0 +1,50 @@
+#!/usr/bin/gawk -f
+#
+# Maintains /etc/resolv.conf and provides USR1 signals to openvpn
+# processes.  Intended for use inside chroot environments ala
+# Lil' Debi or others.
+#
+# Run me against the watchprops program, as in
+# gawk -f watchprops-netevents.gawk <(/system/bin/watchprops 2>&1)
+
+function set_dns(   out_file)
+{
+
+  out_file = "/etc/resolv.conf"
+
+  in_file = "/system/bin/getprop net.dns1 8.8.8.8" 
+  if ((in_file | getline) > 0) {
+    print "nameserver " $0
+    print "nameserver " $0 > out_file
+  }
+  close(in_file)
+
+  in_file = "/system/bin/getprop net.dns2 8.8.8.8" 
+  if ((in_file | getline) > 0) {
+    print "nameserver " $0
+    print "nameserver " $0 >> out_file
+  }
+  close(in_file)
+
+  close(out_file)
+}
+
+function signal_vpns() {
+   ka="pkill -USR1 openvpn"
+   ka | getline
+   close(ka)
+}
+
+
+BEGIN{
+  lasttime = systime()
+  set_dns()
+}
+
+/ net.dns.*/{
+  if ( systime() > lasttime) {
+    lasttime = systime()
+    set_dns()
+    signal_vpns()
+  }
+}