Skip to content

Commit 30b4934

Browse files
committed
Include default installation scripts, as well as ability to symlink a script
1 parent 77b1a25 commit 30b4934

File tree

12 files changed

+346
-11
lines changed

12 files changed

+346
-11
lines changed

app/Http/Controllers/Admin/OptionController.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,16 @@ public function viewVariables(Request $request, $id)
146146
*/
147147
public function viewScripts(Request $request, $id)
148148
{
149-
return view('admin.services.options.scripts', ['option' => ServiceOption::findOrFail($id)]);
149+
$option = ServiceOption::with('copyFrom')->findOrFail($id);
150+
151+
return view('admin.services.options.scripts', [
152+
'copyFromOptions' => ServiceOption::whereNull('copy_script_from')->where([
153+
['service_id', $option->service_id],
154+
['id', '!=', $option->id],
155+
])->get(),
156+
'relyOnScript' => ServiceOption::where('copy_script_from', $option->id)->get(),
157+
'option' => $option,
158+
]);
150159
}
151160

152161
/**
@@ -234,11 +243,14 @@ public function updateScripts(Request $request, $id)
234243

235244
try {
236245
$repo->scripts($id, $request->only([
237-
'script_install', 'script_entry', 'script_container',
246+
'script_install', 'script_entry',
247+
'script_container', 'copy_script_from',
238248
]));
239249
Alert::success('Successfully updated option scripts to be run when servers are installed.')->flash();
240250
} catch (DisplayValidationException $ex) {
241251
return redirect()->route('admin.services.option.scripts', $id)->withErrors(json_decode($ex->getMessage()));
252+
} catch (DisplayException $ex) {
253+
Alert::danger($ex->getMessage())->flash();
242254
} catch (\Exception $ex) {
243255
Log::error($ex);
244256
Alert::danger('An unhandled exception was encountered while attempting to process that request. This error has been logged.')->flash();

app/Http/Controllers/Daemon/OptionController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ public function details(Request $request, $server)
4040

4141
return response()->json([
4242
'scripts' => [
43-
'install' => (! $server->option->script_install) ? null : str_replace(["\r\n", "\n", "\r"], "\n", $server->option->script_install),
43+
'install' => (! $server->option->copy_script_install) ? null : str_replace(["\r\n", "\n", "\r"], "\n", $server->option->copy_script_install),
4444
'privileged' => $server->option->script_is_privileged,
4545
],
4646
'config' => [
47-
'container' => $server->option->script_container,
48-
'entry' => $server->option->script_entry,
47+
'container' => $server->option->copy_script_container,
48+
'entry' => $server->option->copy_script_entry,
4949
],
5050
'env' => $environment->merge([
5151
'STARTUP=' . $server->startup,

app/Models/ServiceOption.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,39 @@ public function getDisplayStartupAttribute($value)
6363
return (is_null($this->startup)) ? $this->service->startup : $this->startup;
6464
}
6565

66+
/**
67+
* Returns the install script for the option; if option is copying from another
68+
* it will return the copied script.
69+
*
70+
* @return string
71+
*/
72+
public function getCopyScriptInstallAttribute($value)
73+
{
74+
return (is_null($this->copy_script_from)) ? $this->script_install : $this->copyFrom->script_install;
75+
}
76+
77+
/**
78+
* Returns the entry command for the option; if option is copying from another
79+
* it will return the copied entry command.
80+
*
81+
* @return string
82+
*/
83+
public function getCopyScriptEntryAttribute($value)
84+
{
85+
return (is_null($this->copy_script_from)) ? $this->script_entry : $this->copyFrom->script_entry;
86+
}
87+
88+
/**
89+
* Returns the install container for the option; if option is copying from another
90+
* it will return the copied install container.
91+
*
92+
* @return string
93+
*/
94+
public function getCopyScriptContainerAttribute($value)
95+
{
96+
return (is_null($this->copy_script_from)) ? $this->script_container : $this->copyFrom->script_container;
97+
}
98+
6699
/**
67100
* Gets service associated with a service option.
68101
*
@@ -102,4 +135,9 @@ public function packs()
102135
{
103136
return $this->hasMany(Pack::class, 'option_id');
104137
}
138+
139+
public function copyFrom()
140+
{
141+
return $this->belongsTo(ServiceOption::class, 'copy_script_from');
142+
}
105143
}

app/Repositories/OptionRepository.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function create(array $data)
4949
'description' => 'required|string',
5050
'tag' => 'required|string|max:255|unique:service_options,tag',
5151
'docker_image' => 'required|string|max:255',
52-
'startup' => 'required|string',
52+
'startup' => 'sometimes|nullable|string',
5353
'config_from' => 'sometimes|required|numeric|exists:service_options,id',
5454
'config_startup' => 'required_without:config_from|json',
5555
'config_stop' => 'required_without:config_from|string|max:255',
@@ -162,6 +162,7 @@ public function update($id, array $data)
162162
* @param array $data
163163
* @return \Pterodactyl\Models\ServiceOption
164164
*
165+
* @throws \Pterodactyl\Exceptions\DisplayException
165166
* @throws \Pterodactyl\Exceptions\DisplayValidationException
166167
*/
167168
public function scripts($id, array $data)
@@ -175,8 +176,22 @@ public function scripts($id, array $data)
175176
'script_is_privileged' => 'sometimes|required|boolean',
176177
'script_entry' => 'sometimes|required|string',
177178
'script_container' => 'sometimes|required|string',
179+
'copy_script_from' => 'sometimes|nullable|numeric',
178180
]);
179181

