Skip to content

Instantly share code, notes, and snippets.

@Niols
Created June 28, 2016 16:08
Show Gist options
  • Save Niols/9677e6fe1b23791819beb312dd1030f9 to your computer and use it in GitHub Desktop.
Save Niols/9677e6fe1b23791819beb312dd1030f9 to your computer and use it in GitHub Desktop.
<!doctype html>
<html lang="en">
<head>
<title>Get Ampache!</title>
<style type="text/css">
pre.command-output
{
font-family: monospace;
background: black;
color: white;
margin-top: 0;
padding: 2px;
border: 1px solid gray;
}
pre.command::before
{
content: "$ ";
}
pre.command
{
font-family: monospace;
background: black;
border: 1px solid blue;
margin-bottom: 0;
padding: 2px;
}
pre.command-success
{
color: green;
}
pre.command-failure
{
color: red;
}
</style>
</head>
<body>
<?php
function command_exists ($command)
{
return trim(shell_exec('which ' . escapeshellarg($command)));
}
function run_command ($command)
{
exec($command, $output, $return);
$command_class = 'command-' . (($return == 0) ? 'success' : 'failure');
echo '<pre class="command ' . $command_class . '">' . $command . '</pre>';
echo '<pre class="command-output">';
foreach ($output as $line)
echo $line . PHP_EOL;
echo '</pre>';
return [ 'rc' => ($return == 0) ? true : false, 'stdout' => $output ];
}
if (isset ($_GET['step']))
$step = (int) $_GET['step'];
else
$step = 0;
echo '<h1>Get Ampache!</h1>';
echo '<h3>Step: ' . $step . '</h3>';
echo '<p>This script will try to install Ampache automatically.</p>';
if ($step == 0)
{
echo '<h2>Checking that git is available</h2>';
$o = run_command('which git');
if (! $o['rc'])
die ('It looks like you don\'t have git installed on your system.<br/>
It is necessary.<br/>
Exiting (<a href="">retry</a>).');
echo 'Great!';
}
else if ($step == 1)
{
echo '<h2>Verifying that the directory is clean</h2>';
$o = run_command('find');
if (count ($o['stdout']) != 2)
die ('Noooooo :-(<br/>
There shouldn\'t be anything else than this script in the directory.<br/>
Please clean this.<br/>
Exiting (<a href="">retry</a>).');
echo 'Awesome!';
}
else if ($step == 2)
{
echo '<h2>Getting Composer...</h2>';
run_command("wget -S 'https://getcomposer.org/composer.phar' 2>&1");
$o = run_command('php composer.phar --version');
if (! $o['rc'])
die ('Errr... It looks like something went wrong.<br/>
Exiting (<a href="">retry</a>).');
echo 'Wonderful!';
}
else if ($step == 3)
{
echo '<h2>Cloning Ampache...</h2>';
$o1 = run_command('git clone https://github.com/ampache/ampache');
$o2 = run_command('mv ampache/* . && rm -r ampache');
if (! ($o1['rc'] && $o2['rc']))
die ('Arf, that was probably my bad :(<br/>Exiting (<a href="">retry</a>).');
echo 'Magnificent!';
}
else if ($step == 4)
{
echo '<h2>Installing dependencies...</h2>';
$o = run_command('php composer.phar install');
if (! $o['rc'])
die ('So close!<br/>Exiting (<a href="">retry</a>).');
echo 'Tremendous!';
echo '<h2>Job done here!</h2>';
echo 'OK, my job here is done. You should now move to the part of the install
that is handled by Ampache itself, <a href="install.php">here</a>.';
}
if ($step < 4)
echo '<br/>Alright. You can now go to <a href="?step='.($step+1).'">next step</a>.';
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment