2022-08-16 09:46:38 +03:00
#!/usr/bin/php
< ? php
require_once ( 'vendor/autoload.php' );
2022-08-29 00:26:46 +03:00
require_once ( 'utils.inc.php' );
2022-08-16 09:46:38 +03:00
2022-08-29 00:26:46 +03:00
use DevCoder\DotEnv ;
$climate = new League\CLImate\CLImate ();
2022-08-16 09:46:38 +03:00
$climate -> description ( 'yeswiki-installer, install YesWiki like a professionnal 🌈🦄' );
2022-08-29 00:26:46 +03:00
if ( 0 == posix_getuid ()) {
$absolutePathToEnvFile = __DIR__ . '/.env' ;
if ( file_exists ( $absolutePathToEnvFile )) {
( new DotEnv ( $absolutePathToEnvFile )) -> load ();
} else {
$climate -> error ( 'ERROR : No .env file found.' );
exit ;
}
$climate -> arguments -> add ([
'domain' => [
'prefix' => 'd' ,
'longPrefix' => 'domain' ,
'description' => 'Domain name used for installation' ,
'required' => true ,
'defaultValue' => 'example.com'
],
'type' => [
2022-08-16 09:46:38 +03:00
'prefix' => 't' ,
'longPrefix' => 'type' ,
'description' => 'Type of installation, can be "solo" or "ferme"' ,
'required' => true ,
'defaultValue' => 'solo'
],
2022-08-29 00:26:46 +03:00
'quota' => [
2022-08-16 09:46:38 +03:00
'prefix' => 'q' ,
'longPrefix' => 'quota' ,
'description' => 'User quota for hard drive space, in bytes' ,
'required' => true ,
2022-08-29 00:26:46 +03:00
'defaultValue' => $_SERVER [ 'soloquota' ],
'castTo' => 'int'
],
'herseuser' => [
'prefix' => 'hu' ,
'longPrefix' => 'herseuser' ,
'description' => 'Username for HTTP auth barrier' ,
],
'hersepass' => [
'prefix' => 'hp' ,
'longPrefix' => 'hersepass' ,
'description' => 'Password for HTTP auth barrier' ,
],
'confirm' => [
'prefix' => 'y' ,
'longPrefix' => 'yes' ,
'description' => 'Say yes to every confirmation check (no prompt)' ,
'noValue' => true ,
2022-08-16 09:46:38 +03:00
],
2022-08-29 00:26:46 +03:00
]);
$climate -> arguments -> parse ();
$domain = $climate -> arguments -> get ( 'domain' );
if ( ! empty ( $domain ) && $domain !== 'example.com' ) {
try {
$quota = $climate -> arguments -> get ( 'quota' );
$type = $climate -> arguments -> get ( 'type' );
$confirm = $climate -> arguments -> get ( 'confirm' );
$herseUser = $climate -> arguments -> get ( 'herseuser' );
$hersePass = $climate -> arguments -> get ( 'hersepass' );
checkDNS ( $domain );
checkIfInstalled ( $domain );
$needHerse = checkHerse ( $herseUser , $hersePass );
$user = generateUserFromDomain ( $domain );
$climate -> bold () -> underline () -> out ( 'Installation of YesWiki' );
$climate -> out ( 'This will install a yeswiki on <bold>' . $domain . " </bold> \n " . 'model <bold>' . $type . '</bold>, <bold>' . str_replace ( '000000' , 'Gb' , $quota ) . ' quota</bold>, with the user <bold>' . $user . '</bold>.' . " \n " . ( $needHerse ? 'An herse with user <bold>' . $herseUser . '</bold> and password <bold>' . $hersePass . '</bold> will be set up.' : '' ));
$input = $climate -> confirm ( 'Is it all good ?' );
if ( $confirm || $input -> confirmed ()) {
$unixUser = createUnixUserWithQuota ( $user , $quota );
2022-09-06 13:38:00 +03:00
$dbUser = createSQLUserAndDatabase ( $user , $type );
2023-02-03 22:15:42 +03:00
createNginxConfig ( $domain , $user , $herseUser , $hersePass );
createPhpFpmConfig ( $user );
2023-02-03 22:08:34 +03:00
if ( $needHerse ) {
copyYesWikiFiles ( $domain , $user , $dbUser , $herseUser , $hersePass );
} else {
copyYesWikiFiles ( $domain , $user , $dbUser );
}
2022-08-29 00:26:46 +03:00
$climate -> shout (
2023-02-03 22:20:02 +03:00
'The yeswiki was successfully installed on <bold>https://' . $domain . '</bold>, congrats ! 🎉' . " \n "
2022-08-29 00:26:46 +03:00
. ' Unix user : <bold>' . $unixUser [ 'user' ] . '</bold> with password : <bold>' . $unixUser [ 'password' ] . '</bold> was created.' . " \n "
. 'MySQL user : <bold>' . $dbUser [ 'user' ] . '</bold> with password : <bold>' . $dbUser [ 'password' ] . '</bold> was created for database <bold>' . $dbUser [ 'database' ] . '</bold>.' . " \n "
);
// TODO : send log, send email
} else {
$climate -> info ( 'Ok, let\'s stop here...' );
}
} catch ( Exception $e ) {
$climate -> error ( 'ERROR : ' . $e -> getMessage ());
}
} else {
$climate -> usage ();
}
2022-08-16 09:46:38 +03:00
} else {
2022-08-29 00:26:46 +03:00
$climate -> error ( 'ERROR : this script needs root privilege to run.' );
exit ;
2022-08-16 09:46:38 +03:00
}