Commit eb2405b1 authored by Румен Петров's avatar Румен Петров
Browse files

use aliases to run commands located in library directory

This avoid use of script wrappers in terminal window.
parent 69aed6ae
......@@ -8,6 +8,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
......@@ -93,6 +94,43 @@ public class Installer {
return file.setExecutable(true, false);
}
public static void printCommandEnvironment(PrintStream out) {
// Note that some ancient Android shell lack test command!
// export path to commands
out.println("PATH=${PATH:+:$PATH}");
out.println("PATH=\"" + Application.xbindir.getPath() + "\"$PATH");
out.println("export PATH");
// export path to libraries
out.println("LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}");
out.println("LD_LIBRARY_PATH=\"" + Application.libdir.getPath() + "\"$LD_LIBRARY_PATH");
out.println("export LD_LIBRARY_PATH");
// export some configuration settings
out.println("OPENSSL_CONF=${OPENSSL_CONF-" + Application.etcdir.getPath() + "/openssl.cnf}");
out.println("export OPENSSL_CONF");
}
public static void printCommandAliases(PrintStream out) {
//common application function that run native command
out.println("sbcmd() {( name=$1; shift; . /proc/self/fd/0 <<< \"$(libexec-sb.so appenv)\"; exec libcmd-$name.so ${1+\"$@\"}; )}");
final Pattern pattern = Pattern.compile("libcmd-(.*).so");
boolean has_openssl = false;
for (String item : Application.xbindir.list()) {
Matcher matcher = pattern.matcher(item);
if (!matcher.find()) continue;
String name = matcher.group(1);
out.println("alias " + name + "='sbcmd " + name + "'");
if ("openssl".equals(name)) has_openssl = true;
}
if (has_openssl) {
for (String name : Installer.openssl_aliases) {
out.println("alias " + name + "='openssl " + name + "'");
}
}
}
public static boolean copy_executable(File source, File target_path) {
int buflen = 32 * 1024; // 32k
byte[] buf = new byte[buflen];
......
......@@ -5,6 +5,7 @@ import android.text.TextUtils;
import com.termoneplus.securebox.Application;
import com.termoneplus.securebox.BuildConfig;
import com.termoneplus.securebox.Installer;
import java.io.BufferedReader;
import java.io.IOException;
......@@ -62,6 +63,12 @@ public class PathResolver implements UnixSocketServer.ConnectionHandler {
case "get appdatadir":
out.println(Application.rootdir.getPath());
break;
case "get appenv":
Installer.printCommandEnvironment(out);
break;
case "get aliases":
Installer.printCommandAliases(out);
break;
}
out.flush();
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment