forked from RikoDEV/pterodactyl-graalvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
107 lines (93 loc) · 4.45 KB
/
Copy pathentrypoint.sh
File metadata and controls
107 lines (93 loc) · 4.45 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
#!/bin/bash
TZ=${TZ:-UTC}
export TZ
INTERNAL_IP=$(ip route get 1 | awk '{print $(NF-2);exit}')
export INTERNAL_IP
cd /home/container || exit 1
sync
printf "\033[1m\033[33mcontainer@pterodactyl~ \033[0mjava -version\n"
java -version
# Helper: check if NUMA is usable
check_numa() {
if /usr/local/bin/check-numa 2>/dev/null; then
echo "-XX:+UseNUMA"
else
echo ""
fi
}
# 2. ---------- Malware Scan ----------
if [[ "${MALWARE_SCAN}" == "1" ]]; then
if [[ ! -f "/MCAntiMalware.jar" ]]; then
echo -e "\033[1m\033[33mcontainer@pterodactyl~ \033[0mMalware scanning jar not found, skipping..."
else
echo -e "\033[1m\033[33mcontainer@pterodactyl~ \033[0mScanning for malware... (This may take a while)"
java -jar /MCAntiMalware.jar --scanDirectory . --singleScan true --disableAutoUpdate true
if [ $? -eq 0 ]; then
echo -e "\033[1m\033[33mcontainer@pterodactyl~ \033[0mMalware scan has passed"
else
echo -e "\033[1m\033[33mcontainer@pterodactyl~ \033[0mMalware scan has failed"
exit 1
fi
fi
else
echo -e "\033[1m\033[33mcontainer@pterodactyl~ \033[0mSkipping malware scan..."
fi
# 3. ---------- Automatic Updating (Leaf & MCJars) ----------
if [[ "${AUTOMATIC_UPDATING}" == "1" ]]; then
if [[ "${SOFTWARE}" == "LEAF" ]]; then
echo -e "\033[1m\033[33mcontainer@pterodactyl~ \033[0mChecking for Leaf updates..."
MC_VERSION=""
CURRENT_BUILD=""
if [ -f "version_history.json" ]; then
RAW_VERSION=$(jq -r '.currentVersion // empty' version_history.json 2>/dev/null)
if [[ -n "$RAW_VERSION" ]]; then
MC_VERSION=$(echo "$RAW_VERSION" | sed -n 's/^\([0-9]\+\.[0-9]\+\.[0-9]\+\)-.*$/\1/p')
CURRENT_BUILD=$(echo "$RAW_VERSION" | sed -n 's/^[0-9]\+\.[0-9]\+\.[0-9]\+-\([0-9]\+\)-.*$/\1/p')
fi
fi
if [[ -z "$MC_VERSION" || -z "$CURRENT_BUILD" ]]; then
if [ -f "server.jar" ]; then
MANIFEST_VERSION=$(unzip -p server.jar META-INF/MANIFEST.MF 2>/dev/null | grep "Implementation-Version" | cut -d' ' -f2 | tr -d '\r')
if [[ -n "$MANIFEST_VERSION" ]]; then
MC_VERSION=$(echo "$MANIFEST_VERSION" | cut -d'-' -f1)
CURRENT_BUILD=$(echo "$MANIFEST_VERSION" | cut -d'-' -f2)
fi
fi
fi
if [[ -n "$MC_VERSION" ]]; then
API_RESPONSE=$(curl -s "https://api.leafmc.one/v2/projects/leaf/versions/${MC_VERSION}")
LATEST_BUILD=$(echo "$API_RESPONSE" | jq -r '.builds | max // empty' 2>/dev/null)
if [[ -n "$LATEST_BUILD" && "$LATEST_BUILD" != "null" ]]; then
if [[ -z "$CURRENT_BUILD" || "$CURRENT_BUILD" == "null" || "$LATEST_BUILD" -gt "$CURRENT_BUILD" ]]; then
echo -e "\033[1m\033[33mcontainer@pterodactyl~ \033[0mNew Leaf build found (${LATEST_BUILD}), updating..."
DOWNLOAD_URL="https://api.leafmc.one/v2/projects/leaf/versions/${MC_VERSION}/builds/${LATEST_BUILD}/downloads/leaf-${MC_VERSION}-${LATEST_BUILD}.jar"
curl -s -o server.jar "$DOWNLOAD_URL"
fi
fi
fi
else
echo -e "\033[1m\033[33mcontainer@pterodactyl~ \033[0mChecking for MCJars updates..."
if [ -f "server.jar" ]; then
HASH=$(sha256sum server.jar | awk '{print $1}')
API_RESPONSE=$(curl -s "https://mcjars.app/api/v1/build/$HASH")
SUCCESS=$(echo "$API_RESPONSE" | jq -r '.success // false')
if [[ "$SUCCESS" == "true" ]]; then
LATEST_ID=$(echo "$API_RESPONSE" | jq -r '.latest.id')
if [[ $(echo "$API_RESPONSE" | jq -r '.build.id') != "$LATEST_ID" ]]; then
echo -e "\033[1m\033[33mcontainer@pterodactyl~ \033[0mUpdating to latest build (${LATEST_ID})..."
bash <(curl -s "https://mcjars.app/api/v1/script/$LATEST_ID/bash?echo=false")
fi
fi
fi
fi
fi
# 4. ---------- Startup Command Construction ----------
MODIFIED_STARTUP=$(echo -e "${STARTUP}" | sed -e 's/{{/${/g' -e 's/}}/}/g')
PARSED=$(eval echo -e "${MODIFIED_STARTUP}")
NUMA_FLAG=$(check_numa)
if [[ -n "$NUMA_FLAG" ]] && [[ ! "$PARSED" =~ "UseNUMA" ]]; then
PARSED=$(echo "$PARSED" | sed -E "s/(^| )java/& $NUMA_FLAG/")
fi
PARSED=$(echo "$PARSED" | tr -s ' ')
printf "\033[1m\033[33mcontainer@pterodactyl~ \033[0m%s\n" "$PARSED"
exec ${PARSED}