Include default installation scripts, as well as ability to symlink a script

This commit is contained in:
Dane Everitt 2017-04-27 16:16:57 -04:00
parent 77b1a258d9
commit 30b4934013
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
12 changed files with 346 additions and 11 deletions

View file

@ -146,7 +146,16 @@ class OptionController extends Controller
*/
public function viewScripts(Request $request, $id)
{
return view('admin.services.options.scripts', ['option' => ServiceOption::findOrFail($id)]);
$option = ServiceOption::with('copyFrom')->findOrFail($id);
return view('admin.services.options.scripts', [
'copyFromOptions' => ServiceOption::whereNull('copy_script_from')->where([
['service_id', $option->service_id],
['id', '!=', $option->id],
])->get(),
'relyOnScript' => ServiceOption::where('copy_script_from', $option->id)->get(),
'option' => $option,
]);
}
/**
@ -234,11 +243,14 @@ class OptionController extends Controller
try {
$repo->scripts($id, $request->only([
'script_install', 'script_entry', 'script_container',
'script_install', 'script_entry',
'script_container', 'copy_script_from',
]));
Alert::success('Successfully updated option scripts to be run when servers are installed.')->flash();
} catch (DisplayValidationException $ex) {
return redirect()->route('admin.services.option.scripts', $id)->withErrors(json_decode($ex->getMessage()));
} catch (DisplayException $ex) {
Alert::danger($ex->getMessage())->flash();
} catch (\Exception $ex) {
Log::error($ex);
Alert::danger('An unhandled exception was encountered while attempting to process that request. This error has been logged.')->flash();

View file

@ -40,12 +40,12 @@ class OptionController extends Controller
return response()->json([
'scripts' => [
'install' => (! $server->option->script_install) ? null : str_replace(["\r\n", "\n", "\r"], "\n", $server->option->script_install),
'install' => (! $server->option->copy_script_install) ? null : str_replace(["\r\n", "\n", "\r"], "\n", $server->option->copy_script_install),
'privileged' => $server->option->script_is_privileged,
],
'config' => [
'container' => $server->option->script_container,
'entry' => $server->option->script_entry,
'container' => $server->option->copy_script_container,
'entry' => $server->option->copy_script_entry,
],
'env' => $environment->merge([
'STARTUP=' . $server->startup,

View file

@ -63,6 +63,39 @@ class ServiceOption extends Model
return (is_null($this->startup)) ? $this->service->startup : $this->startup;
}
/**
* Returns the install script for the option; if option is copying from another
* it will return the copied script.
*
* @return string
*/
public function getCopyScriptInstallAttribute($value)
{
return (is_null($this->copy_script_from)) ? $this->script_install : $this->copyFrom->script_install;
}
/**
* Returns the entry command for the option; if option is copying from another
* it will return the copied entry command.
*
* @return string
*/
public function getCopyScriptEntryAttribute($value)
{
return (is_null($this->copy_script_from)) ? $this->script_entry : $this->copyFrom->script_entry;
}
/**
* Returns the install container for the option; if option is copying from another
* it will return the copied install container.
*
* @return string
*/
public function getCopyScriptContainerAttribute($value)
{
return (is_null($this->copy_script_from)) ? $this->script_container : $this->copyFrom->script_container;
}
/**
* Gets service associated with a service option.
*
@ -102,4 +135,9 @@ class ServiceOption extends Model
{
return $this->hasMany(Pack::class, 'option_id');
}
public function copyFrom()
{
return $this->belongsTo(ServiceOption::class, 'copy_script_from');
}
}

View file

@ -49,7 +49,7 @@ class OptionRepository
'description' => 'required|string',
'tag' => 'required|string|max:255|unique:service_options,tag',
'docker_image' => 'required|string|max:255',
'startup' => 'required|string',
'startup' => 'sometimes|nullable|string',
'config_from' => 'sometimes|required|numeric|exists:service_options,id',
'config_startup' => 'required_without:config_from|json',
'config_stop' => 'required_without:config_from|string|max:255',
@ -162,6 +162,7 @@ class OptionRepository
* @param array $data
* @return \Pterodactyl\Models\ServiceOption
*
* @throws \Pterodactyl\Exceptions\DisplayException
* @throws \Pterodactyl\Exceptions\DisplayValidationException
*/
public function scripts($id, array $data)
@ -175,8 +176,22 @@ class OptionRepository
'script_is_privileged' => 'sometimes|required|boolean',
'script_entry' => 'sometimes|required|string',
'script_container' => 'sometimes|required|string',
'copy_script_from' => 'sometimes|nullable|numeric',
]);
if (isset($data['copy_script_from']) && ! empty($data['copy_script_from'])) {
$select = ServiceOption::whereNull('copy_script_from')->where([
['id', $data['copy_script_from']],
['service_id', $option->service_id],
])->first();
if (! $select) {
throw new DisplayException('The service option selected to copy a script from either does not exist, or is copying from a higher level.');
}
} else {
$data['copy_script_from'] = null;
}
if ($validator->fails()) {
throw new DisplayValidationException(json_encode($validator->errors()));
}

