Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tukusejssirs opened this issue Jan 9, 2019 · 2 comments

Comments

@tukusejssirs
Copy link

tukusejssirs commented Jan 9, 2019

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:

  • allow users to set a time, when the update availability check is to be done (in addition to the frequency of checks, which we can do right now); e.g. I’d like to set it to daily check at 2am;

  • when the time comes, check if there is update available; if yes download it;

  • when the file is downloaded, automatically reboot and install it;

  • after installation boot up the system and add a notification that OpenGapps version XXX was installed.

@Wanket
Copy link
Owner

Wanket commented Jan 29, 2019

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
Copy link
Author

tukusejssirs commented Feb 2, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants