Installer
Installer
Installer
/sbin/sh
#
###########################################
#
# Copyright (C) 2021 FlameGApps Project
#
# This file is part of the FlameGApps Project created by ayandebnath
#
# The FlameGApps scripts are free software, you can redistribute and/or modify
them.
#
# These scripts are distributed in the hope that they will be useful, but WITHOUT
ANY WARRANTY.
#
###########################################
# File Name : installer.sh
###########################################
##
# List of the basic edition gapps files
gapps_list_basic="
AndroidAutoStub
CalendarSync
DigitalWellbeing
GooglePackageInstaller
MarkupGoogle
SetupWizard
SoundPickerGoogle"
rm_list_full="
app/AndroidAutoStubPrebuilt
app/AudioFX
app/Browser
app/Browser2
app/BrowserPrebuilt
app/Calculator
app/Calculator2
app/CalculatorGooglePrebuilt
app/Calendar
app/CalendarGooglePrebuilt
app/CalendarPrebuilt
app/ChromePublic
app/Clock
app/DashClock
app/DeskClock
app/Eleven
app/Email
app/Email2
app/Etar
app/ExactCalculator
app/ExtShared
app/Gallery2
app/GalleryGo
app/GalleryGoPrebuilt
app/GoogleCalendarSyncAdapter
app/GoogleContactsSyncAdapter
app/GoogleExtShared
app/GoogleLocationHistory
app/Hangouts
app/Jelly
app/LatinIMEGoogle
app/LatinIMEGooglePrebuilt
app/MarkupGoogle
app/MarkupGooglePrebuilt
app/MarkupPrebuilt
app/Music
app/Music2
app/MusicPrebuilt
app/Photos
app/PhotosPrebuilt
app/PrebuiltBugle
app/PrebuiltDeskClock
app/PrebuiltDeskClockGoogle
app/RetroMusicPlayer
app/RetroMusicPlayerPrebuilt
app/RevengeOSCalculator
app/SimpleCalendar
app/SimpleGallery
app/SoundPickerGooglePrebuilt
app/Via
app/ViaBrowser
app/ViaBrowserPrebuilt
app/ViaPrebuilt
app/WallpaperPicker
app/WallpaperPickerGooglePrebuilt
app/WallpaperPickerGoogleRelease
app/WallpaperPickerPrebuilt
etc/default-permissions/default-permissions.xml
etc/default-permissions/opengapps-permissions.xml
etc/permissions/com.google.android.dialer.support.xml
etc/permissions/com.google.android.maps.xml
etc/permissions/com.google.android.media.effects.xml
etc/permissions/privapp-permissions-google.xml
etc/permissions/split-permissions-google.xml
etc/preferred-apps/google.xml
etc/sysconfig/dialer_experience.xml
etc/sysconfig/google-hiddenapi-package-whitelist.xml
etc/sysconfig/google.xml
etc/sysconfig/google_build.xml
etc/sysconfig/google_exclusives_enable.xml
etc/sysconfig/nexus.xml
etc/sysconfig/pixel_2018_exclusive.xml
etc/sysconfig/pixel_experience_2017.xml
etc/sysconfig/pixel_experience_2018.xml
framework/com.google.android.dialer.support.jar
framework/com.google.android.maps.jar
framework/com.google.android.media.effects.jar
lib64/libjni_latinimegoogle.so
lib64/libsketchology_native.so
overlay/forceQueryablePackagesOverlay.apk
overlay/GoogleDialerOverlay.apk
priv-app/AndroidAutoStubPrebuilt
priv-app/AndroidMigratePrebuilt
priv-app/AndroidPlafoPlatformServices
priv-app/AudioFX
priv-app/Browser
priv-app/Browser2
priv-app/BrowserPrebuilt
priv-app/Calculator
priv-app/Calendar
priv-app/CarrierSetup
priv-app/Clock
priv-app/ConfigUpdater
priv-app/crDroidMusic
priv-app/DeviceHealthService
priv-app/Eleven
priv-app/Email
priv-app/Email2
priv-app/ExtServices
priv-app/Gallery
priv-app/Gallery2
priv-app/Gallery3d
priv-app/GalleryGo
priv-app/GalleryGoPrebuilt
priv-app/GalleryPrebuilt
priv-app/GmsCore
priv-app/GmsCorePrebuilt
priv-app/GmsCoreSetupPrebuilt
priv-app/GoogleBackupTransport
priv-app/GoogleContacts
priv-app/GoogleDialer
priv-app/GoogleExtServices
priv-app/GooglePackageInstaller
priv-app/GoogleRestore
priv-app/GoogleServicesFramework
priv-app/Hangouts
priv-app/Jelly
priv-app/LatinIMEGooglePrebuilt
priv-app/MarkupGoogle
priv-app/MarkupGooglePrebuilt
priv-app/Music
priv-app/Music2
priv-app/MusicPrebuilt
priv-app/Phonesky
priv-app/Photos
priv-app/PixelSetupWizard
priv-app/PrebuiltDeskClock
priv-app/PrebuiltGalleryGo
priv-app/PrebuiltGmsCore
priv-app/PrebuiltGmsCorePi
priv-app/PrebuiltGmsCoreQt
priv-app/RetroMusicPlayer
priv-app/RetroMusicPlayerPrebuilt
priv-app/SetupWizard
priv-app/SetupWizardPrebuilt
priv-app/SimpleGallery
priv-app/SnapGallery
priv-app/SnapdragonGallery
priv-app/Turbo
priv-app/TurboPrebuilt
priv-app/Via
priv-app/ViaBrowser
priv-app/ViaBrowserPrebuilt
priv-app/ViaPrebuilt
priv-app/WallpaperGooglePrebuilt
priv-app/WallpaperPickerGoogleRelease
priv-app/WallpapersGooglePrebuilt
priv-app/Wellbeing
priv-app/WellbeingGooglePrebuilt
priv-app/WellbeingPrebuilt"
stock_camera="
app/Camera2
app/SimpleCamera
app/Snap
priv-app/Camera2
priv-app/SimpleCamera
priv-app/Snap"
stock_messages="
app/message
app/messages
app/Messages
app/messaging
app/Messaging
app/Messenger
app/QKSMS
app/RevengeMessages
priv-app/messaging
priv-app/Messaging"
stock_soundpicker="
app/PrebuiltSoundPicker
app/SoundPicker
app/SoundPickerPrebuilt
priv-app/PrebuiltSoundPicker
priv-app/SoundPicker
priv-app/SoundPickerPrebuilt"
provision="
app/provision
app/Provision
priv-app/provision
priv-app/Provision"
lineage_setup="
priv-app/LineageSetupWizard"
aosp_dialer="
app/Dialer
priv-app/Dialer"
aosp_contacts="
app/Contact
app/Contacts
priv-app/Contact
priv-app/Contacts"
aosp_keyboard="
app/LatinIME
app/LatinIMEPrebuilt
priv-app/LatinIME
priv-app/LatinIMEPrebuilt"
aosp_packageinstaller="
priv-app/PackageInstaller"
ui_print() {
echo "ui_print $1
ui_print" >> $OUTFD
}
setup_mountpoint() {
[ -L $1 ] && mv -f $1 ${1}_link
if [ ! -d $1 ]; then
rm -f $1
mkdir -p $1
fi
}
recovery_actions() {
OLD_LD_LIB=$LD_LIBRARY_PATH
OLD_LD_PRE=$LD_PRELOAD
OLD_LD_CFG=$LD_CONFIG_FILE
unset LD_LIBRARY_PATH
unset LD_PRELOAD
unset LD_CONFIG_FILE
}
recovery_cleanup() {
[ -z $OLD_LD_LIB ] || export LD_LIBRARY_PATH=$OLD_LD_LIB
[ -z $OLD_LD_PRE ] || export LD_PRELOAD=$OLD_LD_PRE
[ -z $OLD_LD_CFG ] || export LD_CONFIG_FILE=$OLD_LD_CFG
}
clean_up() {
rm -rf /tmp/flamegapps
rm -rf /tmp/config.prop
rm -rf /tmp/flame.prop
rm -rf /tmp/tar_gapps
rm -rf /tmp/unzip_dir
rm -rf $backup_script
rm -rf $temp_backup_script
}
path_info() {
ls / > "$log_dir/rootpathinfo.txt"
ls -RZl $SYSTEM > "$log_dir/systempathinfo.txt"
ls -RZl /product > "$log_dir/productpathinfo.txt" 2>/dev/null
ls -RZl /system_ext > "$log_dir/system_extpathinfo.txt" 2>/dev/null
}
take_logs() {
ui_print " "
ui_print "- Copying logs to /sdcard & $zip_dir"
cp -f $TMP/recovery.log $log_dir/recovery.log
cd $log_dir
tar -cz -f "$TMP/flamegapps_canary_debug_logs.tar.gz" *
cp -f $TMP/flamegapps_canary_debug_logs.tar.gz
"$zip_dir/flamegapps_canary_debug_logs-$build_date-$build_time.tar.gz"
cp -f $TMP/flamegapps_canary_debug_logs.tar.gz
/sdcard/flamegapps_canary_debug_logs-$build_date-$build_time.tar.gz
cd /
rm -rf $TMP/flamegapps_canary_debug_logs.tar.gz
}
get_size() {
local FILE_SIZE=0
FILE_SIZE=`du -sk "$1" | cut -f1`
printf "$FILE_SIZE"
}
get_file_prop() {
grep -m1 "^$2=" "$1" | cut -d= -f2
}
get_prop() {
# check known .prop files using get_file_prop
for f in $PROPFILES; do
if [ -e "$f" ]; then
prop="$(get_file_prop "$f" "$1")"
if [ -n "$prop" ]; then
break # if an entry has been found, break out of the loop
fi
fi
done
# if prop is still empty; try to use recovery's built-in getprop method;
otherwise output current result
if [ -z "$prop" ]; then
getprop "$1" | cut -c1-
else
printf "$prop"
fi
}
get_available_space() {
local available_space=0
available_space=`df -k $1 | tail -1 | awk '{print $3}'`
printf $available_space
}
check_available_space() {
local file_size
local partition="$1"
[ -e $partition ] || return 1
space_required=`get_prop ro.flame.required_size`
space_required=$(($space_required + $buffer_space))
space_available=$(get_available_space "$partition")
for f in $removal_list; do
if [ -e "$partition/$f" ]; then
file_size=`get_size "$partition/$f"`
space_available=$(($space_available + $file_size))
fi
done
echo -e "\n- Available space in ${partition}: $space_available" >> $flame_log
if [ "$space_available" -ge "$space_required" ]; then
return 0
else
return 1
fi
}
remove_fd() {
local LIST="$1"
for f in $LIST; do
rm -rf $SYSTEM/$f
rm -rf $SYSTEM/product/$f
if [ "$rom_sdk" -gt "29" ]; then
rm -rf $SYSTEM/system_ext/$f
fi
done
}
abort() {
sleep 1
ui_print "- Aborting..."
sleep 3
path_info
unmount_all
take_logs
clean_up
recovery_cleanup
exit 1;
}
exit_all() {
sleep 0.5
path_info
log_space "after"
unmount_all
sleep 0.5
set_progress 0.90
take_logs
clean_up
recovery_cleanup
sleep 0.5
ui_print " "
ui_print "- Installation Successful..!"
ui_print " "
set_progress 1.00
exit 0;
}
mount_apex() {
# For reference, check: https://github.com/osm0sis/AnyKernel3/blob/master/META-
INF/com/google/android/update-binary
if [ -d $SYSTEM/apex ]; then
local apex dest loop minorx num
setup_mountpoint /apex
minorx=1
[ -e /dev/block/loop1 ] && minorx=$(ls -l /dev/block/loop1 | awk '{ print
$6 }')
num=0
for apex in $SYSTEM/apex/*; do
dest=/apex/$(basename $apex .apex)
[ "$dest" = /apex/com.android.runtime.release ] &&
dest=/apex/com.android.runtime
mkdir -p $dest
case $apex in
*.apex)
unzip -qo $apex apex_payload.img -d /apex
mv -f /apex/apex_payload.img $dest.img
mount -t ext4 -o ro,noatime $dest.img $dest 2>/dev/null
if [ $? != 0 ]; then
while [ $num -lt 64 ]; do
loop=/dev/block/loop$num
(mknod $loop b 7 $((num * minorx))
losetup $loop $dest.img) 2>/dev/null
num=$((num + 1))
losetup $loop | grep -q $dest.img && break
done
mount -t ext4 -o ro,loop,noatime $loop $dest
if [ $? != 0 ]; then
losetup -d $loop 2>/dev/null
fi
fi
;;
*) mount -o bind $apex $dest;;
esac
done
export ANDROID_RUNTIME_ROOT=/apex/com.android.runtime
export ANDROID_TZDATA_ROOT=/apex/com.android.tzdata
export BOOTCLASSPATH=/apex/com.android.runtime/javalib/core-
oj.jar:/apex/com.android.runtime/javalib/core-
libart.jar:/apex/com.android.runtime/javalib/okhttp.jar:/apex/com.android.runtime/j
avalib/bouncycastle.jar:/apex/com.android.runtime/javalib/apache-
xml.jar:/system/framework/framework.jar:/system/framework/ext.jar:/system/framework
/telephony-common.jar:/system/framework/voip-common.jar:/system/framework/ims-
common.jar:/system/framework/android.test.base.jar:/system/framework/telephony-
ext.jar:/apex/com.android.conscrypt/javalib/conscrypt.jar:/apex/com.android.media/j
avalib/updatable-media.jar
fi
}
unmount_apex() {
if [ -d /apex ]; then
local dest loop
for dest in $(find /apex -type d -mindepth 1 -maxdepth 1); do
if [ -f $dest.img ]; then
loop=$(mount | grep $dest | cut -d" " -f1)
fi
(umount -l $dest
losetup -d $loop) 2>/dev/null
done
rm -rf /apex 2>/dev/null
unset ANDROID_RUNTIME_ROOT ANDROID_TZDATA_ROOT BOOTCLASSPATH
fi
}
mount_all() {
set_progress 0.10
ui_print "- Mounting partitions"
sleep 1
dynamic_partitions=`getprop ro.boot.dynamic_partitions`
SLOT=`getprop ro.boot.slot_suffix`
[ -n "$SLOT" ] && ui_print "- Current boot slot: $SLOT"
if [ -f /etc/fstab ]; then
if [ -n "$(cat /etc/fstab | grep /system_root)" ]; then
MOUNT_POINT=/system_root
else
MOUNT_POINT=/system
fi
else
ui_print "- No fstab detected"
MOUNT_POINT=$ANDROID_ROOT
fi
case $MOUNT_POINT in
/system_root) setup_mountpoint /system
;;
/system)
setup_mountpoint /system_root
mount -o ro -t auto /system_root
;;
esac
sleep 0.3
unmount_all() {
ui_print " "
ui_print "- Unmounting partitions"
unmount_apex
if [ "$unmount_data" ]; then
umount /data
umount -l /data
fi
if [ "$unmount_cache" ]; then
umount /cache
umount -l /cache
fi
for m in /system /system_root /product /system_ext /vendor; do
if [ -e $m ]; then
(umount $m
umount -l $m) 2>/dev/null
fi
done
}
recovery_actions
PROPFILES="$SYSTEM/build.prop $TMP/flame.prop"
CORE_DIR="$TMP/tar_core"
GAPPS_DIR="$TMP/tar_gapps"
EXTRA_DIR="$TMP/tar_extra"
UNZIP_FOLDER="$TMP/unzip_dir"
EX_SYSTEM="$UNZIP_FOLDER/src"
zip_dir="$(dirname "$ZIPFILE")"
log_dir="$TMP/flamegapps/logs"
flame_log="$log_dir/installation_log.txt"
build_info="$log_dir/build_info.prop"
backup_script="$TMP/backup_script.sh"
temp_backup_script="$TMP/temp_backup_script.sh"
overlay_installed="false"
buffer_space=2000
mkdir -p $UNZIP_FOLDER
mkdir -p $log_dir
log_space "before"
case "$device_architecture" in
*x86_64*) arch="x86_64"
;;
*x86*) arch="x86"
;;
*arm64*) arch="arm64"
;;
*armeabi*) arch="arm"
;;
*) arch="unknown"
;;
esac
set_progress 0.20
sleep 1
ui_print " "
ui_print "- Android: $rom_version, SDK: $rom_sdk, ARCH: $arch"
sleep 1
if [ ! "$rom_sdk" = "$flame_sdk" ]; then
ui_print " "
ui_print "****************** WARNING *******************"
ui_print " "
ui_print "! Wrong android version detected"
sleep 0.5
ui_print "This package is for android: $flame_android only"
sleep 0.5
ui_print "Your ROM is Android: $rom_version"
sleep 0.5
ui_print " "
ui_print "******* FlameGApps Installation Failed *******"
ui_print " "
abort
fi
# Check available space and choose the preferred partition for gapps installation
PREFERRED_PARTITION=$SYSTEM
insufficient_space="true"
for p in $SYSTEM/system_ext $SYSTEM/product $SYSTEM; do
if check_available_space "$p"; then
insufficient_space="false"
PREFERRED_PARTITION=$p
PREFERRED_PARTITION_PREFIX="/system"
if contains "$PREFERRED_PARTITION" "/system_ext"; then
PREFERRED_PARTITION_NAME="system_ext"
elif contains "$PREFERRED_PARTITION" "/product"; then
PREFERRED_PARTITION_NAME="product"
else
PREFERRED_PARTITION_NAME="system"
PREFERRED_PARTITION_PREFIX=""
fi
break
fi
done
check_gapps_config() {
for p in "$zip_dir" /sdcard; do
if [ -e "$p/flamegapps-config.txt" ] && [ ! -e $TMP/config.prop ]; then
ui_print "- GApps config detected"
ui_print " "
cp -f "$p/flamegapps-config.txt" $TMP/config.prop
cp -f $TMP/config.prop $log_dir/config.prop
chmod 0644 $TMP/config.prop
gapps_config="true"
fi
done
}
extract_and_install() {
local TYPE="$1"
local SOURCE="$2"
local FILE="$3"
unzip -o "$ZIPFILE" "tar_${TYPE}/$FILE.tar.xz" -d $TMP
tar -xf "$SOURCE/$FILE.tar.xz" -C $UNZIP_FOLDER
rm -rf $SOURCE/$FILE.tar.xz
installed_list="$installed_list\n${FILE}"
file_list="$(find "$EX_SYSTEM/" -mindepth 1 -type f | cut -d/ -f5-)"
dir_list="$(find "$EX_SYSTEM/" -mindepth 1 -type d | cut -d/ -f5-)"
for file in $file_list; do
if contains "$file" "overlay/"; then
if [ "$PREFERRED_PARTITION_NAME" = "system" ]; then
OVERLAY_DEST='product'
else
OVERLAY_DEST=$PREFERRED_PARTITION_NAME
fi
install -D "$EX_SYSTEM/${file}" "$SYSTEM/$OVERLAY_DEST/${file}"
chcon -h u:object_r:vendor_overlay_file:s0 "$SYSTEM/$OVERLAY_DEST/${file}"
chmod 0644 "$SYSTEM/$OVERLAY_DEST/${file}"
backup_file_list="$backup_file_list\n$OVERLAY_DEST/${file}"
overlay_installed="true"
else
install -D "$EX_SYSTEM/${file}" "$PREFERRED_PARTITION/${file}"
chcon -h u:object_r:system_file:s0 "$PREFERRED_PARTITION/${file}"
chmod 0644 "$PREFERRED_PARTITION/${file}"
if [ "$PREFERRED_PARTITION_NAME" = "system" ]; then
backup_file_list="$backup_file_list\n${file}"
else
backup_file_list="$backup_file_list\n${PREFERRED_PARTITION_NAME}/${file}"
fi
fi
done
for dir in $dir_list; do
if ! contains "$dir" "overlay"; then
chcon -h u:object_r:system_file:s0 "$PREFERRED_PARTITION/${dir}"
chmod 0755 "$PREFERRED_PARTITION/${dir}"
fi
done
rm -rf $UNZIP_FOLDER/*
}
install_core() {
set_progress 0.50
ui_print "- Installing Core GApps"
ui_print " "
extract_and_install "core" "$CORE_DIR" "Core"
rm -rf $CORE_DIR
}
install_gapps() {
set_progress 0.70
for g in $gapps_list; do
local gapps=""
if [ "$gapps_config" = "true" ]; then
if [ "$(get_file_prop $TMP/config.prop "$g")" -eq "1" ]; then
gapps="$g"
else
ui_print "- Skipping $g"
fi
else
gapps="$g"
fi
if [ -n "$gapps" ]; then
ui_print "- Installing $gapps"
extract_and_install "gapps" "$GAPPS_DIR" "$gapps"
fi
done
}
install_extra() {
set_progress 0.75
ui_print " "
for g in $extra_list; do
local extra=""
if [ "$(get_file_prop $TMP/config.prop "$g")" -eq "1" ]; then
extra="$g"
fi
if [ -n "$extra" ]; then
ui_print "- Installing $extra"
extract_and_install "extra" "$EXTRA_DIR" "$extra"
fi
done
}
sleep 0.5
set_progress 0.80
ui_print " "
ui_print "- Performing other tasks"
# Change context of /product/overlay dir
[ "$overlay_installed" = "true" ] && chcon -h u:object_r:vendor_overlay_file:s0
"$SYSTEM/$OVERLAY_DEST/overlay"
# Install flame.prop
rm -rf $SYSTEM/etc/flame.prop
cp -f $TMP/flame.prop $SYSTEM/etc/flame.prop
chcon -h u:object_r:system_file:s0 "$SYSTEM/etc/flame.prop"
chmod 0644 "$SYSTEM/etc/flame.prop"
exit_all;