Skip to content

Commit ffc464b

Browse files
authored
feat: flags in install.sh for silent installation (#1766)
* feat: flags in install.sh for silent installation * chore: revise install.sh script * Update install.sh
1 parent 3232781 commit ffc464b

File tree

1 file changed

+140
-68
lines changed

1 file changed

+140
-68
lines changed

install.sh

Lines changed: 140 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,77 @@
11
#!/usr/bin/env bash
22

3+
print_help() {
4+
cat <<EOF
5+
Usage: $0 [-s] -t <type> [-u <webuser>] [-p <password>]
6+
7+
Options:
8+
-s Suppress installation confirmation prompt (sets myQST=y)
9+
-t <type> Type of installation (required if -s is used):
10+
h - hive (requires -u and -p)
11+
s - sensor (no user/pass required)
12+
l - llm (requires -u and -p)
13+
i - mini (requires -u and -p)
14+
m - mobile (no user/pass required)
15+
t - tarpit (requires -u and -p)
16+
-u <webuser> Web interface username (required for h/l/i/t)
17+
-p <password> Web interface password (required for h/l/i/t)
18+
-h Show this help message
19+
EOF
20+
exit 1
21+
}
22+
23+
validate_type() {
24+
[[ "$myTPOT_TYPE" =~ ^[hslimtHSLIMT]$ ]] || {
25+
echo "Invalid installation type: $myTPOT_TYPE"
26+
print_help
27+
}
28+
}
29+
30+
# Defaults
31+
myQST=""
32+
myTPOT_TYPE=""
33+
myWEB_USER=""
34+
myWEB_PW=""
35+
36+
while getopts ":st:u:p:h" opt; do
37+
case "$opt" in
38+
s)
39+
myQST="y"
40+
;;
41+
t)
42+
myTPOT_TYPE="${OPTARG,,}"
43+
validate_type
44+
;;
45+
u)
46+
export myWEB_USER="${OPTARG}"
47+
;;
48+
p)
49+
export myWEB_PW="${OPTARG}"
50+
;;
51+
h|\?)
52+
print_help
53+
;;
54+
:)
55+
echo "Option -${OPTARG} requires an argument."
56+
print_help
57+
;;
58+
esac
59+
done
60+
61+
# -s requires -t
62+
if [[ "$myQST" == "y" && -z "$myTPOT_TYPE" ]]; then
63+
echo "Error: -t is required when using -s to suppress interaction."
64+
print_help
65+
fi
66+
67+
# Determine if user/pass are required based on install type
68+
if [[ "$myTPOT_TYPE" =~ ^[hlit]$ ]]; then
69+
[[ -n "$myWEB_USER" && -n "$myWEB_PW" ]] || {
70+
echo "Error: -u and -p are required for installation type '$myTPOT_TYPE'."
71+
print_help
72+
}
73+
fi
74+
375
myINSTALL_NOTIFICATION="### Now installing required packages ..."
476
myUSER=$(whoami)
577
myTPOT_CONF_FILE="/home/${myUSER}/tpotce/.env"
@@ -43,12 +115,13 @@ echo "$myINSTALLER"
43115
echo
44116
echo
45117
echo "### This script will now install T-Pot and all of its dependencies."
46-
while [ "${myQST}" != "y" ] && [ "${myQST}" != "n" ];
47-
do
118+
if [[ -z "$myQST" ]]; then
119+
while [ "${myQST}" != "y" ] && [ "${myQST}" != "n" ]; do
48120
echo
49121
read -p "### Install? (y/n) " myQST
50122
echo
51123
done
124+
fi
52125
if [ "${myQST}" = "n" ];
53126
then
54127
echo
@@ -183,7 +256,10 @@ echo "### Feed data endlessly to attackers, bots and scanners."
183256
echo "### Also runs a Denial of Service Honeypot (ddospot)."
184257
echo
185258
while true; do
186-
read -p "### Install Type? (h/s/l/i/m/t) " myTPOT_TYPE
259+
if [[ -z "$myTPOT_TYPE" ]]; then
260+
read -p "### Install Type? (h/s/l/i/m/t) " myTPOT_TYPE
261+
fi
262+
187263
case "${myTPOT_TYPE}" in
188264
h|H)
189265
echo
@@ -234,75 +310,71 @@ done
234310
if [ "${myTPOT_TYPE}" == "HIVE" ];
235311
# If T-Pot Type is HIVE ask for WebUI username and password
236312
then
237-
# Preparing web user for T-Pot
238-
echo
239-
echo "### T-Pot User Configuration ..."
240-
echo
241-
# Asking for web user name
242-
myWEB_USER=""
243-
while [ 1 != 2 ];
244-
do
245-
myOK=""
246-
read -rp "### Enter your web user name: " myWEB_USER
247-
myWEB_USER=$(echo $myWEB_USER | tr -cd "[:alnum:]_.-")
248-
echo "### Your username is: ${myWEB_USER}"
249-
while [[ ! "${myOK}" =~ [YyNn] ]];
250-
do
251-
read -rp "### Is this correct? (y/n) " myOK
252-
done
253-
if [[ "${myOK}" =~ [Yy] ]] && [ "$myWEB_USER" != "" ];
254-
then
255-
break
256-
else
257-
echo
258-
fi
259-
done
313+
# Preparing web user for T-Pot
314+
echo
315+
echo "### T-Pot User Configuration ..."
316+
echo
317+
# Asking for web user name
318+
if [[ -z "$myWEB_USER" ]]; then
319+
myWEB_USER=""
320+
while [ 1 != 2 ]; do
321+
myOK=""
322+
read -rp "### Enter your web user name: " myWEB_USER
323+
myWEB_USER=$(echo $myWEB_USER | tr -cd "[:alnum:]_.-")
324+
echo "### Your username is: ${myWEB_USER}"
325+
while [[ ! "${myOK}" =~ [YyNn] ]]; do
326+
read -rp "### Is this correct? (y/n) " myOK
327+
done
328+
if [[ "${myOK}" =~ [Yy] ]] && [ "$myWEB_USER" != "" ]; then
329+
break
330+
else
331+
echo
332+
fi
333+
done
334+
fi
335+
336+
# Asking for web user password
337+
if [[ -z "$myWEB_PW" ]]; then
338+
myWEB_PW="pass1"
339+
myWEB_PW2="pass2"
340+
mySECURE=0
341+
myOK=""
342+
while [ "${myWEB_PW}" != "${myWEB_PW2}" ] && [ "${mySECURE}" == "0" ]; do
343+
echo
344+
while [ "${myWEB_PW}" == "pass1" ] || [ "${myWEB_PW}" == "" ]; do
345+
read -rsp "### Enter password for your web user: " myWEB_PW
346+
echo
347+
done
348+
read -rsp "### Repeat password you your web user: " myWEB_PW2
349+
echo
350+
if [ "${myWEB_PW}" != "${myWEB_PW2}" ]; then
351+
echo "### Passwords do not match."
352+
myWEB_PW="pass1"
353+
myWEB_PW2="pass2"
354+
fi
355+
mySECURE=$(printf "%s" "$myWEB_PW" | /usr/sbin/cracklib-check | grep -c "OK")
356+
if [ "$mySECURE" == "0" ] && [ "$myWEB_PW" == "$myWEB_PW2" ]; then
357+
while [[ ! "${myOK}" =~ [YyNn] ]]; do
358+
read -rp "### Keep insecure password? (y/n) " myOK
359+
done
360+
if [[ "${myOK}" =~ [Nn] ]] || [ "$myWEB_PW" == "" ]; then
361+
myWEB_PW="pass1"
362+
myWEB_PW2="pass2"
363+
mySECURE=0
364+
myOK=""
365+
fi
366+
fi
367+
done
368+
fi
260369