View file

@ -0,0 +1,35 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddCopyScriptFromColumn extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('service_options', function (Blueprint $table) {
$table->unsignedInteger('copy_script_from')->nullable()->after('script_container');
$table->foreign('copy_script_from')->references('id')->on('service_options');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('service_options', function (Blueprint $table) {
$table->dropForeign(['copy_script_from']);
$table->dropColumn('copy_script_from');
});
}
}

View file

@ -110,6 +110,27 @@ EOF;
private function addCoreOptions()
{
$script = <<<'EOF'
#!/bin/ash
# Vanilla MC Installation Script
#
# Server Files: /mnt/server
apk update
apk add curl
cd /mnt/server
LATEST_VERSION=`curl -s https://s3.amazonaws.com/Minecraft.Download/versions/versions.json | grep -o "[[:digit:]]\.[0-9]*\.[0-9]" | head -n 1`
if [ -z "$VANILLA_VERSION" ] || [ "$VANILLA_VERSION" == "latest" ]; then
DL_VERSION=$LATEST_VERSION
else
DL_VERSION=$VANILLA_VERSION
fi
curl -o ${SERVER_JARFILE} https://s3.amazonaws.com/Minecraft.Download/versions/${DL_VERSION}/minecraft_server.${DL_VERSION}.jar
EOF;
$this->option['vanilla'] = ServiceOption::updateOrCreate([
'service_id' => $this->service->id,
'tag' => 'vanilla',
@ -123,8 +144,27 @@ EOF;
'config_stop' => 'stop',
'config_from' => null,
'startup' => null,
'script_install' => $script,
]);
$script = <<<'EOF'
#!/bin/ash
# Spigot Installation Script
#
# Server Files: /mnt/server
## Only download if a path is provided, otherwise continue.
if [ ! -z "${DL_PATH}" ]; then
apk update
apk add curl
cd /mnt/server
MODIFIED_DOWNLOAD=`eval echo $(echo ${DL_PATH} | sed -e 's/{{/${/g' -e 's/}}/}/g')`
curl -sSL -o ${SERVER_JARFILE} ${MODIFIED_DOWNLOAD}
fi
EOF;
$this->option['spigot'] = ServiceOption::updateOrCreate([
'service_id' => $this->service->id,
'tag' => 'spigot',
@ -138,8 +178,23 @@ EOF;
'config_stop' => null,
'config_from' => $this->option['vanilla']->id,
'startup' => null,
'script_install' => $script,
]);
$script = <<<'EOF'
#!/bin/ash
# Sponge Installation Script
#
# Server Files: /mnt/server
apk update
apk add curl
cd /mnt/server
curl -sSL "https://repo.spongepowered.org/maven/org/spongepowered/spongevanilla/${SPONGE_VERSION}/spongevanilla-${SPONGE_VERSION}.jar" -o ${SERVER_JARFILE}
EOF;
$this->option['sponge'] = ServiceOption::updateOrCreate([
'service_id' => $this->service->id,
'tag' => 'sponge',
@ -153,8 +208,26 @@ EOF;
'config_stop' => null,
'config_from' => $this->option['vanilla']->id,
'startup' => null,
'script_install' => $script,
]);
$script = <<<'EOF'
#!/bin/ash
# Bungeecord Installation Script
#
# Server Files: /mnt/server
apk update
apk add curl
cd /mnt/server
if [ -z "${BUNGEE_VERSION}" ] || [ "${BUNGEE_VERSION}" == "latest" ]; then
BUNGEE_VERSION="lastStableBuild"
fi
curl -o ${SERVER_JARFILE} https://ci.md-5.net/job/BungeeCord/${BUNGEE_VERSION}/artifact/bootstrap/target/BungeeCord.jar
EOF;
$this->option['bungeecord'] = ServiceOption::updateOrCreate([
'service_id' => $this->service->id,
'tag' => 'bungeecord',
@ -168,6 +241,7 @@ EOF;
'config_stop' => 'end',
'config_from' => null,
'startup' => null,
'script_install' => $script,
]);
}

