evilsocket/dsploit — pull request #471 by Androguide (2014-02-11 20:43:17+00:00)
Title: Allow nightlies to be built & signed automatically via a cron job

@evilsocket, I don't know if it's ok for you to setup an android build environment on your server (in terms of storage/resources), but here's one way we could have nightlies built automatically.
I have an EC2 we could use if needed, you could then just setup a cron job on your server to wget the latest apk from my ec2 and serve it from there.

Anyways, here are my (long) commit messages :smile_cat: :

----------

##### _Allow nightlies to be built & signed automatically via a cron job (part 1 - gradle)_

This commit modifies dSploit's build.gradle to fetch the signing configuration from Bash environment variables.
The following environment variables need to be set (i.e: in ~/.bashrc) for the apk signing to work properly:
* __$KEYSTORE_PATH__ -> the absolute path where the keystore is located
* __$KEYSTORE_PWD__ -> the keystore passphrase
* __$KEYSTORE_ALIAS__ -> the keystore alias to use
* __$KEYSTORE_ALIAS_PWD__ -> the password of the alias defined in the previous variable
* __$NIGHTLIES_OUT_DIR__ -> the directory where the signed apk should be copied-over once the build has completed successfully (see next commit)

Gradle debug tasks don't require those, so we can keep working in Android Studio peacefully.
But the _assembleRelease_ gradle task will pick those up and sign the apk as defined in the environment variables.
e.g:
```bash
./gradlew assembleRelease
```

See next commit for the crontab and the build script.

----------

##### _Allow nightlies to be built & signed automatically via a cron job (part 2 - bash scripts/cron job)_

This commit adds 2 scripts: _setup-cronjob.sh_ & _nightly-build.sh_

__setup-cronjob.sh__:
This script is a wrapper used to generate a cronjob that will execute `nightly-build.sh` everyday at midnight.
The reason we use this script is to get the correct absolute path to the dsploit repository on the machine for the cronjob.

Alternatively, you can manually copy `nightly-build.sh` to /etc/cron.daily/ and modify its $DIR variable to point to the dsploit repo.

Another way would be to use crontab -e and add the following job:
```bash
00 00 * * * /bin/bash /path/to/dsploit/repo/nightly-build.sh
```

__nightly-build.sh__:
This script is used to build a signed version of the release flavor of dsploit.
It will:
* build the signed apk
* copy the signed apk to the directory the _$NIGHTLIES_OUT_DIR_ environment variable points to, renamed with a timestamp (i.e: _dSploit-2014-02-11-nightly.apk_)
* same as the above, but renamed _latest.apk_

The main purpose of this script is to be executed automatically by cron everyday, on a server where the _$NIGHTLIES_OUT_DIR_ points to an accessible location of its web server (i.e: that allows the download of the apk).
However, it can be used as a commodity script to manually build signed version of dsploit as well.