forked from althafvly/ih8sn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
push.sh
executable file
·80 lines (67 loc) · 2.81 KB
/
push.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
# Loop through command line options
# Set REBOOT flag if "--reboot" option is provided
# Set USE_REMOUNT flag if "--use_remount" option is provided
while getopts ":-:" o; do
case "${OPTARG}" in
reboot)
REBOOT=1
;;
use_remount)
USE_REMOUNT=1
;;
esac
done
# Wait for the device to be available and then run root command
adb wait-for-device root
# Unmount /system/bin and /system/etc if /system is mounted as tmpfs
adb wait-for-device shell "mount | grep -q ^tmpfs\ on\ /system && umount -fl /system/{bin,etc} 2>/dev/null"
# Remount /system as read-write if USE_REMOUNT flag is set, otherwise check if /system has available blocks and mount it as read-write
if [[ "${USE_REMOUNT}" = "1" ]]; then
adb wait-for-device shell "remount"
elif [[ "$(adb shell stat -f --format %a /system)" = "0" ]]; then
echo "ERROR: /system has 0 available blocks, consider using --use_remount"
exit -1
else
adb wait-for-device shell "stat --format %m /system | xargs mount -o rw,remount"
fi
# Push necessary files to the device
adb wait-for-device push system/addon.d/60-props.sh /system/addon.d/
adb wait-for-device push system/bin/props /system/bin/
adb wait-for-device push system/etc/init/props.rc /system/etc/init/
# Get device information
MODEL=$(adb shell getprop ro.product.model | tr ' ' '_' | sed 's/_*$//')
SERIALNO=$(adb shell getprop ro.boot.serialno | tr ' ' '_' | sed 's/_*$//')
PRODUCT=$(adb shell getprop ro.build.product | tr ' ' '_' | sed 's/_*$//')
DEFAULT_CONFIG=system/etc/props.conf
# Check if device-specific configuration file exists, otherwise use default configuration file
if [[ -f "$DEFAULT_CONFIG.${MODEL}" ]]; then
CONFIG=$DEFAULT_CONFIG.${MODEL}
elif [[ -f "$DEFAULT_CONFIG.${SERIALNO}" ]]; then
CONFIG=$DEFAULT_CONFIG.${SERIALNO}
elif [[ -f "$DEFAULT_CONFIG.${PRODUCT}" ]]; then
CONFIG=$DEFAULT_CONFIG.${PRODUCT}
else
CONFIG=$DEFAULT_CONFIG
fi
# Push the configuration file to the device
adb wait-for-device push "$CONFIG" /system/etc/props.conf
# Get SDK version, determine architecture, and push libkeystore-attestation-application-id.so file to the device if necessary
sdk_version=$(adb shell getprop ro.build.version.sdk)
libkeystore="libkeystore-attestation-application-id.so"
arch=$(adb shell getprop ro.product.cpu.abi | grep -o -E 'arm64-v8a|armeabi-v7a')
if [ "$arch" = "arm64-v8a" ]; then
libdir=lib64
else
libdir=lib
fi
if [[ -f "system/$libdir/$sdk_version/$libkeystore" ]]; then
if $(grep -q '^FORCE_BASIC_ATTESTATION=1' "$CONFIG") || ! $(grep -q '^FORCE_BASIC_ATTESTATION=0' "$CONFIG"); then
adb wait-for-device push "system/$libdir/$sdk_version/$libkeystore" /system/$libdir/
fi
fi
# Reboot the device if REBOOT
if [[ "${REBOOT}" = "1" ]]; then
adb wait-for-device reboot
fi
read -r -p "Press any key to exit..." && exit