#!/bin/bash

source "$(dirname $_)/shared.sh"

BAKBASE=".backup"
BAKDB="$BAKBASE.sqlite"
BAKCFG="$BAKBASE.config"

APK="${1:-build/outputs/apk/RxDroid-debug-unaligned.apk}"

if [[ ! -f "$APK" ]]; then
	die "$APK does not exist"
fi

rm -f "$BAKDB" "$BAKCFG"

scripts/db-backup $BAKBASE || die

echo -n "Removing $PKG ... "
adb uninstall $PKG || die

echo -n "Reinstalling $PKG ... "
adb install $APK || die

scripts/db-restore $BAKDB $BAKCFG || die
rm -f $BAKDB $BAKCFG