View file

@ -69,6 +69,27 @@ class SourceServiceTableSeeder extends Seeder
private function addCoreOptions()
{
$script = <<<'EOF'
#!/bin/bash
# SRCDS Base Installation Script
#
# Server Files: /mnt/server
apt update
apt install curl
cd /tmp
curl -sSL -o steamcmd.tar.gz http://media.steampowered.com/installer/steamcmd_linux.tar.gz
mkdir /mnt/server/steamcmd
tar -xzvf steamcmd.tar.gz -C /mnt/server/steamcmd
cd /mnt/server/steamcmd
./steamcmd.sh +login anonymous +force_install_dir /mnt/server +app_update ${SRCDS_APPID} +quit
mkdir -p /mnt/server/.steam/sdk32
cp -v linux32/steamclient.so ../.steam/sdk32/steamclient.so
EOF;
$this->option['source'] = ServiceOption::updateOrCreate([
'service_id' => $this->service->id,
'tag' => 'source',
@ -82,6 +103,9 @@ class SourceServiceTableSeeder extends Seeder
'config_stop' => 'quit',
'config_from' => null,
'startup' => null,
'script_install' => $script,
'script_entry' => 'bash',
'script_container' => 'ubuntu:16.04',
]);
$this->option['insurgency'] = ServiceOption::updateOrCreate([
@ -97,6 +121,7 @@ class SourceServiceTableSeeder extends Seeder
'config_stop' => null,
'config_from' => $this->option['source']->id,
'startup' => './srcds_run -game {{SRCDS_GAME}} -console -port {{SERVER_PORT}} +map {{SRCDS_MAP}} +ip 0.0.0.0 -strictportbind -norestart',
'copy_script_from' => $this->option['source']->id,
]);
$this->option['tf2'] = ServiceOption::updateOrCreate([
@ -112,8 +137,34 @@ class SourceServiceTableSeeder extends Seeder
'config_stop' => null,
'config_from' => $this->option['source']->id,
'startup' => './srcds_run -game {{SRCDS_GAME}} -console -port {{SERVER_PORT}} +map {{SRCDS_MAP}} +ip 0.0.0.0 -strictportbind -norestart',
'copy_script_from' => $this->option['source']->id,
]);
$script = <<<'EOF'
#!/bin/bash
# ARK: Installation Script
#
# Server Files: /mnt/server
apt update
apt install curl
cd /tmp
curl -sSL -o steamcmd.tar.gz http://media.steampowered.com/installer/steamcmd_linux.tar.gz
mkdir /mnt/server/steamcmd
mkdir -p /mnt/server/Engine/Binaries/ThirdParty/SteamCMD/Linux
tar -xzvf steamcmd.tar.gz -C /mnt/server/steamcmd
tar -xzvf steamcmd.tar.gz -C /mnt/server/Engine/Binaries/ThirdParty/SteamCMD/Linux
cd /mnt/server/steamcmd
./steamcmd.sh +login anonymous +force_install_dir /mnt/server +app_update 376030 +quit
mkdir -p /mnt/server/.steam/sdk32
cp -v linux32/steamclient.so ../.steam/sdk32/steamclient.so
EOF;
$this->option['ark'] = ServiceOption::updateOrCreate([
'service_id' => $this->service->id,
'tag' => 'ark',
@ -127,6 +178,9 @@ class SourceServiceTableSeeder extends Seeder
'config_stop' => '^C',
'config_from' => $this->option['source']->id,
'startup' => './ShooterGame/Binaries/Linux/ShooterGameServer TheIsland?listen?ServerPassword={{ARK_PASSWORD}}?ServerAdminPassword={{ARK_ADMIN_PASSWORD}}?Port={{SERVER_PORT}}?MaxPlayers={{SERVER_MAX_PLAYERS}}',
'script_install' => $script,
'script_entry' => 'bash',
'script_container' => 'ubuntu:16.04',
]);
}

