-
Notifications
You must be signed in to change notification settings - Fork 211
/
setup
executable file
·233 lines (203 loc) · 10.2 KB
/
setup
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#!/bin/bash
function removeUnneededFolders {
rm -rf [Cc][Mm][Aa]ctions
rm -rf [Ll]inage[Aa]ctions
rm -rf [Dd]oze
rm -rf [Kk]ey[Hh]andler
}
DEVICE=${1:=${DEVICE}}
JOBS=${JOBS:=12}
ARGS=($@)
REPO_ARGS=(${ARGS[@]:1})
DEVICES_ROOT="$(dirname "$(readlink -f "${0}")")"
REPO_ROOT="$(readlink -f ${DEVICES_ROOT}/../..)"
if [ -z $DEVICE ]; then
echo "Please specify a device codename"
exit 0
fi
if ! [ -f $DEVICES_ROOT/manifests/*_$DEVICE.xml ]; then
echo "The given device is not supported. :("
else
VENDOR=$(basename $DEVICES_ROOT/manifests/*_$DEVICE.xml | cut -d "_" -f1)
echo "*****************************************"
echo "I: Configuring for device $VENDOR"_"$DEVICE"
echo "*****************************************"
# Test if there is already a device configured and the folder exists
if [ -f $REPO_ROOT/.repo/local_manifests/device.xml ]; then
rm $REPO_ROOT/.repo/local_manifests/device.xml
elif ! [ -d $REPO_ROOT/.repo/local_manifests/ ]; then
mkdir $REPO_ROOT/.repo/local_manifests/
fi
# Link the device manifest to the local_manifests folder
ln $DEVICES_ROOT/manifests/$VENDOR"_"$DEVICE.xml $REPO_ROOT/.repo/local_manifests/device.xml
# Synchronize new new sources
repo sync -c -j$JOBS -q ${REPO_ARGS[@]} || cat $REPO_ROOT/.repo/local_manifests/*.xml
# Bail out here if repo sync has an error. Else this can lead to corrupted builds
# It is not enough to rely on previous repo sync by the user
if [ $? -ne 0 ]; then
echo "repo sync failed, check your device manifest. Stopping..."
exit 1
fi
# Refresh the device & common repositories so apks and jars are not copied
# For this to work, all apks and jars need to be removed from
# device/$VENDOR/$DEVICE/*proprietary-files*.txt and
# device/$VENDOR/$DEVICE_COMMON/*proprietary-files*.txt
# A device can have multiple commons as it seems, so we store them in
# DEVICE_COMMON_TEMP and loop through them later.
DEVICE_COMMON_TEMP=$(ls -d $REPO_ROOT/device/$VENDOR/*common* 2>/dev/null | rev | cut -d "/" -f1 | rev)
VENDOR_COMMON_TEMP=$(ls -d $REPO_ROOT/vendor/$VENDOR/*common* 2>/dev/null | rev | cut -d "/" -f1 | rev)
# OnePlus uses the device/oppo/common instead of expected device/oneplus/common for some targets.
# We use a small workaround in order to catch these as well.
if [ $VENDOR="oneplus" ]; then
DEVICE_COMMON_TEMP2=$(ls -d $REPO_ROOT/device/oppo/*common* 2>/dev/null | rev | cut -d "/" -f1 | rev)
VENDOR2="oppo"
fi
DEVICE_TREE=$REPO_ROOT/device/$VENDOR/$DEVICE
VENDOR_TREE=$REPO_ROOT/vendor/$VENDOR
echo "*******************************************"
if [ -f $DEVICE_TREE/setup-makefiles.sh ]; then
echo "I: Refreshing device vendor repository: device/$VENDOR/$DEVICE"
(
cd $DEVICE_TREE
for i in $(find . -name "*proprietary-*.txt"); do
echo "I: Processing proprietary blob file: device/$VENDOR/$DEVICE/$i"
grep -r -v -E '(^.*\.{1}(jar|apk)[|]?.*)' $i >$i".tmp" && mv $i".tmp" $i
done
# Set executable bit, needed for some device trees
chmod +x ./setup-makefiles.sh
# Actually run the script
./setup-makefiles.sh
)
fi
# Since we don't use SELinux we want to make sure we remove the
# ",context=u....:s0" from the fstab file(s) in the $DEVICE folder so we can
# mount the partitions without issues
cd $DEVICE_TREE && for j in $(find . -name "fstab.*"); do
echo "I: Processing fstab file: device/$VENDOR/$DEVICE/$j"
sed -r 's/(,context=.*:s0)//' $j >$j".tmp" && mv $j".tmp" $j
done
# Since we don't have SettingsLib, remove components that rely on it (which we therefore also don't use)
# such as CMActions/LineageActions, KeyHandler and Doze. Simply removing the folder will disable them.
cd $DEVICE_TREE
echo "I: Removing components relying on SettingsLib from: device/$VENDOR/$DEVICE"
removeUnneededFolders
# Loop through values in $DEVICE_COMMON_TEMP
if [ -n "$DEVICE_COMMON_TEMP" ]; then
for k in $DEVICE_COMMON_TEMP; do
echo "I: Procession device vendor common folder: device/$VENDOR/$k"
DEVICE_COMMON_TREE=$REPO_ROOT/device/$VENDOR/$k
# We need to have $VENDOR, $DEVICE and $DEVICE_COMMON or
# $PLATFORM_COMMON available for setup-makefiles.sh in the common
# repository, therefore export them.
export VENDOR
export DEVICE
DEVICE_COMMON_HOLDER=$DEVICE_COMMON
export DEVICE_COMMON=${DEVICE_COMMON:=$k}
PLATFORM_COMMON_HOLDER=$PLATFORM_COMMON
export PLATFORM_COMMON=${PLATFORM_COMMON:=$DEVICE_COMMON}
if [ -f $DEVICE_COMMON_TREE/setup-makefiles.sh ]; then
(
cd $DEVICE_COMMON_TREE
for l in $(find . -name "*proprietary-*.txt"); do
echo "I: Processing proprietary blob file: device/$VENDOR/$k/$l"
grep -r -v -E '(^.*\.{1}(jar|apk)[|]?.*)' $l >$l".tmp" && mv $l".tmp" $l
done
# Set executable bit, needed for some device trees
chmod +x ./setup-makefiles.sh
# Actually run the script
./setup-makefiles.sh
)
fi
# Since we don't use SELinux we want to make sure we remove the
# ",context=u....:s0" from the fstab file(s) in the $DEVICE_COMMON
# folder so we can mount the partitions without issues
cd $DEVICE_COMMON_TREE && for m in $(find . -name "fstab.*"); do
echo "I: Processing fstab file: device/$VENDOR/$m"
sed -r 's/(,context=.*:s0)//' $m >$m".tmp" && mv $m".tmp" $m
done
# Since we don't have SettingsLib, remove components that rely on it (which we therefore also don't use)
# such as CMActions/LineageActions, KeyHandler and Doze. Simply removing the folder will disable them.
cd $DEVICE_COMMON_TREE
echo "I: Removing components relying on SettingsLib from: device/$VENDOR/$k"
removeUnneededFolders
# Since we can have multiple common repos we need to make sure to set
# back the original values in case they exist. Otherwise unset the value.
if [ -n "$DEVICE_COMMON_HOLDER" ]; then
DEVICE_COMMON=$DEVICE_COMMON_HOLDER
else
unset DEVICE_COMMON
fi
if [ -n "$PLATFORM_COMMON_HOLDER" ]; then
PLATFORM_COMMON=$PLATFORM_COMMON_HOLDER
else
unset PLATFORM_COMMON
fi
done
fi
# Loop through values in $DEVICE_COMMON_TEMP2 for certain OnePlus target
if [ -n "$DEVICE_COMMON_TEMP2" ]; then
for k in $DEVICE_COMMON_TEMP2; do
echo "I: Procession device vendor common folder: device/$VENDOR2/$k"
DEVICE_COMMON_TREE2=$REPO_ROOT/device/$VENDOR2/$k
# Since we don't have SettingsLib, remove components that rely on it (which we therefore also don't use)
# such as CMActions/LineageActions, KeyHandler and Doze. Simply removing the folder will disable them.
cd $DEVICE_COMMON_TREE2
echo "I: Removing components relying on SettingsLib from: device/$VENDOR2/$k"
removeUnneededFolders
done
fi
# Loop through values in $VENDOR_COMMON_TEMP
if [ -n "$VENDOR_COMMON_TEMP" ]; then
for k in $VENDOR_COMMON_TEMP; do
echo "I: Processing vendor vendor common folder: /vendor/$VENDOR/$k"
VENDOR_COMMON_TREE=$REPO_ROOT/vendor/$VENDOR/$k
# We need to have $VENDOR, $DEVICE and $DEVICE_COMMON or
# $PLATFORM_COMMON available for setup-makefiles.sh in the common
# repository, therefore export them.
export VENDOR
export DEVICE
DEVICE_COMMON_HOLDER=$DEVICE_COMMON
export DEVICE_COMMON=${DEVICE_COMMON:=$k}
PLATFORM_COMMON_HOLDER=$PLATFORM_COMMON
export PLATFORM_COMMON=${PLATFORM_COMMON:=$DEVICE_COMMON}
if [ -f $VENDOR_COMMON_TREE/setup-makefiles.sh ]; then
(
cd $VENDOR_COMMON_TREE
for l in $(find . -name "*proprietary-*.txt"); do
echo "I: Processing proprietary blob file: $VENDOR_COMMON_TREE/$l"
grep -r -v -E '(^.*\.{1}(jar|apk)[|]?.*)' $l >$l".tmp" && mv $l".tmp" $l
done
# Set executable bit, needed for some device trees
chmod +x ./setup-makefiles.sh
# Actually run the script
./setup-makefiles.sh
)
fi
# Since we don't use SELinux we want to make sure we remove the
# ",context=u....:s0" from the fstab file(s) in the $VENDOR_COMMON
# folder so we can mount the partitions without issues
cd $VENDOR_COMMON_TREE && for m in $(find . -name "fstab.*"); do
echo "I: Processing fstab file: device/$VENDOR/$k/$m"
sed -r 's/(,context=.*:s0)//' $m >$m".tmp" && mv $m".tmp" $m
done
# Since we don't have SettingsLib, remove components that rely on it (which we therefore also don't use)
# such as CMActions/LineageActions, KeyHandler and Doze. Simply removing the folder will disable them.
cd $VENDOR_COMMON_TREE
echo "I: Removing components relying on SettingsLib from: device/$VENDOR/$k"
removeUnneededFolders
# Since we can have multiple common repos we need to make sure to set
# back the original values in case they exist. Otherwise unset the value.
if [ -n "$DEVICE_COMMON_HOLDER" ]; then
DEVICE_COMMON=$DEVICE_COMMON_HOLDER
else
unset DEVICE_COMMON
fi
if [ -n "$PLATFORM_COMMON_HOLDER" ]; then
PLATFORM_COMMON=$PLATFORM_COMMON_HOLDER
else
unset PLATFORM_COMMON
fi
done
fi
echo "*******************************************"
fi