-
Notifications
You must be signed in to change notification settings - Fork 5
/
fastdl.sh
47 lines (38 loc) · 1.8 KB
/
fastdl.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
#!/bin/bash
HOME_URL="https://node.pterodactyl.io"
API_KEY="YOUR_GENERATED_API_KEY"
PTERODACTYL="/var/lib/pterodactyl/volumes/"
FASTDL="/var/www/fastdl"
inotifywait -m -e create --format="%w%f" $PTERODACTYL | while read -r line
do
URL="$HOME_URL/api/application/servers/?filter[uuid]=${line##*/}"
GAME=$(curl -s $URL \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-H "Accept: Application/vnd.pterodactyl.v1+json" \
| grep -oP '(?<=game )[^ ]*' | tail -1)
if [ -z "$GAME" ] || [ "$GAME" == "{{SRCDS_GAME}}" ]; then
GAME=$(curl -s $URL \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-H "Accept: Application/vnd.pterodactyl.v1+json" \
| grep -oP '"SRCDS_GAME":.*?[^\\]",' | perl -pe 's/"SRCDS_GAME"://; s/^"//; s/",$//')
fi
# echo "$(date +'%T') : [FASTDL] CURRENT GAME: $( [ -z $GAME ] && printf %s 'No game detected')" >> /var/log/pterodactyl/fastdl.log
if [ ! -z "$GAME" ]; then
echo "$(date +'%T') : [FASTDL] ${GAME} Detected" >> /var/log/pterodactyl/fastdl.log
ln -s "$line/${GAME}/" "$FASTDL/${line##*/}"
echo "$(date +'%T') : [FASTDL] Creating Symbolic Link: $FASTDL/${line##*/}" >> /var/log/pterodactyl/fastdl.log
chmod 750 "$line"
else
echo "$(date +'%T') : [FASTDL] Not Detected/Supported - Contact Scai#8477" >> /var/log/pterodactyl/fastdl.log
fi
done &
inotifywait -m -e delete --format="%w%f" $PTERODACTYL | while read -r line
do
if [ ! ${line##*/} == '%s' ]; then
echo "$(date +'%T') : [FASTDL] Deleting Symbolic Link: $FASTDL/${line##*/}" >> /var/log/pterodactyl/fastdl.log
rm -rf ${FASTDL}/${line##*/}
fi
done &
wait