mirror of
https://github.com/zeropingheroes/lancache-autofill
synced 2024-11-25 09:00:18 +00:00
Changing environment variables and initialisation commands
This commit is contained in:
parent
15d15ae8c0
commit
256de2f1a5
6 changed files with 43 additions and 29 deletions
|
@ -1,3 +1,3 @@
|
|||
DOWNLOAD_LOCATION="/tmp/lancache-autofill"
|
||||
STEAMCMD="/usr/games/steamcmd/steamcmd.sh"
|
||||
STEAM_USER="your-username-here"
|
||||
DOWNLOADS_DIRECTORY="/tmp/lancache-autofill"
|
||||
STEAMCMD_PATH="/usr/games/steam/steamcmd.sh"
|
||||
DEFAULT_STEAM_USER="your-username-here"
|
|
@ -8,7 +8,7 @@ use Illuminate\Database\Capsule\Manager as Capsule;
|
|||
use Dotenv\Dotenv;
|
||||
|
||||
use Zeropingheroes\LancacheAutofill\Console\Commands\Steam\{UpdateAppList, SearchApps, QueueApp, ShowQueue, StartDownloading};
|
||||
use Zeropingheroes\LancacheAutofill\Console\Commands\{CreateDatabase, DeleteDownloads};
|
||||
use Zeropingheroes\LancacheAutofill\Console\Commands\{InitialiseDatabase, InitialiseDownloadsDirectory};
|
||||
|
||||
// Load Composer's autoloader
|
||||
if (file_exists($a = __DIR__.'/../../autoload.php')) {
|
||||
|
@ -20,7 +20,7 @@ if (file_exists($a = __DIR__.'/../../autoload.php')) {
|
|||
// Load environment variables
|
||||
$dotenv = new Dotenv(__DIR__);
|
||||
$dotenv->load();
|
||||
$dotenv->required(['DOWNLOAD_LOCATION', 'STEAMCMD', 'STEAM_USER']);
|
||||
$dotenv->required(['DOWNLOADS_DIRECTORY', 'STEAMCMD_PATH', 'DEFAULT_STEAM_USER']);
|
||||
|
||||
// Set up the console app
|
||||
$app = new Application(new Container, new Dispatcher, '5.4');
|
||||
|
@ -34,8 +34,8 @@ $capsule->addConnection([
|
|||
$capsule->setAsGlobal();
|
||||
|
||||
// Make commands available
|
||||
$app->add(new CreateDatabase);
|
||||
$app->add(new DeleteDownloads);
|
||||
$app->add(new InitialiseDatabase);
|
||||
$app->add(new InitialiseDownloadsDirectory);
|
||||
|
||||
$app->add(new UpdateAppList);
|
||||
$app->add(new SearchApps);
|
||||
|
|
|
@ -5,21 +5,21 @@ namespace Zeropingheroes\LancacheAutofill\Console\Commands;
|
|||
use Illuminate\Console\Command;
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
class CreateDatabase extends Command
|
||||
class InitialiseDatabase extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'app:create-database';
|
||||
protected $signature = 'app:initialise-database';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create the database';
|
||||
protected $description = 'Initialise the database';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
|
@ -28,8 +28,18 @@ class CreateDatabase extends Command
|
|||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->info('Creating database');
|
||||
if (Capsule::schema()->hasTable('steam_apps') OR Capsule::schema()->hasTable('steam_queue')) {
|
||||
if ($this->confirm('Are you sure you wish to clear all data in the database?')) {
|
||||
$this->info('Removing existing database tables');
|
||||
Capsule::schema()->dropIfExists('steam_apps');
|
||||
Capsule::schema()->dropIfExists('steam_queue');
|
||||
} else {
|
||||
die();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->info('Creating empty database tables');
|
||||
Capsule::schema()->create('steam_apps', function ($table) {
|
||||
$table->integer('appid')->unique();
|
||||
$table->string('name');
|
||||
|
@ -42,6 +52,7 @@ class CreateDatabase extends Command
|
|||
$table->string('account');
|
||||
$table->string('status');
|
||||
$table->string('message')->nullable();
|
||||
$table->string('platform');
|
||||
|
||||
});
|
||||
}
|
|
@ -7,21 +7,21 @@ use Illuminate\Database\Capsule\Manager as Capsule;
|
|||
use Symfony\Component\Process\Process;
|
||||
use Symfony\Component\Process\Exception\ProcessFailedException;
|
||||
|
||||
class DeleteDownloads extends Command
|
||||
class InitialiseDownloadsDirectory extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'app:delete-downloads';
|
||||
protected $signature = 'app:initialise-downloads-directory';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Delete downloads from the disk';
|
||||
protected $description = 'Initialise the downloads directory';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
|
@ -30,8 +30,8 @@ class DeleteDownloads extends Command
|
|||
*/
|
||||
public function handle()
|
||||
{
|
||||
if ($this->confirm('Are you sure you wish to remove all files and folders in "'.getenv('DOWNLOAD_LOCATION').'"?')) {
|
||||
$remove = new Process('rm -r '.getenv('DOWNLOAD_LOCATION'));
|
||||
if ($this->confirm('Are you sure you wish to remove all files and folders in "'.getenv('DOWNLOADS_DIRECTORY').'"?')) {
|
||||
$remove = new Process('rm -r '.getenv('DOWNLOADS_DIRECTORY'));
|
||||
$remove->run(function ($type, $buffer) {
|
||||
|
||||
if (Process::ERR === $type) {
|
||||
|
@ -42,14 +42,14 @@ class DeleteDownloads extends Command
|
|||
|
||||
});
|
||||
|
||||
$create = new Process('mkdir -p '.getenv('DOWNLOAD_LOCATION'));
|
||||
$create = new Process('mkdir -p '.getenv('DOWNLOADS_DIRECTORY'));
|
||||
$create->run();
|
||||
|
||||
if( $remove->isSuccessful() && $create->isSuccessful() ) {
|
||||
$this->info('Successfully removed all files and folders in "'.getenv('DOWNLOAD_LOCATION').'"');
|
||||
$this->info('Successfully removed all files and folders in "'.getenv('DOWNLOADS_DIRECTORY').'"');
|
||||
die();
|
||||
}
|
||||
$this->error('Unable to remove all files and folders in "'.getenv('DOWNLOAD_LOCATION').'"');
|
||||
$this->error('Unable to remove all files and folders in "'.getenv('DOWNLOADS_DIRECTORY').'"');
|
||||
}
|
||||
}
|
||||
}
|
|
@ -15,7 +15,7 @@ class QueueApp extends Command
|
|||
protected $signature = 'steam:queue-app
|
||||
{app_id : The ID of the app}
|
||||
{platforms=windows : Comma separated list of platforms to download the app for [windows, osx, linux]}
|
||||
{--account= : The Steam account to use when downloading the app (if different to the STEAM_USER environment variable)}';
|
||||
{--account= : The Steam account to use when downloading the app (the DEFAULT_STEAM_USER environment variable will be used if this option is omitted)}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
|
@ -42,7 +42,7 @@ class QueueApp extends Command
|
|||
$platforms = explode(',', $this->argument('platforms')) ?? ['windows'];
|
||||
|
||||
// If no account is specified, default to the account set in the .env file
|
||||
$account = $this->option('account') ?? getenv('STEAM_USER');
|
||||
$account = $this->option('account') ?? getenv('DEFAULT_STEAM_USER');
|
||||
|
||||
if( array_diff($platforms, $this::PLATFORMS))
|
||||
{
|
||||
|
|
|
@ -30,6 +30,13 @@ class StartDownloading extends Command
|
|||
*/
|
||||
public function handle()
|
||||
{
|
||||
if ( ! file_exists(getenv('STEAMCMD_PATH')) )
|
||||
{
|
||||
$this->error('SteamCMD not found - please check the STEAMCMD_PATH environment variable is set correctly');
|
||||
die();
|
||||
}
|
||||
|
||||
|
||||
if ( $this->queuedItems() == 0 )
|
||||
{
|
||||
$this->error('Queue is empty - nothing to download');
|
||||
|
@ -44,9 +51,9 @@ class StartDownloading extends Command
|
|||
try {
|
||||
$arguments =
|
||||
[
|
||||
'login' => getenv('STEAM_USER'),
|
||||
'login' => $app->account,
|
||||
'@sSteamCmdForcePlatformType' => $app->platform,
|
||||
'force_install_dir' => getenv('DOWNLOAD_LOCATION').'/'.$app->platform.'/'.$app->appid,
|
||||
'force_install_dir' => getenv('DOWNLOADS_DIRECTORY').'/'.$app->platform.'/'.$app->appid,
|
||||
'app_license_request' => $app->appid,
|
||||
'app_update' => $app->appid,
|
||||
'quit' => null,
|
||||
|
@ -62,7 +69,7 @@ class StartDownloading extends Command
|
|||
// Start SteamCMD with the arguments, using "unbuffer"
|
||||
// as SteamCMD buffers output when it is not run in a
|
||||
// tty, which prevents us showing output line by line
|
||||
$process = new Process('unbuffer steamcmd.sh '.$argumentString);
|
||||
$process = new Process('unbuffer '. getenv('STEAMCMD_PATH') . ' ' . $argumentString);
|
||||
|
||||
// Set a long timeout as downloading could take a while
|
||||
$process->setTimeout(14400);
|
||||
|
@ -79,10 +86,6 @@ class StartDownloading extends Command
|
|||
$this->updateQueueItemStatus($app->id, 'completed');
|
||||
|
||||
} catch (ProcessFailedException $e) {
|
||||
if($process->getExitCode() == 127) {
|
||||
$this->error('SteamCMD not found - please check the correct path is set in your .env file');
|
||||
die();
|
||||
}
|
||||
|
||||
// Create an array of SteamCMD's output (removing excess newlines)
|
||||
$lines = explode(PHP_EOL,trim($process->getOutput()));
|
||||
|
|
Loading…
Reference in a new issue