[Android] darjwx:
A few months ago I thought about the possibility of making my own set of scripts to automatically turn my pc on, sync and build a rom a specific day each week. And that is what I will be explained here. What scripts I am using, why, and how it all is configured. The scripts are not perfect, so feel free to post any suggestions or make a pull request if you want.

Thanks.​

First the basics

We will be using a script that will sync, build and upload the resulting file. We will be using also two different scripts to wake up and turn the pc off.

One important tool here that makes all this work is cron. But what is cron?

"Cron is the name of a program that enables unix users to execute commands or

scripts (groups of commands) automatically at a specified time/date.

Cron is a daemon, which means that it only needs to be started once, and will

lay dormant until it is required."

Cron, configured through what we call a crontab, will be the tool we will use to run the scripts at a specific time.

Now. How do we wake up the pc? The rtc alarm will help us with that.

This needs bios support. This guide is more orientated to the scripts so I won't add here all the instructions. You can follow what is wrote in this page to know more about rtc alarm: rtc-alarm.

If you need help with this, feel free to ask here. I will help if I can.

Crontab

To lunch a crontab, open a terminal and run:

crontab -e

If you want to lunch a crontab for the user root do:

sudo crontab -e

Both files are independant. That means if you add a script in the normal crontab, It won't show up in the other crontab.

Crontab options

A crontab is just a text file where you write the commands it will run in a specific time in the future.

Crontab syntax is what follows:

1 2 3 4 5 /source/directory/script.sh

1: minutes (0-59)

2: hours (0-23, 0 = midnight)

3: days (1-31)

4: month (1-12)

5: day of the week (0-6, 0 = Sunday)

The last part is the command or the file you want to execute.

You can use also wildcards (*) that mean every day, month, hour...

A few examples:

00 14 1 * * /source/directory/script.sh

This command will run each day 1 of every month at 2:00 pm

45 11 * * 0 /source/directory/script.sh

This command will run each Sunday of every week at 11:45 am

If you want to know more about cron you can visit this page. Is a more detailed version of what I just explained here: cron daemon

Scripts

BuildBot

Source

This script handles the sync, build and upload process. It is a minimal version of the script I use daily, without fancy menus.

- Settings:

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:
export USER=

Add to the PATH the directory where the commands are. For example, if you have the repo command in a specific directory, add it there. This is needed to make the script work with cron.

Add to USER your username. Otherwise cron won't work.

WORKING_DIR=
ROM=
MAKE=
DEVICE=
BUILDTYPE=
VARIANT=
THREADS=
CLEAN=
UPLOAD=

WORKING_DIR: directory where the rom source is located

ROM: rom you are building

MAKE: command the rom uses to start the compilation. Normally bacon or the name of the rom.

DEVICE: the device you are building for.

BUILDTYPE: Name you want to give to your build. This may not work with all roms.

VARIANT: user, userdebug or eng.

THREADS: Threads you want to use for building.

CLEAN: If you want to clean or you prefer to do a dirty compilation.

UPLOAD: If you want to upload the resulting file or not.

PROTOCOL=""
HOST=""
USER=""
PASS=""
LOCATION=""
FILE=""

PROTOCOL: ftp or sftp

HOST: where you are uploading your file.

USER: your username

PASS: your password

LOCATION: route to the file

FILE: name of the file. You can use wildcards to make it more generic. For example, CARBON*.zip will upload all the files that start with CARBON and are zip files.

wakeup

Source

This simple script will set a rtc alarm to wake up the computer.

sh -c "echo 0 > /sys/class/rtc/rtc0/wakealarm"

Clean the set alarms

sh -c "echo `date '+%s' -d '+ 168 hours'` > /sys/class/rtc/rtc0/wakealarm"

Sets the next alarm. That command will add an alarm 168 h in the future. You can also use minutes or exact days. Check this page for more information: rtc-alarm

shutdown

Source

This script will just turn the computer off.

shutdown -h now

SETUP

So now that we know what cron is and how to use it, here is my setup that runs every Sunday at 11:10 am.

Scripts

Just configure the options in the BuildBot and choose when you want the rtc alarm.

I have the BuildBot in home/darjwx/bin.

I have shutdown and wakeup in usr/local/bin.

RTC alarm

My RTC alarm is set 168h in the future. This is a tricky part, and maybe it could be done in a different way, but this work for me.

The wakeup script will run every Sunday at 11:00 am, and The next Sunday is exactly 168h away.

Crontab

-crontab with normal access

10 11 * * 0 /bin/bash /home/darjwx/bin/BuildBot.sh

Every Sunday at 11:10 am BuildBot will be executed.

-user root crontab

00 11 * * 0 /bin/bash /usr/local/bin/wakeup.sh
30 12 * * 0 /bin/bash /usr/local/bin/shutdown.sh

-wakeup will run each Sunday at 11:00 am

- shutdown will run every Sunday at 12:30 pm

Take in consideration your specs and your average build time to choose when the shutdown script will run.

I am using this scripts in my hdd to build an arm64 target. It is slower than my arm device on a ssd so I decided to use 1h and a half to be sure.

And that is all for now. Feel free to post any suggestions or doubts you have. If thanks to this thread I can improve my scripts, I will be more than happy.

Thanks, Darío.

XDA:DevDB Information

Automate the building process with scripts and cron, Tool/Utility for the Chef Central

Contributors

darjwx

Source Code: https://github.com/darjwx/android_shell_scripts

Version Information

Status: Testing

Created 2017-09-03

Last Updated 2017-09-03