* @license licenses/mind3rd.license
*/
if(!class_exists('Setup'))
require('Setup.php');
/**
* This class is responsable for the setup/installation
* of the system on Unix based OSs
*
* @author felipe
*/
class UnixSetup extends Setup{
public static $header = '#!/usr/bin/env php';
public static $content= '';
/**
* Creates the mind file, at bin directory
*/
public static function createExecFile()
{
/*
$uriToAdd= getcwd()."/";
//echo $uriToAdd."
";
///usr/local/bin:/usr/bin:/bin
//echo shell_exec('echo $PATH');
echo "
";
echo getenv('PATH').PATH_SEPARATOR.$uriToAdd;
echo "
";
echo shell_exec('expert PATH=$PATH'.PATH_SEPARATOR.$uriToAdd);
echo shell_exec('echo $PATH');
echo "
";
*/
self::$content= ' ".
"/bin/mind");
echo " writing the main commands...\n";
echo shell_exec("sudo echo '".self::$content."' >>".
"/bin/mind;");
echo " setting permissions...\n";
echo shell_exec("sudo chmod +x /bin/mind");
return true;
}
/**
* Remove the executable file in Unix Bases OSs.
*
* This method will *NOT* drop database or remove project's files.
* The user must use it with sudo privilegies.
*/
public static function uninstall($rem){
if(self::isInstalled()){
if($ret = shell_exec("sudo rm /bin/mind") == ''){
if(!$rem){
echo "Mind was successfully uninstalled.\n";
echo "Please note that the database of project's folders weren't removed!\nIf you want to remove them, execute\n sudo ./mind remove\n";
}
}else{
echo $ret;
return false;
}
}else{
echo "No previous installed version detected!\n";
}
return true;
}
public static function remove(){
$fp = fopen('php://stdin', 'r');
echo "Are you sure you want to uninstall mind and ALSO REMOVE ITS DATA?\n";
echo " *** By duing so, you will loose all projects, users and history ***\n [yes/no]: ";
$answer = trim(fgets($fp, 1024));
if($answer != 'yes'){
echo "Not removed\n";
return false;
}
if(self::isInstalled()){
if(self::uninstall(true)){
self::removeDataBase();
self::clearProjects();
}else{
echo "Failed trying to uninstall!";;
return false;
}
}else{
echo "No previous installed version detected!\n";
}
return true;
}
/**
* Installs the program to be used in command line
* or http.
* It uses an inherited method, createDatabase
*/
public static function install(){
parent::init();
if(self::createExecFile())
return self::createDatabase();
return false;
}
}