├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── dependabot.yml └── workflows │ ├── github_action_build.yml │ └── github_release_build.yml ├── .gitignore ├── README.md ├── app ├── build.gradle ├── proguard-rules.pro ├── src │ └── main │ │ ├── AndroidManifest.xml │ │ ├── assets │ │ └── overview.html │ │ ├── java │ │ └── com │ │ │ └── termux │ │ │ └── boot │ │ │ ├── BootActivity.java │ │ │ ├── BootJobService.java │ │ │ └── BootReceiver.java │ │ └── res │ │ ├── drawable-anydpi-v26 │ │ └── ic_launcher.xml │ │ ├── drawable │ │ ├── ic_foreground.xml │ │ └── ic_launcher.xml │ │ └── values │ │ └── strings.xml └── testkey_untrusted.jks ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve Termux:Boot application 4 | 5 | --- 6 | 7 | 13 | 14 | **Problem description** 15 | 19 | 20 | **Steps to reproduce** 21 | 25 | 26 | **Expected behavior** 27 | 30 | 31 | **Additional information** 32 | 33 | * Termux application version: 34 | * Android OS version: 35 | * Device model: 36 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest a new feature for Termux:Boot application 4 | 5 | --- 6 | 7 | 13 | 14 | **Feature description** 15 | 18 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: github-actions 4 | directory: / 5 | schedule: 6 | interval: daily 7 | -------------------------------------------------------------------------------- /.github/workflows/github_action_build.yml: -------------------------------------------------------------------------------- 1 | name: GitHub Action Build 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | branches: 9 | - master 10 | schedule: 11 | - cron: "15 0 1 */2 *" 12 | workflow_dispatch: 13 | 14 | jobs: 15 | build: 16 | runs-on: ubuntu-latest 17 | steps: 18 | - name: Clone repository 19 | uses: actions/checkout@v4 20 | 21 | - name: Build 22 | shell: bash {0} 23 | run: | 24 | exit_on_error() { echo "$1"; exit 1; } 25 | 26 | if [ -z "$JAVA_HOME_17_X64" ] || [ ! -f "$JAVA_HOME_17_X64/bin/javac" ] || [ ! -x "$JAVA_HOME_17_X64/bin/javac" ]; then 27 | exit_on_error "jdk-17 binary not found at path '$JAVA_HOME_17_X64/bin/javac' or is not executable." 28 | fi 29 | 30 | echo "Setting vars" 31 | 32 | if [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then 33 | GITHUB_SHA="${{ github.event.pull_request.head.sha }}" # Do not use last merge commit set in GITHUB_SHA 34 | fi 35 | 36 | # Set RELEASE_VERSION_NAME to "+" 37 | CURRENT_VERSION_NAME_REGEX='\s+versionName "([^"]+)"$' 38 | CURRENT_VERSION_NAME="$(grep -m 1 -E "$CURRENT_VERSION_NAME_REGEX" ./app/build.gradle | sed -r "s/$CURRENT_VERSION_NAME_REGEX/\1/")" 39 | RELEASE_VERSION_NAME="v$CURRENT_VERSION_NAME+${GITHUB_SHA:0:7}" # The "+" is necessary so that versioning precedence is not affected 40 | if ! printf "%s" "${RELEASE_VERSION_NAME/v/}" | grep -qP '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$'; then 41 | exit_on_error "The release version '${RELEASE_VERSION_NAME/v/}' generated from current version '$CURRENT_VERSION_NAME' is not a valid version as per semantic version '2.0.0' spec in the format 'major.minor.patch(-prerelease)(+buildmetadata)'. https://semver.org/spec/v2.0.0.html." 42 | fi 43 | 44 | APK_DIR_PATH="./app/build/outputs/apk/debug" 45 | APK_VERSION_TAG="$RELEASE_VERSION_NAME.github.debug" # Note the ".", GITHUB_SHA will already have "+" before it 46 | APK_BASENAME_PREFIX="termux-boot-app_$APK_VERSION_TAG" 47 | 48 | # Used by upload step later 49 | echo "APK_DIR_PATH=$APK_DIR_PATH" >> $GITHUB_ENV 50 | echo "APK_VERSION_TAG=$APK_VERSION_TAG" >> $GITHUB_ENV 51 | echo "APK_BASENAME_PREFIX=$APK_BASENAME_PREFIX" >> $GITHUB_ENV 52 | 53 | echo "Building APK file for '$RELEASE_VERSION_NAME' release with '$APK_VERSION_TAG' tag" 54 | export TERMUX_BOOT_APP_BUILD__APP_VERSION_NAME="${RELEASE_VERSION_NAME/v/}" # Used by app/build.gradle 55 | export TERMUX_BOOT_APP_BUILD__APK_VERSION_TAG="$APK_VERSION_TAG" # Used by app/build.gradle 56 | export GRADLE_OPTS="-Dorg.gradle.java.home=$JAVA_HOME_17_X64" 57 | if ! ./gradlew assembleDebug; then 58 | exit_on_error "Build failed for '$RELEASE_VERSION_NAME' release with '$APK_VERSION_TAG' tag." 59 | fi 60 | 61 | echo "Validating APK file" 62 | if ! test -f "$APK_DIR_PATH/${APK_BASENAME_PREFIX}.apk"; then 63 | files_found="$(ls "$APK_DIR_PATH")" 64 | exit_on_error "Failed to find built APK file at '$APK_DIR_PATH/${APK_BASENAME_PREFIX}.apk'. Files found: "$'\n'"$files_found" 65 | fi 66 | 67 | echo "Generating checksums-sha256.txt file" 68 | if ! (cd "$APK_DIR_PATH"; sha256sum "${APK_BASENAME_PREFIX}.apk" > checksums-sha256.txt); then 69 | exit_on_error "Generate checksums-sha256.txt file failed for '$RELEASE_VERSION_NAME' release." 70 | fi 71 | echo "checksums-sha256.txt:"$'\n```\n'"$(cat "$APK_DIR_PATH/checksums-sha256.txt")"$'\n```' 72 | 73 | - name: Upload files to action 74 | uses: actions/upload-artifact@v4 75 | with: 76 | name: ${{ env.APK_BASENAME_PREFIX }} 77 | path: | 78 | ${{ env.APK_DIR_PATH }}/${{ env.APK_BASENAME_PREFIX }}.apk 79 | ${{ env.APK_DIR_PATH }}/checksums-sha256.txt 80 | ${{ env.APK_DIR_PATH }}/output-metadata.json 81 | -------------------------------------------------------------------------------- /.github/workflows/github_release_build.yml: -------------------------------------------------------------------------------- 1 | name: GitHub Release Build 2 | 3 | on: 4 | release: 5 | types: 6 | - published 7 | 8 | jobs: 9 | build: 10 | runs-on: ubuntu-latest 11 | env: 12 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 13 | steps: 14 | - name: Clone repository 15 | uses: actions/checkout@v4 16 | with: 17 | ref: ${{ env.GITHUB_REF }} 18 | 19 | - name: Build and upload files to release 20 | shell: bash {0} 21 | run: | 22 | exit_on_error() { 23 | echo "$1" 24 | echo "Deleting '$RELEASE_VERSION_NAME' release and '$GITHUB_REF' tag" 25 | hub release delete "$RELEASE_VERSION_NAME" 26 | git push --delete origin "$GITHUB_REF" 27 | exit 1 28 | } 29 | 30 | if [ -z "$JAVA_HOME_17_X64" ] || [ ! -f "$JAVA_HOME_17_X64/bin/javac" ] || [ ! -x "$JAVA_HOME_17_X64/bin/javac" ]; then 31 | exit_on_error "jdk-17 binary not found at path '$JAVA_HOME_17_X64/bin/javac' or is not executable." 32 | fi 33 | 34 | echo "Setting vars" 35 | RELEASE_VERSION_NAME="${GITHUB_REF/refs\/tags\//}" 36 | if ! printf "%s" "${RELEASE_VERSION_NAME/v/}" | grep -qP '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$'; then 37 | exit_on_error "The release version '${RELEASE_VERSION_NAME/v/}' is not a valid version as per semantic version '2.0.0' spec in the format 'major.minor.patch(-prerelease)(+buildmetadata)'. https://semver.org/spec/v2.0.0.html." 38 | fi 39 | 40 | APK_DIR_PATH="./app/build/outputs/apk/debug" 41 | APK_VERSION_TAG="$RELEASE_VERSION_NAME+github.debug" 42 | APK_BASENAME_PREFIX="termux-boot-app_$APK_VERSION_TAG" 43 | 44 | echo "Building APK file for '$RELEASE_VERSION_NAME' release with '$APK_VERSION_TAG' tag" 45 | export TERMUX_BOOT_APP_BUILD__APK_VERSION_TAG="$APK_VERSION_TAG" # Used by app/build.gradle 46 | export GRADLE_OPTS="-Dorg.gradle.java.home=$JAVA_HOME_17_X64" 47 | if ! ./gradlew assembleDebug; then 48 | exit_on_error "Build failed for '$RELEASE_VERSION_NAME' release with '$APK_VERSION_TAG' tag." 49 | fi 50 | 51 | echo "Validating APK file" 52 | if ! test -f "$APK_DIR_PATH/${APK_BASENAME_PREFIX}.apk"; then 53 | files_found="$(ls "$APK_DIR_PATH")" 54 | exit_on_error "Failed to find built APK file at '$APK_DIR_PATH/${APK_BASENAME_PREFIX}.apk'. Files found: "$'\n'"$files_found" 55 | fi 56 | 57 | echo "Generating checksums-sha256.txt file" 58 | if ! (cd "$APK_DIR_PATH"; sha256sum "${APK_BASENAME_PREFIX}.apk" > checksums-sha256.txt); then 59 | exit_on_error "Generate checksums-sha256.txt file failed for '$RELEASE_VERSION_NAME' release." 60 | fi 61 | echo "checksums-sha256.txt:"$'\n```\n'"$(cat "$APK_DIR_PATH/checksums-sha256.txt")"$'\n```' 62 | 63 | echo "Uploading files to release" 64 | if ! gh release upload "$RELEASE_VERSION_NAME" \ 65 | "$APK_DIR_PATH/${APK_BASENAME_PREFIX}.apk" \ 66 | "$APK_DIR_PATH/checksums-sha256.txt" \ 67 | ; then 68 | exit_on_error "Upload files to release failed for '$RELEASE_VERSION_NAME' release." 69 | fi 70 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | local.properties 3 | .gradle/ 4 | .idea/ 5 | *.iml -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Termux:Boot 2 | 3 | [![Build status](https://github.com/termux/termux-boot/workflows/Build/badge.svg)](https://github.com/termux/termux-boot/actions) 4 | [![Join the chat at https://gitter.im/termux/termux](https://badges.gitter.im/termux/termux.svg)](https://gitter.im/termux/termux) 5 | 6 | A [Termux](https://termux.dev) add-on app to run programs at boot. 7 | 8 | When developing (or packaging), note that this app needs to be signed with the 9 | same key as the main Termux app in order to have the permission to execute scripts. 10 | 11 | ## Installation 12 | 13 | Termux:Boot application can be obtained from [F-Droid](https://f-droid.org/en/packages/com.termux.boot/). 14 | 15 | Additionally we provide per-commit debug builds for those who want to try 16 | out the latest features or test their pull request. This build can be obtained 17 | from one of the workflow runs listed on [Github Actions](https://github.com/termux/termux-boot/actions/workflows/github_action_build.yml?query=branch%3Amaster+event%3Apush) 18 | page. 19 | 20 | Signature keys of all offered builds are different. Before you switch the 21 | installation source, you will have to uninstall the Termux application and 22 | all currently installed plugins. Check https://github.com/termux/termux-app#Installation for more info. 23 | 24 | ## How to use 25 | 26 | 1. Install the Termux:Boot app. 27 | 2. Start the Termux:Boot app once by clicking on its launcher icon. This allows the app to be run at boot. 28 | 3. Create the `~/.termux/boot/` directory. 29 | 4. Put scripts you want to execute inside the `~/.termux/boot/` directory. If there are multiple files, they will be executed in a sorted order. 30 | 5. Note that you may want to run `termux-wake-lock` as first thing if you want to ensure that the device is prevented from sleeping. 31 | 32 | ### Examples 33 | 34 | To start an sshd server and prevent the device from sleeping at boot, 35 | create the following file at `~/.termux/boot/start-sshd`: 36 | 37 | ```sh 38 | #!/data/data/com.termux/files/usr/bin/sh 39 | termux-wake-lock 40 | sshd 41 | ``` 42 | 43 | To start 44 | [termux-services](https://wiki.termux.com/wiki/Termux-services), which 45 | in turn starts enabled services, you can put the following in 46 | `~/.termux/boot/start-services`: 47 | 48 | ```sh 49 | #!/data/data/com.termux/files/usr/bin/sh 50 | termux-wake-lock 51 | source /data/data/com.termux/files/usr/etc/profile.d/start-services.sh 52 | ``` 53 | 54 | ## License 55 | 56 | Released under [the GPLv3 license](https://www.gnu.org/licenses/gpl.html). 57 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | namespace "com.termux.boot" 5 | 6 | compileSdk project.properties.compileSdkVersion.toInteger() 7 | 8 | def appVersionName = System.getenv("TERMUX_BOOT_APP_BUILD__APP_VERSION_NAME") ?: "" 9 | def apkVersionTag = System.getenv("TERMUX_BOOT_APP_BUILD__APK_VERSION_TAG") ?: "" 10 | 11 | defaultConfig { 12 | applicationId "com.termux.boot" 13 | minSdk project.properties.minSdkVersion.toInteger() 14 | targetSdk project.properties.targetSdkVersion.toInteger() 15 | versionCode 1000 16 | versionName "0.8.1" 17 | 18 | if (appVersionName) versionName = appVersionName 19 | validateVersionName(versionName) 20 | } 21 | 22 | signingConfigs { 23 | debug { 24 | storeFile file('testkey_untrusted.jks') 25 | keyAlias 'alias' 26 | storePassword 'xrj45yWGLbsO7W0v' 27 | keyPassword 'xrj45yWGLbsO7W0v' 28 | } 29 | } 30 | 31 | buildTypes { 32 | release { 33 | minifyEnabled true 34 | shrinkResources true 35 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 36 | } 37 | 38 | debug { 39 | signingConfig signingConfigs.debug 40 | } 41 | } 42 | 43 | compileOptions { 44 | sourceCompatibility JavaVersion.VERSION_1_8 45 | targetCompatibility JavaVersion.VERSION_1_8 46 | } 47 | 48 | applicationVariants.all { variant -> 49 | variant.outputs.all { output -> 50 | outputFileName = new File("termux-boot-app_" + 51 | (apkVersionTag ? apkVersionTag : "v" + versionName + "+" + variant.buildType.name) + ".apk") 52 | } 53 | } 54 | } 55 | 56 | dependencies { 57 | implementation "androidx.annotation:annotation:1.7.0" 58 | } 59 | 60 | task versionName { 61 | doLast { 62 | print android.defaultConfig.versionName 63 | } 64 | } 65 | 66 | def validateVersionName(String versionName) { 67 | // https://semver.org/spec/v2.0.0.html#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string 68 | // ^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$ 69 | if (!java.util.regex.Pattern.matches("^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?\$", versionName)) 70 | throw new GradleException("The versionName '" + versionName + "' is not a valid version as per semantic version '2.0.0' spec in the format 'major.minor.patch(-prerelease)(+buildmetadata)'. https://semver.org/spec/v2.0.0.html.") 71 | } 72 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/fornwall/lib/android-sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 24 | 25 | 26 | 27 | 28 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /app/src/main/assets/overview.html: -------------------------------------------------------------------------------- 1 |

The Termux:Boot add-on provides functionality to run programs under Termux when the device boots up. 2 | 3 |

Usage

4 | 11 | 12 |

Example

13 |

To start an sshd server and prevent the device from sleeping at boot, create a file at ~/.termux/boot/start-sshd containing the three lines

14 | 15 |
16 |     #!/data/data/com.termux/files/usr/bin/sh
17 |     termux-wake-lock
18 |     sshd
19 | 
20 | 21 |

Learn more

22 |

Join the Termux community through the various channels listed at https://termux.org/community 23 | 24 |

Report issues

25 |

https://github.com/termux/termux-boot/issues 26 | -------------------------------------------------------------------------------- /app/src/main/java/com/termux/boot/BootActivity.java: -------------------------------------------------------------------------------- 1 | package com.termux.boot; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.webkit.WebView; 6 | 7 | import androidx.annotation.Nullable; 8 | 9 | public class BootActivity extends Activity { 10 | 11 | @Override 12 | protected void onCreate(@Nullable Bundle savedInstanceState) { 13 | super.onCreate(savedInstanceState); 14 | WebView webView = new WebView(this); 15 | webView.loadUrl("file:///android_asset/overview.html"); 16 | setContentView(webView); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /app/src/main/java/com/termux/boot/BootJobService.java: -------------------------------------------------------------------------------- 1 | package com.termux.boot; 2 | 3 | import android.app.job.JobParameters; 4 | import android.app.job.JobService; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.net.Uri; 8 | import android.os.Build; 9 | import android.os.PersistableBundle; 10 | import android.util.Log; 11 | 12 | public class BootJobService extends JobService { 13 | 14 | public static final String SCRIPT_FILE_PATH = "com.termux.boot.script_path"; 15 | 16 | private static final String TAG = "termux"; 17 | 18 | // Constants from TermuxService. 19 | private static final String TERMUX_SERVICE = "com.termux.app.TermuxService"; 20 | private static final String ACTION_EXECUTE = "com.termux.service_execute"; 21 | private static final String EXTRA_EXECUTE_IN_BACKGROUND = "com.termux.execute.background"; 22 | 23 | @Override 24 | public boolean onStartJob(JobParameters params) { 25 | Log.i(TAG, "Executing job " + params.getJobId() + "."); 26 | 27 | PersistableBundle extras = params.getExtras(); 28 | String filePath = extras.getString(SCRIPT_FILE_PATH); 29 | 30 | Uri scriptUri = new Uri.Builder().scheme("com.termux.file").path(filePath).build(); 31 | Intent executeIntent = new Intent(ACTION_EXECUTE, scriptUri); 32 | executeIntent.setClassName("com.termux", TERMUX_SERVICE); 33 | executeIntent.putExtra(EXTRA_EXECUTE_IN_BACKGROUND, true); 34 | 35 | Context context = getApplicationContext(); 36 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 37 | // https://developer.android.com/about/versions/oreo/background.html 38 | context.startForegroundService(executeIntent); 39 | } else { 40 | context.startService(executeIntent); 41 | } 42 | 43 | return false; // offloaded to Termux; job is done 44 | } 45 | 46 | @Override 47 | public boolean onStopJob(JobParameters params) { 48 | Log.i(TAG, "Execution of job " + params.getJobId() + " has been cancelled."); 49 | return false; // do not reschedule 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /app/src/main/java/com/termux/boot/BootReceiver.java: -------------------------------------------------------------------------------- 1 | package com.termux.boot; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.app.job.JobInfo; 5 | import android.app.job.JobScheduler; 6 | import android.content.BroadcastReceiver; 7 | import android.content.ComponentName; 8 | import android.content.Context; 9 | import android.content.Intent; 10 | import android.os.PersistableBundle; 11 | import android.util.Log; 12 | 13 | import java.io.File; 14 | import java.util.Arrays; 15 | 16 | public class BootReceiver extends BroadcastReceiver { 17 | 18 | public static final int TERMUX_BOOT_JOB_ID_BASE = 1000; 19 | static int jobId = TERMUX_BOOT_JOB_ID_BASE; 20 | 21 | @Override 22 | public void onReceive(Context context, Intent intent) { 23 | if (!Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) return; 24 | 25 | @SuppressLint("SdCardPath") final String BOOT_SCRIPT_PATH = "/data/data/com.termux/files/home/.termux/boot"; 26 | final File BOOT_SCRIPT_DIR = new File(BOOT_SCRIPT_PATH); 27 | File[] files = BOOT_SCRIPT_DIR.listFiles(); 28 | if (files == null) files = new File[0]; 29 | 30 | // Sort files so that they get executed in a repeatable and logical order. 31 | Arrays.sort(files, (f1, f2) -> f1.getName().compareTo(f2.getName())); 32 | 33 | StringBuilder logMessage = new StringBuilder(); 34 | for (File file : files) { 35 | if (!file.isFile()) return; 36 | 37 | if (logMessage.length() > 0) logMessage.append(", "); 38 | logMessage.append(file.getName()); 39 | 40 | ensureFileReadableAndExecutable(file); 41 | 42 | PersistableBundle extras = new PersistableBundle(); 43 | extras.putString(BootJobService.SCRIPT_FILE_PATH, file.getAbsolutePath()); 44 | 45 | ComponentName serviceComponent = new ComponentName(context, BootJobService.class); 46 | JobInfo job = new JobInfo.Builder(jobId++, serviceComponent) 47 | .setExtras(extras) 48 | .setOverrideDeadline(3 * 1000) 49 | .build(); 50 | JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE); 51 | assert jobScheduler != null; 52 | jobScheduler.schedule(job); 53 | } 54 | 55 | if (logMessage.length() > 0) { 56 | Log.i("termux", "Executed files at boot: " + logMessage); 57 | } else { 58 | Log.i("termux", "No files to execute at boot"); 59 | } 60 | } 61 | 62 | /** Ensure readable and executable file if user forgot to do so. */ 63 | @SuppressWarnings("ResultOfMethodCallIgnored") 64 | private static void ensureFileReadableAndExecutable(File file) { 65 | if (!file.canRead()) file.setReadable(true); 66 | if (!file.canExecute()) file.setExecutable(true); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_foreground.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 18 | 19 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 12 | 13 | 14 | 24 | 25 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Termux:Boot 3 | 4 | -------------------------------------------------------------------------------- /app/testkey_untrusted.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/termux/termux-boot/613dc9893f672313e2c572c0089ece7475e04f5b/app/testkey_untrusted.jks -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | mavenCentral() 4 | google() 5 | } 6 | 7 | dependencies { 8 | classpath "com.android.tools.build:gradle:8.3.2" 9 | } 10 | } 11 | 12 | allprojects { 13 | repositories { 14 | mavenCentral() 15 | google() 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | 19 | android.useAndroidX=true 20 | 21 | minSdkVersion=21 22 | targetSdkVersion=28 23 | compileSdkVersion=34 24 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/termux/termux-boot/613dc9893f672313e2c572c0089ece7475e04f5b/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-all.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | # This is normally unused 84 | # shellcheck disable=SC2034 85 | APP_BASE_NAME=${0##*/} 86 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) 87 | APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit 88 | 89 | # Use the maximum available, or set MAX_FD != -1 to use that value. 90 | MAX_FD=maximum 91 | 92 | warn () { 93 | echo "$*" 94 | } >&2 95 | 96 | die () { 97 | echo 98 | echo "$*" 99 | echo 100 | exit 1 101 | } >&2 102 | 103 | # OS specific support (must be 'true' or 'false'). 104 | cygwin=false 105 | msys=false 106 | darwin=false 107 | nonstop=false 108 | case "$( uname )" in #( 109 | CYGWIN* ) cygwin=true ;; #( 110 | Darwin* ) darwin=true ;; #( 111 | MSYS* | MINGW* ) msys=true ;; #( 112 | NONSTOP* ) nonstop=true ;; 113 | esac 114 | 115 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 116 | 117 | 118 | # Determine the Java command to use to start the JVM. 119 | if [ -n "$JAVA_HOME" ] ; then 120 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 121 | # IBM's JDK on AIX uses strange locations for the executables 122 | JAVACMD=$JAVA_HOME/jre/sh/java 123 | else 124 | JAVACMD=$JAVA_HOME/bin/java 125 | fi 126 | if [ ! -x "$JAVACMD" ] ; then 127 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 128 | 129 | Please set the JAVA_HOME variable in your environment to match the 130 | location of your Java installation." 131 | fi 132 | else 133 | JAVACMD=java 134 | if ! command -v java >/dev/null 2>&1 135 | then 136 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | fi 142 | 143 | # Increase the maximum file descriptors if we can. 144 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 145 | case $MAX_FD in #( 146 | max*) 147 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 148 | # shellcheck disable=SC2039,SC3045 149 | MAX_FD=$( ulimit -H -n ) || 150 | warn "Could not query maximum file descriptor limit" 151 | esac 152 | case $MAX_FD in #( 153 | '' | soft) :;; #( 154 | *) 155 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 156 | # shellcheck disable=SC2039,SC3045 157 | ulimit -n "$MAX_FD" || 158 | warn "Could not set maximum file descriptor limit to $MAX_FD" 159 | esac 160 | fi 161 | 162 | # Collect all arguments for the java command, stacking in reverse order: 163 | # * args from the command line 164 | # * the main class name 165 | # * -classpath 166 | # * -D...appname settings 167 | # * --module-path (only if needed) 168 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 169 | 170 | # For Cygwin or MSYS, switch paths to Windows format before running java 171 | if "$cygwin" || "$msys" ; then 172 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 173 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 174 | 175 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 176 | 177 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 178 | for arg do 179 | if 180 | case $arg in #( 181 | -*) false ;; # don't mess with options #( 182 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 183 | [ -e "$t" ] ;; #( 184 | *) false ;; 185 | esac 186 | then 187 | arg=$( cygpath --path --ignore --mixed "$arg" ) 188 | fi 189 | # Roll the args list around exactly as many times as the number of 190 | # args, so each arg winds up back in the position where it started, but 191 | # possibly modified. 192 | # 193 | # NB: a `for` loop captures its iteration list before it begins, so 194 | # changing the positional parameters here affects neither the number of 195 | # iterations, nor the values presented in `arg`. 196 | shift # remove old arg 197 | set -- "$@" "$arg" # push replacement arg 198 | done 199 | fi 200 | 201 | 202 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 203 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 204 | 205 | # Collect all arguments for the java command: 206 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, 207 | # and any embedded shellness will be escaped. 208 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be 209 | # treated as '${Hostname}' itself on the command line. 210 | 211 | set -- \ 212 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 213 | -classpath "$CLASSPATH" \ 214 | org.gradle.wrapper.GradleWrapperMain \ 215 | "$@" 216 | 217 | # Stop when "xargs" is not available. 218 | if ! command -v xargs >/dev/null 2>&1 219 | then 220 | die "xargs is not available" 221 | fi 222 | 223 | # Use "xargs" to parse quoted args. 224 | # 225 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 226 | # 227 | # In Bash we could simply go: 228 | # 229 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 230 | # set -- "${ARGS[@]}" "$@" 231 | # 232 | # but POSIX shell has neither arrays nor command substitution, so instead we 233 | # post-process each arg (as a line of input to sed) to backslash-escape any 234 | # character that might be a shell metacharacter, then use eval to reverse 235 | # that process (while maintaining the separation between arguments), and wrap 236 | # the whole thing up as a single "set" statement. 237 | # 238 | # This will of course break if any of these variables contains a newline or 239 | # an unmatched quote. 240 | # 241 | 242 | eval "set -- $( 243 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 244 | xargs -n1 | 245 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 246 | tr '\n' ' ' 247 | )" '"$@"' 248 | 249 | exec "$JAVACMD" "$@" 250 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | @rem This is normally unused 30 | set APP_BASE_NAME=%~n0 31 | set APP_HOME=%DIRNAME% 32 | 33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 35 | 36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 38 | 39 | @rem Find java.exe 40 | if defined JAVA_HOME goto findJavaFromJavaHome 41 | 42 | set JAVA_EXE=java.exe 43 | %JAVA_EXE% -version >NUL 2>&1 44 | if %ERRORLEVEL% equ 0 goto execute 45 | 46 | echo. 47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 48 | echo. 49 | echo Please set the JAVA_HOME variable in your environment to match the 50 | echo location of your Java installation. 51 | 52 | goto fail 53 | 54 | :findJavaFromJavaHome 55 | set JAVA_HOME=%JAVA_HOME:"=% 56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 57 | 58 | if exist "%JAVA_EXE%" goto execute 59 | 60 | echo. 61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 62 | echo. 63 | echo Please set the JAVA_HOME variable in your environment to match the 64 | echo location of your Java installation. 65 | 66 | goto fail 67 | 68 | :execute 69 | @rem Setup the command line 70 | 71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 72 | 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if %ERRORLEVEL% equ 0 goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | set EXIT_CODE=%ERRORLEVEL% 85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 87 | exit /b %EXIT_CODE% 88 | 89 | :mainEnd 90 | if "%OS%"=="Windows_NT" endlocal 91 | 92 | :omega 93 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------