/** * @param string $action */ public function execPluginScript(\Twig_Environment $twig, Plugin $plugin, $action) { if ($action != 'install' && $action != 'uninstall' && $action != 'activate' && $action != 'deactivate') { throw new \BadMethodCallException('Only actions available for SteamServers plugin scripts are : install, uninstall, activate and deactivate.'); } $conn = $this->getMachine()->getConnection(); // En cas d'installation, vérification des dépendances du plugin if ($action == 'install') { $packetDependencies = $plugin->getPacketDependencies(); if (!empty($packetDependencies)) { $missingPackets = array(); foreach ($packetDependencies as $dep) { if (!$conn->isInstalled($dep)) { $missingPackets[] = $dep; } } if (!empty($missingPackets)) { throw new MissingPacketException($missingPackets); } } } $dir = $this->getAbsoluteGameContentDir(); $scriptName = $plugin->getScriptName(); $scriptPath = $dir . $scriptName . '.sh'; $pluginScript = $twig->render('DPSteamServerBundle:sh:Plugin/' . $scriptName . '.sh.twig', array('gameDir' => $dir)); $conn->upload($scriptPath, $pluginScript); $screenName = $this->getPluginInstallScreenName($scriptName); $screenCmd = 'screen -dmS ' . $screenName . ' ' . $scriptPath . ' ' . $action; if ($action == 'install') { $screenCmd .= ' "' . $plugin->getDownloadUrl() . '"'; } $conn->exec($screenCmd); }