This repository has been archived by the owner on Aug 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ut4dedicated.sh
179 lines (150 loc) · 4.4 KB
/
ut4dedicated.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
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
#!/bin/bash
# Script Variables
USER="CHANGE"
DIRECTORY=/opt/ut4/update
TYPE="install"
LINK="none"
FILE="none"
# Server Variables
SERVERNAME="Unreal Server"
MOTD="Welcome"
PORT=7777
MAP="DM-DeckTest"
GAMETYPE="Duel"
# Don't change
EXEDIRECTORY=$DIRECTORY/LinuxServer/Engine/Binaries/Linux
CONDIRECTORY=$DIRECTORY/LinuxServer/UnrealTournament/Saved/Config/LinuxServer
# Check Variables
## FILE & LINK
CLINK=false
if [[ "$FILE" != "none" ]]; then
# Check if the file is correct
if [[ -f $FILE ]]; then
CLINK=true
else
echo "The FILE you entered is invalid"
fi
fi
if [[ "$CLINK" == false ]]; then
# Check if LINK is different
if [[ "$LINK" == "none" ]]; then
echo "You must change the variable LINK"
exit 1
else
# Checking Link ( soon )
CLINK=true
fi
fi
FILENAME=$(basename $LINK)
# Check TYPE
if [[ $TYPE == "install" ]]; then
echo "*** Instalation of Unreal Tournament 4 Dedicated Server ***"
elif [[ $TYPE == "update" ]]; then
echo "*** Update of Unreal Tournament 4 Dedicated Server ***"
else
echo "Unknown type [ install / update ]"
exit 1
fi
# Check User Exist
## Check user
id $USER > /dev/null 2> /dev/null
if [ $? -eq 1 ];
then
echo "User not exist"
exit 1
fi
## Check isroot ?
if [ "$UID" -ne "0" ];
then
VARROOT=""
else
VARROOT="sudo -u $USER"
fi
# Check Directory Exist
if [ ! -d $DIRECTORY ];
then
echo "Directory not exist"
exit 1
fi
# Check if user got correct right on the Directory
$VARROOT test -w $DIRECTORY
if [[ $? == "1" ]]; then
echo 'User cant write into the directory.'
exit 1
fi
# Check unzip installed
if [ $(which unzip | wc -l) -eq 0 ];
then
echo "Installer le paquet 'unzip'."
echo "sudo apt-get install unzip"
exit 1
fi
# Actions
## Download
if [[ "$LINK" != "none" ]]; then
$VARROOT wget -P $DIRECTORY $LINK
fi
## If update then delete directory and kill proc
if [[ "$TYPE" == "update" ]]; then
echo "Pausing the cron during update..."
$VARROOT touch $DIRECTORY/cron.save
$VARROOT crontab -l > $DIRECTORY/cron.save
$VARROOT crontab -r
echo "Killing process..."
$VARROOT pidof UE4Server > /dev/null
$VARROOT kill $?
echo "Removing directory..."
$VARROOT rm -R $DIRECTORY/LinuxServer
fi
## Unzipping
echo 'Unzipping archive...'
if [[ "$LINK" != "none" ]]; then
$VARROOT unzip -q $DIRECTORY/$FILENAME -d $DIRECTORY
else
$VARROOT unzip -q $FILE -d $DIRECTORY
fi
## Right 1
echo 'Settings rights...'
$VARROOT chmod +x $EXEDIRECTORY/UE4Server
## First Launch that will crash
echo 'First Launch'
$VARROOT $EXEDIRECTORY/UE4Server UnrealTournament DM-DeckTest -log > /dev/null
echo 'First launch finish'
if [[ "$TYPE" == "install" ]]; then
echo "Creation of configs files"
# Creation of config's files
$VARROOT mkdir $DIRECTORY/Configs
$VARROOT touch $DIRECTORY/Configs/Engine.ini
$VARROOT touch $DIRECTORY/Configs/Game.ini
$VARROOT touch $DIRECTORY/launch.sh
$VARROOT touch $DIRECTORY/reboot.sh
# Engine.ini
printf "[/Script/UnrealTournament.UTGameEngine]\n bFirstRun = False\n" >> $DIRECTORY/Configs/Engine.ini
# Game.ini
printf "[/Script/UnrealTournament.UTGameState]\n" >> $DIRECTORY/Configs/Game.ini
printf "ServerName=%s\n" "$SERVERNAME" >> $DIRECTORY/Configs/Game.ini
printf "ServerMOTD=%s\n" "$MOTD" >> $DIRECTORY/Configs/Game.ini
# Creation of the launch script
printf "#!/bin/bash\nps -eaf | grep UE4Server | grep %s\nif [ \$? -eq 1 ]\nthen\n%s\n else\necho 'The Server is already running on port %s!'\nfi\n" "$PORT" "$EXEDIRECTORY/UE4Server UnrealTournament $MAP?Game=$GAMETYPE?MustBeReady=1 -port=$PORT" "$PORT" >> $DIRECTORY/launch.sh
# Creation of the reboot script
printf "#!/bin/bash\npid=\$(pidof UE4Server)\nkill \$pid" >> $DIRECTORY/reboot.sh
# Creation of the CRONTAB File
echo "Creation of CRON"
$VARROOT touch $DIRECTORY/cron
$VARROOT crontab -l > $DIRECTORY/cron
printf "*/1 * * * * bash %s > /dev/null \n" "$DIRECTORY/launch.sh" >> $DIRECTORY/cron
$VARROOT crontab $DIRECTORY/cron
$VARROOT rm $DIRECTORY/cron
elif [[ "$TYPE" == "update" ]]; then
echo "Reactive the cron..."
$VARROOT crontab $DIRECTORY/cron.save
$VARROOT rm $DIRECTORY/cron.save
fi
# Remove Engine and Game to set Symbolinks Links
$VARROOT rm $CONDIRECTORY/Engine.ini
$VARROOT rm $CONDIRECTORY/Game.ini
# Creating symbolinks links
$VARROOT ln -s $DIRECTORY/Configs/Engine.ini $CONDIRECTORY/Engine.ini
$VARROOT ln -s $DIRECTORY/Configs/Game.ini $CONDIRECTORY/Game.ini
echo 'Done.'
exit 0