-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbeef-installer.sh
263 lines (200 loc) · 7.3 KB
/
beef-installer.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#!/data/data/com.termux/files/usr/bin/bash
############################################
# ANSI variables
# ==========================================
############################################
# ANSI styles
NORMAL="\e[0m"
BOLD="\e[1m"
FAINT="\e[2m"
ITALIC="\e[3m"
UNDERLINE="\e[4m"
############################################
# ANSI Foregroud Colors
BLACK="\e[30m"
RED="\e[31m"
GREEN="\e[32m"
YELLOW="\e[33m"
BLUE="\e[34m"
PURPLE="\e[35m"
CYAN="\e[36m"
LIGHT_GRAY="\e[37m"
############################################
# ANSI Background Colors
BG_BLACK="\e[40m"
BG_RED="\e[41m"
BG_GREEN="\e[42m"
BG_YELLOW="\e[43m"
BG_BLUE="\e[44m"
BG_PURPLE="\e[45m"
BG_CYAN="\e[46m"
BG_LIGHT_GRAY="\e[47m"
# ========= end of ANSI variables =========
###########################################
# Unicode variables
# =========================================
TICK="\u2713"
CROSS="\u274c"
# ======== end of Unicode variables =======
###########################################
# Global variables
# =========================================
###########################################
# dirs and files
curr_dir="$(eval pwd)"
beef_dir="${PREFIX}/opt/beef"
log_file=".beef-installer-logs"
repo_link="https://github.com/beefproject/beef.git"
###########################################
# beef authentication
beefuser="beefroot"
beefpasswd="toor"
# ======== end of Global variables ========
###########################################
# Functions
# =========================================
###########################################
# prints banner on the screen
banner(){
clear
echo -e "${CYAN}"
echo -e "██████╗ ███████╗███████╗███████╗"
echo -e "██╔══██╗██╔════╝██╔════╝██╔════╝"
echo -e "██████╔╝█████╗ █████╗ █████╗"
echo -e "██╔══██╗██╔══╝ ██╔══╝ ██╔══╝"
echo -e "██████╔╝███████╗███████╗██║"
echo -e "╚═════╝ ╚══════╝╚══════╝╚═╝"
echo -e "${NORMAL}${PURPLE}"
echo -e "╦┌┐┌┌─┐┌┬┐┌─┐┬ ┬ ┌─┐┬─┐"
echo -e "║│││└─┐ │ ├─┤│ │ ├┤ ├┬┘"
echo -e "╩┘└┘└─┘ ┴ ┴ ┴┴─┘┴─┘└─┘┴└─"
echo -e "${NORMAL}"
echo -e "================================================"
echo -e "Script by ${GREEN}dmdhrumilmistry${NORMAL}"
echo -e "================================================\n\n"
}
###########################################
# checks for return value and prints
# message according
check_result(){
local msg_succ=$1
local msg_err=$2
local status=$3
if [ $status != 0 ]; then
print_err "$msg_err"
exit 1
else
print_success "$msg_succ"
fi
}
###########################################
# prints info message
print_info(){
local message=$1
if [ "$message" != "" ]; then
echo -e "${BOLD}${YELLOW}[*] ${message}${NORMAL}"
fi
}
###########################################
# prints error message
print_err(){
local message=$1
if [ "$message" != "" ]; then
echo -e "${BOLD}${RED}[${CROSS}] ${message}${NORMAL}"
fi
}
###########################################
# prints successs message
print_success(){
local message=$1
if [ "$message" != "" ]; then
echo -e "${BOLD}${GREEN}[${TICK}] ${message}${NORMAL}"
fi
}
###########################################
# to install requirements
install_reqs(){
local packages=("python" "python2" "ruby" "git" "wget" "curl" "nano" "gnupg" "libiconv" "pkg-config" "clang" "make" "libffi" "libyaml" "libxslt" "bison" "espeak" "zlib" "zlib-static" "postgresql" "libpcap" "libpcap-static" "libxslt-static" "libxml2" "libxml2-static" "libcurl" "libcurl-static" "libtool" "liblzma" "patch" "lzlib" "cmake" "build-essential" "openssl" "sqlite" "autoconf" "automake" "nodejs")
# log time
echo -e "\n\n" >> $log_file
date >> $log_file
for package in "${packages[@]}"; do
print_info "Installing $package package."
# log package
echo "Installing $package package." >> $log_file
apt install $package -y >> $log_file 2>>$log_file
echo -e "\n" >> $log_file
check_result "$package installed successfully." "$package installation failed! Exiting." $?
done
}
###########################################
# Download files from internet using wget
download_files(){
local files=("https://raw.githubusercontent.com/dmdhrumilmistry/TermuxScripts/main/Installation/Beef/files/Gemfile" "https://raw.githubusercontent.com/dmdhrumilmistry/TermuxScripts/main/Installation/Beef/files/config.yaml")
for file in "${files[@]}"; do
wget $file >> $log_file 2>>$log_file
check_result "${file} downloaded successfully" "Failed to download file ${https://raw.githubusercontent.com/dmdhrumilmistry/TermuxScripts/beef-installer/Installation/Beef/files/Gemfile}" $?
done
}
###########################################
# clone Beef Repo
clone_repo(){
if [ -d "${beef_dir}" ]; then
print_info "${beef_dir} found. Deleting and creating new directory"
rm -rf $beef_dir
fi
print_info "Creating new ${beef_dir} directory"
mkdir -p $beef_dir
print_info "Cloning beef project" "Falied to clone Beef! Exiting." $?
git clone $repo_link $beef_dir --depth=1 >> $log_file 2>>$log_file
check_result "Beef Cloned successfully." "Beef Cloned successfully." $?
}
###########################################
# installs ruby gems
install_gems(){
cd $beef_dir
print_info "Installing Required Gems"
gem install bundler
gem install nokogiri -- --use-system-libraries --with-xml2-config=/data/data/com.termux/files/usr/bin/xml2-config --with-xml2-include=/data/data/com.termux/files/usr/include/libxml2
check_result "Required Gems installed successfully." "Failed to install required gems." $?
print_info "Removing and Downloading Gemfile & config.yaml files"
rm -f Gemfile
rm -f config.yaml
download_files
if [ -f "${beef_dir}/Gemfile" ]; then
print_info "Beef Gemfile found. installing gems..."
# try `bundle install` if bundler install fails
bundler install
check_result "Beef Gems installed successfully" "Falied to install gems! Exiting." $?
cd $curr_dir
else
print_err "Gemfile is missing. Cannot proceed further. Exiting!!"
exit 1
fi
}
###########################################
# configure and install beef
install_beef(){
install_gems
print_info "${beef_dir} contains beef executable"
print_info "default username : ${beefuser}"
print_info "default passwd : ${beefpasswd}"
}
# ======== end of functions ==============
##############################################
# Start Script
# exit script if any error occurs
# set -e
# print banner
banner
# install requirements
print_info "Installing Requirements...."
install_reqs
echo -e "\n"
print_info "Downloading Beef...."
clone_repo
echo -e "\n"
print_info "Installing Beef..."
install_beef
exit 0
# =========== end of start script ============