#!/bin/sh
IP=$(nmap -n -p 5555 --open $(LANG= /sbin/ifconfig|awk '/inet addr:/{print $2}'|sed -e 's/addr://;s/\(.*\)..*/\1/'|grep -v 127.0.0.|head -1)0/24|awk '/Nmap scan report for/{print $5}'|head -1)

if [ "$IP" ]; then
    FIREDTVLAUNCHER=$(wget -qO- https://github.com/Redth/FiredTVLauncher/releases|awk -F\" '/com.altusapps.firedtvlauncher-/{print $2}'|head -1)
    echo $FIREDTVLAUNCHER|wget -Ni- -B https://github.com
    adb kill-server
    adb start-server
    adb disconnect
    adb connect $IP
    adb wait-for-device
    adb uninstall de.belu.firestarter
    adb uninstall com.altusapps.firedtvlauncher
    adb install ${FIREDTVLAUNCHER##*/}
    adb shell monkey -p com.altusapps.firedtvlauncher -c android.intent.category.LAUNCHER 1
    adb disconnect
    adb kill-server
fi
echo http://www.amazon.de/AltusApps-FiredTV-Launcher/dp/B00PQWDDQK/
echo Hint: free alternative with autolaunch: FireStarter
