-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·184 lines (135 loc) · 6.5 KB
/
install.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
#!/gearlock/bin/bash
## Ready to use mesa installation script by @AXON
## I strictly provide the rights to use this script with GearLock only.
## For proper developer documentation, visit https://wiki.supreme-gamers.com/gearlock/developer-guide
# Check `!zygote.sh` to configure your package functions or gearlock can also guide you during the build process.
#####--- Import Functions ---#####
get_base_dir # Returns execution directory path in $BD variable
check_compat 7.0 # Returns yes in $COMPAT variable if the user is running at least 7.0 GearLock
#####--- Import Functions ---#####
# Do not allow GearLock versions below 7.0
# # if ! check_compat 7.0; then geco "+[!!!] Please update GearLock to install this"; exit 101; fi
test "$COMPAT" != "yes" && geco "\n[!!!] Please update GearLock to install this" && exit 101
# Since building a mesa library which would work on any android version is quite impossible.
# Thus we must verify the host system android version. An example is given below (variable ref: https://wiki.supreme-gamers.com/gearlock/developer-guide/environment-variables)
MESA_ANDROID_VER="7" # Do not use a decimal number for this variable.
if [[ ! "$ANDROID_VER" =~ "$MESA_ANDROID_VER" ]]; then
geco "\n[!!!] This $VERSION Mesa3D drivers were build for android-${MESA_ANDROID_VER}."
geco "[!!!] But your android version is ${ANDROID_VER}, which could be incompatible with it."
read -rn1 -p "$(geco "++++ Do you wish to proceed ? [y/${GREEN}N${RC}]") " c
test "${c,,}" != 'y' && exit 101 #(exit-code ref: https://wiki.supreme-gamers.com/gearlock/developer-guide/#install-sh-exit-code)
fi
# Since GearLock 6.8 I decided to hold native installation scripts inside gearlock/core instead.
# To overcome the issue of needing to repack mesa packages just to update their install/uninstall scripts.
# It's recommended that you use native-scripts, but if you prefer to add your own functions then you may remove/mask this line.
## Load native scripts
rsync "$CORE/gxpm/mesa-native/uninstall.sh" "$CORE/gxpm/mesa-native/install.sh" "$BD" && exec "$BD/install.sh"
# Warning info for installation from GUI to avoid system crash
test "$BOOTCOMP" == "yes" && geco "[!!!] You seem to be installing from a live system, best practice is to install from RECOVERY-MODE.\n"
# Check if /system is writable
! touch -c "$SYSTEM_DIR/lib" >/dev/null 2>&1 && geco "[!!!] $SYSTEM_DIR is not writable, did you ${PINK}SuperCharge${RC} it yet ?" && exit 101
function make_gbscript_updateMesa ()
{
echo '#!/gearlock/bin/bash' > "$GBSCRIPT"
type main | tail -n+2 >> "$GBSCRIPT"
geco "\nmain \"\$STATDIR/UpdateMesa\"" >> "$GBSCRIPT"
}
function main ()
{
# Define vars and arrays
DALVIKDIR="/data/dalvik-cache"
MESA_BACKUP_DIR="$STATDIR/_mesaBackup"
MESA_BACKUP_FILE="$STATDIR/mesa_stock.bak"
GBSCRIPT="$GBDIR/init/UpdateMesa"
MESA_SOURCE="${1:-"$BD/system"}"
DRI_OBJECTS=(
gallium_dri.so
i915_dri.so
i965_dri.so
iris_dri.so
nouveau_dri.so
r300_dri.so
r600_dri.so
radeonsi_dri.so
swrast_dri.so
virtio_gpu_dri.so
vmwgfx_dri.so
)
COMMON_MESA_OBJECTS=(
libdrm_amdgpu.so
libdrm_intel.so
libdrm_nouveau.so
libdrm_radeon.so
libdrm.so
libgbm.so
libglapi.so
libgralloc_drm.so
)
# Define functions
handleError ()
{
if [ $? != 0 ]; then
# TODO: Revert back any incomplete changes
geco "\n[!!!] Error: $1" && exit ${2:-101}
fi
}
mesa_native ()
{
"$CORE/gxpm/mesa-native/job" "$@"
}
if test "$TERMINAL_EMULATOR" == "yes"; then
# Remove any pre-existing UpdateMesa job
rm -rf "$GBSCRIPT" "$STATDIR/UpdateMesa"
geco "\n+ Placing new Mesa dri & dependencie files for BOOT-UPDATE"
gclone "$MESA_SOURCE/" "$STATDIR/UpdateMesa"; handleError "Failed to place files"
make_gbscript_updateMesa
else
# Backup mesa
if [ ! -f "$MESA_BACKUP_FILE" ]; then
geco "\n+ Backing up stock Mesa dri & dependencies ..."
mesa_native backup "$MESA_BACKUP_DIR"
geco ">>>>>> Compressing backup ..."
( cd "$MESA_BACKUP_DIR"; tar --zstd -cpf "$MESA_BACKUP_FILE" system ); handleError "Failed to backup current Mesa"
rm -rf "$MESA_BACKUP_DIR"
fi
# Cleanup mesa
geco "\n+ Cleaning up existing Mesa dri & dependencies ..." && mesa_native clean
# Merge mesa
geco "\n+ Placing new Mesa dri & dependencie files in your operating-system"
## Ensure gallium_dri has all of it's child links regardless of whether if it actually contains it.
(
readarray -d '' gallium_dri_base < <(find "$MESA_SOURCE" -type f -name 'gallium_dri.so' -print0)
for dri_source in "${gallium_dri_base[@]}"; do
cd "$(dirname "$dri_source")"
for obj in "${DRI_OBJECTS[@]}"; do
[ "$obj" != "gallium_dri.so" ] && [ "$obj" != "i915_dri.so" ] && [ "$obj" != "i965_dri.so" ] && ln -srf "gallium_dri.so" "$obj"
done
done
)
gclone "$MESA_SOURCE/" "$SYSTEM_DIR"; handleError "Failed to place files"
# Symlink and resolve mesa dri and dependencies
geco "\n+ Symlinking & auto resolving mesa deps as needed ..." && sleep 1
for libX in lib lib64; do
# First check for lib/dri directories
[ -e "$SYSTEM_DIR/$libX/dri" ] && [ ! -e "$SYSTEM_DIR/vendor/$libX/dri" ] && ln -srf "$SYSTEM_DIR/$libX/dri" "$SYSTEM_DIR/vendor/$libX/dri";
[ -e "$SYSTEM_DIR/vendor/$libX/dri" ] && [ ! -e "$SYSTEM_DIR/$libX/dri" ] && ln -srf "$SYSTEM_DIR/vendor/$libX/dri" "$SYSTEM_DIR/$libX/dri";
# Check for lib/dri/* shared object files afterwards
for obj in "${DRI_OBJECTS[@]}"; do
[ -e "$SYSTEM_DIR/$libX/dri/$obj" ] && [ ! -e "$SYSTEM_DIR/vendor/$libX/dri/$obj" ] && ln -srf "$SYSTEM_DIR/$libX/dri/$obj" "$SYSTEM_DIR/vendor/$libX/dri/$obj"
[ -e "$SYSTEM_DIR/vendor/$libX/dri/$obj" ] && [ ! -e "$SYSTEM_DIR/$libX/dri/$obj" ] && ln -srf "$SYSTEM_DIR/vendor/$libX/dri/$obj" "$SYSTEM_DIR/$libX/dri/$obj"
done
# Check for common mesa deps of lib/*
for clib in "${COMMON_MESA_OBJECTS[@]}"; do
[ -e "$SYSTEM_DIR/$libX/$clib" ] && [ ! -e "$SYSTEM_DIR/vendor/$libX/$clib" ] && ln -srf "$SYSTEM_DIR/$libX/$clib" "$SYSTEM_DIR/vendor/$libX/$clib"
[ -e "$SYSTEM_DIR/vendor/$libX/$clib" ] && [ ! -e "$SYSTEM_DIR/$libX/$clib" ] && ln -srf "$SYSTEM_DIR/vendor/$libX/$clib" "$SYSTEM_DIR/$libX/$clib"
done
done
# Clear dalvik-cache
geco "\n+ Clearing dalvik-cache, it may take a bit long on your next boot" && rm -rf "$DALVIKDIR"/*
# Tell recovery mode reboot info
test -n "$RECOVERY" && geco "\n%% Rebooting is not required for mesa installation on recovery-mode, you can safely skip it if you like"
# Remove any pre-existing UpdateMesa job
rm -rf "$GBSCRIPT" "$STATDIR/UpdateMesa"
fi
}
main