View file

@ -69,6 +69,21 @@ class TerrariaServiceTableSeeder extends Seeder
private function addCoreOptions()
{
$script = <<<'EOF'
#!/bin/ash
# TShock Installation Script
#
# Server Files: /mnt/server
apk update
apk add curl unzip
cd /tmp
curl -sSLO https://github.com/NyxStudios/TShock/releases/download/v${T_VERSION}/tshock_${T_VERSION}.zip
unzip -o tshock_${T_VERSION}.zip -d /mnt/server
EOF;
$this->option['tshock'] = ServiceOption::updateOrCreate([
'service_id' => $this->service->id,
'tag' => 'tshock',
@ -82,6 +97,7 @@ class TerrariaServiceTableSeeder extends Seeder
'config_logs' => '{"custom": false, "location": "ServerLog.txt"}',
'config_stop' => 'exit',
'startup' => null,
'script_install' => $script,
]);
}

View file

@ -69,6 +69,22 @@ class VoiceServiceTableSeeder extends Seeder
private function addCoreOptions()
{
$script = <<<'EOF'
#!/bin/ash
# Mumble Installation Script
#
# Server Files: /mnt/server
apk update
apk add tar curl
cd /tmp
curl -sSLO https://github.com/mumble-voip/mumble/releases/download/${MUMBLE_VERSION}/murmur-static_x86-${MUMBLE_VERSION}.tar.bz2
tar -xjvf murmur-static_x86-${MUMBLE_VERSION}.tar.bz2
cp -r murmur-static_x86-${MUMBLE_VERSION}/* /mnt/server
EOF;
$this->option['mumble'] = ServiceOption::updateOrCreate([
'service_id' => $this->service->id,
'tag' => 'mumble',
@ -82,8 +98,46 @@ class VoiceServiceTableSeeder extends Seeder
'config_stop' => '^C',
'config_from' => null,
'startup' => './murmur.x86 -fg',
'script_install' => $script,
]);
$script = <<<'EOF'
#!/bin/ash
# TS3 Installation Script
#
# Server Files: /mnt/server
apk update
apk add tar curl
cd /tmp
curl -sSLO http://dl.4players.de/ts/releases/${TS_VERSION}/teamspeak3-server_linux_amd64-${TS_VERSION}.tar.bz2
tar -xjvf teamspeak3-server_linux_amd64-${TS_VERSION}.tar.bz2
cp -r teamspeak3-server_linux_amd64/* /mnt/server
echo "machine_id=
default_voice_port=${SERVER_PORT}
voice_ip=0.0.0.0
licensepath=
filetransfer_port=30033
filetransfer_ip=
query_port=${SERVER_PORT}
query_ip=0.0.0.0
query_ip_whitelist=query_ip_whitelist.txt
query_ip_blacklist=query_ip_blacklist.txt
dbplugin=ts3db_sqlite3
dbpluginparameter=
dbsqlpath=sql/
dbsqlcreatepath=create_sqlite/
dbconnections=10
logpath=logs
logquerycommands=0
dbclientkeepdays=30
logappend=0
query_skipbruteforcecheck=0" > /mnt/server/ts3server.ini
EOF;
$this->option['ts3'] = ServiceOption::updateOrCreate([
'service_id' => $this->service->id,
'tag' => 'ts3',
@ -97,6 +151,7 @@ class VoiceServiceTableSeeder extends Seeder
'config_stop' => '^C',
'config_from' => null,
'startup' => './ts3server_minimal_runscript.sh default_voice_port={{SERVER_PORT}} query_port={{SERVER_PORT}}',
'script_install' => $script,
]);
}

View file

@ -79,7 +79,10 @@
</tr>
<tr>
<td>Service</td>
<td>{{ $server->option->service->name }} :: {{ $server->option->name }}</td>
<td>
<a href="{{ route('admin.services.view', $server->option->service->id) }}">{{ $server->option->service->name }}</a> ::
<a href="{{ route('admin.services.option.view', $server->option->id) }}">{{ $server->option->name }}</a>
</td>
</tr>
<tr>
<td>Name</td>

View file

@ -47,7 +47,7 @@
<label for="pServiceId" class="form-label">Associated Service</label>
<select name="service_id" id="pServiceId">
@foreach($services as $service)
<option value="{{ $service->id }}">{{ $service->name }}</option>
<option value="{{ $service->id }}" {{ old('service_id') != $service->id ?: 'selected' }}>{{ $service->name }}</option>
@endforeach
</select>
</div>

View file

@ -52,27 +52,58 @@
<div class="box-header with-border">
<h3 class="box-title">Install Script</h3>
</div>
@if(! is_null($option->copyFrom))
<div class="box-body">
<div class="callout callout-warning no-margin">
This service option is copying installation scripts and containe options from <a href="{{ route('admin.services.option.view', $option->copyFrom->id) }}">{{ $option->copyFrom->name }}</a>. Any changes you make to this script will not apply unless you select "None" from the dropdown box below.
</div>
</div>
@endif
<div class="box-body no-padding">
<div id="editor_install"style="height:300px">{{ $option->script_install }}</div>
</div>
<div class="box-body">
<div class="row">
<div class="form-group col-sm-6">
<div class="form-group col-sm-4">
<label class="control-label">Copy Script From</label>
<select id="pCopyScriptFrom" name="copy_script_from">
<option value="0">None</option>
@foreach($copyFromOptions as $opt)
<option value="{{ $opt->id }}" {{ $option->copy_script_from !== $opt->id ?: 'selected' }}>{{ $opt->name }}</option>
@endforeach
</select>
<p class="text-muted small">If selected, script above will be ignored and script from selected option will be used in place.</p>
</div>
<div class="form-group col-sm-4">
<label class="control-label">Script Container</label>
<input type="text" name="script_container" class="form-control" value="{{ $option->script_container }}" />
<p class="text-muted small">Docker container to use when running this script for the server.</p>
</div>
<div class="form-group col-sm-6">
<div class="form-group col-sm-4">
<label class="control-label">Script Entrypoint Command</label>
<input type="text" name="script_entry" class="form-control" value="{{ $option->script_entry }}" />
<p class="text-muted small">The entrypoint command to use for this script.</p>
</div>
</div>
<div class="row">
<div class="col-xs-12 text-muted">
The following service options rely on this script:
@if(count($relyOnScript) > 0)
@foreach($relyOnScript as $rely)
<a href="{{ route('admin.services.option.view', $rely->id) }}">
<code>{{ $rely->name }}</code>&nbsp;
</a>
@endforeach
@else
<em>none</em>
@endif
</div>
</div>
</div>
<div class="box-footer">
{!! csrf_field() !!}
<textarea name="script_install" class="hidden"></textarea>
<button type="submit" class="btn btn-primary btn-sm pull-right">Save Scripts</button>
<button type="submit" class="btn btn-primary btn-sm pull-right">Save Script</button>
</div>
</div>
</div>
@ -86,6 +117,8 @@
{!! Theme::js('vendor/ace/ext-modelist.js') !!}
<script>
$(document).ready(function () {
$('#pCopyScriptFrom').select2();
const InstallEditor = ace.edit('editor_install');
const Modelist = ace.require('ace/ext/modelist')