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

move installation of shell wrapper scripts to Installer class

Minimizes dependency of Application class from some regex.* classes.
parent 06750ccc
......@@ -18,8 +18,6 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import androidx.annotation.RequiresApi;
......@@ -146,7 +144,7 @@ public class Application extends android.app.Application {
if (!r) return false;
}
r = install_wrapper_scripts();
r = Installer.install_wrapper_scripts();
if (!r) return false;
return r;
......@@ -192,63 +190,6 @@ public class Application extends android.app.Application {
return target.setReadable(true, false);
}
// backward compatible installation of shell wrapper scripts ...
private final boolean install_wrapper_scripts() {
boolean r;
// Note that some ancient Android shell lack test command!
final String[] env_script = {
"#! " + _PATH_BSHELL,
"",
"OPENSSL_CONF=${OPENSSL_CONF-" + etcdir.getPath() + "/openssl.cnf}",
"export OPENSSL_CONF",
"",
"LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}",
"LD_LIBRARY_PATH=" + libdir.getPath() + "$LD_LIBRARY_PATH",
"export LD_LIBRARY_PATH"
};
{
File file = new File(etcdir, "env");
r = Installer.install_text_file(env_script, file);
if (!r) return false;
}
final String[] shell_script = {
"#! " + _PATH_BSHELL,
"",
"xbincmd=${0##*/}",
"",
". " + etcdir.getPath() + "/env",
"",
"exec \\",
xbindir.getPath() + "/libcmd-$xbincmd.so \\",
"${1+\"$@\"}"
};
final Pattern pattern = Pattern.compile("libcmd-(.*).so");
for (String item : xbindir.list()) {
Matcher matcher = pattern.matcher(item);
if (!matcher.find()) continue;
r = Installer.install_shell_script(shell_script, bindir, matcher.group(1));
if (!r) return false;
}
{
File openssl = new File(bindir, "openssl");
if (openssl.exists()) {
for (String cmd : Installer.openssl_aliases) {
String[] cmd_script = {
"#! " + _PATH_BSHELL,
"",
openssl.getPath() + " " + cmd + " ${1+\"$@\"}"
};
r = Installer.install_shell_script(cmd_script, bindir, cmd);
if (!r) return false;
}
}
}
return true;
}
private static class CompatPackageInfo {
static long getVersion(PackageInfo pkg_info) {
......
......@@ -137,4 +137,65 @@ public class Installer {
}
return true;
}
// installation of shell wrapper scripts for backward compatibility
public static boolean install_wrapper_scripts() {
boolean r;
// Note that some ancient Android shell lack test command!
final String[] env_script = {
"#! " + Application._PATH_BSHELL,
"",
"OPENSSL_CONF=${OPENSSL_CONF-" + Application.etcdir.getPath() + "/openssl.cnf}",
"export OPENSSL_CONF",
"",
"LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}",
"LD_LIBRARY_PATH=" + Application.libdir.getPath() + "$LD_LIBRARY_PATH",
"export LD_LIBRARY_PATH"
};
{
File file = new File(Application.etcdir, "env");
r = install_text_file(env_script, file);
if (!r) return false;
}
{// command wrapper scripts
String[] shell_script = {
"#! " + Application._PATH_BSHELL,
"",
"xbincmd=${0##*/}",
"",
". " + Application.etcdir.getPath() + "/env",
"",
"exec \\",
Application.xbindir.getPath() + "/libcmd-$xbincmd.so \\",
"${1+\"$@\"}"
};
final Pattern pattern = Pattern.compile("libcmd-(.*).so");
for (String item : Application.xbindir.list()) {
Matcher matcher = pattern.matcher(item);
if (!matcher.find()) continue;
r = install_shell_script(shell_script, Application.bindir, matcher.group(1));
if (!r) return false;
}
}
{// openssl command aliases
File openssl = new File(Application.bindir, "openssl");
if (openssl.exists()) {
for (String cmd : openssl_aliases) {
String[] cmd_script = {
"#! " + Application._PATH_BSHELL,
"",
openssl.getPath() + " " + cmd + " ${1+\"$@\"}"
};
r = install_shell_script(cmd_script, Application.bindir, cmd);
if (!r) return false;
}
}
}
return true;
}
}
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