Skip to content

Instantly share code, notes, and snippets.

@leonschreuder
Created July 14, 2022 14:50
Show Gist options
  • Save leonschreuder/4e52daffe78129b801b5d3daf4773ba3 to your computer and use it in GitHub Desktop.
Save leonschreuder/4e52daffe78129b801b5d3daf4773ba3 to your computer and use it in GitHub Desktop.
aosp helper script for syncing files built using mm
#!/bin/bash
# little application
main() {
assertCorrectAdb
assertAdbConnected
remountAsRootIfRequired
echo "# syncing..."
adb sync
echo "# restarting..."
adb shell 'stop; start'
echo "# DONE"
}
assertCorrectAdb() {
if [[ "$(which adb)" == "/usr/bin/adb" ]]; then
exitWithError "it doesn't seem like you've had lunch yet"
fi
}
assertAdbConnected() {
if ! adb get-state 1>/dev/null 2>&1; then
exitWithError "no device connected"
fi
}
remountAsRootIfRequired() {
result="$(adb shell 'getprop service.adb.root')"
if [[ $result != 1 ]];then
echo "# getting root..."
adb root
sleep 1
fi
if ! adb shell 'test -w /product/etc/selinux/'; then
echo "# remounting..."
adb remount
sleep 2
fi
}
exitWithError() {
echo "ERROR: $*" >&2
exit 1
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment