From: Nathaniel Wesley Filardo Date: Sun, 5 Oct 2014 20:52:54 +0000 (-0400) Subject: Some small utilities for Lil' Debi on Android X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=4c28d6b0c05261cae1d562ad3ec218710af04782;p=smallutils Some small utilities for Lil' Debi on Android --- diff --git a/android/lildebi-hooks b/android/lildebi-hooks new file mode 100644 index 0000000..171cf40 --- /dev/null +++ b/android/lildebi-hooks @@ -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 index 0000000..f1a9651 --- /dev/null +++ b/android/watchprops-netevents.gawk @@ -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() + } +}