Skip to content

Commit 2c82a55

Browse files
1 parent 708281c commit 2c82a55

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

app/src/main/java/com/termux/app/TermuxInstaller.java

+27-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616
import com.termux.shared.interact.MessageDialogUtils;
1717
import com.termux.shared.logger.Logger;
1818
import com.termux.shared.markdown.MarkdownUtils;
19+
import com.termux.shared.models.ExecutionCommand;
1920
import com.termux.shared.models.errors.Error;
2021
import com.termux.shared.packages.PackageUtils;
22+
import com.termux.shared.shell.TermuxShellEnvironmentClient;
23+
import com.termux.shared.shell.TermuxTask;
2124
import com.termux.shared.termux.TermuxConstants;
2225
import com.termux.shared.termux.TermuxUtils;
2326

@@ -187,7 +190,8 @@ public void run() {
187190
outStream.write(buffer, 0, readBytes);
188191
}
189192
if (zipEntryName.startsWith("bin/") || zipEntryName.startsWith("libexec") ||
190-
zipEntryName.startsWith("lib/apt/apt-helper") || zipEntryName.startsWith("lib/apt/methods")) {
193+
zipEntryName.startsWith("lib/apt/apt-helper") || zipEntryName.startsWith("lib/apt/methods") ||
194+
zipEntryName.equals("etc/termux/bootstrap/termux-bootstrap-second-stage.sh")) {
191195
//noinspection OctalInteger
192196
Os.chmod(targetFile.getAbsolutePath(), 0700);
193197
}
@@ -208,6 +212,28 @@ public void run() {
208212
throw new RuntimeException("Moving termux prefix staging to prefix directory failed");
209213
}
210214

215+
// Run Termux bootstrap second stage
216+
Logger.logInfo(LOG_TAG, "Running Termux bootstrap second stage.");
217+
String termuxBootstrapSecondStageFile = TERMUX_PREFIX_DIR_PATH + "/etc/termux/bootstrap/termux-bootstrap-second-stage.sh";
218+
if (FileUtils.fileExists(termuxBootstrapSecondStageFile, false)) {
219+
ExecutionCommand executionCommand = new ExecutionCommand(-1,
220+
termuxBootstrapSecondStageFile, null, null,
221+
null, true, false);
222+
executionCommand.commandLabel = "Termux Bootstrap Second Stage Command";
223+
executionCommand.backgroundCustomLogLevel = Logger.LOG_LEVEL_NORMAL;
224+
TermuxTask termuxTask = TermuxTask.execute(activity, executionCommand, null, new TermuxShellEnvironmentClient(), true);
225+
boolean stderrSet = !executionCommand.resultData.stderr.toString().isEmpty();
226+
if (termuxTask == null || !executionCommand.isSuccessful() || executionCommand.resultData.exitCode != 0 || stderrSet) {
227+
// Delete prefix directory as otherwise when app is restarted, the broken prefix directory would be used and logged into
228+
error = FileUtils.deleteFile("termux prefix directory", TERMUX_PREFIX_DIR_PATH, true);
229+
if (error != null)
230+
Logger.logErrorExtended(LOG_TAG, error.toString());
231+
232+
showBootstrapErrorDialog(activity, whenDone, MarkdownUtils.getMarkdownCodeForString(executionCommand.toString(), true));
233+
return;
234+
}
235+
}
236+
211237
Logger.logInfo(LOG_TAG, "Bootstrap packages installed successfully.");
212238
activity.runOnUiThread(whenDone);
213239

0 commit comments

Comments
 (0)