182+
if (isset($data['copy_script_from']) && ! empty($data['copy_script_from'])) {
183+
$select = ServiceOption::whereNull('copy_script_from')->where([
184+
['id', $data['copy_script_from']],
185+
['service_id', $option->service_id],
186+
])->first();
187+
188+
if (! $select) {
189+
throw new DisplayException('The service option selected to copy a script from either does not exist, or is copying from a higher level.');
190+
}
191+
} else {
192+
$data['copy_script_from'] = null;
193+
}
194+
180195
if ($validator->fails()) {
181196
throw new DisplayValidationException(json_encode($validator->errors()));
182197
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class AddCopyScriptFromColumn extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::table('service_options', function (Blueprint $table) {
17+
$table->unsignedInteger('copy_script_from')->nullable()->after('script_container');
18+
19+
$table->foreign('copy_script_from')->references('id')->on('service_options');
20+
});
21+
}
22+
23+
/**
24+
* Reverse the migrations.
25+
*
26+
* @return void
27+
*/
28+
public function down()
29+
{
30+
Schema::table('service_options', function (Blueprint $table) {
31+
$table->dropForeign(['copy_script_from']);
32+
$table->dropColumn('copy_script_from');
33+
});
34+
}
35+
}

database/seeds/MinecraftServiceTableSeeder.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,27 @@ private function addCoreService()
110110

