Skip to content

Commit 6293f5f

Browse files
Added APT package info when generating "Report Issue" text
This will now take a few more seconds due to "apt update" command being run.
1 parent e5c5174 commit 6293f5f

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-0
lines changed

app/src/main/java/com/termux/app/terminal/TermuxTerminalViewClient.java

+4
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,10 @@ public void reportIssueFromTranscript() {
420420
reportString.append("\n\n").append(TermuxUtils.getAppInfoMarkdownString(mActivity, true));
421421
reportString.append("\n\n").append(TermuxUtils.getDeviceInfoMarkdownString(mActivity));
422422

423+
String termuxAptInfo = TermuxUtils.geAPTInfoMarkdownString(mActivity);
424+
if (termuxAptInfo != null)
425+
reportString.append("\n\n").append(termuxAptInfo);
426+
423427
ReportActivity.startReportActivity(mActivity, new ReportInfo(UserAction.REPORT_ISSUE_FROM_TRANSCRIPT, TermuxConstants.TERMUX_APP.TERMUX_ACTIVITY_NAME, title, null, reportString.toString(), "\n\n" + TermuxUtils.getReportIssueMarkdownString(mActivity), false));
424428
}
425429

termux-shared/src/main/java/com/termux/shared/termux/TermuxUtils.java

+55
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,17 @@
1414
import com.termux.shared.R;
1515
import com.termux.shared.logger.Logger;
1616
import com.termux.shared.markdown.MarkdownUtils;
17+
import com.termux.shared.models.ExecutionCommand;
1718
import com.termux.shared.packages.PackageUtils;
19+
import com.termux.shared.shell.TermuxTask;
20+
21+
import org.apache.commons.io.IOUtils;
1822

1923
import java.io.BufferedReader;
2024
import java.io.IOException;
2125
import java.io.InputStream;
2226
import java.io.InputStreamReader;
27+
import java.nio.charset.Charset;
2328
import java.text.SimpleDateFormat;
2429
import java.util.Date;
2530
import java.util.List;
@@ -30,6 +35,8 @@
3035

3136
public class TermuxUtils {
3237

38+
private static final String LOG_TAG = "TermuxUtils";
39+
3340
/**
3441
* Get the {@link Context} for {@link TermuxConstants#TERMUX_PACKAGE_NAME} package.
3542
*
@@ -286,6 +293,54 @@ public static String getReportIssueMarkdownString(@NonNull final Context context
286293

287294

288295

296+
/**
297+
* Get a markdown {@link String} for APT info of the app.
298+
*
299+
* This will take a few seconds to run due to running {@code apt update} command.
300+
*
301+
* @param context The context for operations.
302+
* @return Returns the markdown {@link String}.
303+
*/
304+
public static String geAPTInfoMarkdownString(@NonNull final Context context) {
305+
306+
String aptInfoScript = null;
307+
InputStream inputStream = context.getResources().openRawResource(com.termux.shared.R.raw.apt_info_script);
308+
try {
309+
aptInfoScript = IOUtils.toString(inputStream, Charset.defaultCharset());
310+
} catch (IOException e) {
311+
Logger.logError(LOG_TAG, "Failed to get APT info script: " + e.getMessage());
312+
return null;
313+
}
314+
315+
IOUtils.closeQuietly(inputStream);
316+
317+
if (aptInfoScript == null || aptInfoScript.isEmpty()) {
318+
Logger.logError(LOG_TAG, "The APT info script is null or empty");
319+
return null;
320+
}
321+
322+
aptInfoScript = aptInfoScript.replaceAll(Pattern.quote("@TERMUX_PREFIX@"), TermuxConstants.TERMUX_PREFIX_DIR_PATH);
323+
324+
ExecutionCommand executionCommand = new ExecutionCommand(1, TermuxConstants.TERMUX_BIN_PREFIX_DIR_PATH + "/bash", null, aptInfoScript, null, true, false);
325+
TermuxTask termuxTask = TermuxTask.execute(context, executionCommand, null, true);
326+
if (termuxTask == null || !executionCommand.isSuccessful() || executionCommand.exitCode != 0) {
327+
Logger.logError(LOG_TAG, executionCommand.toString());
328+
return null;
329+
}
330+
331+
if (executionCommand.stderr != null && !executionCommand.stderr.isEmpty())
332+
Logger.logError(LOG_TAG, executionCommand.toString());
333+
334+
StringBuilder markdownString = new StringBuilder();
335+
336+
markdownString.append("## ").append(TermuxConstants.TERMUX_APP_NAME).append(" APT Info\n\n");
337+
markdownString.append(executionCommand.stdout);
338+
339+
return markdownString.toString();
340+
}
341+
342+
343+
289344
public static Properties getSystemProperties() {
290345
Properties systemProperties = new Properties();
291346

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/bash
2+
3+
subscribed_repositories() {
4+
local main_sources
5+
main_sources=$(grep -P '^\s*deb\s' "@TERMUX_PREFIX@/etc/apt/sources.list")
6+
7+
if [ -n "$main_sources" ]; then
8+
echo "#### sources.list"
9+
echo "\`$main_sources\`"
10+
fi
11+
12+
local filename repo_package supl_sources
13+
while read -r filename; do
14+
repo_package=$(dpkg -S "$filename" 2>/dev/null | cut -d : -f 1)
15+
supl_sources=$(grep -P '^\s*deb\s' "$filename")
16+
17+
if [ -n "$supl_sources" ]; then
18+
if [ -n "$repo_package" ]; then
19+
echo "#### $repo_package (sources.list.d/$(basename "$filename"))"
20+
else
21+
echo "#### sources.list.d/$(basename "$filename")"
22+
fi
23+
echo "\`$supl_sources\`"
24+
fi
25+
done < <(find "@TERMUX_PREFIX@/etc/apt/sources.list.d" -maxdepth 1 ! -type d)
26+
}
27+
28+
updatable_packages() {
29+
local updatable
30+
31+
if [ "$(id -u)" = "0" ]; then
32+
echo "Running as root. Cannot check updatable packages."
33+
else
34+
apt update >/dev/null 2>&1
35+
updatable=$(apt list --upgradable 2>/dev/null | tail -n +2)
36+
37+
if [ -z "$updatable" ];then
38+
echo "All packages up to date"
39+
else
40+
echo "\`$updatable\`"
41+
fi
42+
fi
43+
}
44+
45+
output="
46+
### Subscribed Repositories
47+
48+
$(subscribed_repositories)
49+
##
50+
51+
52+
### Updatable Packages
53+
$(updatable_packages)
54+
##
55+
56+
"
57+
58+
echo "$output"

0 commit comments

Comments
 (0)