#!/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
    APP=com.spotify.music
    URL=$(wget -qO- https://www.spotify.com/de/download/other/|awk -F\" '/SpotifyAndroid\.apk/{print $4}')
    APK=${URL##*/}
    wget -N "$URL"
    adb kill-server
    adb start-server
    adb disconnect
    adb connect $IP
    adb wait-for-device
    #adb uninstall $APP
    adb install -r $APK
    adb shell monkey -p $APP -c android.intent.category.LAUNCHER 1
    adb disconnect
    adb kill-server
fi
cat <<'EOT'
Register: https://www.spotify.com

Menu: http://www.amazon.de/Spotify-Music/dp/B00KLBR6IC

Buy, then sync!

To control connect USB/BT mouse or use Wukong TV Remote (free)

https://play.google.com/store/apps/details?id=com.wukongtv.wkremote.client.en

EOT
