2023-09-10 04:25:36 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# assert ANDROID_HOME is set
|
2023-09-22 06:12:53 +02:00
|
|
|
if [ -z "$ANDROID_HOME" ]; then
|
|
|
|
echo "ANDROID_HOME is not set"
|
2023-09-10 04:25:36 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# assert 2 parameters are provided
|
|
|
|
if [ $# -ne 2 ]; then
|
|
|
|
echo "Usage: $0 <emulator_name> <system_image>"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
EMULATOR_NAME=$1
|
|
|
|
SYSTEM_IMAGE=$2
|
|
|
|
|
|
|
|
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
|
|
|
|
DEVELOPMENT_DIR=$SCRIPT_DIR/..
|
|
|
|
ROOT_PROJECT_DIR=$SCRIPT_DIR/../../..
|
|
|
|
|
|
|
|
echo "Downloading system image..."
|
2023-09-22 06:12:53 +02:00
|
|
|
$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --install "$SYSTEM_IMAGE"
|
2023-09-10 04:25:36 +02:00
|
|
|
|
|
|
|
# create AVD if it doesn't exist
|
2023-09-22 06:12:53 +02:00
|
|
|
if $ANDROID_HOME/cmdline-tools/latest/bin/avdmanager list avd | grep -q "$EMULATOR_NAME"; then
|
2023-09-10 04:25:36 +02:00
|
|
|
echo "AVD already exists. Skipping creation."
|
|
|
|
else
|
|
|
|
echo "Creating AVD..."
|
2023-09-22 06:12:53 +02:00
|
|
|
echo 'no' | $ANDROID_HOME/cmdline-tools/latest/bin/avdmanager create avd -n "$EMULATOR_NAME" -k "$SYSTEM_IMAGE"
|
2023-09-10 04:25:36 +02:00
|
|
|
sleep 1
|
|
|
|
fi
|
|
|
|
|
2023-09-22 06:12:53 +02:00
|
|
|
EMULATOR_DEVICE_NAME=$($ANDROID_HOME/platform-tools/adb devices | grep emulator | cut -f1)
|
2023-09-10 04:25:36 +02:00
|
|
|
|
2023-10-08 20:16:53 +02:00
|
|
|
if [ -z "$EMULATOR_DEVICE_NAME" ]; then
|
|
|
|
$SCRIPT_DIR/start_emulator.sh "$EMULATOR_NAME"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# wait for emulator device to appear with 180 second timeout
|
|
|
|
echo "Waiting for emulator device..."
|
|
|
|
|
|
|
|
for i in {1..180}; do
|
|
|
|
if [ -z "$EMULATOR_DEVICE_NAME" ]; then
|
|
|
|
sleep 1
|
|
|
|
EMULATOR_DEVICE_NAME=$($ANDROID_HOME/platform-tools/adb devices | grep emulator | cut -f1)
|
|
|
|
else
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2023-09-10 04:25:36 +02:00
|
|
|
if [ -z "$EMULATOR_DEVICE_NAME" ]; then
|
|
|
|
echo "Emulator device name not found"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-09-22 06:12:53 +02:00
|
|
|
ADB="$ANDROID_HOME/platform-tools/adb -s $EMULATOR_DEVICE_NAME"
|
2023-09-10 04:25:36 +02:00
|
|
|
|
|
|
|
echo "Waiting for emulator to boot..."
|
|
|
|
$ADB wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;'
|
|
|
|
|
|
|
|
echo "Provisioning emulator for write access to '/system'..."
|
|
|
|
$ADB root
|
|
|
|
sleep 3 # wait for adb to restart
|
|
|
|
$ADB remount # remount /system as writable
|
|
|
|
|
|
|
|
echo "Rebooting emulator..."
|
|
|
|
$ADB reboot # need to reboot first time we remount
|
|
|
|
$ADB wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;'
|
|
|
|
|
|
|
|
echo "Provisioning emulator for Seedvault..."
|
|
|
|
$SCRIPT_DIR/install_app.sh
|
|
|
|
|
2023-10-08 20:16:53 +02:00
|
|
|
echo "Rebooting emulator..."
|
|
|
|
$ADB reboot
|
|
|
|
$ADB wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;'
|
|
|
|
|
2023-09-10 04:25:36 +02:00
|
|
|
echo "Setting backup transport to Seedvault..."
|
|
|
|
$ADB shell bmgr enable true
|
2023-10-08 20:16:53 +02:00
|
|
|
sleep 5
|
2023-09-10 04:25:36 +02:00
|
|
|
$ADB shell bmgr transport com.stevesoltys.seedvault.transport.ConfigurableBackupTransport
|
|
|
|
|
2023-10-08 20:16:53 +02:00
|
|
|
echo "Downloading and extracting test backup to '/sdcard/seedvault_baseline'..."
|
2023-09-10 04:25:36 +02:00
|
|
|
|
2023-10-08 20:16:53 +02:00
|
|
|
if [ ! -f backup.tar.gz ]; then
|
|
|
|
echo "Downloading test backup..."
|
|
|
|
wget --quiet https://github.com/seedvault-app/seedvault-test-data/releases/download/1/backup.tar.gz
|
|
|
|
fi
|
|
|
|
|
|
|
|
$ADB root
|
|
|
|
sleep 3 # wait for adb to restart
|
|
|
|
$ADB push backup.tar.gz /sdcard
|
2023-09-14 08:37:38 +02:00
|
|
|
rm backup.tar.gz
|
|
|
|
|
2023-10-08 20:16:53 +02:00
|
|
|
$ADB wait-for-device
|
2023-09-14 08:37:38 +02:00
|
|
|
$ADB shell mkdir -p /sdcard/seedvault_baseline
|
|
|
|
$ADB shell tar xzf /sdcard/backup.tar.gz --directory=/sdcard/seedvault_baseline
|
|
|
|
$ADB shell rm /sdcard/backup.tar.gz
|
|
|
|
|
2023-09-10 04:25:36 +02:00
|
|
|
echo "Emulator '$EMULATOR_NAME' has been provisioned with Seedvault!"
|