From 0098f094b7d726b5f77268d5633c56bdaf6da15c Mon Sep 17 00:00:00 2001 From: Mingye Wang Date: Sun, 25 Oct 2015 01:49:56 -0400 Subject: [PATCH] Remove busybox dependency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 配上一点测试,busybox 就是可选依赖了。 --- chnroutes.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/chnroutes.py b/chnroutes.py index 99401a6..bb12dbf 100755 --- a/chnroutes.py +++ b/chnroutes.py @@ -157,18 +157,26 @@ def generate_android(metric): upscript_header=textwrap.dedent("""\ #!/bin/sh - alias nestat='/system/xbin/busybox netstat' - alias grep='/system/xbin/busybox grep' - alias awk='/system/xbin/busybox awk' - alias route='/system/xbin/busybox route' + busybox="$(PATH="/system/xbin/busybox:$PATH" which busybox || echo /system/xbin/busybox)" + phas(){ type "$@" &>/dev/null; } + bhas(){ "$busybox" "$@" &>/dev/null; } - OLDGW=`netstat -rn | grep ^0\.0\.0\.0 | awk '{print $2}'` + phas netstat || alias nestat='"$busybox" netstat' + phas grep || alias grep='"$busybox" grep' + phsa route || alias route='"$busybox" route' + + read _ OLDGW _ << EOF + $(netstat -rn | grep ^0\.0\.0\.0) + EOF """) downscript_header=textwrap.dedent("""\ #!/bin/sh - alias route='/system/xbin/busybox route' + busybox="$(PATH="/system/xbin/busybox:$PATH" which busybox || echo /system/xbin/busybox)" + phas(){ type "$@" &>/dev/null; } + bhas(){ "$busybox" "$@" &>/dev/null; } + phas route || alias route='/system/xbin/busybox route' """)