How to automatically run shell script files at boot on a rooted Amazon Fire TV or Fire TV Stick

Shell scripts are simply text files that contain a series of commands. Those commands can be entered manually into a shell prompt on a Fire TV device, but placing them in a script file gives you an easy and convenient way to run several commands at once. It also allows you to automate the running of those commands. This guide will show you how to configure a rooted Amazon Fire TV, Fire TV Stick, or Fire TV Edition television to run shell scripts you add at boot up as the device powers on.

This guide is based on tgellen’s great guide for enabling OTG on a Fire TV Stick 1 on boot. I have purposely left this guide generic so that it works with any shell scripts you may want to run on boot.

Configure device to auto-run scripts

  1. Download the necessary factoryadb.sh file from here.
  2. Connect to your Fire TV device via ADB.
  3. Transfer the factoryadb.sh file to your Fire TV’s /sdcard/ directory by running the command:
    adb push /PATH-ON-PC/factoryadb.sh /sdcard/
    NOTE: Be sure to replace /PATH-ON-PC in the above command with the correct location of the downloaded factoryadb.sh file on your PC.
  4. Enter the device’s shell prompt by running the command:
    adb shell
  5. Enter SU mode by running the command:
    su
  6. Make your system directory writable by running the command:
    mount -o remount,rw /system
  7. Create the necessary init.d directory by running the command:
    mkdir /etc/init.d
  8. Copy the factoryadb.sh you transferred earlier from your /sdcard/ directory to the /system/bin/ directory by running the command:
    cp /sdcard/factoryadb.sh /system/bin/
  9. Set the necessary directory and file ownership by running the command:
    chown 0:0 /system/bin/factoryadb.sh /etc/init.d
  10. Set the necessary directory and file permission by running the command:
    chmod 755 /system/bin/factoryadb.sh /etc/init.d
  11. (OPTIONAL) Delete the factoryadb.sh file in your /sdcard/ directory by running the command:
    rm -f /sdcard/factoryadb.sh
  12. Set your system directory back to read-only by running the command:
    mount -o remount,ro /system
  13. Exit SU mode by running the command: exit
  14. Exit ADB shell by running the command: exit

Add scripts to be auto-run

Once you’ve followed the above steps, your Fire TV device will be configured to run any shell script file located in the directory /etc/init.d/ on boot. Whenever you want to add a shell script file that you want to be run on boot, do the following:

  1. Connect to your Fire TV device via ADB
  2. Transfer the shell script file to your Fire TV’s /sdcard/ directory by running the command:
    adb push /PATH-ON-PC/YOUR-SHELL-SCRIPT-FILE /sdcard/
    NOTE: Be sure to replace /PATH-ON-PC/YOUR-SHELL-SCRIPT-FILE in the above command with the correct location of the shell script file on your PC.
  3. Enter the device’s shell prompt by running the command:
    adb shell
  4. Enter SU mode by running the command:
    su
  5. Make your system directory writable by running the command:
    mount -o remount,rw /system
  6. Copy the shell script file you transferred earlier from your /sdcard/ directory to the /etc/init.d/ directory by running the command:
    cp /sdcard/YOUR-SHELL-SCRIPT-FILE /etc/init.d/
    NOTE: Be sure to replace YOUR-SHELL-SCRIPT-FILE in the above command with the name of your shell script file.
  7. Set the necessary file ownership by running the command:
    chown 0:0 /etc/init.d/YOUR-SHELL-SCRIPT-FILE
    NOTE: Be sure to replace YOUR-SHELL-SCRIPT-FILE in the above command with the name of your shell script file.
  8. Set the necessary directory and file permission by running the command:
    chmod 755 /etc/init.d/YOUR-SHELL-SCRIPT-FILE
    NOTE: Be sure to replace YOUR-SHELL-SCRIPT-FILE in the above command with the name of your shell script file.
  9. (OPTIONAL) Delete the shell script file in your /sdcard/ directory by running the command:
    rm -f /sdcard/YOUR-SHELL-SCRIPT-FILE
    NOTE: Be sure to replace YOUR-SHELL-SCRIPT-FILE in the above command with the name of your shell script file.
  10. Set your system directory back to read-only by running the command:
    mount -o remount,ro /system
  11. Exit SU mode by running the command: exit
  12. Exit ADB shell by running the command: exit

Delete scripts that are auto-run

If you want to remove an auto-run shell script that you’ve added, do the following:

  1. Connect to your Fire TV device via ADB.
  2. Enter the device’s shell prompt by running the command:
    adb shell
  3. Enter SU mode by running the command:
    su
  4. Make your system directory writable by running the command:
    mount -o remount,rw /system
  5. Delete a single shell script by running the command:
    rm -f /etc/init.d/YOUR-SHELL-SCRIPT-FILE
    NOTE: Be sure to replace YOUR-SHELL-SCRIPT-FILE in the above command with the name of the shell script file you want to delete.

    Alternatively, you can delete ALL of your shell scripts by running the command:
    rm -f /etc/init.d/*

  6. Set your system directory back to read-only by running the command:
    mount -o remount,ro /system
  7. Exit SU mode by running the command: exit
  8. Exit ADB shell by running the command: exit

Revert all changes

If you no longer want to auto-run any shell scripts and want to revert all changes made by following the steps above, do the following:

  1. Connect to your Fire TV device via ADB.
  2. Enter the device’s shell prompt by running the command:
    adb shell
  3. Enter SU mode by running the command:
    su
  4. Make your system directory writable by running the command:
    mount -o remount,rw /system
  5. Delete all existing shell scripts and the /etc/init.d/ directory by running the command:
    rm -rf /etc/init.d

  6. Delete the factoryadb.sh configuration file by running the command:
    rm -f /system/bin/factoryadb.sh

  7. Set your system directory back to read-only by running the command:
    mount -o remount,ro /system
  8. Exit SU mode by running the command: exit
  9. Exit ADB shell by running the command: exit

ShareTweetShare+1

One comment
  1. drewb0y says:

    So what would be an example (or examples) of a good script to run on startup? Maybe something that clears cache of apps, or checks that updates are disabled?

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Get notified of new posts

Enter your email address to receive notifications of new posts by email.