installer/index.php

46 lines
1.2 KiB
PHP
Raw Normal View History

2022-03-08 11:39:35 +01:00
#!/usr/bin/env php
<?php
function line($line) {
echo $line . PHP_EOL;
}
function run($command) {
line("> $command");
exec($command, $output, $return);
foreach ($output as $line)
line($line);
return $return === 0;
}
2022-06-17 17:04:15 +02:00
$repository = 'git@git.bluesquare.io:bluesquare/cli.git';
2022-03-08 11:39:35 +01:00
$home = $_SERVER['HOME'] ?? ($_SERVER['HOMEPATH'] ?? $_SERVER['HOMEDRIVE']);
$dir = __DIR__;
line("Répertoire utilisateur détecté : $home");
2022-06-17 17:04:15 +02:00
if (is_dir("$home/.bcli")) {
line("Le dossier $home/.bcli existe déjà.");
2022-03-08 11:39:35 +01:00
exit(1);
}
2022-06-17 17:04:15 +02:00
if (!run("cd $home && git clone $repository .bcli"))
2022-03-08 11:39:35 +01:00
exit(1);
2022-06-17 17:04:15 +02:00
if (!run("cd $home/.bcli && composer install"))
2022-03-08 11:39:35 +01:00
exit(1);
$source = file_exists("$home/.zshrc") ? "$home/.zshrc" : "$home/.bashrc";
$contents = file_exists($source) ? file_get_contents($source) : "";
2022-06-17 17:04:15 +02:00
if (strpos($contents, ".bcli/bin") === false) {
2022-03-08 11:39:35 +01:00
line("----------------------------------------------------");
line("----------------------------------------------------");
2022-06-17 17:04:15 +02:00
line("Pour pouvoir utiliser la commande `bcli` :");
line("echo 'export PATH=\"$home/.bcli/bin:\$PATH\"' >> $source");
2022-03-08 11:39:35 +01:00
line("source $source");
line("----------------------------------------------------");
}
exit(0);