forked from NotAOSP/proprietary_vendor_lge_gee
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathextract.sh
executable file
·186 lines (150 loc) · 5.04 KB
/
extract.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
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
#!/bin/sh
set -e
SCRIPT_NAME=$(basename $0)
KERNEL_NAME=$(uname -s)
# Kick off with generic configuration
VENDOR=lge
DEVICE=mako
echo "# VENDOR=$VENDOR"
echo "# DEVICE=$DEVICE"
# Do a bit more generic configuration
for ROOT in $(dirname $0) .; do
for MID in ../../.. ../.. .. .; do
if [ -d $ROOT/$MID/vendor/$VENDOR/$DEVICE ]; then
REPO_ROOT=$ROOT/$MID/vendor/$VENDOR/$DEVICE
fi
done
done
if [ -z $REPO_ROOT ]; then
REPO_ROOT=$(dirname $0)
fi
if [ $KERNEL_NAME == "Linux" ]; then
REPO_ROOT=$(readlink -m $REPO_ROOT)
fi
echo "# REPO_ROOT=$REPO_ROOT"
# Follow up with even more generic configuration
BLOBS_ROOT=$REPO_ROOT/proprietary
VENDOR_MAKEFILE=$REPO_ROOT/device-vendor.mk
echo " BLOBS_ROOT=$BLOBS_ROOT"
echo " VENDOR_MAKEFILE=$VENDOR_MAKEFILE"
# All hail the common header
HEADER="# Copyright (C) $(date +"%Y") ParanoidAndroid Project
#
# 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.
# This file was automatically generated by vendor/$VENDOR/$DEVICE/extract.sh"
# Look up the proprietary-blobs.txt file to use
if [ -f $REPO_ROOT/proprietary-blobs.txt ]; then
BLOBS_TXT=$REPO_ROOT/proprietary-blobs.txt
elif [ -f $REPO_ROOT/../../../device/$VENDOR/$DEVICE/proprietary-blobs.txt ]; then
BLOBS_TXT=$REPO_ROOT/../../../device/$VENDOR/$DEVICE/proprietary-blobs.txt
else
echo ""
echo " $SCRIPT_NAME: missing proprietary-blobs.txt"
echo ""
echo " A proprietary-blobs.txt file was expected either in"
echo " the vendor repository or in the regular device tree"
echo " (device/$VENDOR/$DEVICE/) but could not be found."
echo ""
exit 1
fi
if [ $KERNEL_NAME == "Linux" ]; then
BLOBS_TXT=$(readlink -m $BLOBS_TXT)
fi
echo "# BLOBS_TXT=$BLOBS_TXT"
# Check on what the source should be set to
if [ $# -eq 0 ]; then
SOURCE=adb
elif [ $# -eq 1 ]; then
SOURCE=$1
else
echo ""
echo " $SCRIPT_NAME: unexpected arguments specified"
echo ""
echo " usage: $SCRIPT_NAME [path-to-source]"
echo ""
echo " If the path-to-source argument gets specified, it should be"
echo " the absolute path to the root of the extracted device's image."
echo " If not specified, it is set as adb instead, denoting that the"
echo " connected device will be the source of the files."
echo ""
exit 2
fi
if [ $KERNEL_NAME == "Linux" ] && [ $SOURCE != adb ]; then
SOURCE=$(readlink -m $SOURCE)
fi
echo "# SOURCE=$SOURCE"
# Do simple initial checks before continuing
if [ ! -d $BLOBS_ROOT ]; then
echo ""
echo " $SCRIPT_NAME: missing blobs root directory"
echo ""
echo " To continue with the current configuration, manually"
echo " create ${BLOBS_ROOT}."
echo ""
exit 3
fi
if [ $SOURCE != adb ] && [ ! -d $SOURCE ]; then
echo ""
echo " $SCRIPT_NAME: missing source directory"
echo ""
echo " To continue with the current configuration, extract"
echo " your device to ${SOURCE}."
echo ""
exit 4
fi
# Throw in a simple seperator
echo ""
# Make sure we really have a source
if [ $SOURCE == adb ]; then
echo "Waiting for the connected device..."
adb wait-for-device
fi
# Stop preparing and start by removing all old files
echo "Making old files disappear..."
rm -rf $BLOBS_ROOT/*
# Do the real pulling and copying of files
echo "Making new files appear..."
for FILE in $(cat $BLOBS_TXT | grep -v -E '^ *(#|$)' | sed 's/^[-\/]*//' | sort -s); do
# Ensure we have a target directory
FILE_DIR=$(dirname $FILE)
if [ ! -d $BLOBS_ROOT/$FILE_DIR ]; then
mkdir -p $BLOBS_ROOT/$FILE_DIR
fi
# Pull and copy!
if [ "$SOURCE" = "adb" ]; then
adb pull -p -a $FILE $BLOBS_ROOT/$FILE
else
cp $SOURCE/$FILE $BLOBS_ROOT/$FILE
fi
done
# Inform the user of the good status
echo "Done with moving files. Setting up makefiles..."
# Throw in a clean, generic makefile as soon as possible
(cat << EOF) > $VENDOR_MAKEFILE
$HEADER
# An overlay for features that depend on proprietary files
DEVICE_PACKAGE_OVERLAYS := vendor/$VENDOR/$DEVICE/overlay
# Builder instructions about what proprietary files to include
EOF
echo -n "PRODUCT_COPY_FILES +=" >> $VENDOR_MAKEFILE
for FILE in $(cat $BLOBS_TXT | grep -v -E '^ *(#|$)' | sed 's/^[-\/]*//' | sort -s); do
echo -n " \\
vendor/$VENDOR/$DEVICE/proprietary/$FILE:$FILE" >> $VENDOR_MAKEFILE
done
echo "" >> $VENDOR_MAKEFILE
# Throw in an additional empty board configuration
(cat << EOF) > $REPO_ROOT/BoardConfigVendor.mk
$HEADER
EOF
# Let the user know we performed well and finished nicely
echo "Done with setting up makefiles."