111111
private function addCoreOptions()
112112
{
113+
$script = <<<'EOF'
114+
#!/bin/ash
115+
# Vanilla MC Installation Script
116+
#
117+
# Server Files: /mnt/server
118+
apk update
119+
apk add curl
120+
121+
cd /mnt/server
122+
123+
LATEST_VERSION=`curl -s https://s3.amazonaws.com/Minecraft.Download/versions/versions.json | grep -o "[[:digit:]]\.[0-9]*\.[0-9]" | head -n 1`
124+
125+
if [ -z "$VANILLA_VERSION" ] || [ "$VANILLA_VERSION" == "latest" ]; then
126+
DL_VERSION=$LATEST_VERSION
127+
else
128+
DL_VERSION=$VANILLA_VERSION
129+
fi
130+
131+
curl -o ${SERVER_JARFILE} https://s3.amazonaws.com/Minecraft.Download/versions/${DL_VERSION}/minecraft_server.${DL_VERSION}.jar
132+
EOF;
133+
113134
$this->option['vanilla'] = ServiceOption::updateOrCreate([
114135
'service_id' => $this->service->id,
115136
'tag' => 'vanilla',
@@ -123,8 +144,27 @@ private function addCoreOptions()
123144
'config_stop' => 'stop',
124145
'config_from' => null,
125146
'startup' => null,
147+
'script_install' => $script,
126148
]);
127149

150+
$script = <<<'EOF'
151+
#!/bin/ash
152+
# Spigot Installation Script
153+
#
154+
# Server Files: /mnt/server
155+
156+
## Only download if a path is provided, otherwise continue.
157+
if [ ! -z "${DL_PATH}" ]; then
158+
apk update
159+
apk add curl
160+
161+
cd /mnt/server
162+
163+
MODIFIED_DOWNLOAD=`eval echo $(echo ${DL_PATH} | sed -e 's/{{/${/g' -e 's/}}/}/g')`
164+
curl -sSL -o ${SERVER_JARFILE} ${MODIFIED_DOWNLOAD}
165+
fi
166+
EOF;
167+
128168
$this->option['spigot'] = ServiceOption::updateOrCreate([
129169
'service_id' => $this->service->id,
130170
'tag' => 'spigot',
@@ -138,8 +178,23 @@ private function addCoreOptions()
138178
'config_stop' => null,
139179
'config_from' => $this->option['vanilla']->id,
140180
'startup' => null,
181+
'script_install' => $script,
141182
]);
142183

184+
$script = <<<'EOF'
185+
#!/bin/ash
186+
# Sponge Installation Script
187+
#
188+
# Server Files: /mnt/server
189+
190+
apk update
191+
apk add curl
192+
193+
cd /mnt/server
194+
195+
curl -sSL "https://repo.spongepowered.org/maven/org/spongepowered/spongevanilla/${SPONGE_VERSION}/spongevanilla-${SPONGE_VERSION}.jar" -o ${SERVER_JARFILE}
196+
EOF;
197+
143198
$this->option['sponge'] = ServiceOption::updateOrCreate([
144199
'service_id' => $this->service->id,
145200
'tag' => 'sponge',
@@ -153,8 +208,26 @@ private function addCoreOptions()
153208
'config_stop' => null,
154209
'config_from' => $this->option['vanilla']->id,
155210
'startup' => null,
211+
'script_install' => $script,
156212
]);
157213

214+
$script = <<<'EOF'
215+
#!/bin/ash
216+
# Bungeecord Installation Script
217+
#
218+
# Server Files: /mnt/server
219+
apk update
220+
apk add curl
221+
222+
cd /mnt/server
223+
224+
if [ -z "${BUNGEE_VERSION}" ] || [ "${BUNGEE_VERSION}" == "latest" ]; then
225+
BUNGEE_VERSION="lastStableBuild"
226+
fi
227+
228+
curl -o ${SERVER_JARFILE} https://ci.md-5.net/job/BungeeCord/${BUNGEE_VERSION}/artifact/bootstrap/target/BungeeCord.jar
229+
EOF;
230+
158231
$this->option['bungeecord'] = ServiceOption::updateOrCreate([
159232
'service_id' => $this->service->id,
160233
'tag' => 'bungeecord',
@@ -168,6 +241,7 @@ private function addCoreOptions()
168241
'config_stop' => 'end',
169242
'config_from' => null,
170243
'startup' => null,
244+
'script_install' => $script,
171245
]);
172246
}
173247

database/seeds/SourceServiceTableSeeder.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,27 @@ private function addCoreService()
6969

