114 lines
2.3 KiB
Bash
114 lines
2.3 KiB
Bash
#!/sbin/sh
|
|
|
|
OUTFD="/proc/self/fd/$2"
|
|
ZIP=$3
|
|
|
|
exec_util() {
|
|
LD_LIBRARY_PATH=$LD_PATH $UTILS $1
|
|
}
|
|
|
|
set_con() {
|
|
exec_util "chcon -h u:object_r:"$1":s0 $2"
|
|
exec_util "chcon u:object_r:"$1":s0 $2"
|
|
}
|
|
|
|
set_perm() {
|
|
exec_util "chmod $1 $2"
|
|
}
|
|
|
|
set_owner() {
|
|
exec_util "chown $1:$2 $3"
|
|
}
|
|
|
|
ui_print() {
|
|
echo "ui_print $1" > "$OUTFD";
|
|
echo "ui_print" > "$OUTFD";
|
|
}
|
|
|
|
ui_print "**********************"
|
|
ui_print "MindTheGapps installer"
|
|
ui_print "**********************"
|
|
|
|
ABDEVICE=`getprop ro.build.system_root_image`
|
|
|
|
ui_print "Mounting system partition"
|
|
|
|
if [ "$ABDEVICE" == "true" ]; then
|
|
SYSTEM="/system/system"
|
|
# TODO: Actually handle A/B ota devices
|
|
ui_print "A/B OTA device detected! This is unsupported. Aborting"
|
|
exit 1
|
|
else
|
|
SYSTEM="/system"
|
|
if mount $SYSTEM; then
|
|
ui_print "$SYSTEM mounted"
|
|
else
|
|
ui_print "Could not mount $SYSTEM! Aborting"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
if [ -f $SYSTEM/bin/toybox ]; then
|
|
UTILS=$SYSTEM/bin/toybox
|
|
LD_PATH=$SYSTEM/lib
|
|
else
|
|
ui_print "Could not find $SYSTEM/bin/toybox! Aborting"
|
|
exit 1
|
|
fi
|
|
|
|
DIRS="addon.d app priv-app framework etc lib"
|
|
|
|
if [ -d $SYSTEM/lib64 ]; then
|
|
DIRS="$DIRS lib64"
|
|
LD_PATH=$SYSTEM/lib64
|
|
fi
|
|
|
|
LOWMEM=1572864
|
|
MEM=`cat /proc/meminfo | head -1 | sed 's/[^0-9]*//g'`
|
|
|
|
ui_print "Extracting files"
|
|
cd /tmp
|
|
unzip -o "$ZIP"
|
|
exec_util "rm -rf META-INF"
|
|
cd system
|
|
#if [ "$MEM" -lt "$LOWMEM" ]; then
|
|
# ui_print "Low RAM device detected, removing Google SuW"
|
|
exec_util "rm -rf priv-app/SetupWizard"
|
|
#fi
|
|
ui_print "Generating addon.d file"
|
|
cat addon.d/addond_head > addon.d/30-gapps.sh
|
|
for f in `exec_util "find . -type f"`; do
|
|
line=$(echo "$f" | sed 's/\.\///')
|
|
echo "$line" >> addon.d/30-gapps.sh
|
|
done
|
|
cat addon.d/addond_tail >> addon.d/30-gapps.sh
|
|
ui_print "Preparing files for copying"
|
|
for dirs in $DIRS; do
|
|
set_perm 0755 $dir
|
|
for d in `exec_util "find ./$dir -type d"`; do
|
|
set_perm 0755 $d
|
|
set_owner root root $d
|
|
done
|
|
for f in `exec_util "find ./$dir -type f"`; do
|
|
type=$(echo "$f" | sed 's/.*\.//')
|
|
if [ "$type" == "sh" ] || [ "$type" == "$f" ]; then
|
|
set_perm 0755 $f
|
|
else
|
|
set_perm 0644 $f
|
|
fi
|
|
set_owner root root $f
|
|
set_con system_file $f
|
|
done
|
|
done
|
|
ui_print "Copying files"
|
|
exec_util "cp --preserve=a -r ./* $SYSTEM/"
|
|
ui_print "Cleaning up files"
|
|
cd ../
|
|
exec_util "rm -rf system/"
|
|
|
|
ui_print "Unmounting system partition"
|
|
umount $SYSTEM
|
|
|
|
ui_print "Done!"
|
|
exit 0
|