[Fire TV Android Development] Sus_i:
Thats really good :good:

Yeah, should work fine. You see, we get your files ready for the scripts and flash system, boot.img and recovery...

No, you don't need two working folders.

In my case I had the scripts and the sdat2img.py onto a folder on desktop and my shared folder was onto a folder on an usb stick. I used a live system running from dvd, so the working folder was on a stick.

In your case I think you have installed ubuntu and you can do it just in one folder on desktop. I forgot to mention that linux is case sensitive, so if you name a folder 'Folder' you have to consider this by editing the path the same...

In addition to my post above...

Lets say your shared folder is on your desktop, named Folder.

In there is the sdat2img.sh & sdat2img.py file and a folder named: bueller-5.2.7.0-rooted_r1 (you get this folder usually if you copy the prerooted zip in your 'Folder' and extract it there into it's own folder).

In the bueller-5.2.7.0-rooted_r1 folder you can see the system_new file etc.

Then I would set this paths in the script:

SHARED="/home/locomex12/Desktop/Folder"

ZIP="${SHARED}/bueller-5.2.7.0-rooted_r1"

BACKUP="${SHARED}/backup"

SDAT2IMG=~/Desktop/Folder/sdat2img.py

And the edited script would look like this:

#!/bin/sh

# This is my shared folder where I put backups and the zip files, i.e. usb stick...
UNLOCKED="yes"
SHARED="/home/locomex12/Desktop/Folder"

# Unzip rbox's prerooted zips to your $SHARED folder then set this to the location of that folder
# Get those here: https://xdaforums.com/fire-tv/development/prerooted-stock-images-t2882337
ZIP="${SHARED}/bueller-5.2.7.0-rooted_r1"

# Location where the backups of the CURRENT image on the fire tv will go before it's overwritten
BACKUP="${SHARED}/backup"

# Download here https://github.com/xpirt/sdat2img
# Then change this to the location of the python script
SDAT2IMG=~/Desktop/Folder/sdat2img.py

# This should be the same on most linux systems (tested on Kali linux)
DEVDIR="/dev/disk/by-partlabel"

# Where to mount the mmc partitions
MNT="/mnt/emmc"
SYSTEM=$MNT/system

# WORKING
# Extract the image from the ZIP
if [ ! -e "${ZIP}/system_sdat2img.img" ]
then
echo -n "Converting system.new.dat to img format... "
$SDAT2IMG $ZIP/system.transfer.list $ZIP/system.new.dat $ZIP/system_sdat2img.img
echo "Done!"
else
echo "sdat2img already exists."
fi

Edit:

If there isn't an error, you find a 'system_sdat2img.img' file in /Desktop/Folder/bueller-5.2.7.0-rooted_r1

The next script makes a backup, flash system, boot.img and recovery and roots the flashed system. The backup should be located in /Desktop/Folder/backup.

#!/bin/sh

# This is my shared folder where I put backups and the zip files, i.e. usb stick...
UNLOCKED="yes"
SHARED="/home/locomex12/Desktop/Folder"

# Unzip rbox's prerooted zips to your $SHARED folder then set this to the location of that folder
# Get those here: https://xdaforums.com/fire-tv/development/prerooted-stock-images-t2882337
ZIP="${SHARED}/bueller-5.2.7.0-rooted_r1"

# Location where the backups of the CURRENT image on the fire tv will go before it's overwritten
BACKUP="${SHARED}/backup"

# Download here https://github.com/xpirt/sdat2img
# Then change this to the location of the python script
SDAT2IMG=~/Desktop/Folder/sdat2img.py

# This should be the same on most linux systems (tested on Kali linux)
DEVDIR="/dev/disk/by-partlabel"

# Where to mount the mmc partitions
MNT="/mnt/emmc"
SYSTEM=$MNT/system

# Back everything up JUST IN CASE...

DATE=`date +"%Y-%m-%d-%H%M"`

# echo "Backing up... "
mkdir -p $BACKUP/$DATE
echo -n "Unmounting system..."
umount $DEVDIR/system
echo "Done."
dd if=$DEVDIR/system | pv -s 805306368 | dd of=$BACKUP/$DATE/system.img
echo "Done."
echo -n "Unmounting recovery..."
umount $DEVDIR/recovery
echo "Done."
dd if=$DEVDIR/recovery | pv -s 9773056 | dd of=$BACKUP/$DATE/recovery.img
echo "Done."
echo -n "Unmounting boot..."
umount $DEVDIR/boot
echo "Done."
dd if=$DEVDIR/boot | pv -s 6627328 | dd of=$BACKUP/$DATE/boot.img
echo "Done."

echo -n "Clearing cache..."
umount $DEVDIR/cache
mkfs.ext4 $DEVDIR/cache
echo "Done."

# Write the images
# WORKING - Don't use bs=1024 ?? Stalled at 507mb
dd if=$ZIP/system_sdat2img.img | pv -s 805306368 | dd of=$DEVDIR/system || exit 1
dd if=$ZIP/boot_unlocked.img | pv -s 6627328 | dd of=$DEVDIR/boot
dd if=$ZIP/recovery/recovery.img | pv -s 9773056 | dd of=$DEVDIR/recovery

# Mount system

echo "Mounting system..."
mkdir -p $SYSTEM
mount -o rw $DEVDIR/system $SYSTEM || exit 1
if [ ! -e "${SYSTEM}/xbin" ]; then
echo "ERROR: couldn't find /system/xbin - is the mount point correct?"
exit 1
fi

# Now copy stuff and root it

echo "Installing TWRP..."
cp -r $ZIP/recovery $SYSTEM
rm -f $SYSTEM/recovery/recovery.img
echo "Chmodding and chconing RECOVERY..."
chown -R 0:0 $SYSTEM/recovery
chmod -R 0755 $SYSTEM/recovery
chcon -R --reference=$SYSTEM/bin $SYSTEM/recovery

# Backing up e2fsck and symlinking it to 2ndinitstub...
mv -i $SYSTEM/bin/e2fsck $SYSTEM/bin/e2fsck.real
echo "Symlink e2fsck to 2ndinitstub..."
ln -sf ../recovery/2ndinitstub $SYSTEM/bin/e2fsck
chcon --reference=$SYSTEM/bin/e2fsck.real -h $SYSTEM/bin/e2fsck

echo "Installing SU..."

cp -f $ZIP/su/su $ZIP/su/supolicy $SYSTEM/xbin/
chown 0:2000 $SYSTEM/xbin/su $SYSTEM/xbin/supolicy
chmod 0755 $SYSTEM/xbin/su $SYSTEM/xbin/supolicy
chcon --reference=$SYSTEM/xbin/trapz $SYSTEM/xbin/su $SYSTEM/xbin/supolicy
ln -sf su $SYSTEM/xbin/daemonsu
chcon --reference=$SYSTEM/xbin/trapz -h $SYSTEM/xbin/daemonsu

cp $ZIP/su/libsupol.so $SYSTEM/lib/
chmod 0644 $SYSTEM/lib/libsupol.so
chown 0:0 $SYSTEM/lib/libsupol.so
chcon --reference=$SYSTEM/lib/libsuspend.so $SYSTEM/lib/libsupol.so

cp -r $ZIP/su/SuperSU $SYSTEM/app/
chown -R 0:0 $SYSTEM/app/SuperSU
chmod -R 0755 $SYSTEM/app/SuperSU
chcon --reference=$SYSTEM/app/Bluetooth -R $SYSTEM/app/SuperSU

echo "Unmounting system..."
umount $SYSTEM

echo "Done"

If the first script runs fine and you have the sparse image extracted, you can copy/paste the second script into a txt file, rename it to flash.sh

Next do this:

sudo dos2unix flash.sh

sudo chmod u+x flash.sh

with the emmc reader plugged in, you can run the script with:

sudo ./flash.sh

If the script asks about clearing the cache partition, you have to press Y onto your keyboard.

Best is if you copy the full output of the script, in order to look at it later...

Edit2, fixed a typo in the second script...