Wanket / Open-GApps-Updater

MIT License
7 stars 1 forks source link

feature request: automatically check+download+install at user-set time #3

Open tukusejssirs opened 5 years ago

tukusejssirs commented 5 years ago

Thank you for this app. It’s very useful if one wants to keep the gapps latest.

However, in my opinion, the updates are available quite often. And even if would be once a year, I would like to automate it.

My proposal is the following:

Wanket commented 5 years ago

Android 9 may limit or postpone the background work of applications, so this may have strange consequences, such as restarting in Recovery during the day, but not at 2 am. Also, sdk 26+ restricts the launch of a background task after the start of Android, so notification after updating OpenGapps by conventional means is impossible. https://developer.android.com/about/versions/oreo/background

tukusejssirs commented 5 years ago

I did it using Termux + Termux:Tasker + Tasker. Anyone who would like to do it like I did it, needs to install these three apps first.

Here is current version of the script. You can run it from Termux without need of Termux:Tasker or Tasker. These two apps are needed only for the the ‘cronjob’ part.

# This script can be used to check the latest version of OpenGApps, download latest version of them, automatically reboot to TWRP, install it and reboot back to Android again.

# It can be used in some kind of cronjob to make it fully automatic. I execute the script in Termux and via termux-tasker connect it to Tasker, in which I created a recurring task at 2am each day to execute this script.

# author:  Tukusej's Sirs
# version: 1.0
# date:    1 Feb 2019

# dependencies (Android):     termux termux-tasker tasker rooted_android su bash_shell
# dependencies (Termux/Bash): termux-sudo coreutils grep sed curl jq wget ncurses-utils

# TODO:
# - make it work without termux
# - create ogus_init.sh

#!/data/data/com.termux/files/usr/bin/bash
# Colour definitions
fdefault="\e[39m"  # Default format and colour
lred="\e[91m"      # Light red
lmagenta="\e[95m"  # Light magenta

echo -e "${lmagenta}Checking Open GApps configuration and version ...${fdefault}"
type=$(sudo cat /system/etc/g.prop | grep ro.addon.type | sed 's/^.*type=\(.*\)$/\1/' -)

if [[ $type == "gapps" ]]; then
    arch=$(sudo cat /system/etc/g.prop | grep arch | sed 's/^.*arch=\(.*\)$/\1/' -)
    sdk=$(sudo cat /system/etc/g.prop | grep sdk | sed 's/^.*sdk=\(.*\)$/\1/' -)
    platform=$(sudo cat /system/etc/g.prop | grep platform | sed 's/^.*platform=\(.*\)$/\1/' -)
    open_type=$(sudo cat /system/etc/g.prop | grep open_type | sed 's/^.*open_type=\(.*\)$/\1/' -)
    curVer=$(sudo cat /system/etc/g.prop | grep version | sed 's/^.*version=\(.*\)$/\1/' -)
    latVer=$(curl --silent "https://api.github.com/repos/opengapps/arm64/releases/latest" | jq -r .tag_name)

    if [[ $curVer < $latVer ]]; then
        echo -e "${lmagenta}Found newer version ($latVer).\nDownloading ...${fdefault}"
        wget -q -O /storage/emulated/0/dls/update.zip https://github.com/opengapps/$arch/releases/download/$latVer/open_gapps-$arch-$platform-$open_type-$latVer.zip

        echo -e "${lmagenta}Download complete.\nCreating Open Recovery Script and rebooting ...${fdefault}"
        # src: https://android.stackexchange.com/questions/67622/shell-script-to-reboot-into-recovery-and-install-zip
        sudo bash -c "echo -e 'install /storage/emulated/0/dls/update.zip\nreboot' > /cache/recovery/openrecoveryscript"
        sudo reboot recovery
    elif [[ $curVer == $latVer ]]; then
        echo -e "${lmagenta}Open GApps version $latVer is already the latest version, no need to update it.${fdefault}"
    else
        echo -e "${lred}ERROR: Something has happened: current and latest version cannot be compared.\n\ncurrent version = $curVer\nlatest version  = $latVer${fdefault}"
        exit 1
    fi
else
    echo -e "${lred}ERROR: This script only updates Open GApps. On current system, the Open GApps are not installed.${fdefault}"
    exit 2
fi

Those who would like to use this script needs to install some dependencies and do some other stuff. Everything besides installing the three apps and creating a Tasker profile is in the ogus_init.sh.

The Tasker profile is in ogus_cron.prf.xml. Instructions of how to import the profile into Tasker are located at the end of the ogus_init.sh.

Latest version of the files are located here.

I do know that the script is not the best, it would use of some optimalisation and improvemnt. If anyone has any suggestions that would/could improve it, feel free to open an issue. Thanks. :)

Edit: I have just updated the script to reflect the change to SourceForge. Latest version of the files are still located here.