forked from cSploit/android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nightly-build.sh
executable file
·82 lines (65 loc) · 2.54 KB
/
nightly-build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
# Copyleft (C) 2014 The dSploit Project
#
# Author: Louis Teboul (a.k.a Androguide.fr)
#
# Licensed under the GNU GENERAL PUBLIC LICENSE version 3 'or later'
# The GNU General Public License is a free, copyleft license for software and other kinds of works.
# see the LICENSE file distributed with this work for a full version of the License.
CYAN="\\033[1;36m"
GREEN="\\033[1;32m"
YELLOW="\\E[33;44m"
RED="\\033[1;31m"
RESET="\\e[0m"
DATE=`date +%Y-%m-%d`
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
LOG_DIR="${DIR}/logs/"
MAX_DAYS="15"
PREVIOUS_COMMIT=$(cat "${LOG_DIR}last_commit")
die() {
echo -n -e "${RED}An error occured while building the nightly apk${RESET}\n"
echo -n -e "${RED}See $LOG_DIR/$DATE.log for more info\n${RESET}\n"
exec 3>&-
exit 1
}
jni_die() {
cat "${DIR}/dSploit/jni/build.log" >&3
die
}
if [ ! -d "${LOG_DIR}" ]; then
mkdir -p $LOG_DIR
fi
if [ -z "${NIGHTLIES_OUT_DIR}" ]; then
NIGHTLIES_OUT_DIR="${DIR}/dSploit/build"
fi
if [ ! -d "${NIGHTLIES_OUT_DIR}" ]; then
mkdir -p $NIGHTLIES_OUT_DIR
fi
exec 3> $LOG_DIR/$DATE.log
cd "${DIR}" >&3 2>&1 || die
echo -n -e "${YELLOW}Cleaning old files${RESET}\n" | tee >(cat - >&3)
LAST_APK=$(readlink "${NIGHTLIES_OUT_DIR}/dSploit-lastest.apk")
find $NIGHTLIES_OUT_DIR -type f -a -mtime +${MAX_DAYS} -a ! -name "${LAST_APK}" -exec rm -f "{}" \; >&3 2>&1
find $LOG_DIR -type f -a -mtime +${MAX_DAYS} -exec rm -f "{}" \; >&3 2>&1
echo -n -e "${CYAN}Syncing git repo...${RESET}\n" | tee >(cat - >&3)
git fetch --all && git reset --hard origin/master && git submodule update --init >&3 2>&1 || die
LAST_COMMIT=$(git rev-parse HEAD)
if [ -n "${PREVIOUS_COMMIT}" -a "${PREVIOUS_COMMIT}" == "${LAST_COMMIT}" ]; then
echo -n -e "${YELLOW}Nothing changed${RESET}" | tee >(cat - >&3)
echo -n -e "${GREEN}Done" | tee >(cat - >&3)
exit 0
fi
echo -n -e "${CYAN}Building dSploit...${RESET}\n" | tee >(cat - >&3)
rm -f $(find . -name "dSploit-release.apk" -type f)
oldpwd=$(pwd)
cd dSploit/jni >&3 2>&1 || die
./build.sh >&3 2>&1 || jni_die
cd "$oldpwd" >&3 2>&1 || die
./gradlew clean >&3 2>&1 || die
./gradlew assembleRelease >&3 2>&1 || die
echo -n -e "${GREEN}Copying signed apk to output directory${RESET}\n" | tee >(cat - >&3)
cp $(find . -name "dSploit-release.apk" -type f) $NIGHTLIES_OUT_DIR/dSploit-$LAST_COMMIT.apk >&3 2>&1 || die
ln -sf "dSploit-${LAST_COMMIT}.apk" $NIGHTLIES_OUT_DIR/dSploit-nightly.apk >&3 2>&1 || die
echo "${LAST_COMMIT}" > "${LOG_DIR}last_commit" 2>&3 || die
echo -n -e "${GREEN}Done.${RESET}\n\n" | tee >(cat - >&3)