fix(terminal): bootstrap packages are not installed on first install

This commit is contained in:
Akash Yadav
2023-11-15 10:23:20 +05:30
parent 8f6d41982a
commit 84dbbe7bcb
4 changed files with 24 additions and 4 deletions
@@ -52,8 +52,8 @@ class TerminalActivity : TermuxActivity() {
}
override fun onServiceConnected(componentName: ComponentName?, service: IBinder?) {
writeSourcesList()
super.onServiceConnected(componentName, service)
writeSourcesList()
}
private fun writeSourcesList() {
@@ -33,10 +33,13 @@ import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import static com.itsaky.androidide.utils.Environment.PREFIX;
import static com.itsaky.androidide.utils.Environment.SHELL;
import static com.termux.shared.termux.TermuxConstants.TERMUX_PREFIX_DIR;
import static com.termux.shared.termux.TermuxConstants.TERMUX_PREFIX_DIR_PATH;
import static com.termux.shared.termux.TermuxConstants.TERMUX_STAGING_PREFIX_DIR;
import static com.termux.shared.termux.TermuxConstants.TERMUX_STAGING_PREFIX_DIR_PATH;
import static com.termux.shared.termux.shell.TermuxShellUtils.shellExists;
/**
* Install the Termux bootstrap packages if necessary by following the below steps:
@@ -102,8 +105,7 @@ public final class TermuxInstaller {
return;
}
// If prefix directory exists, even if its a symlink to a valid directory and symlink is not broken/dangling
if (FileUtils.directoryFileExists(TERMUX_PREFIX_DIR_PATH, true)) {
if (shellExists(false)) {
if (TermuxFileUtils.isTermuxPrefixDirectoryEmpty()) {
Logger.logInfo(LOG_TAG, "The termux prefix directory \"" + TERMUX_PREFIX_DIR_PATH + "\" exists but is empty or only contains specific unimportant files.");
} else {
@@ -31,7 +31,11 @@ public class AndroidShellEnvironment extends UnixShellEnvironment {
@NonNull
@Override
public HashMap<String, String> getEnvironment(@NonNull Context currentPackageContext, boolean isFailSafe) {
HashMap<String, String> environment = new HashMap<>(Environment.getEnvironment());
HashMap<String, String> environment = new HashMap<>();
if (!isFailSafe) {
environment.putAll(Environment.getEnvironment());
}
environment.put(ENV_HOME, "/");
environment.put(ENV_LANG, "en_US.UTF-8");
@@ -3,13 +3,16 @@ package com.termux.shared.termux.shell;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.itsaky.androidide.utils.Environment;
import com.termux.shared.errors.Error;
import com.termux.shared.file.filesystem.FileTypes;
import com.termux.shared.shell.command.environment.UnixShellEnvironment;
import com.termux.shared.termux.TermuxConstants;
import com.termux.shared.file.FileUtils;
import com.termux.shared.logger.Logger;
import com.termux.shared.termux.settings.properties.TermuxAppSharedProperties;
import com.termux.shared.termux.shell.command.environment.TermuxShellEnvironment;
import org.apache.commons.io.filefilter.TrueFileFilter;
import java.io.File;
@@ -23,6 +26,17 @@ public class TermuxShellUtils {
private static final String LOG_TAG = "TermuxShellUtils";
public static boolean shellExists(boolean failsafe) {
for (String shellBinary : UnixShellEnvironment.LOGIN_SHELL_BINARIES) {
File shellFile = new File(Environment.PREFIX, shellBinary);
if (shellFile.canExecute()) {
return true;
}
}
return false;
}
/**
* Setup shell command arguments for the execute. The file interpreter may be prefixed to
* command arguments if needed.