7070
private function addCoreOptions()
7171
{
72+
$script = <<<'EOF'
73+
#!/bin/bash
74+
# SRCDS Base Installation Script
75+
#
76+
# Server Files: /mnt/server
77+
apt update
78+
apt install curl
79+
80+
cd /tmp
81+
curl -sSL -o steamcmd.tar.gz http://media.steampowered.com/installer/steamcmd_linux.tar.gz
82+
83+
mkdir /mnt/server/steamcmd
84+
tar -xzvf steamcmd.tar.gz -C /mnt/server/steamcmd
85+
cd /mnt/server/steamcmd
86+
87+
./steamcmd.sh +login anonymous +force_install_dir /mnt/server +app_update ${SRCDS_APPID} +quit
88+
89+
mkdir -p /mnt/server/.steam/sdk32
90+
cp -v linux32/steamclient.so ../.steam/sdk32/steamclient.so
91+
EOF;
92+
7293
$this->option['source'] = ServiceOption::updateOrCreate([
7394
'service_id' => $this->service->id,
7495
'tag' => 'source',
@@ -82,6 +103,9 @@ private function addCoreOptions()
82103
'config_stop' => 'quit',
83104
'config_from' => null,
84105
'startup' => null,
106+
'script_install' => $script,
107+
'script_entry' => 'bash',
108+
'script_container' => 'ubuntu:16.04',
85109
]);
86110

87111
$this->option['insurgency'] = ServiceOption::updateOrCreate([
@@ -97,6 +121,7 @@ private function addCoreOptions()
97121
'config_stop' => null,
98122
'config_from' => $this->option['source']->id,
99123
'startup' => './srcds_run -game {{SRCDS_GAME}} -console -port {{SERVER_PORT}} +map {{SRCDS_MAP}} +ip 0.0.0.0 -strictportbind -norestart',
124+
'copy_script_from' => $this->option['source']->id,
100125
]);
101126

102127
$this->option['tf2'] = ServiceOption::updateOrCreate([
@@ -112,8 +137,34 @@ private function addCoreOptions()
112137
'config_stop' => null,
113138
'config_from' => $this->option['source']->id,
114139
'startup' => './srcds_run -game {{SRCDS_GAME}} -console -port {{SERVER_PORT}} +map {{SRCDS_MAP}} +ip 0.0.0.0 -strictportbind -norestart',
140+
'copy_script_from' => $this->option['source']->id,
115141
]);
116142

143+
$script = <<<'EOF'
144+
#!/bin/bash
145+
# ARK: Installation Script
146+
#
147+
# Server Files: /mnt/server
148+
apt update
149+
apt install curl
150+
151+
cd /tmp
152+
curl -sSL -o steamcmd.tar.gz http://media.steampowered.com/installer/steamcmd_linux.tar.gz
153+
154+
mkdir /mnt/server/steamcmd
155+
mkdir -p /mnt/server/Engine/Binaries/ThirdParty/SteamCMD/Linux
156+
157+
tar -xzvf steamcmd.tar.gz -C /mnt/server/steamcmd
158+
tar -xzvf steamcmd.tar.gz -C /mnt/server/Engine/Binaries/ThirdParty/SteamCMD/Linux
159+
160+
cd /mnt/server/steamcmd
161+
162+
./steamcmd.sh +login anonymous +force_install_dir /mnt/server +app_update 376030 +quit
163+
164+
mkdir -p /mnt/server/.steam/sdk32
165+
cp -v linux32/steamclient.so ../.steam/sdk32/steamclient.so
166+
EOF;
167+
117168
$this->option['ark'] = ServiceOption::updateOrCreate([
118169
'service_id' => $this->service->id,
119170
'tag' => 'ark',
@@ -127,6 +178,9 @@ private function addCoreOptions()
127178
'config_stop' => '^C',
128179
'config_from' => $this->option['source']->id,
129180
'startup' => './ShooterGame/Binaries/Linux/ShooterGameServer TheIsland?listen?ServerPassword={{ARK_PASSWORD}}?ServerAdminPassword={{ARK_ADMIN_PASSWORD}}?Port={{SERVER_PORT}}?MaxPlayers={{SERVER_MAX_PLAYERS}}',
181+
'script_install' => $script,
182+
'script_entry' => 'bash',
183+
'script_container' => 'ubuntu:16.04',
130184
]);
131185
}
132186

0 commit comments

Comments
 (0)