forked from GrapheneOS/script
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Android Auto: Helper script to disable liboemcrypto.sh
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/bin/bash | ||
|
||
set -o errexit -o pipefail | ||
|
||
source "$(dirname ${BASH_SOURCE[0]})/common.sh" | ||
|
||
cd $(dirname ${BASH_SOURCE[0]})/.. | ||
|
||
[[ ! -z "$TARGET_PRODUCT" ]] || user_error "TARGET_PRODUCT not set. Please prepare env." | ||
|
||
PROP_FILE=vendor/google_devices/$TARGET_PRODUCT/proprietary/Android.bp | ||
|
||
[[ -f "$PROP_FILE" ]] || user_error "Please download proprietary files for $TARGET_PRODUCT first." | ||
|
||
LINE_NUMBER=$(grep -n "name: \"liboemcrypto" vendor/google_devices/$TARGET_PRODUCT/proprietary/Android.bp | awk -F: '{print $1}') | ||
|
||
TMPFILE_PRE=$(mktemp) | ||
TMPFILE_POST=$(mktemp) | ||
TMPFILE_NEW=$(mktemp) | ||
trap 'rm -- "$TMPFILE_PRE" "$TMPFILE_POST" "$TMPFILE_NEW"' EXIT | ||
|
||
head -n $LINE_NUMBER $PROP_FILE > $TMPFILE_PRE | ||
tail -n +$((LINE_NUMBER+1)) $PROP_FILE > $TMPFILE_POST | ||
|
||
LAST_EMPTY_LINE=$(grep -E --line-number --with-filename '^$' $TMPFILE_PRE | tail -n1 | awk -F: '{print $2}') | ||
FIRST_EMPTY_LINE=$(grep -E --line-number --with-filename '^$' $TMPFILE_POST | head -n1 | awk -F: '{print $2}') | ||
|
||
if [ "$(tail -n +$((LAST_EMPTY_LINE+1)) $TMPFILE_PRE | head -n1)" = "/*" ] ; then | ||
echo "Already disabled" | ||
exit | ||
fi | ||
|
||
head $TMPFILE_PRE -n $LAST_EMPTY_LINE > $TMPFILE_NEW | ||
echo "/*" >> $TMPFILE_NEW | ||
tail -n +$((LAST_EMPTY_LINE+1)) $TMPFILE_PRE >> $TMPFILE_NEW | ||
|
||
head $TMPFILE_POST -n $((FIRST_EMPTY_LINE-1)) >> $TMPFILE_NEW | ||
echo "*/" >> $TMPFILE_NEW | ||
tail -n +$FIRST_EMPTY_LINE $TMPFILE_POST >> $TMPFILE_NEW | ||
|
||
cat $TMPFILE_NEW > $PROP_FILE | ||
|
||
echo "Successfully disabled" |