16
16
import com .termux .shared .interact .MessageDialogUtils ;
17
17
import com .termux .shared .logger .Logger ;
18
18
import com .termux .shared .markdown .MarkdownUtils ;
19
+ import com .termux .shared .models .ExecutionCommand ;
19
20
import com .termux .shared .models .errors .Error ;
20
21
import com .termux .shared .packages .PackageUtils ;
22
+ import com .termux .shared .shell .TermuxShellEnvironmentClient ;
23
+ import com .termux .shared .shell .TermuxTask ;
21
24
import com .termux .shared .termux .TermuxConstants ;
22
25
import com .termux .shared .termux .TermuxUtils ;
23
26
@@ -187,7 +190,8 @@ public void run() {
187
190
outStream .write (buffer , 0 , readBytes );
188
191
}
189
192
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" )) {
191
195
//noinspection OctalInteger
192
196
Os .chmod (targetFile .getAbsolutePath (), 0700 );
193
197
}
@@ -208,6 +212,28 @@ public void run() {
208
212
throw new RuntimeException ("Moving termux prefix staging to prefix directory failed" );
209
213
}
210
214
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
+
211
237
Logger .logInfo (LOG_TAG , "Bootstrap packages installed successfully." );
212
238
activity .runOnUiThread (whenDone );
213
239
0 commit comments