-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·267 lines (229 loc) · 7.86 KB
/
setup.sh
File metadata and controls
executable file
·267 lines (229 loc) · 7.86 KB
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
264
265
266
267
#!/bin/bash
# CTF Tools Interactive Installer - Main Script
# Version 1.2.1 - Modular Edition
#
# This is the main entry point for the CTF Tools installer.
# It loads all modular components and starts the main menu system.
# Get the directory where this script is located
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Export for use in other scripts
export SCRIPT_DIR
# Check for core_functions directory in different locations
CORE_FUNCTIONS_DIR="$SCRIPT_DIR/core_functions"
if [[ ! -d "$CORE_FUNCTIONS_DIR" ]]; then
if [[ -d "/opt/autosetup/core_functions" ]]; then
CORE_FUNCTIONS_DIR="/opt/autosetup/core_functions"
elif [[ -d "/etc/autosetup/core_functions" ]]; then
CORE_FUNCTIONS_DIR="/etc/autosetup/core_functions"
elif [[ -d "/opt/ctftools/core_functions" ]]; then
CORE_FUNCTIONS_DIR="/opt/ctftools/core_functions"
elif [[ -d "/etc/ctftools/core_functions" ]]; then
CORE_FUNCTIONS_DIR="/etc/ctftools/core_functions"
fi
fi
export CORE_FUNCTIONS_DIR
# Check for menu_system directory in different locations
MENU_SYSTEM_DIR="$SCRIPT_DIR/menu_system"
if [[ ! -d "$MENU_SYSTEM_DIR" ]]; then
if [[ -d "/opt/autosetup/menu_system" ]]; then
MENU_SYSTEM_DIR="/opt/autosetup/menu_system"
elif [[ -d "/etc/autosetup/menu_system" ]]; then
MENU_SYSTEM_DIR="/etc/autosetup/menu_system"
elif [[ -d "/opt/ctftools/menu_system" ]]; then
MENU_SYSTEM_DIR="/opt/ctftools/menu_system"
elif [[ -d "/etc/ctftools/menu_system" ]]; then
MENU_SYSTEM_DIR="/etc/ctftools/menu_system"
fi
fi
export MENU_SYSTEM_DIR
# Source all core function modules
if [[ ! -f "$CORE_FUNCTIONS_DIR/colors_utils.sh" || ! -f "$CORE_FUNCTIONS_DIR/app_manager.sh" || ! -f "$CORE_FUNCTIONS_DIR/installer.sh" ]]; then
echo -e "\033[0;31mError: Required core function modules not found!\033[0m"
echo -e "\033[1;33mPlease make sure CTF Tools is properly installed.\033[0m"
echo -e "Searched in: $CORE_FUNCTIONS_DIR"
exit 1
fi
source "$CORE_FUNCTIONS_DIR/colors_utils.sh"
source "$CORE_FUNCTIONS_DIR/app_manager.sh"
source "$CORE_FUNCTIONS_DIR/installer.sh"
# Source all menu system modules
if [[ ! -f "$MENU_SYSTEM_DIR/main_menu.sh" || ! -f "$MENU_SYSTEM_DIR/install_menu.sh" ]]; then
echo -e "\033[0;31mError: Required menu system modules not found!\033[0m"
echo -e "\033[1;33mPlease make sure CTF Tools is properly installed.\033[0m"
echo -e "Searched in: $MENU_SYSTEM_DIR"
exit 1
fi
source "$MENU_SYSTEM_DIR/main_menu.sh"
source "$MENU_SYSTEM_DIR/install_menu.sh"
# Initialize the application
initialize_app() {
# Check if running as root first
check_root
# Check for updates (unless skipped)
if [[ "${SKIP_UPDATE_CHECK:-}" != "1" ]] && [[ "${1:-}" != "--no-update-check" ]]; then
check_for_updates
else
echo -e "${YELLOW}Skipping update check...${NC}"
fi
# Load applications from JSON
load_apps
# Initialize tool selections
init_selections
# Initialization complete - go straight to menu
}
# Main application entry point
main() {
# Initialize everything
initialize_app "$@"
# Start the main menu loop
main_menu_loop
}
# Handle script interruption gracefully
cleanup() {
echo ""
echo -e "${YELLOW}Installation interrupted by user.${NC}"
echo -e "${GREEN}Thank you for using CTF Tools!${NC}"
exit 130
}
# Set up signal handlers
trap cleanup SIGINT SIGTERM
# Error handling (disabled during installation to allow individual tool failures)
# set -e
handle_error() {
local line_number=$1
echo -e "${RED}An error occurred on line $line_number${NC}"
echo -e "${YELLOW}Please report this issue if it persists.${NC}"
exit 1
}
# trap 'handle_error $LINENO' ERR
# Dependency check
check_dependencies() {
local missing_deps=()
# Check for required commands
command -v jq >/dev/null 2>&1 || missing_deps+=("jq")
command -v curl >/dev/null 2>&1 || missing_deps+=("curl")
if [[ ${#missing_deps[@]} -gt 0 ]]; then
echo -e "${RED}Missing required dependencies:${NC}"
for dep in "${missing_deps[@]}"; do
echo -e " - $dep"
done
echo ""
echo -e "${YELLOW}Installing missing dependencies...${NC}"
sudo apt update && sudo apt install -y "${missing_deps[@]}"
if [[ $? -ne 0 ]]; then
echo -e "${RED}Failed to install dependencies. Please install them manually.${NC}"
exit 1
fi
echo -e "${GREEN}Dependencies installed successfully!${NC}"
sleep 1
fi
}
# Pre-flight checks
preflight_checks() {
echo -e "${YELLOW}Performing pre-flight checks...${NC}"
# Check dependencies
check_dependencies
# Get the directory where this script is located
local SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Load version number from file
if [[ -f "$SCRIPT_DIR/version" ]]; then
CURRENT_VERSION=$(cat "$SCRIPT_DIR/version")
elif [[ -f "/opt/autosetup/version" ]]; then
CURRENT_VERSION=$(cat "/opt/autosetup/version")
elif [[ -f "/etc/autosetup/version" ]]; then
CURRENT_VERSION=$(cat "/etc/autosetup/version")
elif [[ -f "/opt/ctftools/version" ]]; then
CURRENT_VERSION=$(cat "/opt/ctftools/version")
elif [[ -f "/etc/ctftools/version" ]]; then
CURRENT_VERSION=$(cat "/etc/ctftools/version")
else
CURRENT_VERSION="unknown"
fi
# Check if scripts directory exists
local SCRIPTS_DIR="$SCRIPT_DIR/scripts"
# Also check system installation paths as fallback
if [[ ! -d "$SCRIPTS_DIR" ]]; then
if [[ -d "/opt/autosetup/scripts" ]]; then
SCRIPTS_DIR="/opt/autosetup/scripts"
elif [[ -d "/etc/autosetup/scripts" ]]; then
SCRIPTS_DIR="/etc/autosetup/scripts"
elif [[ -d "/opt/ctftools/scripts" ]]; then
SCRIPTS_DIR="/opt/ctftools/scripts"
elif [[ -d "/etc/ctftools/scripts" ]]; then
SCRIPTS_DIR="/etc/ctftools/scripts"
fi
fi
if [[ ! -d "$SCRIPTS_DIR" ]]; then
echo -e "${RED}Error: scripts directory not found!${NC}"
echo -e "${YELLOW}Attempted locations:${NC}"
echo -e " - Script directory: $SCRIPTS_DIR"
echo -e " - System locations: /opt/autosetup/scripts, /etc/autosetup/scripts, /opt/ctftools/scripts, /etc/ctftools/scripts"
exit 1
fi
# Export the scripts directory path for use in other parts of the program
export SCRIPTS_DIR
echo -e "${GREEN}All checks passed!${NC}"
sleep 1
}
# Show startup banner
show_banner() {
clear
echo -e "${BLUE}===============================================${NC}"
echo -e "${BLUE} CTF Tools (autosetup) Installer ${NC}"
echo -e "${BLUE} Version ${CURRENT_VERSION} ${NC}"
echo -e "${BLUE}===============================================${NC}"
echo ""
echo -e "${GREEN}Welcome to the ultimate CTF tools installer!${NC}"
echo -e "${CYAN}This tool will help you set up a complete CTF environment.${NC}"
echo ""
sleep 0.5
}
# Show usage information
show_usage() {
echo "CTF Tools Interactive Installer v${CURRENT_VERSION}"
echo ""
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --no-update-check Skip the automatic update check"
echo " --web Start the web interface"
echo " --help, -h Show this help message"
echo ""
echo "Environment Variables:"
echo " SKIP_UPDATE_CHECK=1 Skip the automatic update check"
echo ""
}
# Handle command line arguments
handle_args() {
for arg in "$@"; do
case $arg in
--help|-h)
show_usage
exit 0
;;
--web)
sudo docker run --rm -p 8080:8080 -it --ulimit nofile=65536:65536 securecodebox/bodgeit:latest
exit 0
;;
--no-update-check)
# This is handled in initialize_app
;;
*)
echo -e "${RED}Unknown option: $arg${NC}"
echo "Use --help for usage information."
exit 1
;;
esac
done
}
# Entry point with full initialization
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
# Handle command line arguments
handle_args "$@"
# Show banner
show_banner
# Run pre-flight checks
preflight_checks
# Start main application
main "$@"
fi