forked from Open-TEE/Open-TEE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_android.sh
executable file
·121 lines (105 loc) · 3.83 KB
/
install_android.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash
#
# Copyright (C) 2015 Aalto University.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Open-TEE install targets
OT_PROGS=${OT_PROGS-"opentee-engine conn_test_app"}
OT_LIBS=${OT_LIBS-"libtee libCommonApi libInternalApi libcrypto_test libstorage_test"}
OT_LIBSX=${OT_LIBSX-"libLauncherApi libManagerApi"}
OT_TAS=${OT_TAS-"libta_conn_test_app"}
OT_CONFIG=${OT_CONFIG-"opentee.conf"}
# Destinations
OT_PREFIX=${OT_PREFIX-"/system"}
OT_PROGS_DEST=${OT_PROGS_DEST-"$OT_PREFIX/bin"}
OT_LIBS_DEST=${OT_LIBS_DEST-"$OT_PREFIX/lib"}
OT_LIBSX_DEST=${OT_LIBSX_DEST-"$OT_PREFIX/lib/tee"}
OT_TAS_DEST=${OT_TAS_DEST-"$OT_PREFIX/lib/ta"}
OT_CONFIG_DEST=${OT_CONFIG_DEST-"$OT_PREFIX/etc"}
# Open-TEE project directory
OT_BASEDIR="$(dirname "${BASH_SOURCE[0]}")/project"
# Returns the adb shell user from connected device
adb_whoami()
{
echo $(echo "echo \$USER; exit" | adb shell | tail -1 | tr -d '\r')
}
# Write error message to stdout and exit
fail()
{
echo "`basename $0`: $1" >&2
exit 1
}
# Make sure ANDROID_PRODUCT_OUT is set to the product-specific directory that
# contains the generated binaries
if [ -z "$ANDROID_PRODUCT_OUT" ]; then
fail "ANDROID_PRODUCT_OUT not set, run lunch to set build target, aborting"
fi
# Restart adbd daemon as root if needed
if [ "x$(adb_whoami)" != "xroot" ]; then
printf "Restarting adbd daemon with root permissions: "
adb root
sleep 5s
if [ "x$(adb_whoami)" != "xroot" ]; then
echo "FAILED"
fail "failed restart adbd with root permissions, aborting"
else
echo "OK"
fi
fi
# Remount system partions read-write"
printf "Remounting /system read-write: "
adb remount || fail "failed to remount /system read-write, aborting"
# Create destination directories
adb shell mkdir -p "$OT_TAS_DEST" || fail "failed to create '$TA_DEST', aborting"
adb shell chmod 755 "$OT_TAS_DEST" || fail "failed to set permissions for '$OT_TAS_DEST', aborting"
adb shell mkdir -p "$OT_LIBSX_DEST" || fail "failed to create '$OT_LIBSX_DEST', aborting"
adb shell chmod 755 "$OT_LIBSX_DEST" || fail "failed to set permissions for '$OT_LIBSX_DEST', aborting"
# Push programs
for target in $OT_PROGS
do
infile="$ANDROID_PRODUCT_OUT/system/bin/$target"
echo "Pushing '$target' to '$OT_PROGS_DEST'"
adb push "$infile" "$OT_PROGS_DEST" || fail "failed to push '$target', aborting"
adb shell chmod 755 "$OT_PROGS_DEST/$target" || fail "failed to set permissions for '$target', aborting"
done
# Push libraries
for target in $OT_LIBS
do
infile="$ANDROID_PRODUCT_OUT/system/lib/${target}.so"
echo "Pushing '$target' to '$OT_LIBS_DEST'"
adb push "$infile" "$OT_LIBS_DEST" || fail "failed to push '$target', aborting"
done
# Push additional libraries
for target in $OT_LIBSX
do
infile="$ANDROID_PRODUCT_OUT/system/lib/${target}.so"
echo "Pushing '$target' to '$OT_LIBSX_DEST'"
adb push "$infile" "$OT_LIBSX_DEST" || fail "failed to push '$target', aborting"
done
# Push TAs
for target in $OT_TAS
do
infile="$ANDROID_PRODUCT_OUT/system/lib/${target}.so"
echo "Pushing '$target' to '$OT_TAS_DEST'"
adb push "$infile" "$OT_TAS_DEST" || fail "failed to push '$target', aborting"
done
# Push config
for target in $OT_CONFIG
do
infile="$OT_BASEDIR/${target}.android"
echo "Pushing '$target' to '$OT_CONFIG_DEST'"
adb push "$infile" "$OT_CONFIG_DEST/${target}" || fail "failed to push '$target', aborting"
done
# Done
exit 0