261-
# Asking for web user password
262-
myWEB_PW="pass1"
263-
myWEB_PW2="pass2"
264-
mySECURE=0
265-
myOK=""
266-
while [ "${myWEB_PW}" != "${myWEB_PW2}" ] && [ "${mySECURE}" == "0" ]
267-
do
268-
echo
269-
while [ "${myWEB_PW}" == "pass1" ] || [ "${myWEB_PW}" == "" ]
270-
do
271-
read -rsp "### Enter password for your web user: " myWEB_PW
272-
echo
273-
done
274-
read -rsp "### Repeat password you your web user: " myWEB_PW2
275-
echo
276-
if [ "${myWEB_PW}" != "${myWEB_PW2}" ];
277-
then
278-
echo "### Passwords do not match."
279-
myWEB_PW="pass1"
280-
myWEB_PW2="pass2"
281-
fi
282-
mySECURE=$(printf "%s" "$myWEB_PW" | /usr/sbin/cracklib-check | grep -c "OK")
283-
if [ "$mySECURE" == "0" ] && [ "$myWEB_PW" == "$myWEB_PW2" ];
284-
then
285-
while [[ ! "${myOK}" =~ [YyNn] ]];
286-
do
287-
read -rp "### Keep insecure password? (y/n) " myOK
288-
done
289-
if [[ "${myOK}" =~ [Nn] ]] || [ "$myWEB_PW" == "" ];
290-
then
291-
myWEB_PW="pass1"
292-
myWEB_PW2="pass2"
293-
mySECURE=0
294-
myOK=""
295-
fi
296-
fi
297-
done
298370

299-
# Write username and password to T-Pot config file
300-
echo "### Creating base64 encoded htpasswd username and password for T-Pot config file: ${myTPOT_CONF_FILE}"
301-
myWEB_USER_ENC=$(htpasswd -b -n "${myWEB_USER}" "${myWEB_PW}")
371+
# Write username and password to T-Pot config file
372+
echo "### Creating base64 encoded htpasswd username and password for T-Pot config file: ${myTPOT_CONF_FILE}"
373+
myWEB_USER_ENC=$(htpasswd -b -n "${myWEB_USER}" "${myWEB_PW}")
302374
myWEB_USER_ENC_B64=$(echo -n "${myWEB_USER_ENC}" | base64 -w0)
303375

304-
echo
305-
sed -i "s|^WEB_USER=.*|WEB_USER=${myWEB_USER_ENC_B64}|" ${myTPOT_CONF_FILE}
376+
echo
377+
sed -i "s|^WEB_USER=.*|WEB_USER=${myWEB_USER_ENC_B64}|" ${myTPOT_CONF_FILE}
306378
fi
307379

308380
# Pull docker images

0 commit comments

Comments
 (0)