-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.sh
115 lines (90 loc) · 3.15 KB
/
start.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
#!/bin/bash
# Version = "V2"
# Terminal colors
GREEN='\033[0;32m'
WHITE='\033[0;37m'
CYAN='\033[0;36m'
RED='\033[0;31m'
# Function to ensure venv is installed
install_venv_if_needed() {
if ! dpkg -s python3-venv >/dev/null 2>&1; then
echo -e "${CYAN}Installing python3-venv package..."
sudo apt update
sudo apt install python3-venv -y
fi
}
# Function to create and activate virtual environment
setup_virtualenv() {
# Install venv if necessary
install_venv_if_needed
# Create a virtual environment if it doesn't exist
if [ ! -d "venv" ]; then
echo -e "${CYAN}Creating Python virtual environment..."
python3 -m venv venv
fi
# Activate the virtual environment
echo -e "${CYAN}Activating virtual environment..."
source venv/bin/activate
}
# Function to start the HTTP server
start_http_server() {
sudo apt install nodejs -y
sudo apt install npm -y
npm install > /dev/null
npm start > /dev/null &
# Install required Python packages inside the virtual environment
pip3 install -r requirements.txt
python3 utils/bot.py &
python3 server.py &
}
# Function to start Cloudflared without authentication
start_cloudflared() {
echo -e "\n${RED}[${WHITE}-${RED}]${GREEN} Launching Cloudflared..."
# Launch Cloudflared for redirection
./.server/cloudflared tunnel --url http://localhost:25565 --logfile .server/.cld.log > /dev/null 2>&1 &
sleep 8
cldflr_url=$(grep -o 'https://[-0-9a-z]*\.trycloudflare.com' ".server/.cld.log" | head -n 1)
if [ -z "$cldflr_url" ]; then
echo -e "${RED}[${WHITE}--${RED}]${CYAN} Log file not found. Unable to retrieve Cloudflared URL."
else
echo -e "\n${GREEN}[${WHITE}+${GREEN}]${CYAN} Connect to the Minecraft server using the following link: ${WHITE}$cldflr_url"
# Send the message in markdown format to Discord
send_markdown_to_discord "$cldflr_url"
fi
}
# Function to send the content of a Markdown file to Discord via the /send endpoint
send_markdown_to_discord() {
local cldflr_url=$1
message="Connect to the Minecraft server using the following link: \`$cldflr_url\`"
# Send a POST request to the /send endpoint with the message in markdown format
curl -X POST http://localhost:8080/send \
-H "Content-Type: application/json" \
-d "{\"message\": \"$message\"}"
}
# Main function
main() {
HOST="localhost"
PORT="25565" # Change to your server's port
# Check Cloudflared installation
if [[ ! -e ".server/cloudflared" ]]; then
echo -e "${RED}[${WHITE}--${RED}]${CYAN} Cloudflared not installed correctly. Exiting."
exit 1
fi
# Set up the virtual environment
setup_virtualenv
# Start the HTTP server
start_http_server
# Start Cloudflared
start_cloudflared
make
# Start Mineflared-Firewall
./minefirewall &
make test
# Start the Minecraft server
echo "Minecraft server starting with Cloudflared IP."
echo "Open http://localhost:5000 for config page"
sleep 14s
java -Xmx1024M -Xms1024M -jar paper-1.21.1-110.jar nogui
}
# Execute the main function
main