-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.sh
executable file
·227 lines (176 loc) · 6.43 KB
/
setup.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
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
#!/bin/bash
function misc_stringInFile()
{
STRING_TO_FIND="$1"
FILE_TO_SEARCH="$2"
if grep -qF "$STRING_TO_FIND" "$FILE_TO_SEARCH";then
echo "TRUE"
else
echo "FALSE"
fi
}
function setup_platform_tools()
{
rm -Rf $HOME/platform-tools-latest-linux.zip
rm -Rf $HOME/platform-tools
sudo apt-get install -y curl
cd "$HOME"
rm -f platform-tools-latest-linux.zip
wget "https://dl.google.com/android/repository/platform-tools-latest-linux.zip"
unzip -o $HOME/platform-tools-latest-linux.zip -d $HOME
PATH_STRING_ALREADY_ADDED=$(misc_stringInFile '$HOME/platform-tools' "$HOME/.profile")
if [ "$PATH_STRING_ALREADY_ADDED" = "FALSE" ]
then
echo '# add Android SDK platform tools to path
if [ -d "$HOME/platform-tools" ] ; then
PATH="$HOME/platform-tools:$PATH"
fi' >> $HOME/.profile
fi
source $HOME/.profile
}
function setup_packages()
{
sudo apt-get install -y bc bison build-essential ccache curl flex g++-multilib gcc-multilib git gnupg gperf imagemagick lib32ncurses5-dev lib32readline-dev lib32z1-dev liblz4-tool libncurses5-dev libsdl1.2-dev libssl-dev libwxgtk3.0-dev libxml2 libxml2-utils lzop pngcrush rsync schedtool squashfs-tools xsltproc zip zlib1g-dev
sudo apt-get install -y openjdk-9-jdk
sudo apt-get install -y libtinfo5 libncurses5
}
function setup_repo_command()
{
rm -Rf $HOME/bin/repo
sudo apt-get install -y curl
mkdir -p $HOME/bin/
curl https://storage.googleapis.com/git-repo-downloads/repo > $HOME/bin/repo
chmod a+x $HOME/bin/repo
PATH_STRING_ALREADY_ADDED=$(misc_stringInFile '$HOME/bin' "$HOME/.profile")
if [ "$PATH_STRING_ALREADY_ADDED" = "FALSE" ]
then
echo '# set PATH so it includes users private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi' >> $HOME/.profile
fi
source $HOME/.profile
}
function setup_lineage_source()
{
mkdir -p $HOME/android/lineage
cd $HOME/android/lineage
repo init -u https://github.com/LineageOS/android.git -b lineage-16.0
repo sync
}
function setup_switchroot_manifest()
{
mkdir -p $HOME/android/lineage/.repo/local_manifests
git clone https://gitlab.com/switchroot/android/manifest.git $HOME/android/lineage/.repo/local_manifests
cd $HOME/android/lineage
repo sync
}
function misc_getTimestamp()
{
date +"%Y-%m-%d_%H-%M-%S"
}
function misc_applyPatch()
{
DIRECTORY_TO_PATCH="$1"
PATCH_FILE="$2"
PATCH_NAME="$3"
cd "$DIRECTORY_TO_PATCH"
if ! patch -R -p1 -s -f --dry-run <$PATCH_FILE; then
echo "Applying Patch $PATCH_NAME to $DIRECTORY_TO_PATCH"
patch -p1 <$PATCH_FILE
else
echo "Skipping Patch $PATCH_NAME to $DIRECTORY_TO_PATCH - Applied already or failed..."
fi
}
function setup_patches()
{
BASE_DIR="$HOME/android/lineage"
PATCHES_DIR="$BASE_DIR/.repo/local_manifests/patches"
cd "$BASE_DIR"
source build/envsetup.sh
repopick -t nvidia-enhancements-p
repopick -t joycon-p
repopick -t icosa-bt
misc_applyPatch "$BASE_DIR/vendor/lineage" "$PATCHES_DIR/vendor_lineage-kmod.patch" "vendor_lineage-kmod"
misc_applyPatch "$BASE_DIR/frameworks/native" "$PATCHES_DIR/frameworks_native-hwc.patch" "frameworks_native-hwc.patch"
}
function setup_optional_patches()
{
BASE_DIR="$HOME/android/lineage"
PATCHES_DIR="$BASE_DIR/.repo/local_manifests/patches"
cd "$BASE_DIR"
source build/envsetup.sh
misc_applyPatch "$BASE_DIR/frameworks/base" "$PATCHES_DIR/frameworks_base-rsmouse.patch" "frameworks_base-rsmouse.patch"
misc_applyPatch "$BASE_DIR/vendor/nvidia" "$PATCHES_DIR/0001-HACK-use-platform-sig-for-shieldtech.patch" "0001-HACK-use-platform-sig-for-shieldtech.patch"
#Backup Original NvShieldTech just in case
#Put a timestamp on file to preserve original if script is ran again
mkdir -p "$HOME/Backups"
NVIDIA_BACKUP_FILENAME="$HOME/Backups/NvShieldTech.apk_"
NVIDIA_BACKUP_FILENAME+=$(misc_getTimestamp)
cp -f "$BASE_DIR/vendor/nvidia/shield/shieldtech/app/NvShieldTech.apk" "$NVIDIA_BACKUP_FILENAME"
#Overwrite NvShieldTech with Switchroot Version
cp -f "$PATCHES_DIR/NvShieldTech-hack.apk" "$BASE_DIR/vendor/nvidia/shield/shieldtech/app/NvShieldTech.apk"
}
function misc_findReplace()
{
VARIABLE_FIND="$1"
VARIABLE_REPLACE="$2"
VARIABLE_FILE="$3"
sed -i "s/${VARIABLE_FIND}/${VARIABLE_REPLACE}/g" "$VARIABLE_FILE"
}
function setup_build_image()
{
BASE_DIR="$HOME/android/lineage"
cd "$BASE_DIR"
mkdir -p "$BASE_DIR/out/target/product/foster_tab/vendor/lib/modules"
source build/envsetup.sh
export USE_CCACHE=1
ccache -M 50G
lunch lineage_icosa-userdebug #or lunch lineage_foster_tab-userdebug if the icosa variant doesn't work
#Modifying BoardConfig.mk
BOARD_CONFIG_FILE="$BASE_DIR/device/nvidia/foster/BoardConfig.mk"
BOARD_KERNEL_IMAGE_NAME='BOARD_KERNEL_IMAGE_NAME := zImage'
BOARD_MKBOOTIMG_ARGS='BOARD_MKBOOTIMG_ARGS += --cmdline " "'
COMBINED_STRINGS="$BOARD_KERNEL_IMAGE_NAME\n$BOARD_MKBOOTIMG_ARGS"
BOARD_MKBOOTIMG_ARGS_ADDED=$(misc_stringInFile "$BOARD_MKBOOTIMG_ARGS" "$BOARD_CONFIG_FILE")
if [ "$BOARD_MKBOOTIMG_ARGS_ADDED" = "FALSE" ]
then
misc_findReplace "$BOARD_KERNEL_IMAGE_NAME" "$COMBINED_STRINGS" "$BOARD_CONFIG_FILE"
fi
make bootimage -j$(nproc)
make systemimage -j$(nproc)
make vendorimage -j$(nproc)
}
function misc_promptForChoice()
{
COMMAND="$1"
QUESTION="$2"
while true; do
read -p "$QUESTION" yn
case $yn in
[Yy]* ) $COMMAND; break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
}
function main_setupEnvironment()
{
setup_platform_tools
setup_packages
setup_repo_command
}
function main_setupSource()
{
setup_lineage_source
setup_switchroot_manifest
}
function main()
{
misc_promptForChoice "main_setupEnvironment" "Do the Build Environment Tools need to be setup?"
misc_promptForChoice "main_setupSource" "Do you want to download/update the code for LineageOS/Switchroot?"
misc_promptForChoice "setup_patches" "Do you want to apply the Switchroot Patches if they haven't already been applied?"
misc_promptForChoice "setup_optional_patches" "(Optional) Do you want to apply the Optional Switchroot Patches if they haven't already been applied? (RSMouse, NvShieldTech)"
misc_promptForChoice "setup_build_image" "Ready to build the image?"
}
main