#!/bin/bash
# wget http://its.alexunderboots.ru/bas-ip/smile.sh; chmod +x smile.sh

if [ "$#" -ne 1 ]; then
    echo "Usage: $0 <IP>"
	exit 1
fi

if ! dpkg -s adb &> /dev/null; then
	echo "install ADB"
	apt install -y android-tools-adb
fi

cd /root
if [ ! -f /root/talk.apk ]; then
	wget http://its.alexunderboots.ru/bas-ip/talk.apk
fi

adb connect $1
adb push talk.apk /data/talk.apk
adb shell "mount -o rw,remount /system"
adb shell "cp -f /data/talk.apk /system/app/talk.apk"
adb shell "rm /data/talk.apk"
adb shell "mount -o ro,remount /system"
adb shell "pm install -r /system/app/talk.apk"
echo "talk.apk installed, now reboot"
adb shell "reboot"

adb disconnect $1